Skip to content

Commit 6a03688

Browse files
authored
refactor(ios): prune converged snapshot paths (#2383)
The daemon snapshot assembly no longer presents. `shouldPresentLegacyIosInteractiveSnapshot` fired whenever an xctest capture arrived without a producer, or with a producer whose capability table still named `snapshot-state` as its presentation owner — which `simulator-ax-bridge` still did after routing moved it onto the engine, so a bridge capture with `--interactive-only` ran the iOS semantic presentation twice (#2188 invariant 2). Rather than deleting a runtime guard and hoping, `buildSnapshotState` now takes `SnapshotCaptureProvenance`: a capture either knows nothing about its origin or carries the whole pair, so the producer-less branch does not compile. Requiring the pair broke only test fixtures, which is the proof that production never omitted it. `presentationOwner` had one value left once the bridge was accounted for, so the capability and its type are gone; the truncation verdict that read it now reads `truncationEvidence`, which is the fact it was standing in for and matches it producer for producer. Post-wire scope planning names the channels that still need the pass instead of excluding the ones that do not, which takes iOS out of it. `compactIosInteractiveSnapshot` was a byte-identical alias of `presentIosInteractiveSnapshot` with no production caller. R74 holds it: the assembly and the Simulator bridge producer adapter may not import iOS presentation, and the assembly may not name the iOS channel or a producer.
1 parent 527a56a commit 6a03688

24 files changed

Lines changed: 582 additions & 156 deletions

‎packages/capture-kit/src/ios-snapshot-acquisition.ts‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ const ACQUIRED_PRODUCER_CAPABILITY_DEFAULTS = {
2222
viewportEvidence: 'available',
2323
hittabilityEvidence: 'unavailable',
2424
truncationEvidence: 'unavailable',
25-
presentationOwner: 'ios-snapshot-engine',
2625
} as const;
2726

2827
const IOS_SNAPSHOT_PRODUCER_CAPABILITY_VALUES = {
@@ -38,7 +37,6 @@ const IOS_SNAPSHOT_PRODUCER_CAPABILITY_VALUES = {
3837
viewportEvidence: 'available',
3938
hittabilityEvidence: 'available',
4039
truncationEvidence: 'available',
41-
presentationOwner: 'ios-snapshot-engine',
4240
},
4341
'simulator-ax-bridge': {
4442
...ACQUIRED_PRODUCER_CAPABILITY_DEFAULTS,
@@ -49,7 +47,6 @@ const IOS_SNAPSHOT_PRODUCER_CAPABILITY_VALUES = {
4947
},
5048
hittabilityEvidence: 'available',
5149
truncationEvidence: 'available',
52-
presentationOwner: 'snapshot-state',
5350
},
5451
'appium-source': {
5552
...ACQUIRED_PRODUCER_CAPABILITY_DEFAULTS,

‎packages/capture-kit/src/ios-snapshot-engine/engine.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import {
1313
} from '@agent-device/capture-kit/ios-snapshot-planning';
1414
import { toIosSnapshotEngineErrorDetails } from './types.ts';
1515
import {
16-
compactIosInteractiveSnapshot,
1716
createIosSnapshotEngine,
1817
IosSnapshotEngineError,
18+
presentIosInteractiveSnapshot,
1919
presentIosSnapshot,
2020
publishIosSnapshot,
2121
} from './index.ts';
@@ -326,7 +326,7 @@ test('unavailable hittability never becomes regular actionability', () => {
326326

327327
test('interactive compaction stays available through the engine boundary', () => {
328328
const rowRect = { x: 16, y: 80, width: 288, height: 52 };
329-
const compacted = compactIosInteractiveSnapshot([
329+
const compacted = presentIosInteractiveSnapshot([
330330
node(0, 'Application', 'App', viewport),
331331
node(1, 'Table', 'Settings', { x: 0, y: 40, width: 320, height: 200 }, 0),
332332
node(2, 'Cell', 'General', rowRect, 1, 2),

‎packages/capture-kit/src/ios-snapshot-engine/engine.ts‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,6 @@ export function presentIosSnapshot(
7171
return presentIosRunnerSnapshot(input, request, foldPolicy);
7272
}
7373

74-
export function compactIosInteractiveSnapshot(nodes: RawSnapshotNode[]): RawSnapshotNode[] {
75-
return buildIosInteractiveSnapshotPresentation(nodes).nodes;
76-
}
77-
7874
function presentAcquiredSnapshot(
7975
acquisition: IosSnapshotAcquisition,
8076
request: IosSnapshotRequest,

‎packages/capture-kit/src/ios-snapshot-engine/index.ts‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
export {
2-
compactIosInteractiveSnapshot,
3-
createIosSnapshotEngine,
4-
presentIosSnapshot,
5-
publishIosSnapshot,
6-
} from './engine.ts';
1+
export { createIosSnapshotEngine, presentIosSnapshot, publishIosSnapshot } from './engine.ts';
72
export { presentIosRunnerSnapshot } from './runner-presentation.ts';
83
export {
94
buildIosInteractiveSnapshotPresentation,

‎packages/capture-kit/src/ios-snapshot-planning.test.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,6 @@ function acquiredProducer(
252252
viewportEvidence: 'available',
253253
hittabilityEvidence: 'available',
254254
truncationEvidence: 'available',
255-
presentationOwner: 'snapshot-state',
256255
...overrides,
257256
};
258257
}

‎packages/contracts/src/ios-snapshot.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export type IosAcquisitionIntent = 'full' | 'surface-observation';
1515
export type IosSnapshotProjection = 'regular' | 'raw';
1616
export type IosSnapshotCompleteness = 'complete' | 'incomplete';
1717
export type IosSnapshotEvidenceAvailability = 'available' | 'unavailable';
18-
export type IosSnapshotPresentationOwner = 'ios-snapshot-engine' | 'snapshot-state';
1918

2019
export type IosSnapshotGeneration = string;
2120

@@ -86,7 +85,6 @@ type IosSnapshotProducerCapabilityFacts = Readonly<{
8685
viewportEvidence: IosSnapshotEvidenceAvailability;
8786
hittabilityEvidence: IosSnapshotEvidenceAvailability;
8887
truncationEvidence: IosSnapshotEvidenceAvailability;
89-
presentationOwner: IosSnapshotPresentationOwner;
9088
}>;
9189

9290
export type IosSnapshotAcquisitionProducerCapabilities = IosSnapshotProducerCapabilityFacts &

‎packages/kernel/src/snapshot.ts‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,26 @@ type OptionalProducerProvenance<Pair> = Pair extends {
198198
: never;
199199

200200
/**
201-
* The provenance carrier for {@link SnapshotState}: the producer may be absent (legacy states
202-
* and fixtures predate it), but a present pair still has to come from the
203-
* {@link SnapshotProvenance} table — the channel may not carry a foreign producer.
201+
* The provenance carrier for {@link SnapshotState}: the producer may be absent (a client-side
202+
* fallback that rebuilds a state from a bare backend result knows the channel and nothing more),
203+
* but a present pair still has to come from the {@link SnapshotProvenance} table — the channel
204+
* may not carry a foreign producer.
204205
*/
205206
export type SnapshotStateProvenance =
206207
| OptionalProducerProvenance<SnapshotProvenance>
207208
| { backend?: undefined; producer?: undefined };
208209

210+
/**
211+
* The provenance a capture hands to the daemon snapshot assembly: either nothing is known about
212+
* the origin, or the WHOLE pair is. A channel that arrived without its producer would leave the
213+
* assembly guessing who presented the tree, which is exactly the backend-name presentation
214+
* policy #2199 deleted — so it does not compile. Every production capture satisfies this: the
215+
* interactor boundary (`SnapshotResult`) already carries {@link SnapshotProvenance}.
216+
*/
217+
export type SnapshotCaptureProvenance =
218+
| SnapshotProvenance
219+
| { backend?: undefined; producer?: undefined };
220+
209221
/**
210222
* Narrows a provenance-carrying value to just its pair without decorrelating the two fields
211223
* (reading `backend` and `producer` separately would lose the pairing for the type system).

‎scripts/layering/check.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ import { sessionResourceOwnershipViolations } from './session-resource-ownership
113113
import { applicationLifecycleOwnershipViolations } from './application-lifecycle-policy.ts';
114114
import { iosSnapshotEngineOwnershipViolations } from './ios-snapshot-engine-policy.ts';
115115
import { providerSnapshotPresentationViolations } from './provider-snapshot-presentation-policy.ts';
116+
import { snapshotAssemblyPresentationViolations } from './snapshot-assembly-presentation-policy.ts';
116117
import { RETIRED_PATH_RULES, retiredPathRuleViolations } from './retired-paths-policy.ts';
117118

118119
const repoRoot = execFileSync('git', ['rev-parse', '--show-toplevel'], {
@@ -435,6 +436,7 @@ export const LAYERING_RULE_IDS = [
435436
'replay-ownership',
436437
'ios-snapshot-engine-ownership',
437438
'provider-snapshot-presentation-ownership',
439+
'snapshot-assembly-presentation-neutrality',
438440
] as const;
439441

440442
export type LayeringRuleId = (typeof LAYERING_RULE_IDS)[number];
@@ -487,6 +489,8 @@ export const LAYERING_RULES: Readonly<Record<LayeringRuleId, LayeringRule>> = {
487489
),
488490
'provider-snapshot-presentation-ownership': (context) =>
489491
providerSnapshotPresentationViolations(context.sources, context.edges),
492+
'snapshot-assembly-presentation-neutrality': (context) =>
493+
snapshotAssemblyPresentationViolations(context.sources, context.edges),
490494
};
491495

492496
export function main(): number {
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
import assert from 'node:assert/strict';
2+
import fs from 'node:fs';
3+
import path from 'node:path';
4+
import { test } from 'node:test';
5+
import {
6+
SNAPSHOT_ASSEMBLY_FILES,
7+
SNAPSHOT_ASSEMBLY_PRESENTATION_RULE,
8+
snapshotAssemblyPresentationViolations,
9+
} from './snapshot-assembly-presentation-policy.ts';
10+
import { resolveImportEdges } from './model.ts';
11+
import { workspaceSpecifierTargets } from './package-boundaries.ts';
12+
import { listTrackedProductionSources } from './tracked-sources.ts';
13+
14+
const repoRoot = path.resolve(import.meta.dirname, '../..');
15+
const assemblyFile = 'src/core/snapshot-state.ts';
16+
const producerAdapter = 'packages/platform-apple/src/snapshot-source/adapter.ts';
17+
18+
function currentSources(overrides: ReadonlyMap<string, string> = new Map()): Map<string, string> {
19+
const sources = new Map(
20+
listTrackedProductionSources(repoRoot).map((file) => [
21+
file,
22+
fs.readFileSync(path.join(repoRoot, file), 'utf8'),
23+
]),
24+
);
25+
for (const [file, source] of overrides) sources.set(file, source);
26+
return sources;
27+
}
28+
29+
function violations(overrides: ReadonlyMap<string, string> = new Map()) {
30+
const sources = currentSources(overrides);
31+
return snapshotAssemblyPresentationViolations(
32+
sources,
33+
resolveImportEdges(sources, workspaceSpecifierTargets(repoRoot)),
34+
);
35+
}
36+
37+
function appended(file: string, addition: string): ReadonlyMap<string, string> {
38+
return new Map([[file, `${fs.readFileSync(path.join(repoRoot, file), 'utf8')}${addition}`]]);
39+
}
40+
41+
test('the snapshot assembly and the producer adapters are presentation-neutral', () => {
42+
assert.deepEqual(violations(), []);
43+
});
44+
45+
test('R74 rejects the assembly importing the iOS snapshot engine', () => {
46+
const result = violations(
47+
appended(
48+
assemblyFile,
49+
`\nimport { presentIosInteractiveSnapshot } from '@agent-device/capture-kit/ios-snapshot-engine';\nvoid presentIosInteractiveSnapshot;\n`,
50+
),
51+
);
52+
53+
assert.ok(
54+
result.some(
55+
(entry) =>
56+
entry.rule === SNAPSHOT_ASSEMBLY_PRESENTATION_RULE &&
57+
entry.file === assemblyFile &&
58+
entry.message.includes('must not import iOS presentation'),
59+
),
60+
JSON.stringify(result),
61+
);
62+
});
63+
64+
test('R74 rejects the assembly reading the producer capability table', () => {
65+
const result = violations(
66+
appended(
67+
assemblyFile,
68+
`\nimport { IOS_SNAPSHOT_PRODUCER_CAPABILITIES } from '@agent-device/capture-kit/ios-snapshot-acquisition';\nvoid IOS_SNAPSHOT_PRODUCER_CAPABILITIES;\n`,
69+
),
70+
);
71+
72+
assert.ok(
73+
result.some(
74+
(entry) =>
75+
entry.rule === SNAPSHOT_ASSEMBLY_PRESENTATION_RULE &&
76+
entry.file === assemblyFile &&
77+
entry.message.includes('ios-snapshot-acquisition'),
78+
),
79+
JSON.stringify(result),
80+
);
81+
});
82+
83+
test('R74 rejects a backend-name presentation branch in the assembly', () => {
84+
const result = violations(
85+
appended(
86+
assemblyFile,
87+
`\nexport function presentsHere(backend: string): boolean {\n return backend === 'xctest';\n}\n`,
88+
),
89+
);
90+
91+
assert.ok(
92+
result.some(
93+
(entry) =>
94+
entry.rule === SNAPSHOT_ASSEMBLY_PRESENTATION_RULE &&
95+
entry.file === assemblyFile &&
96+
entry.message.includes("('xctest')"),
97+
),
98+
JSON.stringify(result),
99+
);
100+
});
101+
102+
test('R74 rejects an assembly branch on a producer name', () => {
103+
const result = violations(
104+
appended(assemblyFile, `\nexport const legacyOwner = 'simulator-ax-bridge';\n`),
105+
);
106+
107+
assert.ok(
108+
result.some(
109+
(entry) =>
110+
entry.rule === SNAPSHOT_ASSEMBLY_PRESENTATION_RULE &&
111+
entry.file === assemblyFile &&
112+
entry.message.includes("('simulator-ax-bridge')"),
113+
),
114+
JSON.stringify(result),
115+
);
116+
});
117+
118+
test('R74 rejects a producer adapter importing iOS presentation', () => {
119+
const result = violations(
120+
appended(
121+
producerAdapter,
122+
`\nimport { presentIosSnapshot } from '@agent-device/capture-kit/ios-snapshot-engine';\nvoid presentIosSnapshot;\n`,
123+
),
124+
);
125+
126+
assert.ok(
127+
result.some(
128+
(entry) =>
129+
entry.rule === SNAPSHOT_ASSEMBLY_PRESENTATION_RULE &&
130+
entry.file === producerAdapter &&
131+
entry.message.includes('producers report acquisition facts'),
132+
),
133+
JSON.stringify(result),
134+
);
135+
});
136+
137+
test('R74 fails closed when the assembly moves out from under it', () => {
138+
const sources = currentSources();
139+
for (const file of SNAPSHOT_ASSEMBLY_FILES) sources.delete(file);
140+
141+
const result = snapshotAssemblyPresentationViolations(
142+
sources,
143+
resolveImportEdges(sources, workspaceSpecifierTargets(repoRoot)),
144+
);
145+
146+
assert.deepEqual(
147+
result.filter((entry) => entry.message.includes('is missing')).map((entry) => entry.file),
148+
[...SNAPSHOT_ASSEMBLY_FILES],
149+
);
150+
});

0 commit comments

Comments
 (0)