Skip to content

Commit 648a2ed

Browse files
test(dead-exports): shrink end-to-end probe to a narrow tsconfig
1 parent 742e043 commit 648a2ed

3 files changed

Lines changed: 44 additions & 1 deletion

File tree

‎scripts/check-dead-exports.test.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,12 +362,34 @@ describe("scan coverage floor", () => {
362362
// scripts/ tree, the real guard runs as a subprocess, and the run must exit
363363
// nonzero naming the probe. The probe lives only for the test (never
364364
// committed) so the keep-alive check cannot itself become a dead export.
365+
//
366+
// The guard normally scans the full project via ts-prune (~5s); the probe's
367+
// temp tsconfig includes only the probe file, so this run pays only ts-prune
368+
// startup while still exercising the same wired-up gate (config load,
369+
// allowlist validation, node-spawned ts-prune, output parsing, coverage
370+
// floor, exit code).
365371
describe("violation end to end", () => {
366372
test("a temp dead export fails the guard, which names it", () => {
367373
const probeFile = `dead-export-guard-probe-${process.pid}.ts`;
368374
const probeName = `deadExportGuardProbe${process.pid}`;
369375
const probePath = join(repoRoot, "scripts", probeFile);
376+
const narrowTsconfigFile = `dead-export-guard-tsconfig-${process.pid}.json`;
377+
const narrowTsconfigPath = join(repoRoot, "scripts", narrowTsconfigFile);
370378
writeFileSync(probePath, `export const ${probeName} = 1;\n`);
379+
writeFileSync(
380+
narrowTsconfigPath,
381+
JSON.stringify({
382+
compilerOptions: {
383+
noEmit: true,
384+
target: "ESNext",
385+
module: "ESNext",
386+
moduleResolution: "bundler",
387+
skipLibCheck: true,
388+
},
389+
// Relative to the narrow tsconfig's own directory (scripts/).
390+
files: [probeFile],
391+
}),
392+
);
371393
try {
372394
const ran = spawnSync(
373395
process.execPath,
@@ -381,6 +403,7 @@ describe("violation end to end", () => {
381403
env: {
382404
...process.env,
383405
DEAD_EXPORT_GUARD_SCANNED_FILES: String(liveScannedFileCount()),
406+
DEAD_EXPORT_GUARD_TSCONFIG: `scripts/${narrowTsconfigFile}`,
384407
},
385408
},
386409
);
@@ -390,6 +413,7 @@ describe("violation end to end", () => {
390413
);
391414
} finally {
392415
rmSync(probePath, { force: true });
416+
rmSync(narrowTsconfigPath, { force: true });
393417
}
394418
}, 120_000);
395419
});

‎scripts/check-dead-exports.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ import { fileURLToPath } from "node:url";
2525
// sets it, so the gate always computes the count in normal runs.
2626
const scannedFilesEnv = "DEAD_EXPORT_GUARD_SCANNED_FILES";
2727

28+
// Test injection (same pattern as scannedFilesEnv): a subprocess test that
29+
// needs the wired-up gate without paying for the ~5s full-project ts-prune
30+
// run can point the pinned scan at a smaller tsconfig. Production never sets
31+
// it, so the gate always scans the pinned tsconfig in normal runs.
32+
const tsconfigEnv = "DEAD_EXPORT_GUARD_TSCONFIG";
33+
2834
const here = dirname(fileURLToPath(import.meta.url));
2935
const repoRoot = dirname(here);
3036
const allowlistPath = join(here, "dead-export-allowlist.txt");
@@ -351,6 +357,19 @@ function main(): void {
351357
} catch (err) {
352358
fail(`dead-export guard: invalid guard config: ${(err as Error).message}`);
353359
}
360+
const overrideTsconfig = process.env[tsconfigEnv];
361+
if (overrideTsconfig !== undefined) {
362+
if (!existsSync(join(repoRoot, overrideTsconfig))) {
363+
fail(
364+
`dead-export guard: tsconfig override not found: ${overrideTsconfig}`,
365+
);
366+
}
367+
config = {
368+
...config,
369+
tsconfig: overrideTsconfig,
370+
tsPruneArgs: ["-p", overrideTsconfig],
371+
};
372+
}
354373
const allowlistText = readFileSync(allowlistPath, "utf8");
355374
const allowlistProblems = [
356375
...validateAllowlistText(allowlistText),

‎scripts/ci-timings.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"version": 1,
33
"files": {
4-
"scripts/check-dead-exports.test.ts": 6178,
4+
"scripts/check-dead-exports.test.ts": 1769,
55
"scripts/test-parallel.test.ts": 2496,
66
"src/plugins/shell-guard-plugin.test.ts": 1883,
77
"src/tui/tool-execution-watchdog.test.ts": 1853,

0 commit comments

Comments
 (0)