Skip to content

Commit d37f40b

Browse files
betegonclaude
andcommitted
test(dsn): add deep nesting and depth-limit regression tests
Add test for deeply nested monorepo files (depth 5 from root, the specific case from the original bug) and a negative test confirming non-monorepo directories still respect the depth limit. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 34b3978 commit d37f40b

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

test/lib/dsn/code-scanner.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,40 @@ describe("Code Scanner", () => {
462462
expect(beResult?.packagePath).toBe("packages/backend");
463463
});
464464

465+
test("finds DSNs deeply nested in monorepo packages", async () => {
466+
// packages/spotlight/src/electron/main/index.ts is depth 5 from root,
467+
// but after monorepo reset at packages/spotlight/, it's depth 3 —
468+
// exactly at MAX_SCAN_DEPTH. This was a specific failing case.
469+
mkdirSync(join(testDir, "packages/spotlight/src/electron/main"), {
470+
recursive: true,
471+
});
472+
writeFileSync(
473+
join(testDir, "packages/spotlight/src/electron/main/index.ts"),
474+
'Sentry.init({ dsn: "https://electron@o123.ingest.sentry.io/333" });'
475+
);
476+
477+
const result = await scanCodeForDsns(testDir);
478+
expect(result.dsns).toHaveLength(1);
479+
expect(result.dsns[0]?.raw).toBe(
480+
"https://electron@o123.ingest.sentry.io/333"
481+
);
482+
expect(result.dsns[0]?.packagePath).toBe("packages/spotlight");
483+
});
484+
485+
test("respects depth limit for non-monorepo directories", async () => {
486+
// src/very/deeply/nested/config.ts is depth 4 — beyond MAX_SCAN_DEPTH (3).
487+
// Should NOT be found. This confirms the depth reset only applies to
488+
// monorepo package directories, not arbitrary subdirectories.
489+
mkdirSync(join(testDir, "src/very/deeply/nested"), { recursive: true });
490+
writeFileSync(
491+
join(testDir, "src/very/deeply/nested/config.ts"),
492+
'const DSN = "https://deep@o123.ingest.sentry.io/999";'
493+
);
494+
495+
const result = await scanCodeForDsns(testDir);
496+
expect(result.dsns).toEqual([]);
497+
});
498+
465499
test("gracefully handles unreadable files", async () => {
466500
const { chmodSync } = require("node:fs") as typeof import("node:fs");
467501
const filePath = join(testDir, "secret.ts");

0 commit comments

Comments
 (0)