Skip to content

Commit 7b43676

Browse files
committed
chore(gates): classify #2278 daemon-platform-runtime edges (R74) and ratchet handler session authority (R75)
1 parent 5ba4ac7 commit 7b43676

7 files changed

Lines changed: 683 additions & 7 deletions

‎scripts/layering/check.ts‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ import { selectorPipelineOwnershipViolations } from './selector-pipeline-ownersh
101101
import { recordRuntimeRegistryJoinViolations } from './record-runtime-registry-policy.ts';
102102
import { recordRuntimeDaemonMechanicsViolations } from './record-runtime-mechanics-policy.ts';
103103
import { checkDaemonPlatformBoundary } from './daemon-platform-boundary.ts';
104+
import {
105+
checkDaemonPlatformRuntimeInventory,
106+
DAEMON_PLATFORM_RUNTIME_EDGES,
107+
} from './daemon-platform-runtime-inventory.ts';
108+
import { checkSessionAuthorityOverlay, handlerOwnedOverlay } from './session-authority-overlay.ts';
104109
import {
105110
listTrackedPlatformZoneFiles,
106111
listTrackedProductionSources,
@@ -351,6 +356,9 @@ function report(
351356
(sum, count) => sum + count,
352357
0,
353358
);
359+
const measuredOverlay = handlerOwnedOverlay(ratchets.sessionAuthority);
360+
const handlerOwnedShapeFiles = measuredOverlay.shapeFiles.length;
361+
const handlerOwnedAuthorityFiles = measuredOverlay.authorityFiles.length;
354362
process.stdout.write(
355363
`Layering guard: OK — ${files.length} source files satisfy R2 and contain no ` +
356364
`value-import cycles (both checked globally); the ranked target spine contains no ` +
@@ -362,8 +370,12 @@ function report(
362370
`${ratchets.largestTypeCycle.length} files (R9); ${daemonModularitySummary(reference)}; ` +
363371
`${packageBoundariesSummary(repoRoot)}; ${platformPackagePolicySummary()}; ` +
364372
`runtime facts remain the only device-command admission authority and daemon code cannot ` +
365-
`manufacture narrowed runtime proof (R66); and R65 keeps production src/daemon free of ` +
366-
`concrete platform imports in every executable and type-only form.\n`,
373+
`manufacture narrowed runtime proof (R66); R65 keeps production src/daemon free of ` +
374+
`concrete platform imports in every executable and type-only form; ` +
375+
`${DAEMON_PLATFORM_RUNTIME_EDGES.length} daemon-to-root platform-runtime edges hold ` +
376+
`their #2278 classification (R74); and the handler-owned SessionState/SessionStore ` +
377+
`authority overlay holds at or under the merge-base (R75, ` +
378+
`${handlerOwnedShapeFiles} shape / ${handlerOwnedAuthorityFiles} authority files).\n`,
367379
);
368380
return 0;
369381
}
@@ -435,6 +447,8 @@ export const LAYERING_RULE_IDS = [
435447
'replay-ownership',
436448
'ios-snapshot-engine-ownership',
437449
'provider-snapshot-presentation-ownership',
450+
'daemon-platform-runtime-inventory',
451+
'session-authority-overlay',
438452
] as const;
439453

440454
export type LayeringRuleId = (typeof LAYERING_RULE_IDS)[number];
@@ -487,6 +501,13 @@ export const LAYERING_RULES: Readonly<Record<LayeringRuleId, LayeringRule>> = {
487501
),
488502
'provider-snapshot-presentation-ownership': (context) =>
489503
providerSnapshotPresentationViolations(context.sources, context.edges),
504+
'daemon-platform-runtime-inventory': (context) =>
505+
checkDaemonPlatformRuntimeInventory(context.edges),
506+
'session-authority-overlay': (context) =>
507+
checkSessionAuthorityOverlay(
508+
context.ratchets.sessionAuthority,
509+
context.reference.sessionAuthority,
510+
),
490511
};
491512

492513
export function main(): number {
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
import assert from 'node:assert/strict';
2+
import { test } from 'node:test';
3+
import { resolveImportEdges, type LayeringViolation } from './model.ts';
4+
import {
5+
checkDaemonPlatformRuntimeInventory,
6+
DAEMON_PLATFORM_RUNTIME_EDGES,
7+
DAEMON_PLATFORM_RUNTIME_RULE,
8+
isRootPlatformRuntimeTarget,
9+
} from './daemon-platform-runtime-inventory.ts';
10+
11+
const DEVICE_READY_TARGET = 'src/platform-runtime-device-ready.ts';
12+
const DEVICE_READY_STUB =
13+
'export async function ensureLocalPlatformDeviceReady(device: unknown) { return false; }\n';
14+
15+
function violations(sources: Record<string, string>): LayeringViolation[] {
16+
return checkDaemonPlatformRuntimeInventory(resolveImportEdges(new Map(Object.entries(sources))));
17+
}
18+
19+
function edgeViolations(sources: Record<string, string>, file: string): LayeringViolation[] {
20+
return violations(sources).filter((violation) => violation.file === file);
21+
}
22+
23+
test('R74 accepts a classified edge with the exact recorded symbols', () => {
24+
const sources = {
25+
[DEVICE_READY_TARGET]: DEVICE_READY_STUB,
26+
'src/daemon/device-ready.ts':
27+
"import { ensureLocalPlatformDeviceReady } from '../platform-runtime-device-ready.ts';\n" +
28+
'void ensureLocalPlatformDeviceReady;\n',
29+
};
30+
assert.deepEqual(edgeViolations(sources, 'src/daemon/device-ready.ts'), []);
31+
});
32+
33+
test('R74 reports every classified edge missing from the tree as stale, not the other way around', () => {
34+
const sources = {
35+
[DEVICE_READY_TARGET]: DEVICE_READY_STUB,
36+
'src/daemon/device-ready.ts':
37+
"import { ensureLocalPlatformDeviceReady } from '../platform-runtime-device-ready.ts';\n" +
38+
'void ensureLocalPlatformDeviceReady;\n',
39+
};
40+
const stale = violations(sources).filter(
41+
(violation) => violation.file === 'scripts/layering/daemon-platform-runtime-inventory.ts',
42+
);
43+
assert.equal(stale.length, DAEMON_PLATFORM_RUNTIME_EDGES.length - 1);
44+
assert.ok(stale.every((violation) => violation.message.includes('stale classified edge')));
45+
const deviceReadyStale = stale.find((violation) =>
46+
violation.message.includes(DEVICE_READY_TARGET),
47+
);
48+
assert.equal(deviceReadyStale, undefined);
49+
});
50+
51+
test('R74 rejects an unclassified edge with the pair and its line', () => {
52+
const sources = {
53+
'src/platform-runtime-android-tool-host.ts': 'export function createAndroidToolHost() {}\n',
54+
'src/daemon/fixture.ts':
55+
"import { createAndroidToolHost } from '../platform-runtime-android-tool-host.ts';\n" +
56+
'void createAndroidToolHost;\n',
57+
};
58+
const found = edgeViolations(sources, 'src/daemon/fixture.ts');
59+
assert.equal(found.length, 1);
60+
assert.equal(found[0]!.rule, DAEMON_PLATFORM_RUNTIME_RULE);
61+
assert.equal(found[0]!.line, 1);
62+
assert.match(found[0]!.message, /unclassified daemon-to-root platform-runtime coupling/);
63+
assert.match(
64+
found[0]!.message,
65+
/src\/daemon\/fixture\.ts -> src\/platform-runtime-android-tool-host\.ts/,
66+
);
67+
});
68+
69+
test('R74 rejects new symbols on a classified edge', () => {
70+
const sources = {
71+
[DEVICE_READY_TARGET]: DEVICE_READY_STUB + 'export function extraReadiness() {}\n',
72+
'src/daemon/device-ready.ts':
73+
"import { ensureLocalPlatformDeviceReady, extraReadiness } from '../platform-runtime-device-ready.ts';\n" +
74+
'void [ensureLocalPlatformDeviceReady, extraReadiness];\n',
75+
};
76+
const found = edgeViolations(sources, 'src/daemon/device-ready.ts');
77+
assert.equal(found.length, 1);
78+
assert.equal(found[0]!.rule, DAEMON_PLATFORM_RUNTIME_RULE);
79+
assert.match(found[0]!.message, /classified symbols drifted/);
80+
assert.match(found[0]!.message, /ensureLocalPlatformDeviceReady, extraReadiness/);
81+
});
82+
83+
test('R74 matches a dynamic import by target with empty symbols', () => {
84+
const sources = {
85+
'src/platform-runtime-operation-host.ts':
86+
'export async function recoverLegacyAppLogMarkersAfterDaemonLock() { return {}; }\n',
87+
'src/daemon/server/daemon-runtime.ts':
88+
"const mod = await import('../../platform-runtime-operation-host.ts');\nvoid mod;\n",
89+
};
90+
assert.deepEqual(edgeViolations(sources, 'src/daemon/server/daemon-runtime.ts'), []);
91+
});
92+
93+
test('R74 treats the import and re-export of one classified pair as one entry', () => {
94+
const sources = {
95+
'src/platform-runtime-open-target.ts':
96+
'export async function resolveSoleForegroundIosApp() { return undefined; }\n',
97+
'src/daemon/ios-app-session-hint.ts':
98+
"import { resolveSoleForegroundIosApp } from '../platform-runtime-open-target.ts';\n" +
99+
"export { resolveSoleForegroundIosApp } from '../platform-runtime-open-target.ts';\n" +
100+
'void resolveSoleForegroundIosApp;\n',
101+
};
102+
assert.deepEqual(edgeViolations(sources, 'src/daemon/ios-app-session-hint.ts'), []);
103+
});
104+
105+
test('R74 ignores test-shaped and non-daemon importers', () => {
106+
const sources = {
107+
'src/platform-runtime-android-tool-host.ts': 'export function createAndroidToolHost() {}\n',
108+
'src/daemon/__tests__/fixture.test.ts':
109+
"import { createAndroidToolHost } from '../platform-runtime-android-tool-host.ts';\n" +
110+
'void createAndroidToolHost;\n',
111+
'src/cli.ts':
112+
"import { createAndroidToolHost } from './platform-runtime-android-tool-host.ts';\n" +
113+
'void createAndroidToolHost;\n',
114+
};
115+
assert.deepEqual(
116+
violations(sources).filter(
117+
(violation) => violation.file !== 'scripts/layering/daemon-platform-runtime-inventory.ts',
118+
),
119+
[],
120+
);
121+
});
122+
123+
test('R74 ignores retired-zone targets, which R65 owns', () => {
124+
const sources = {
125+
'src/platforms/android.ts': 'export const legacy = 1;\n',
126+
'src/daemon/fixture.ts': 'import { legacy } from "../platforms/android.ts";\nvoid legacy;\n',
127+
};
128+
assert.deepEqual(edgeViolations(sources, 'src/daemon/fixture.ts'), []);
129+
});
130+
131+
test('the root composition family is src/platform-runtime.ts plus src/platform-runtime-*.ts only', () => {
132+
assert.equal(isRootPlatformRuntimeTarget('src/platform-runtime.ts'), true);
133+
assert.equal(isRootPlatformRuntimeTarget('src/platform-runtime-android.ts'), true);
134+
assert.equal(isRootPlatformRuntimeTarget('src/platform-runtime-gateway.ts'), true);
135+
assert.equal(isRootPlatformRuntimeTarget('src/platform-runtime-android.tsx'), false);
136+
assert.equal(isRootPlatformRuntimeTarget('src/platform-runtime.ts.bak'), false);
137+
assert.equal(isRootPlatformRuntimeTarget('src/platforms/runtime.ts'), false);
138+
assert.equal(isRootPlatformRuntimeTarget('src/daemon/platform-runtime.ts'), false);
139+
});

0 commit comments

Comments
 (0)