Skip to content

Commit 4210fe2

Browse files
committed
refactor: migrate diff to request-bound runtime
1 parent 4bba404 commit 4210fe2

23 files changed

Lines changed: 989 additions & 647 deletions

‎scripts/layering/check.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
// composition file; premature implementation loading and forbidden cross-boundary edges fail (R13).
3737
// - Over COMMAND-ATOMIC RUNTIME CUTOVERS: one parametrized gate reads the migrated-command
3838
// table (appstate R22, shutdown R23, boot R20, apps R21, install/deploy R24-R27,
39-
// lifecycle R28-R31, devices R17, logs R14, network R15, record R16) and proves each command keeps
39+
// lifecycle R28-R31, devices R17, logs R14, network R15, record R16, snapshot R32, diff R33)
40+
// and proves each command keeps
4041
// exactly one platform-execution path — retired routes, admission, modules, and widened
4142
// runtime access cannot coexist with its operation-fact-derived descriptor and handler.
4243
// - Over CONTRACTS PRODUCTION SOURCE: contracts owns vocabulary only — host, process, and timer

‎scripts/layering/runtime-command-cutover-snapshot.test.ts‎

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,33 @@ import { test } from 'node:test';
33
import { snapshotPlatformPolicyBranchViolations } from './runtime-command-cutover-snapshot.ts';
44

55
const ROUTE = 'src/daemon/snapshot-runtime.ts';
6+
const COMMAND = 'src/daemon/snapshot-command-runtime.ts';
67
const BINDING = 'src/daemon/snapshot-runtime-binding.ts';
78

8-
function violationsFor(route: string, binding = ''): string[] {
9+
function violationsFor(route: string, binding = '', command = SHARED_COMMAND): string[] {
910
return snapshotPlatformPolicyBranchViolations(
1011
new Map([
1112
[ROUTE, route],
13+
[COMMAND, command],
1214
[BINDING, binding],
1315
]),
1416
).map(({ message }) => message);
1517
}
1618

17-
const FACTS_FIRST_ROUTE = `
19+
const PUBLIC_ROUTE = `
1820
async function dispatchSnapshotViaRuntime(params) {
21+
return dispatchSnapshotRuntimeCommand({ ...params, command: 'snapshot' });
22+
}
23+
`;
24+
25+
const SHARED_COMMAND = `
26+
async function dispatchSnapshotRuntimeCommand(params) {
27+
return resolveBoundSnapshotCaptureRuntime(params, params.command);
28+
}
29+
`;
30+
31+
const FACTS_FIRST_BINDING = `
32+
async function resolveBoundSnapshotCaptureRuntime(params) {
1933
const plan = resolveSnapshotRuntimePlan(normalizedIntent);
2034
const admission = await inspectRequiredRuntimeUse({
2135
device,
@@ -28,37 +42,39 @@ const FACTS_FIRST_ROUTE = `
2842
`;
2943

3044
test('R32 accepts the normalized plan through the shared facts-first seam', () => {
31-
assert.deepEqual(violationsFor(FACTS_FIRST_ROUTE), []);
45+
assert.deepEqual(violationsFor(PUBLIC_ROUTE, FACTS_FIRST_BINDING), []);
3246
});
3347

3448
test('R32 rejects a locally reimplemented admission policy, including object-wrapped identity', () => {
3549
assert.deepEqual(
3650
violationsFor(
51+
PUBLIC_ROUTE,
3752
`
38-
async function dispatchSnapshotViaRuntime(params) {
53+
async function resolveBoundSnapshotCaptureRuntime(params) {
3954
const plan = resolveSnapshotRuntimePlan(normalizedIntent);
4055
return inspectSnapshotCaptureAdmission(params, plan);
4156
}
42-
`,
43-
`
4457
function inspectSnapshotCaptureAdmission(device) {
4558
const wrapped = { device };
4659
if (wrapped.device.platform === 'apple') return { admitted: true };
4760
}
4861
`,
4962
),
5063
[
51-
'snapshot route must admit exactly once through inspectRequiredRuntimeUse(device, plan.use, inspectFacts)',
64+
'snapshot owning interface must admit exactly once through inspectRequiredRuntimeUse(device, plan.use, inspectFacts)',
5265
'snapshot admission must not be reimplemented beside the shared facts seam',
5366
],
5467
);
5568
});
5669

5770
test('R32 rejects an admission call not coupled to the selected plan use', () => {
5871
assert.deepEqual(
59-
violationsFor(FACTS_FIRST_ROUTE.replace('use: plan.use', 'use: captureSnapshotUse')),
72+
violationsFor(
73+
PUBLIC_ROUTE,
74+
FACTS_FIRST_BINDING.replace('use: plan.use', 'use: captureSnapshotUse'),
75+
),
6076
[
61-
'snapshot route must admit exactly once through inspectRequiredRuntimeUse(device, plan.use, inspectFacts)',
77+
'snapshot owning interface must admit exactly once through inspectRequiredRuntimeUse(device, plan.use, inspectFacts)',
6278
],
6379
);
6480
});

‎scripts/layering/runtime-command-cutover-snapshot.ts‎

Lines changed: 60 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,84 @@ import type { UnruledViolation } from './runtime-command-cutover-model.ts';
66
type AstNode = Record<string, unknown>;
77

88
const SNAPSHOT_ROUTE_FILE = 'src/daemon/snapshot-runtime.ts';
9+
const SNAPSHOT_COMMAND_FILE = 'src/daemon/snapshot-command-runtime.ts';
910
const SNAPSHOT_BINDING_FILE = 'src/daemon/snapshot-runtime-binding.ts';
1011

1112
/** R32 admits only through the shared facts-first seam selected by the normalized runtime plan. */
1213
export function snapshotPlatformPolicyBranchViolations(
1314
sources: ReadonlyMap<string, string>,
1415
): UnruledViolation[] {
15-
const source = sources.get(SNAPSHOT_ROUTE_FILE);
16-
if (source === undefined) return [violation(1, 'snapshot runtime route is missing')];
16+
const routeSource = sources.get(SNAPSHOT_ROUTE_FILE);
17+
if (routeSource === undefined) {
18+
return [violation(SNAPSHOT_ROUTE_FILE, 1, 'snapshot runtime route is missing')];
19+
}
20+
const commandSource = sources.get(SNAPSHOT_COMMAND_FILE);
21+
if (commandSource === undefined) {
22+
return [violation(SNAPSHOT_COMMAND_FILE, 1, 'snapshot runtime command owner is missing')];
23+
}
24+
const bindingSource = sources.get(SNAPSHOT_BINDING_FILE);
25+
if (bindingSource === undefined) {
26+
return [violation(SNAPSHOT_BINDING_FILE, 1, 'snapshot runtime binding is missing')];
27+
}
1728

18-
const program = parseSync(SNAPSHOT_ROUTE_FILE, source).program as AstNode;
19-
const route = namedFunction(program, 'dispatchSnapshotViaRuntime');
20-
if (route === undefined) return [violation(1, 'snapshot public runtime route is missing')];
29+
const routeProgram = parseSync(SNAPSHOT_ROUTE_FILE, routeSource).program as AstNode;
30+
const route = namedFunction(routeProgram, 'dispatchSnapshotViaRuntime');
31+
if (route === undefined) {
32+
return [violation(SNAPSHOT_ROUTE_FILE, 1, 'snapshot public runtime route is missing')];
33+
}
34+
const commandProgram = parseSync(SNAPSHOT_COMMAND_FILE, commandSource).program as AstNode;
35+
const commandOwner = namedFunction(commandProgram, 'dispatchSnapshotRuntimeCommand');
36+
if (commandOwner === undefined) {
37+
return [violation(SNAPSHOT_COMMAND_FILE, 1, 'snapshot runtime command owner is missing')];
38+
}
39+
const bindingProgram = parseSync(SNAPSHOT_BINDING_FILE, bindingSource).program as AstNode;
40+
const owner = namedFunction(bindingProgram, 'resolveBoundSnapshotCaptureRuntime');
41+
if (owner === undefined) {
42+
return [
43+
violation(SNAPSHOT_BINDING_FILE, 1, 'snapshot bound capture owning interface is missing'),
44+
];
45+
}
2146

2247
const violations: UnruledViolation[] = [];
23-
if (countNamedCalls(route, 'resolveSnapshotRuntimePlan') !== 1) {
48+
if (countNamedCalls(route, 'dispatchSnapshotRuntimeCommand') !== 1) {
49+
violations.push(
50+
violation(
51+
SNAPSHOT_ROUTE_FILE,
52+
lineOf(routeSource, route),
53+
'snapshot route must delegate exactly once to the shared runtime command owner',
54+
),
55+
);
56+
}
57+
if (countNamedCalls(commandOwner, 'resolveBoundSnapshotCaptureRuntime') !== 1) {
2458
violations.push(
25-
violation(lineOf(source, route), 'snapshot route must select exactly one normalized plan'),
59+
violation(
60+
SNAPSHOT_COMMAND_FILE,
61+
lineOf(commandSource, commandOwner),
62+
'snapshot runtime command owner must resolve one bound capture',
63+
),
64+
);
65+
}
66+
if (countNamedCalls(owner, 'resolveSnapshotRuntimePlan') !== 1) {
67+
violations.push(
68+
violation(
69+
SNAPSHOT_BINDING_FILE,
70+
lineOf(bindingSource, owner),
71+
'snapshot owning interface must select exactly one normalized plan',
72+
),
2673
);
2774
}
2875

29-
const admissions = namedCalls(route, 'inspectRequiredRuntimeUse');
76+
const admissions = namedCalls(owner, 'inspectRequiredRuntimeUse');
3077
if (admissions.length !== 1 || !hasExactAdmissionInput(admissions[0])) {
3178
violations.push(
3279
violation(
33-
lineOf(source, admissions[0] ?? route),
34-
'snapshot route must admit exactly once through inspectRequiredRuntimeUse(device, plan.use, inspectFacts)',
80+
SNAPSHOT_BINDING_FILE,
81+
lineOf(bindingSource, admissions[0] ?? owner),
82+
'snapshot owning interface must admit exactly once through inspectRequiredRuntimeUse(device, plan.use, inspectFacts)',
3583
),
3684
);
3785
}
3886

39-
const bindingSource = sources.get(SNAPSHOT_BINDING_FILE) ?? '';
4087
if (bindingSource.includes('inspectSnapshotCaptureAdmission')) {
4188
violations.push({
4289
file: SNAPSHOT_BINDING_FILE,
@@ -82,6 +129,6 @@ function isNode(node: unknown, type: string): node is AstNode {
82129
return node !== null && typeof node === 'object' && (node as AstNode).type === type;
83130
}
84131

85-
function violation(line: number, message: string): UnruledViolation {
86-
return { file: SNAPSHOT_ROUTE_FILE, line, message };
132+
function violation(file: string, line: number, message: string): UnruledViolation {
133+
return { file, line, message };
87134
}

‎scripts/layering/runtime-command-cutover-table.test.ts‎

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,27 @@ test('R32 snapshot rejects legacy admission and dispatcher projection', () => {
6060
],
6161
[
6262
'src/daemon/snapshot-runtime.ts',
63+
`
64+
function dispatchSnapshotViaRuntime(params) {
65+
requireCommandSupported('snapshot', device);
66+
return dispatchSnapshotRuntimeCommand({ ...params, command: 'snapshot' });
67+
}
68+
function handleSnapshotCommands() {
69+
dispatchSnapshotViaRuntime(request);
70+
}
71+
handleSnapshotCommands(request);
72+
`,
73+
],
74+
[
75+
'src/daemon/snapshot-command-runtime.ts',
76+
`
77+
function dispatchSnapshotRuntimeCommand(params) {
78+
return resolveBoundSnapshotCaptureRuntime(params, params.command);
79+
}
80+
`,
81+
],
82+
[
83+
'src/daemon/snapshot-runtime-binding.ts',
6384
`
6485
function selectActiveAppSnapshot() { runtime.operations.captureSnapshot(input); }
6586
function selectCustomActionsSnapshot() {
@@ -68,22 +89,17 @@ test('R32 snapshot rejects legacy admission and dispatcher projection', () => {
6889
function selectSnapshotWithoutActiveApp() {
6990
runtime.operations.captureSnapshotWithoutActiveApp(input);
7091
}
71-
function dispatchSnapshotViaRuntime() {
92+
function resolveBoundSnapshotCaptureRuntime(params) {
7293
const plan = resolveSnapshotRuntimePlan(normalizedIntent);
7394
inspectRequiredRuntimeUse({
7495
device,
7596
use: plan.use,
7697
inspectFacts: params.inspectFacts,
7798
});
78-
requireCommandSupported('snapshot', device);
99+
return bindSnapshotCaptureRuntime(params.bindDevice, device, plan);
79100
}
80-
function handleSnapshotCommands() {
81-
dispatchSnapshotViaRuntime(request);
82-
}
83-
handleSnapshotCommands(request);
84101
`,
85102
],
86-
['src/daemon/snapshot-runtime-binding.ts', ''],
87103
['src/core/dispatch.ts', 'function handleSnapshotCommand() { return legacy.snapshot(); }'],
88104
[
89105
'src/core/capabilities.ts',
@@ -104,7 +120,7 @@ test('R32 snapshot rejects legacy admission and dispatcher projection', () => {
104120
);
105121
});
106122

107-
// Per-row acceptance for the five migrated commands. Every older-row case here was carried over
123+
// Per-row acceptance for migrated commands. Every older-row case here was carried over
108124
// from the per-command policy tests these rows replaced; the mechanism itself is proven
109125
// in runtime-command-cutover-policy.test.ts.
110126

‎scripts/layering/runtime-command-cutover-table.ts‎

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ import { retiredDispatchProjectionViolations } from './runtime-command-cutover-d
2525
*
2626
* A row id is a report heading, so it must be unique across every stack that adds rows here.
2727
* `cutoverTableDefects` rejects a duplicate; lifecycle starts at R28 after the accepted
28-
* shutdown, install/deploy, and application-lifecycle allocations. Snapshot starts at R32.
28+
* shutdown, install/deploy, and application-lifecycle allocations. Snapshot starts at R32;
29+
* diff follows at R33.
2930
*/
3031
export const MIGRATED_COMMAND_CUTOVERS: readonly MigratedCommandCutover[] = [
3132
{
@@ -472,6 +473,40 @@ export const MIGRATED_COMMAND_CUTOVERS: readonly MigratedCommandCutover[] = [
472473
},
473474
extensions: [snapshotRetiredDispatchProjectionProof, snapshotPlatformPolicyBranchViolations],
474475
},
476+
{
477+
rule: 'R33 diff-runtime-cutover',
478+
command: 'diff',
479+
subject: 'snapshot diff capture',
480+
tier: 'request-scoped',
481+
execution: 'device-runtime',
482+
legacyRetirement: {
483+
modulePaths: ['src/daemon/snapshot-diff-legacy-admission.ts'],
484+
importPatterns: [/(?:^|\/)snapshot-diff-legacy-admission(?:\.[cm]?[jt]s)?$/],
485+
routeNames: ['requireLegacyDiffCustomActionsSupported', 'requireLegacyDiffIosAppSession'],
486+
},
487+
runtimeTypeNames: ['SnapshotRuntimeOperations'],
488+
operations: {
489+
names: [
490+
'captureSnapshot',
491+
'captureSnapshotWithCustomActions',
492+
'captureSnapshotWithoutActiveApp',
493+
],
494+
},
495+
singularExecution: {
496+
routes: ['handleSnapshotCommands'],
497+
operations: [
498+
'captureSnapshot',
499+
'captureSnapshotWithCustomActions',
500+
'captureSnapshotWithoutActiveApp',
501+
],
502+
operationOwners: {
503+
captureSnapshot: ['selectActiveAppSnapshot'],
504+
captureSnapshotWithCustomActions: ['selectCustomActionsSnapshot'],
505+
captureSnapshotWithoutActiveApp: ['selectSnapshotWithoutActiveApp'],
506+
},
507+
},
508+
extensions: [diffRetiredDispatchProjectionProof],
509+
},
475510
];
476511

477512
function snapshotRetiredDispatchProjectionProof(
@@ -480,6 +515,12 @@ function snapshotRetiredDispatchProjectionProof(
480515
return retiredDispatchProjectionViolations(sources, 'snapshot');
481516
}
482517

518+
function diffRetiredDispatchProjectionProof(
519+
sources: ReadonlyMap<string, string>,
520+
): UnruledViolation[] {
521+
return retiredDispatchProjectionViolations(sources, 'diff');
522+
}
523+
483524
/** The record mechanics policy predates the row model and reports `path: message`. */
484525
function recordDaemonMechanicsProof(sources: ReadonlyMap<string, string>): UnruledViolation[] {
485526
const production = [...sources].map(([path, source]) => ({ path, source }));

‎scripts/layering/session-state.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ export const SESSION_STATE_FIELD_OWNERS: Readonly<Record<string, readonly string
7676
pendingInteractionOutcome: ['src/daemon/interaction-outcome-policy.ts'],
7777
postGestureStabilization: ['src/daemon/deferred-interaction-outcome.ts'],
7878

79-
// Snapshot lineage on a freshly BUILT record. snapshot-runtime.ts constructs a new
79+
// Snapshot lineage on a freshly BUILT record. snapshot-command-runtime.ts constructs a new
8080
// SessionState rather than mutating the stored one, so it cannot call setSessionSnapshot —
8181
// but the rule is the same, so the two-field transition lives in session-snapshot.ts.
82-
appName: ['src/daemon/snapshot-runtime.ts'],
82+
appName: ['src/daemon/snapshot-command-runtime.ts'],
8383
// Open execution owns the paired lease/claim transition after the handler has admitted one
8484
// lifecycle binding. Keeping the records together prevents request-policy routing from gaining
8585
// a second durable owner as the execution seam stays package-bound.

‎src/core/__tests__/capabilities.test.ts‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ test('core commands support iOS simulator, iOS device, and Android', () => {
161161
'back',
162162
'boot',
163163
'click',
164-
'diff',
165164
'fill',
166165
'find',
167166
'focus',
@@ -247,7 +246,6 @@ test('macOS supports the Apple runner interaction core but excludes mobile-only
247246
'alert',
248247
'back',
249248
'click',
250-
'diff',
251249
'fill',
252250
'find',
253251
'focus',
@@ -321,7 +319,6 @@ test('Linux supports desktop interaction commands and blocks mobile/unsupported
321319
'back',
322320
'click',
323321
'clipboard',
324-
'diff',
325322
'fill',
326323
'find',
327324
'focus',
@@ -372,7 +369,6 @@ test('web supports only the initial browser interaction slice', () => {
372369
'app-switcher',
373370
'back',
374371
'clipboard',
375-
'diff',
376372
'gesture',
377373
'home',
378374
'keyboard',

0 commit comments

Comments
 (0)