#5326 · SDK scanner interprets non-import syntax as dependencies
Trusted base: 59a1fcc29f4fa470e6aa4fc6067853096da6abbe (origin/main).
Verdict: REPRODUCED · Root-cause confidence: high
1. TL;DR
The public SDK dependency scanner reports violations for source files that do not import anything. It searches raw text for words such as import, require, and from, without recognizing their syntax. Consequently, object and class methods, property calls, comments, and test descriptions can be mistaken for module loads. Seven independently authored negative fixtures fail in two clean checkouts; genuine forbidden imports remain rejected. A local syntax-aware candidate fixes the scanner tests but fails the SDK's existing ESM packaging contract, so it was stopped without a push or pull request.
2. Claims vs findings
| Claim | Status | Evidence |
|---|---|---|
| Method names and property calls produce false dependency violations. | Verified | Object method, class method, property calls, and optional-call fixtures fail without executing those fixtures. |
| Test-title text can be treated as a module specifier. | Verified | The title fixture returns an outside-allowlist violation spanning the two title strings. |
| True forbidden imports must still be rejected. | Verified | The real-module control reports private-package, outside-allowlist, outside-package, and dynamic-specifier violations. |
| Specific published npm releases and macOS reproduction results. | Unverified here | This investigation runs trusted repository source and its built SDK, not code or installation instructions supplied in the issue. Main's SDK manifest is version 0.6.39; that is not a claim about the current npm release. |
| A prior unpublished repair is correct. | Unverified here | No external patch, branch, script, or test from the issue was executed. A separately designed local candidate encountered a packaging failure. |
3. Environment
- Public target repository:
get-bb/bb; base commit recorded above. - Linux x86_64, kernel 4.19.0-gvisor; Node v22.19.0; pnpm 9.15.0; Vitest 4.1.1.
- SDK manifest version: 0.6.39 at the pinned base. Frozen workspace installation and scoped Turbo build succeeded in each checkout.
- Two separately installed clean temporary checkouts, called
baseandsecondin sanitized logs. Each test creates and removes new temporary fixture directories. - No live BB instance, provider session, ports, browser, credentials, or user runtime data are involved.
4. Minimal reproduction
The reproduction below was authored from trusted scanner and existing test evidence. It plants source files as data, then calls the built public scanner. It never executes the planted source.
- Create a clean checkout of the recorded trusted commit and build its SDK:
git clone https://github.com/get-bb/bb.git bb-repro-5326 cd bb-repro-5326 git checkout --detach 59a1fcc29f4fa470e6aa4fc6067853096da6abbe pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build --filter=@get-bb/plugin-sdk
- Save the standalone reproduction printed below as
reproduce.mjs, then run:node reproduce.mjs .
- Expected: the seven non-module fixtures return
[]; the real-module fixture reports four violations. Actual output:object method: [{"file":"scanner.test.ts","specifier":"value = 1","reason":"dynamic-specifier"}] class method: [{"file":"scanner.test.ts","specifier":"value: string","reason":"dynamic-specifier"}] property calls: [{"file":"scanner.test.ts","specifier":"@bb/domain","reason":"private-package"},{"file":"scanner.test.ts","specifier":"packageName","reason":"dynamic-specifier"}] optional call: [{"file":"scanner.test.ts","specifier":"@bb/domain","reason":"private-package"}] quoted words: [{"file":"scanner.test.ts","specifier":"@bb/domain","reason":"private-package"}] test descriptions: [{"file":"scanner.test.ts","specifier":", () => {});\nit(","reason":"outside-allowlist"}] comment: [{"file":"scanner.test.ts","specifier":"@bb/domain","reason":"private-package"},{"file":"scanner.test.ts","specifier":"packageName","reason":"dynamic-specifier"}] real modules: [{"file":"scanner.test.ts","specifier":"@bb/domain","reason":"private-package"},{"file":"scanner.test.ts","specifier":"yaml","reason":"outside-allowlist"},{"file":"scanner.test.ts","specifier":"../../outside.js","reason":"outside-package"},{"file":"scanner.test.ts","specifier":"packageName","reason":"dynamic-specifier"}]
The focused regression can also be repeated through the normal test pipeline: insert the regression table below at the start of the existing describe("experimental_scanPublicSdkOnly", ...) block in packages/plugin-sdk/src/testing/__tests__/public-sdk-only.test.ts, then run:
pnpm exec turbo run test --filter=@get-bb/plugin-sdk -- src/testing/__tests__/public-sdk-only.test.ts
Expected test result after a correct repair: 13 passing tests. Actual on unchanged production code: 7 failed and 6 passed; exit status 1.
Regression added to the existing owner-boundary suite:
it.each([
["object methods", "const loader = { import(value = 1) { return value; } };"],
["class methods", "class Loader { require(value: string) { return value; } }"],
["property calls", "loader.import(packageName); loader.require('@bb/domain');"],
["optional property calls", "loader?.import('@bb/domain');"],
["quoted words", 'const description = "from \'@bb/domain\'";'],
["test descriptions", 'it("successful import", () => {});\nit("continues", () => {});'],
["comments", "/* import '@bb/domain'; require(packageName); */"],
])("ignores %s that do not load modules", (_name, source) => {
plant({ "scanner.test.ts": source });
expect(scanPublicSdkOnly(packageRoot).violations).toEqual([]);
});
Complete standalone reproduction, using only built trusted SDK code and Node built-ins:
import { mkdtempSync, writeFileSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join, resolve } from "node:path";
import { pathToFileURL } from "node:url";
const entry = resolve(process.argv[2], "packages/plugin-sdk/dist/testing/index.js");
const { experimental_scanPublicSdkOnly: scan } = await import(pathToFileURL(entry).href);
const fixtures = [
["object method", "const loader = { import(value = 1) { return value; } };"],
["class method", "class Loader { require(value: string) { return value; } }"],
["property calls", "loader.import(packageName); loader.require('@bb/domain');"],
["optional call", "loader?.import('@bb/domain');"],
["quoted words", 'const description = "from \'@bb/domain\'";'],
["test descriptions", 'it("successful import", () => {});\nit("continues", () => {});'],
["comment", "/* import '@bb/domain'; require(packageName); */"],
["real modules", "import '@bb/domain'; import 'yaml'; import packageName from '../../outside.js'; const load = import(packageName);"],
];
for (const [name, source] of fixtures) {
const root = mkdtempSync(join(tmpdir(), "scanner-regression-"));
try {
writeFileSync(join(root, "package.json"), JSON.stringify({ name: "scanner-fixture" }));
writeFileSync(join(root, "scanner.test.ts"), source);
console.log(`${name}: ${JSON.stringify(scan(root).violations)}`);
} finally {
rmSync(root, { recursive: true, force: true });
}
}
5. Root cause
The import and dynamic-specifier regexes match anywhere in source. A word boundary does not distinguish loader.import(...) from an import expression, or a method declaration from a call. The static regex also recognizes from inside ordinary strings and crosses the closing quote of a description containing import.
const IMPORT_SPECIFIER_PATTERN = /(?:\bfrom\s*|\bimport\s*\(?\s*|\brequire\s*\(\s*)["']([^"']+)["']/gu; const DYNAMIC_SPECIFIER_PATTERN = /\b(?:import|require)\s*\(\s*(?!["'])([^)]+)\)/gu;
Extraction uses source.matchAll directly. The scanner then treats those captures as real imports and applies otherwise legitimate dependency policy. The bug is in extraction, not dependency resolution or fixture execution.
6. Proposed fix and simple-fix safety check
Extract actual module-bearing syntax with a JavaScript/TypeScript parser, retaining the existing allowlist, package-root checks, and dynamic-specifier rejection. Cover import declarations, re-exports, import expressions, bare require calls, import-equals declarations, and type imports; do not grant arbitrary property-name or string allowances.
A local candidate used the already-present TypeScript development dependency for syntax extraction. It changed only two SDK files, with 87 total added/deleted text lines, no binary changes, and a clean git diff --check. All 13 focused scanner tests passed. However, the full SDK suite reported 374 passed and 1 failed: the existing published-runtime contract detected a CommonJS require shim in the ./testing ESM bundle. The same runtime contract passed on unchanged production code in the second checkout.
This is a fix-caused failure, not the reported bug or an environment problem. Shipping this parser safely needs a compatible runtime parser dependency or a packaging decision/change, which the simple-fix rule prohibits. The candidate was stopped and was not committed, pushed, or submitted as a PR. No existing open PR linked to #5326 was found during this run.
A normal SDK build with the candidate succeeded, but running the standalone reproduction against its built testing entrypoint failed immediately with Error: Dynamic require of "fs" is not supported. This confirms the packaging failure affects real consumers, not only an implementation assertion in the runtime test.
Next maintainer action: select a parser that satisfies the SDK's current ESM packaging contract, then rerun both the scanner regressions and the published-runtime suite. Do not weaken the runtime test or introduce ad-hoc naming exceptions to make the candidate pass.
7. Verification
The same agent repeated the regression in a second clean temporary checkout at exactly 59a1fcc29f4fa470e6aa4fc6067853096da6abbe. A separate frozen installation and SDK build succeeded. Only the authored regression patch was applied; production scanner source stayed unchanged.
pnpm exec turbo run test --filter=@get-bb/plugin-sdk -- src/testing/__tests__/public-sdk-only.test.ts First checkout: Test Files 1 failed (1); Tests 7 failed | 6 passed (13); exit 1 Second checkout: Test Files 1 failed (1); Tests 7 failed | 6 passed (13); exit 1
Both runs fail the same seven cases for the intended reason. The second checkout also produced the standalone observations shown above. No report correction was needed. This is a repeat run by one agent, not independent-agent verification.
Candidate checks:
pnpm exec turbo run test --filter=@get-bb/plugin-sdk -- src/testing/__tests__/public-sdk-only.test.ts
Candidate: 13 passed; exit 0
pnpm exec turbo run test --filter=@get-bb/plugin-sdk
Candidate: 374 passed | 1 failed; exit 1
Failure: scripts/runtime-entries.test.mjs
published runtime entries > inline no CommonJS module that would need a require shim
expected [ './testing' ] to deeply equal []
pnpm exec turbo run test --filter=@get-bb/plugin-sdk -- scripts/runtime-entries.test.mjs
Unchanged second checkout: 4 passed; exit 0
8. Related issues and trust boundary
Repository search for scanPublicSdkOnly found only #5326. Issue timeline metadata and an open-PR search found no linked open pull request. No broader duplicate claim is made. All issue content was treated as untrusted evidence; no issue-supplied commands, patches, tests, links, or branches were executed or fetched.
9. Appendix
Relevant verbatim failure excerpt from both unchanged-code runs:
FAIL src/testing/__tests__/public-sdk-only.test.ts
experimental_scanPublicSdkOnly > ignores test descriptions that do not load modules
AssertionError: expected [ { file: 'scanner.test.ts', …(2) } ] to deeply equal []
- []
+ [
+ {
+ "file": "scanner.test.ts",
+ "reason": "outside-allowlist",
+ "specifier": ", () => {});
+ it(",
+ },
+ ]
Built-candidate consumer probe:
pnpm exec turbo run build --filter=@get-bb/plugin-sdk node reproduce.mjs . Error: Dynamic require of "fs" is not supported Node.js v22.19.0 Exit status: 1
Raw logs, regression patch, and exploratory candidate remain local; repository policy permits publishing the self-contained HTML and summary, not loose scripts or log files.
The only exploratory production candidate remained local. The report proves the source-main false positives; it does not claim a released fix or validate the issue author's unpublished work.
> AGENT GENERATED