@@ -2,122 +2,63 @@ import assert from 'node:assert/strict';
22import { test } from 'node:test' ;
33import { snapshotPlatformPolicyBranchViolations } from './runtime-command-cutover-snapshot.ts' ;
44
5- const SNAPSHOT_RUNTIME_BINDING_FILE = 'src/daemon/snapshot-runtime-binding.ts' ;
6- const SNAPSHOT_FACTS_FIRST_ADMISSION = `
7- const facts = await requireRuntimeFacts(params.inspectFacts)(device);
8- const plan = resolveSnapshotRuntimePlan({
9- customActions: params.req.flags?.snapshotCustomActions === true,
10- hasActiveApp: session?.appBundleId !== undefined,
11- });
12- for (const operation of plan.use.required) {
13- const fact = facts.operations[operation];
14- if (fact.available) continue;
15- }
16- ` ;
5+ const ROUTE = 'src/daemon/snapshot-runtime.ts' ;
6+ const BINDING = 'src/daemon/snapshot-runtime-binding.ts' ;
177
18- function violationsFor ( extraAdmission = '' ) : string [ ] {
8+ function violationsFor ( route : string , binding = '' ) : string [ ] {
199 return snapshotPlatformPolicyBranchViolations (
2010 new Map ( [
21- [
22- SNAPSHOT_RUNTIME_BINDING_FILE ,
23- `
24- function inspectSnapshotCaptureAdmission(params, device, session) {
25- ${ SNAPSHOT_FACTS_FIRST_ADMISSION }
26- ${ extraAdmission }
27- }
28- ` ,
29- ] ,
11+ [ ROUTE , route ] ,
12+ [ BINDING , binding ] ,
3013 ] ) ,
31- ) . map ( ( { file , message } ) => ` ${ file } : ${ message } ` ) ;
14+ ) . map ( ( { message } ) => message ) ;
3215}
3316
34- test ( 'R32 snapshot accepts only the normalized plan and selected operation facts seam' , ( ) => {
35- assert . deepEqual ( violationsFor ( ) , [ ] ) ;
36- } ) ;
37-
38- test ( 'R32 snapshot rejects a direct device-leaf branch in daemon admission' , ( ) => {
39- assert . deepEqual (
40- violationsFor ( "if (device.platform === 'apple' && device.kind === 'simulator') return plan;" ) ,
41- [
42- 'src/daemon/snapshot-runtime-binding.ts: snapshot admission reads device-owner identity instead of selected operation facts' ,
43- ] ,
44- ) ;
45- } ) ;
46-
47- test ( 'R32 snapshot rejects a provider-mode branch in daemon admission' , ( ) => {
48- assert . deepEqual (
49- violationsFor ( "if (facts.device.providerMode === 'provider-runtime') return plan;" ) ,
50- [
51- 'src/daemon/snapshot-runtime-binding.ts: snapshot admission reads device-owner identity instead of selected operation facts' ,
52- ] ,
53- ) ;
54- } ) ;
55-
56- test ( 'R32 snapshot rejects device-owner policy through chained aliases' , ( ) => {
57- assert . deepEqual (
58- violationsFor ( `
59- const identity = device;
60- const owner = identity;
61- if (owner.platform === 'apple') return plan;
62- ` ) ,
63- [
64- 'src/daemon/snapshot-runtime-binding.ts: snapshot admission reads device-owner identity instead of selected operation facts' ,
65- ] ,
66- ) ;
67- } ) ;
68-
69- test ( 'R32 snapshot rejects destructured provider-owner policy' , ( ) => {
70- assert . deepEqual (
71- violationsFor ( `
72- const { providerMode } = facts.device;
73- if (providerMode === 'provider-runtime') return plan;
74- ` ) ,
75- [
76- 'src/daemon/snapshot-runtime-binding.ts: snapshot admission reads device-owner identity instead of selected operation facts' ,
77- ] ,
78- ) ;
79- } ) ;
17+ const FACTS_FIRST_ROUTE = `
18+ async function dispatchSnapshotViaRuntime(params) {
19+ const plan = resolveSnapshotRuntimePlan(normalizedIntent);
20+ const admission = await inspectRequiredRuntimeUse({
21+ device,
22+ use: plan.use,
23+ inspectFacts: params.inspectFacts,
24+ });
25+ if (!admission.admitted) return unavailable(admission);
26+ return bindSnapshotCaptureRuntime(params.bindDevice, device, plan);
27+ }
28+ ` ;
8029
81- test ( 'R32 snapshot rejects nested device-leaf destructuring from admission params' , ( ) => {
82- assert . deepEqual (
83- violationsFor ( `
84- const { device: selectedDevice } = params;
85- const { kind } = selectedDevice;
86- if (kind === 'simulator') return plan;
87- ` ) ,
88- [
89- 'src/daemon/snapshot-runtime-binding.ts: snapshot admission reads device-owner identity instead of selected operation facts' ,
90- ] ,
91- ) ;
30+ test ( 'R32 accepts the normalized plan through the shared facts-first seam' , ( ) => {
31+ assert . deepEqual ( violationsFor ( FACTS_FIRST_ROUTE ) , [ ] ) ;
9232} ) ;
9333
94- test ( 'R32 snapshot rejects device-owner policy through an assigned alias ' , ( ) => {
34+ test ( 'R32 rejects a locally reimplemented admission policy, including object-wrapped identity ' , ( ) => {
9535 assert . deepEqual (
96- violationsFor ( `
97- let identity;
98- identity = device;
99- if (identity.kind === 'simulator') return plan;
100- ` ) ,
36+ violationsFor (
37+ `
38+ async function dispatchSnapshotViaRuntime(params) {
39+ const plan = resolveSnapshotRuntimePlan(normalizedIntent);
40+ return inspectSnapshotCaptureAdmission(params, plan);
41+ }
42+ ` ,
43+ `
44+ function inspectSnapshotCaptureAdmission(device) {
45+ const wrapped = { device };
46+ if (wrapped.device.platform === 'apple') return { admitted: true };
47+ }
48+ ` ,
49+ ) ,
10150 [
102- 'src/daemon/snapshot-runtime-binding.ts: snapshot admission reads device-owner identity instead of selected operation facts' ,
51+ 'snapshot route must admit exactly once through inspectRequiredRuntimeUse(device, plan.use, inspectFacts)' ,
52+ 'snapshot admission must not be reimplemented beside the shared facts seam' ,
10353 ] ,
10454 ) ;
10555} ) ;
10656
107- test ( 'R32 snapshot rejects device-owner policy delegated to a renamed helper' , ( ) => {
108- assert . deepEqual ( violationsFor ( 'if (supportsIosSimulator(device)) return plan;' ) , [
109- 'src/daemon/snapshot-runtime-binding.ts: snapshot admission reads device-owner identity instead of selected operation facts' ,
110- ] ) ;
111- } ) ;
112-
113- test ( 'R32 snapshot rejects device-owner policy through object-rest identity' , ( ) => {
57+ test ( 'R32 rejects an admission call not coupled to the selected plan use' , ( ) => {
11458 assert . deepEqual (
115- violationsFor ( `
116- const { ...identity } = device;
117- if (identity.platform === 'apple') return plan;
118- ` ) ,
59+ violationsFor ( FACTS_FIRST_ROUTE . replace ( 'use: plan.use' , 'use: captureSnapshotUse' ) ) ,
11960 [
120- 'src/daemon/ snapshot-runtime-binding.ts: snapshot admission reads device-owner identity instead of selected operation facts ' ,
61+ 'snapshot route must admit exactly once through inspectRequiredRuntimeUse(device, plan.use, inspectFacts) ' ,
12162 ] ,
12263 ) ;
12364} ) ;
0 commit comments