Skip to content

Commit 9d95852

Browse files
thymikeeclaude
andcommitted
test(gates): fail R82 on a stale entry and cover every denied module
A renamed `src/daemon.ts` or collector module turned the reach walk into a silent pass. R82 now reports an entry or denied module that is not a tracked source as stale. The tests plant both denied modules over a dynamic chain and a static-only chain. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 3389177 commit 9d95852

3 files changed

Lines changed: 68 additions & 18 deletions

File tree

‎scripts/layering/check.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ export const LAYERING_RULES: Readonly<Record<LayeringRuleId, LayeringRule>> = {
583583
snapshotAssemblyPresentationViolations(context.sources, context.edges),
584584
'daemon-platform-runtime-inventory': (context) =>
585585
checkDaemonPlatformRuntimeInventory(context.edges),
586-
'daemon-process-reach': (context) => checkDaemonProcessReach(context.edges),
586+
'daemon-process-reach': (context) => checkDaemonProcessReach(context.sourceFiles, context.edges),
587587
'daemon-client-entry': (context) => checkDaemonClientEntry(context.edges),
588588
'session-authority-overlay': (context) =>
589589
checkSessionAuthorityOverlay(

‎scripts/layering/daemon-process-reach.test.ts‎

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@ import {
99

1010
const COLLECTOR = 'packages/replay-port/src/source-discovery.ts';
1111

12+
/** Every denied module exists as a stub, so a case fails only on what it plants. */
1213
function reach(sources: Record<string, string>) {
13-
return checkDaemonProcessReach(resolveImportEdges(new Map(Object.entries(sources))));
14+
const tree = new Map<string, string>([
15+
...DAEMON_PROCESS_DENIED_MODULES.map(
16+
(module) => [module, 'export const collect = 1;\n'] as const,
17+
),
18+
...Object.entries(sources),
19+
]);
20+
return checkDaemonProcessReach([...tree.keys()], resolveImportEdges(tree));
1421
}
1522

1623
test('the denied set names replay-port caller-side collector modules', () => {
@@ -21,22 +28,38 @@ test('the denied set names replay-port caller-side collector modules', () => {
2128
]);
2229
});
2330

24-
test('a root platform-runtime module behind a dynamic import cannot reach the collector', () => {
25-
const found = reach({
26-
'src/daemon.ts': "export const load = () => import('./daemon-composition.ts');\n",
27-
'src/daemon-composition.ts': "import './platform-runtime-daemon-services.ts';\n",
28-
'src/platform-runtime-daemon-services.ts':
29-
"import '../packages/replay-port/src/source-discovery.ts';\n",
30-
[COLLECTOR]: 'export const collect = () => [];\n',
31+
for (const denied of DAEMON_PROCESS_DENIED_MODULES) {
32+
test(`a root platform-runtime module behind a dynamic import cannot reach ${denied}`, () => {
33+
const found = reach({
34+
'src/daemon.ts': "export const load = () => import('./daemon-composition.ts');\n",
35+
'src/daemon-composition.ts': "import './platform-runtime-daemon-services.ts';\n",
36+
'src/platform-runtime-daemon-services.ts': `import '../${denied}';\n`,
37+
});
38+
assert.equal(found.length, 1);
39+
assert.equal(found[0]!.rule, DAEMON_PROCESS_REACH_RULE);
40+
assert.equal(found[0]!.file, 'src/platform-runtime-daemon-services.ts');
41+
assert.ok(
42+
found[0]!.message.includes(
43+
`Chain: src/daemon.ts -> src/daemon-composition.ts -> src/platform-runtime-daemon-services.ts -> ${denied}.`,
44+
),
45+
found[0]!.message,
46+
);
3147
});
32-
assert.equal(found.length, 1);
33-
assert.equal(found[0]!.rule, DAEMON_PROCESS_REACH_RULE);
34-
assert.equal(found[0]!.file, 'src/platform-runtime-daemon-services.ts');
35-
assert.match(
36-
found[0]!.message,
37-
/src\/daemon\.ts -> src\/daemon-composition\.ts -> src\/platform-runtime-daemon-services\.ts -> packages\/replay-port\/src\/source-discovery\.ts/,
38-
);
39-
});
48+
49+
test(`a static-only chain from the entry cannot reach ${denied}`, () => {
50+
const found = reach({
51+
'src/daemon.ts': "import './daemon-server.ts';\n",
52+
'src/daemon-server.ts': `import '../${denied}';\n`,
53+
});
54+
assert.equal(found.length, 1);
55+
assert.equal(found[0]!.file, 'src/daemon-server.ts');
56+
assert.equal(found[0]!.line, 1);
57+
assert.ok(
58+
found[0]!.message.includes(`Chain: src/daemon.ts -> src/daemon-server.ts -> ${denied}.`),
59+
found[0]!.message,
60+
);
61+
});
62+
}
4063

4164
test('a type-only edge loads nothing, and the client may import the collector', () => {
4265
assert.deepEqual(
@@ -50,3 +73,16 @@ test('a type-only edge loads nothing, and the client may import the collector',
5073
[],
5174
);
5275
});
76+
77+
test('a renamed entry or denied module fails as stale instead of passing silently', () => {
78+
const found = checkDaemonProcessReach(
79+
['src/daemon.ts', 'packages/replay-port/src/script-source-bundle.ts'],
80+
[],
81+
);
82+
assert.deepEqual(
83+
found.map((violation) => violation.message.split(' is not')[0]),
84+
[`stale module: ${COLLECTOR}`],
85+
);
86+
assert.equal(found[0]!.rule, DAEMON_PROCESS_REACH_RULE);
87+
assert.equal(checkDaemonProcessReach([COLLECTOR], [], 'src/daemon.ts', [COLLECTOR]).length, 1);
88+
});

‎scripts/layering/daemon-process-reach.ts‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,32 @@ export const DAEMON_PROCESS_DENIED_MODULES: readonly string[] = [
1818
* Catches: any module the daemon process can load — over static and dynamic edges, so the
1919
* composition root and every platform-runtime module behind a function-scoped `await import`
2020
* count — reaching a denied module. The violation names the edge that brings the denied module
21-
* in and the shortest chain from the entry to it.
21+
* in and the shortest chain from the entry to it. An entry or denied module that is not a
22+
* tracked source fails as stale, so a rename or move cannot turn the walk into a silent pass.
2223
* Evidence: the client-only placement of replay-port's caller-side collector was a convention
2324
* until #3517; a path-scoped R11 gate covered only files under the daemon root plus two named
2425
* root files, so a root platform-runtime module or a reached package could still import it.
2526
* Cost: one breadth-first walk over the already-resolved edges, inside `pnpm check:layering`.
2627
* Kill criterion: the collector moves into a package the daemon package cannot depend on.
2728
*/
2829
export function checkDaemonProcessReach(
30+
sourceFiles: readonly string[],
2931
edges: readonly ResolvedImportEdge[],
3032
entry: string = DAEMON_PROCESS_ENTRY,
3133
denied: readonly string[] = DAEMON_PROCESS_DENIED_MODULES,
3234
): LayeringViolation[] {
35+
const tracked = new Set(sourceFiles);
36+
const stale = [entry, ...denied].filter((module) => !tracked.has(module));
37+
if (stale.length > 0) {
38+
return stale.map((module) => ({
39+
rule: DAEMON_PROCESS_REACH_RULE,
40+
file: 'scripts/layering/daemon-process-reach.ts',
41+
line: 1,
42+
message:
43+
`stale module: ${module} is not a tracked source. Point DAEMON_PROCESS_ENTRY or ` +
44+
`DAEMON_PROCESS_DENIED_MODULES at its new path so the reach check keeps a real target.`,
45+
}));
46+
}
3347
const outgoing = new Map<string, ResolvedImportEdge[]>();
3448
for (const edge of edges) {
3549
if (edge.typeOnly && !edge.dynamic) continue;

0 commit comments

Comments
 (0)