Skip to content

Commit cbb6bdf

Browse files
committed
refactor(gates): hold R75 and its fixtures to the live layer roots
The first pass dropped the dead spellings but still hardcoded the two handler roots as literals and left the rest of scripts/layering planting synthetic daemon fixtures under the pre-fold handlers/ root. R75 now derives both roots and the SessionStore target from DAEMON_SOURCE_ROOT, gains an end-to-end classification case for each live handler folder (the pre-fold spelling stays measurable but out of the ratcheted subset, and each root is bite-proofed against a rename), and gains a case that measures the real merge-base through mergeBaseRatchets and asserts its handler-owned set arrives in head coordinates and the base really held src/daemon/handlers/. Nine synthetic fixtures moved onto sessions/handlers/. The R10 retired-handler path lists keep their historical spelling on purpose: they name deleted files, and retargeting them would reject legitimate new files in the live folders.
1 parent 6b9a1d0 commit cbb6bdf

9 files changed

Lines changed: 86 additions & 24 deletions

‎scripts/layering/daemon-platform-boundary.test.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,12 @@ test('R65 rejects static, type-only, dynamic, type, and re-export dependencies w
8787

8888
test('R65 recognizes side-effect and aliased imports, including nested daemon paths', () => {
8989
const source = [
90-
"import '../../../../src/platforms/web/runtime.ts';",
90+
"import '../../../../../src/platforms/web/runtime.ts';",
9191
"import { runtime as platformRuntime } from '@agent-device/platform-web/runtime';",
9292
].join('\n');
9393

9494
assert.deepEqual(
95-
dependencies(source, 'packages/daemon/src/handlers/terminal-boundary-fixture.ts').map(
95+
dependencies(source, 'packages/daemon/src/sessions/handlers/terminal-boundary-fixture.ts').map(
9696
(found) => ({
9797
kind: found.kind,
9898
line: found.line,
@@ -104,7 +104,7 @@ test('R65 recognizes side-effect and aliased imports, including nested daemon pa
104104
{
105105
kind: 'static import',
106106
line: 1,
107-
spec: '../../../../src/platforms/web/runtime.ts',
107+
spec: '../../../../../src/platforms/web/runtime.ts',
108108
target: 'src/platforms/web/runtime.ts',
109109
},
110110
{

‎scripts/layering/model.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ test('session-state writes are found by field, and non-daemon or undeclared name
591591
"if (session.refFrame === 'active') return;",
592592
],
593593
// a write into a sub-object is not a write to the field itself
594-
['packages/daemon/src/handlers/session-probe.ts', 'session.refFrame.inner = 1;'],
594+
['packages/daemon/src/sessions/handlers/session-probe.ts', 'session.refFrame.inner = 1;'],
595595
// a different binding that happens to have a matching property
596596
[
597597
'packages/daemon/src/sessions/session-lifecycle/internal/session-close.ts',

‎scripts/layering/package-boundaries-facade.test.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ test('the ./testing/* refusal bites inside packages and through the vi.mock scan
6363
assert.deepEqual(
6464
checkPackageInternalSites(
6565
daemon,
66-
sites('packages/daemon/src/handlers/production.ts', '@agent-device/daemon/testing/x'),
66+
sites(
67+
'packages/daemon/src/sessions/handlers/production.ts',
68+
'@agent-device/daemon/testing/x',
69+
),
6770
[daemon],
6871
true,
6972
).length,

‎scripts/layering/ratchet-reference.test.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,16 @@ test('measureRatchets reports all ratchets from one tree', () => {
6161
sessionAuthority: { shapeFiles: [], authorityFiles: [] },
6262
});
6363
const withAuthority = tree({
64-
'packages/daemon/src/handlers/fixture.ts':
65-
"import type { SessionState } from '../core/session-state.ts';\n" +
66-
"import { SessionStore } from '../core/session-store.ts';",
64+
'packages/daemon/src/sessions/handlers/fixture.ts':
65+
"import type { SessionState } from '../../core/session-state.ts';\n" +
66+
"import { SessionStore } from '../../core/session-store.ts';",
6767
'packages/daemon/src/core/session-store.ts': 'export class SessionStore {}',
6868
});
6969
assert.deepEqual(
7070
measureRatchets(withAuthority, resolveImportEdges(withAuthority)).sessionAuthority,
7171
{
72-
shapeFiles: ['packages/daemon/src/handlers/fixture.ts'],
73-
authorityFiles: ['packages/daemon/src/handlers/fixture.ts'],
72+
shapeFiles: ['packages/daemon/src/sessions/handlers/fixture.ts'],
73+
authorityFiles: ['packages/daemon/src/sessions/handlers/fixture.ts'],
7474
},
7575
);
7676
});

‎scripts/layering/selector-pipeline-ownership.test.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ import {
1313
* `parseImports` the gate uses. That is the point of the shape: a bypass is
1414
* only refused in every import FORM if the check never looks at symbol names.
1515
*/
16-
function violations(source: string, file = 'packages/daemon/src/handlers/planted.ts'): string[] {
16+
function violations(
17+
source: string,
18+
file = 'packages/daemon/src/sessions/handlers/planted.ts',
19+
): string[] {
1720
const edges: ResolvedImportEdge[] = parseImports(source).map((edge) => ({
1821
...edge,
1922
file,

‎scripts/layering/session-authority-overlay.test.ts‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import assert from 'node:assert/strict';
2+
import { execFileSync } from 'node:child_process';
23
import { test } from 'node:test';
34
import { resolveImportEdges } from './model.ts';
5+
import { mergeBaseRatchets } from './ratchet-reference.ts';
6+
import { readCommittedSources } from '../__tests__/committed-source-tree.ts';
47
import {
58
checkSessionAuthorityOverlay,
69
handlerOwnedOverlay,
@@ -165,6 +168,56 @@ test('the end-to-end measurement feeds the ratchet: a new handler importer is re
165168
assert.equal(violations[0]!.file, 'packages/daemon/src/sessions/handlers/new.ts');
166169
});
167170

171+
test('the overlay classifies handler writes in both live handler roots, measured end to end', () => {
172+
// A write planted in each live layer folder must land in the ratcheted subset; the pre-fold
173+
// flat handlers/ spelling is dead in both trees (R10's retired-path guards own re-creation
174+
// there), so a write there stays out of scope even though the raw measurement sees it.
175+
const sources = {
176+
'packages/daemon/src/core/session-state.ts': STATE_STUB,
177+
'packages/daemon/src/core/session-store.ts': STORE_STUB,
178+
'packages/daemon/src/sessions/handlers/session-runtime.ts':
179+
"import { SessionStore } from '../../core/session-store.ts';\n",
180+
'packages/daemon/src/execution/handlers/snapshot-route.ts':
181+
"import type { SessionState } from '../../core/session-state.ts';\n",
182+
'packages/daemon/src/handlers/legacy.ts':
183+
"import type { SessionState } from '../core/session-state.ts';\n",
184+
};
185+
const measured = handlerOwnedOverlay(overlayOf(sources));
186+
assert.deepEqual(measured, {
187+
shapeFiles: ['packages/daemon/src/execution/handlers/snapshot-route.ts'],
188+
authorityFiles: ['packages/daemon/src/sessions/handlers/session-runtime.ts'],
189+
});
190+
// The raw overlay sees the stale spelling, so the exclusion above is the root filter's doing.
191+
assert.ok(overlayOf(sources).shapeFiles.includes('packages/daemon/src/handlers/legacy.ts'));
192+
});
193+
194+
test('the merge-base overlay arrives in head coordinates through the rename mapping', () => {
195+
// The merge-base tree declares SessionState under src/daemon/... and holds no layer folders.
196+
// mergeBaseRatchets canonicalizes every base path through renamedSince (the base's
197+
// src/daemon/handlers/*.ts pair with the head's layer-folder handlers/*.ts, and
198+
// session-store.ts pairs under core/), so the reference handler-owned set must already name
199+
// the live roots. This is what lets checkSessionAuthorityOverlay compare paths directly and
200+
// what makes the old flat handlers/ spellings in this rule dead weight.
201+
const repoRoot = execFileSync('git', ['rev-parse', '--show-toplevel'], {
202+
encoding: 'utf8',
203+
}).trim();
204+
const reference = mergeBaseRatchets(repoRoot);
205+
const scoped = handlerOwnedOverlay(reference.sessionAuthority);
206+
assert.ok(scoped.shapeFiles.length > 0 && scoped.authorityFiles.length > 0);
207+
for (const file of [...scoped.shapeFiles, ...scoped.authorityFiles]) {
208+
assert.match(
209+
file,
210+
/^packages\/daemon\/src\/(?:sessions|execution)\/handlers\//,
211+
`merge-base handler member left the live roots: ${file}`,
212+
);
213+
}
214+
const baseSources = readCommittedSources(repoRoot, reference.ref).sources;
215+
assert.ok(
216+
[...baseSources.keys()].some((file) => file.startsWith('src/daemon/handlers/')),
217+
'the merge-base tree is expected to hold the pre-layer-folder src/daemon/handlers/ root',
218+
);
219+
});
220+
168221
test('R75 catches a new handler shape edge expressed as an import type', () => {
169222
const base = {
170223
'packages/daemon/src/core/session-state.ts': STATE_STUB,

‎scripts/layering/session-authority-overlay.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isProductionSourceFile } from './tracked-sources.ts';
1+
import { DAEMON_SOURCE_ROOT, isProductionSourceFile } from './tracked-sources.ts';
22
import type { LayeringViolation, ResolvedImportEdge } from './model.ts';
33
import { sessionStateDeclarationFile } from './session-state.ts';
44

@@ -20,12 +20,12 @@ export const SESSION_AUTHORITY_OVERLAY_RULE = 'R75 session-authority-overlay';
2020

2121
/** The handler folders: the layer folders the pre-fold handlers/ tree split into. */
2222
const HANDLER_ROOTS = [
23-
'packages/daemon/src/sessions/handlers/',
24-
'packages/daemon/src/execution/handlers/',
23+
`${DAEMON_SOURCE_ROOT}sessions/handlers/`,
24+
`${DAEMON_SOURCE_ROOT}execution/handlers/`,
2525
];
2626

2727
/** The SessionStore authority module; the merge-base measurement canonicalizes onto this path. */
28-
const SESSION_STORE_AUTHORITY_TARGET = 'packages/daemon/src/core/session-store.ts';
28+
const SESSION_STORE_AUTHORITY_TARGET = `${DAEMON_SOURCE_ROOT}core/session-store.ts`;
2929

3030
export type SessionAuthorityOverlay = Readonly<{
3131
/** Production files importing the SessionState symbol from its declaring module, sorted. */

‎scripts/layering/session-resource-ownership.test.ts‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ test('session resources are constructed only by their durable domain owners', ()
1212
assert.deepEqual(
1313
summaries([
1414
[
15-
'packages/daemon/src/handlers/planted.ts',
15+
'packages/daemon/src/sessions/handlers/planted.ts',
1616
`sessionStore.set(name, {
1717
...session,
1818
appLog: log,
@@ -46,11 +46,11 @@ test('session resources are constructed only by their durable domain owners', ()
4646
],
4747
]),
4848
[
49-
'packages/daemon/src/handlers/planted.ts: session appLog record constructed outside its owner',
50-
'packages/daemon/src/handlers/planted.ts: session appLogFailure record constructed outside its owner',
51-
'packages/daemon/src/handlers/planted.ts: session audioProbe record constructed outside its owner',
52-
'packages/daemon/src/handlers/planted.ts: session perfCapture record constructed outside its owner',
53-
'packages/daemon/src/handlers/planted.ts: session screenRecording record constructed outside its owner',
49+
'packages/daemon/src/sessions/handlers/planted.ts: session appLog record constructed outside its owner',
50+
'packages/daemon/src/sessions/handlers/planted.ts: session appLogFailure record constructed outside its owner',
51+
'packages/daemon/src/sessions/handlers/planted.ts: session audioProbe record constructed outside its owner',
52+
'packages/daemon/src/sessions/handlers/planted.ts: session perfCapture record constructed outside its owner',
53+
'packages/daemon/src/sessions/handlers/planted.ts: session screenRecording record constructed outside its owner',
5454
'packages/daemon/src/screen-recording-session-binding.ts: session screenRecording record constructed outside its owner',
5555
'packages/capture-kit/src/capture-admission/audio-probe-session-resource.ts: session audioProbe record constructed outside its owner',
5656
'packages/capture-kit/src/capture-admission/perf-capture-session-resource.ts: session perfCapture record constructed outside its owner',
@@ -80,10 +80,13 @@ test('teardown app-log discriminants are policy input rather than session constr
8080
`teardownSessionResources({ appLog: 'run' });
8181
teardownSessionResources({ appLog: 'already-settled' });`,
8282
],
83-
['packages/daemon/src/handlers/planted.ts', `teardownSessionResources({ appLog: 'skip' });`],
83+
[
84+
'packages/daemon/src/sessions/handlers/planted.ts',
85+
`teardownSessionResources({ appLog: 'skip' });`,
86+
],
8487
]),
8588
[
86-
'packages/daemon/src/handlers/planted.ts: session appLog record constructed outside its owner',
89+
'packages/daemon/src/sessions/handlers/planted.ts: session appLog record constructed outside its owner',
8790
],
8891
);
8992
});

‎scripts/layering/session-state.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ test('explicit owner patches name their writes and retain direct assignment chec
2828
assert.ok(SESSION_STATE_FIELD_OWNERS.appLogFailure!.includes(OWNER));
2929
const foreign = scan(
3030
'sessionStore.update(ref, { appLogFailure: error });',
31-
'packages/daemon/src/handlers/probe.ts',
31+
'packages/daemon/src/sessions/handlers/probe.ts',
3232
)[0]!;
3333
assert.equal(foreign.field, 'appLogFailure');
3434
assert.ok(!SESSION_STATE_FIELD_OWNERS[foreign.field]!.includes(foreign.file));

0 commit comments

Comments
 (0)