Skip to content

Commit 352428d

Browse files
thymikeeclaude
andauthored
test: characterize replay-test reporter contract and extend R10 (#1505)
* test: characterize replay-test reporter contract and extend R10 P3 of #1478 moves the replay-test scheduler into `packages/replay-test` and makes attempt identity scheduler-owned. Before production code moves, pin what a shipped custom reporter actually observes today, and close the import boundary the extraction has to end up satisfying. Reporter values (all pinned as shipped, none proposed): - the `RequestProgressEvent` -> reporter-value projection field by field, including key presence for absent optionals and the dropped `command` events; - `session` provenance across the seam: the start value is always `attempt-1` (it is built before any attempt runs), step values track the running attempt through the per-attempt AsyncLocalStorage context, and result values carry the attempt that produced them, so a retried case reports three different sessions to one reporter; - the shard-scoped session prefix and device identity a sharded run reports; - module export spelling precedence, the six optional hook names, the live-hook vs final-hook error asymmetry, and exit-code recommendation semantics. Late-timeout finalization/cleanup: - finalization always runs before cleanup, and the timing trace records that order (`finalize_start/stop` then `cleanup_start/stop`); - a replay settling inside the 2s grace window cleans up once and is not marked `timeout_cleanup_pending`, and the raced TIMEOUT response still wins; - a replay that misses the window defers its second cleanup until the abandoned replay settles, and that late cleanup's failure is swallowed. R10 now rejects replay-test imports from `src/request/**` and engine internals (`src/replay/`, `src/compat/`, `src/maestro/`, `src/ad-replay/`), with the four imports that exist today recorded as shrink-only migration entries so the rule enforces immediately and the extraction must delete them. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01RXQLYV7etZx3gcXsUsrQJ8 * test(daemon): assert reporter hint on the real onTestResult value The failing-suite characterization supplied `hint` as input but never asserted it on the hook value, so dropping `hint: error.hint` from the scheduler path left all reporter tests green. Assert it on the real reporter value so the ratchet catches a shipped field going missing. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01RXQLYV7etZx3gcXsUsrQJ8 --------- Co-authored-by: Claude <[email protected]>
1 parent 9b5035f commit 352428d

7 files changed

Lines changed: 980 additions & 12 deletions

File tree

‎scripts/layering/daemon-modularity.test.ts‎

Lines changed: 79 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { test } from 'node:test';
33
import {
44
checkDaemonModularityRatchets,
55
DAEMON_MODULARITY_BASELINE,
6+
LOGICAL_MODULE_POLICIES,
67
TYPE_CYCLE_BASELINE,
78
} from './daemon-modularity.ts';
89
import { SESSION_STATE_FIELD_OWNERS } from './session-state.ts';
@@ -27,6 +28,20 @@ function baselineDaemonTypesEdges(): ResolvedImportEdge[] {
2728
);
2829
}
2930

31+
function recordedMigrationEdges(): ResolvedImportEdge[] {
32+
return LOGICAL_MODULE_POLICIES.flatMap((module) =>
33+
(module.recordedMigrationImports ?? []).map((recorded) => {
34+
const [file, target] = recorded.split(' -> ');
35+
return importEdge(file!, target!);
36+
}),
37+
);
38+
}
39+
40+
/** Every recorded import present and nothing else forbidden: the quiet state of the ratchets. */
41+
function baselineEdges(): ResolvedImportEdge[] {
42+
return [...baselineDaemonTypesEdges(), ...recordedMigrationEdges()];
43+
}
44+
3045
test('daemon modularity baseline records the measured R7 ownership pressure', () => {
3146
assert.equal(
3247
Object.keys(SESSION_STATE_FIELD_OWNERS).length,
@@ -49,11 +64,14 @@ test('external daemon/types.ts importer membership changes require the baseline
4964
]),
5065
);
5166

52-
const violations = checkDaemonModularityRatchets([...baselineDaemonTypesEdges(), ...edges], []);
67+
const violations = checkDaemonModularityRatchets([...baselineEdges(), ...edges], []);
5368
assert.equal(violations.length, 1);
5469
assert.match(violations[0]!.message, /may only shrink from the recorded 4/);
5570

56-
const removed = checkDaemonModularityRatchets(baselineDaemonTypesEdges().slice(1), []);
71+
const removed = checkDaemonModularityRatchets(
72+
[...baselineDaemonTypesEdges().slice(1), ...recordedMigrationEdges()],
73+
[],
74+
);
5775
assert.equal(removed.length, 1);
5876
assert.match(removed[0]!.message, /delete it from externalDaemonTypesImporters/);
5977
});
@@ -66,11 +84,67 @@ test('planned logical modules start with zero forbidden imports', () => {
6684
]),
6785
);
6886

69-
const violations = checkDaemonModularityRatchets([...baselineDaemonTypesEdges(), ...edges], []);
87+
const violations = checkDaemonModularityRatchets([...baselineEdges(), ...edges], []);
7088
assert.equal(violations.length, 1);
7189
assert.match(violations[0]!.message, /replay-test must not import/);
7290
});
7391

92+
test('replay-test rejects request-global and engine-internal imports', () => {
93+
const edges = resolveImportEdges(
94+
new Map([
95+
[
96+
'src/replay/test/scheduler.ts',
97+
[
98+
"import { emitRequestProgress } from '../../request/progress.ts';",
99+
"import { readReplayScriptMetadata } from '../script.ts';",
100+
"import { parseMaestroProgram } from '../../compat/maestro/program-ir-parser.ts';",
101+
].join('\n'),
102+
],
103+
['src/request/progress.ts', 'export function emitRequestProgress() {}'],
104+
['src/replay/script.ts', 'export function readReplayScriptMetadata() {}'],
105+
['src/compat/maestro/program-ir-parser.ts', 'export function parseMaestroProgram() {}'],
106+
]),
107+
);
108+
109+
const violations = checkDaemonModularityRatchets([...baselineEdges(), ...edges], []);
110+
assert.deepEqual(
111+
violations.map(({ message }) => message.replace(/;.*/, '')),
112+
[
113+
'replay-test must not import src/request/progress.ts',
114+
'replay-test must not import src/replay/script.ts',
115+
'replay-test must not import src/compat/maestro/program-ir-parser.ts',
116+
],
117+
);
118+
});
119+
120+
test('replay-test may still import its own files inside the wider replay engine root', () => {
121+
const edges = resolveImportEdges(
122+
new Map([
123+
['src/replay/test/reporting.ts', "import { spec } from './reporters/spec.ts';"],
124+
['src/replay/test/reporters/spec.ts', 'export const spec = 1;'],
125+
]),
126+
);
127+
128+
assert.deepEqual(checkDaemonModularityRatchets([...baselineEdges(), ...edges], []), []);
129+
});
130+
131+
test('recorded replay-test migration imports are exempt until the import is deleted', () => {
132+
const recorded = LOGICAL_MODULE_POLICIES.find(
133+
({ name }) => name === 'replay-test',
134+
)?.recordedMigrationImports;
135+
assert.deepEqual(recorded, [
136+
'src/replay/test/reporters/default.ts -> src/replay/divergence.ts',
137+
'src/replay/test/reporters/progress.ts -> src/request/progress.ts',
138+
'src/replay/test/reporters/registry.ts -> src/request/progress.ts',
139+
'src/replay/test/reporting.ts -> src/request/progress.ts',
140+
]);
141+
assert.deepEqual(checkDaemonModularityRatchets(baselineEdges(), []), []);
142+
143+
const withoutOne = checkDaemonModularityRatchets(baselineEdges().slice(0, -1), []);
144+
assert.equal(withoutOne.length, 1);
145+
assert.match(withoutOne[0]!.message, /delete it from replay-test's recordedMigrationImports/);
146+
});
147+
74148
test('internal trees reject deep imports globally, including from daemon', () => {
75149
const edges = resolveImportEdges(
76150
new Map([
@@ -79,7 +153,7 @@ test('internal trees reject deep imports globally, including from daemon', () =>
79153
]),
80154
);
81155

82-
const violations = checkDaemonModularityRatchets([...baselineDaemonTypesEdges(), ...edges], []);
156+
const violations = checkDaemonModularityRatchets([...baselineEdges(), ...edges], []);
83157
assert.equal(violations.length, 1);
84158
assert.match(violations[0]!.message, /must not import maestro's internal tree/);
85159
});
@@ -89,7 +163,7 @@ test('R9 records zone ceilings and keeps engine files outside the largest compon
89163
{ length: DAEMON_MODULARITY_BASELINE.largestTypeCycle.zoneMembers.commands + 1 },
90164
(_, index) => `src/commands/probe-${index}.ts`,
91165
);
92-
const violations = checkDaemonModularityRatchets(baselineDaemonTypesEdges(), [
166+
const violations = checkDaemonModularityRatchets(baselineEdges(), [
93167
...commandMembers,
94168
'src/ad-replay/internal/engine.ts',
95169
]);

‎scripts/layering/daemon-modularity.ts‎

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ type LogicalModulePolicy = {
3636
name: string;
3737
roots: readonly string[];
3838
forbiddenTargetRoots: readonly string[];
39+
/**
40+
* Imports that already violate `forbiddenTargetRoots` on the day the rule was written, recorded
41+
* as `source -> target`. The rule enforces immediately for everything else, so a new violation
42+
* cannot be added while the module waits for its extraction PR; each recorded edge must be
43+
* deleted from this list by the change that removes the import, and re-adding one is a diff a
44+
* reviewer sees.
45+
*/
46+
recordedMigrationImports?: readonly string[];
3947
};
4048

4149
/**
@@ -61,9 +69,28 @@ export const LOGICAL_MODULE_POLICIES: readonly LogicalModulePolicy[] = [
6169
forbiddenTargetRoots: ['src/daemon/', 'src/platforms/', 'src/providers/', 'src/ad-replay/'],
6270
},
6371
{
72+
// Replay-test schedules and reports; it must stay format-neutral. `src/request/` is
73+
// request-global daemon plumbing (progress sinks, cancellation, AsyncLocalStorage), and the
74+
// remaining roots are engine internals — reaching into either is how a scheduler quietly
75+
// acquires daemon authority or an engine-specific value shape.
6476
name: 'replay-test',
6577
roots: ['src/replay/test/'],
66-
forbiddenTargetRoots: ['src/daemon/', 'src/platforms/', 'src/providers/'],
78+
forbiddenTargetRoots: [
79+
'src/daemon/',
80+
'src/platforms/',
81+
'src/providers/',
82+
'src/request/',
83+
'src/replay/',
84+
'src/compat/',
85+
'src/maestro/',
86+
'src/ad-replay/',
87+
],
88+
recordedMigrationImports: [
89+
'src/replay/test/reporters/default.ts -> src/replay/divergence.ts',
90+
'src/replay/test/reporters/progress.ts -> src/request/progress.ts',
91+
'src/replay/test/reporters/registry.ts -> src/request/progress.ts',
92+
'src/replay/test/reporting.ts -> src/request/progress.ts',
93+
],
6794
},
6895
];
6996

@@ -185,6 +212,7 @@ function checkDaemonTypesImporters(edges: readonly ResolvedImportEdge[]): Layeri
185212

186213
function checkLogicalModuleImports(edges: readonly ResolvedImportEdge[]): LayeringViolation[] {
187214
const violations: LayeringViolation[] = [];
215+
const observedMigrationImports = new Set<string>();
188216
for (const edge of edges) {
189217
const sourceModule = moduleForFile(edge.file);
190218
const targetModule = moduleForFile(edge.target);
@@ -203,14 +231,36 @@ function checkLogicalModuleImports(edges: readonly ResolvedImportEdge[]): Layeri
203231
}
204232

205233
if (!sourceModule) continue;
206-
if (sourceModule.forbiddenTargetRoots.some((root) => edge.target.startsWith(root))) {
234+
// A module's own files are never a forbidden target: `replay-test` sits inside the wider
235+
// `src/replay/` engine root it may not import from.
236+
if (sourceModule.roots.some((root) => edge.target.startsWith(root))) continue;
237+
if (!sourceModule.forbiddenTargetRoots.some((root) => edge.target.startsWith(root))) continue;
238+
const migrationImport = `${edge.file} -> ${edge.target}`;
239+
if (sourceModule.recordedMigrationImports?.includes(migrationImport)) {
240+
observedMigrationImports.add(migrationImport);
241+
continue;
242+
}
243+
violations.push({
244+
rule: 'R10 daemon-modularity',
245+
file: edge.file,
246+
line: edge.line,
247+
message: `${sourceModule.name} must not import ${edge.target}; communicate through its façade and a narrow port with two real adapters.`,
248+
});
249+
}
250+
return [...violations, ...checkRecordedMigrationImports(observedMigrationImports)];
251+
}
252+
253+
function checkRecordedMigrationImports(observed: ReadonlySet<string>): LayeringViolation[] {
254+
const violations: LayeringViolation[] = [];
255+
for (const module of LOGICAL_MODULE_POLICIES) {
256+
for (const migrationImport of module.recordedMigrationImports ?? []) {
257+
if (observed.has(migrationImport)) continue;
207258
violations.push({
208259
rule: 'R10 daemon-modularity',
209-
file: edge.file,
210-
line: edge.line,
211-
message: `${sourceModule.name} must not import ${edge.target}; communicate through its façade and a narrow port with two real adapters.`,
260+
file: 'scripts/layering/daemon-modularity.ts',
261+
line: 1,
262+
message: `${migrationImport} no longer exists — delete it from ${module.name}'s recordedMigrationImports in the same change so the import cannot return.`,
212263
});
213-
continue;
214264
}
215265
}
216266
return violations;
@@ -237,10 +287,14 @@ function countBy(values: readonly string[], keyOf: (value: string) => string): M
237287

238288
export function daemonModularitySummary(): string {
239289
const session = DAEMON_MODULARITY_BASELINE.sessionState;
290+
const recordedMigrationImports = LOGICAL_MODULE_POLICIES.reduce(
291+
(sum, module) => sum + (module.recordedMigrationImports?.length ?? 0),
292+
0,
293+
);
240294
return (
241295
`R10 pins R7 at ${session.writerOwnedFields} writer-owned fields / ` +
242296
`${session.ownerFileClaims} owner claims, R9 at ${TYPE_CYCLE_BASELINE} files with zone ceilings, ` +
243297
`${DAEMON_MODULARITY_BASELINE.externalDaemonTypesImporters.length} external daemon/types.ts importers, ` +
244-
'and zero forbidden logical-module imports'
298+
`and zero forbidden logical-module imports beyond ${recordedMigrationImports} recorded migration import(s)`
245299
);
246300
}

0 commit comments

Comments
 (0)