Skip to content

Commit 2542f67

Browse files
committed
fix(ios): close post-merge audit gaps
1 parent 009be5c commit 2542f67

8 files changed

Lines changed: 168 additions & 20 deletions

File tree

‎docs/adr/0004-ios-snapshot-backend-strategy.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ Android acquisition remains in its platform module and adapts its raw hierarchy
7777
carrier. Swift keeps its runner-side `SnapshotPresentation` implementation because it consumes the
7878
capture-plan tier before the process boundary. The iOS engine fixture is the shared proof between
7979
those runtimes; it does not imply that Swift and TypeScript share an implementation.
80+
The macOS XCTest runner is the desktop-surface exception: its already-presented nodes bypass the iOS
81+
presentation engine and continue through neutral snapshot assembly.
8082

8183
The same split now holds for the three remaining Wave 4 policies tracked by #1983, so
8284
`src/snapshot/` is the host-side owner of snapshot policy generally rather than of presentation

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
"maestro:conformance": "node --experimental-strip-types scripts/node-test-tmpdir.ts --experimental-strip-types --test scripts/maestro-conformance/format-generated-json.test.mjs packages/maestro/test/conformance/verify.test.ts packages/maestro/test/conformance/differential/engine-process.test.ts packages/maestro/test/conformance/differential/report-output.test.ts packages/maestro/test/conformance/differential/run.test.ts packages/maestro/test/conformance/differential/invariants.test.ts",
118118
"maestro:conformance:regenerate": "node --experimental-strip-types scripts/maestro-conformance/regenerate.mjs",
119119
"maestro:conformance:differential": "node --experimental-strip-types packages/maestro/test/conformance/differential/run.ts",
120-
"test:ios-snapshot-differential": "node --experimental-strip-types scripts/node-test-tmpdir.ts --experimental-strip-types --test scripts/ios-snapshot-differential.test.ts",
120+
"test:ios-snapshot-differential": "node --experimental-strip-types scripts/swift-toolchain-tmpdir.ts swift test --package-path apple/snapshot-presentation && node --experimental-strip-types scripts/node-test-tmpdir.ts --experimental-strip-types --test scripts/ios-snapshot-differential.test.ts",
121121
"size": "node scripts/size-report.mjs",
122122
"perf": "node --experimental-strip-types scripts/perf/run.ts",
123123
"mutation:run": "node --experimental-strip-types scripts/mutation/run.ts",

‎packages/platform-apple/src/runner/__tests__/runner-cache-metadata.test.ts‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,58 @@ test('runner cache metadata fingerprints shared snapshot presentation sources',
178178

179179
assert.notEqual(after, before);
180180
});
181+
182+
test('runner cache metadata ignores development-only SwiftPM trees but keeps runner unit tests', () => {
183+
const root = mkdtempForTestSync('agent-device-runner-cache-source-roots-');
184+
onTestFinished(() => fs.rmSync(root, { recursive: true, force: true }));
185+
fs.writeFileSync(path.join(root, 'package.json'), JSON.stringify({ version: '0.0.0' }));
186+
187+
const runnerRoot = path.join(root, 'apple', 'runner', 'AgentDeviceRunner');
188+
const runnerUnitTest = path.join(
189+
runnerRoot,
190+
'AgentDeviceRunnerUITests',
191+
'UnitTests',
192+
'Invariant.swift',
193+
);
194+
const sharedRoot = path.join(root, 'apple', 'snapshot-presentation');
195+
fs.mkdirSync(path.dirname(runnerUnitTest), { recursive: true });
196+
fs.mkdirSync(path.join(sharedRoot, 'Sources'), { recursive: true });
197+
fs.writeFileSync(path.join(runnerRoot, 'Runner.swift'), 'runner\n');
198+
fs.writeFileSync(runnerUnitTest, 'unit-one\n');
199+
fs.writeFileSync(path.join(sharedRoot, 'Sources', 'Presentation.swift'), 'shared\n');
200+
201+
for (const directory of [
202+
'Tests',
203+
'SnapshotPresentationConformance',
204+
'.build',
205+
'.swiftpm',
206+
'xcuserdata',
207+
]) {
208+
const file = path.join(sharedRoot, directory, 'Ignored.swift');
209+
fs.mkdirSync(path.dirname(file), { recursive: true });
210+
fs.writeFileSync(file, 'ignored-one\n');
211+
}
212+
213+
const before = resolveExpectedRunnerCacheMetadata(IOS_SIMULATOR, root).runnerSourceFingerprint;
214+
for (const directory of [
215+
'Tests',
216+
'SnapshotPresentationConformance',
217+
'.build',
218+
'.swiftpm',
219+
'xcuserdata',
220+
]) {
221+
fs.writeFileSync(path.join(sharedRoot, directory, 'Ignored.swift'), 'ignored-two\n');
222+
}
223+
const afterIgnoredChanges = resolveExpectedRunnerCacheMetadata(
224+
IOS_SIMULATOR,
225+
root,
226+
).runnerSourceFingerprint;
227+
assert.equal(afterIgnoredChanges, before);
228+
229+
fs.writeFileSync(runnerUnitTest, 'unit-two\n');
230+
const afterRunnerTestChange = resolveExpectedRunnerCacheMetadata(
231+
IOS_SIMULATOR,
232+
root,
233+
).runnerSourceFingerprint;
234+
assert.notEqual(afterRunnerTestChange, afterIgnoredChanges);
235+
});

‎packages/platform-apple/src/runner/__tests__/runner-xctestrun.test.ts‎

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,33 @@ test('setup metadata script matches expected iOS simulator cache metadata', asyn
256256
path.join(projectRoot, 'apple', 'runner', 'AgentDeviceRunner', 'Runner.swift'),
257257
'final class Runner {}\n',
258258
);
259+
const runnerUnitTest = path.join(
260+
projectRoot,
261+
'apple',
262+
'runner',
263+
'AgentDeviceRunner',
264+
'AgentDeviceRunnerUITests',
265+
'UnitTests',
266+
'Invariant.swift',
267+
);
268+
fs.mkdirSync(path.dirname(runnerUnitTest), { recursive: true });
269+
fs.writeFileSync(runnerUnitTest, 'unit-one\n');
270+
const ignoredSharedSource = path.join(
271+
projectRoot,
272+
'apple',
273+
'snapshot-presentation',
274+
'Tests',
275+
'Ignored.swift',
276+
);
277+
fs.mkdirSync(path.dirname(ignoredSharedSource), { recursive: true });
278+
fs.writeFileSync(ignoredSharedSource, 'ignored-one\n');
259279
const { writeXcuitestCacheMetadata } = await import(
260280
`${pathToFileURL(scriptPath).href}?case=${Date.now()}`
261281
);
262-
writeXcuitestCacheMetadata(['ios', derivedRoot, 'generic/platform=iOS Simulator'], projectRoot);
282+
const firstMetadata = writeXcuitestCacheMetadata(
283+
['ios', derivedRoot, 'generic/platform=iOS Simulator'],
284+
projectRoot,
285+
);
263286

264287
const actual = JSON.parse(
265288
fs.readFileSync(path.join(derivedRoot, '.agent-device-runner-cache.json'), 'utf8'),
@@ -269,6 +292,20 @@ test('setup metadata script matches expected iOS simulator cache metadata', asyn
269292
resolveExpectedRunnerCacheMetadata(iosSimulator, projectRoot);
270293

271294
assert.deepEqual(actualComparable, expectedComparable);
295+
296+
fs.writeFileSync(ignoredSharedSource, 'ignored-two\n');
297+
const secondMetadata = writeXcuitestCacheMetadata(
298+
['ios', derivedRoot, 'generic/platform=iOS Simulator'],
299+
projectRoot,
300+
);
301+
assert.equal(secondMetadata.runnerSourceFingerprint, firstMetadata.runnerSourceFingerprint);
302+
303+
fs.writeFileSync(runnerUnitTest, 'unit-two\n');
304+
const thirdMetadata = writeXcuitestCacheMetadata(
305+
['ios', derivedRoot, 'generic/platform=iOS Simulator'],
306+
projectRoot,
307+
);
308+
assert.notEqual(thirdMetadata.runnerSourceFingerprint, secondMetadata.runnerSourceFingerprint);
272309
});
273310
}, 15_000);
274311

‎packages/platform-apple/src/runner/runner-cache-metadata.ts‎

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ const DEFAULT_IOS_RUNNER_APP_BUNDLE_ID = 'com.callstack.agentdevice.runner';
2626
const RUNNER_DERIVED_ROOT = path.join(os.homedir(), '.agent-device', 'apple-runner');
2727
export const RUNNER_CACHE_METADATA_FILE = '.agent-device-runner-cache.json';
2828
const RUNNER_CACHE_SCHEMA_VERSION = 2;
29+
const RUNNER_SOURCE_IGNORED_DIR_NAMES = new Set(['.build', '.swiftpm', 'xcuserdata']);
30+
const SNAPSHOT_PRESENTATION_SOURCE_IGNORED_DIR_NAMES = new Set([
31+
'.build',
32+
'.swiftpm',
33+
'SnapshotPresentationConformance',
34+
'Tests',
35+
'xcuserdata',
36+
]);
2937
const RUNNER_SANDBOX_BUILD_ARGS = [
3038
'-IDEPackageSupportDisableManifestSandbox=1',
3139
'-IDEPackageSupportDisablePluginExecutionSandbox=1',
@@ -247,12 +255,18 @@ const runnerSourceFingerprintCache = new Map<string, RunnerSourceFingerprintCach
247255

248256
function computeRunnerSourceFingerprint(projectRoot: string): string {
249257
const sourceRoots = [
250-
resolveAppleRunnerSourceRoot(projectRoot),
251-
resolveAppleSnapshotPresentationSourceRoot(projectRoot),
258+
{
259+
path: resolveAppleRunnerSourceRoot(projectRoot),
260+
ignoredDirectoryNames: RUNNER_SOURCE_IGNORED_DIR_NAMES,
261+
},
262+
{
263+
path: resolveAppleSnapshotPresentationSourceRoot(projectRoot),
264+
ignoredDirectoryNames: SNAPSHOT_PRESENTATION_SOURCE_IGNORED_DIR_NAMES,
265+
},
252266
];
253267
const files = collectRunnerSourceFiles(sourceRoots);
254268
const fileStatsFingerprint = computeRunnerSourceFileStatsFingerprint(projectRoot, files);
255-
const cacheKey = JSON.stringify(sourceRoots);
269+
const cacheKey = JSON.stringify(sourceRoots.map(({ path: sourcePath }) => sourcePath));
256270
const cached = runnerSourceFingerprintCache.get(cacheKey);
257271
if (cached?.fileStatsFingerprint === fileStatsFingerprint) {
258272
return cached.sourceFingerprint;
@@ -288,23 +302,40 @@ function computeRunnerSourceFileStatsFingerprint(
288302
return hash.digest('hex');
289303
}
290304

291-
function collectRunnerSourceFiles(roots: readonly string[]): string[] {
292-
return [...new Set(roots.flatMap(collectRunnerSourceFilesUnderRoot))].sort((a, b) =>
293-
a.localeCompare(b),
294-
);
305+
type RunnerSourceRoot = Readonly<{
306+
path: string;
307+
ignoredDirectoryNames: ReadonlySet<string>;
308+
}>;
309+
310+
function collectRunnerSourceFiles(roots: readonly RunnerSourceRoot[]): string[] {
311+
return [
312+
...new Set(
313+
roots.flatMap(({ path: sourcePath, ignoredDirectoryNames }) =>
314+
collectRunnerSourceFilesUnderRoot(sourcePath, ignoredDirectoryNames),
315+
),
316+
),
317+
].sort((a, b) => a.localeCompare(b));
295318
}
296319

297-
function collectRunnerSourceFilesUnderRoot(root: string): string[] {
298-
return fs.existsSync(root) ? collectRunnerSourceFilesInDirectory(root) : [];
320+
function collectRunnerSourceFilesUnderRoot(
321+
root: string,
322+
ignoredDirectoryNames: ReadonlySet<string>,
323+
): string[] {
324+
return fs.existsSync(root)
325+
? collectRunnerSourceFilesInDirectory(root, ignoredDirectoryNames)
326+
: [];
299327
}
300328

301-
function collectRunnerSourceFilesInDirectory(directory: string): string[] {
329+
function collectRunnerSourceFilesInDirectory(
330+
directory: string,
331+
ignoredDirectoryNames: ReadonlySet<string>,
332+
): string[] {
302333
const files: string[] = [];
303334
for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
304335
const fullPath = path.join(directory, entry.name);
305336
if (entry.isDirectory()) {
306-
if (entry.name !== 'xcuserdata') {
307-
files.push(...collectRunnerSourceFilesInDirectory(fullPath));
337+
if (!ignoredDirectoryNames.has(entry.name)) {
338+
files.push(...collectRunnerSourceFilesInDirectory(fullPath, ignoredDirectoryNames));
308339
}
309340
} else if (entry.isFile() && isRunnerSourceFile(entry.name, fullPath)) {
310341
files.push(fullPath);

‎scripts/write-xcuitest-cache-metadata.mjs‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ const USAGE =
1515
'Usage: write-xcuitest-cache-metadata.mjs <ios|macos|tvos|visionos> <derived> <destination>';
1616

1717
const DEFAULT_IOS_RUNNER_APP_BUNDLE_ID = 'com.callstack.agentdevice.runner';
18+
const RUNNER_SOURCE_IGNORED_DIR_NAMES = new Set(['.build', '.swiftpm', 'xcuserdata']);
19+
const SNAPSHOT_PRESENTATION_SOURCE_IGNORED_DIR_NAMES = new Set([
20+
'.build',
21+
'.swiftpm',
22+
'SnapshotPresentationConformance',
23+
'Tests',
24+
'xcuserdata',
25+
]);
1826

1927
function isTruthy(value) {
2028
return ['1', 'true', 'TRUE', 'yes', 'YES', 'on', 'ON'].includes(String(value ?? ''));
@@ -50,8 +58,14 @@ function resolveRunnerTestBundleId() {
5058

5159
function computeRunnerSourceFingerprint() {
5260
const sourceRoots = [
53-
path.join(projectRoot, 'apple', 'runner', 'AgentDeviceRunner'),
54-
path.join(projectRoot, 'apple', 'snapshot-presentation'),
61+
{
62+
path: path.join(projectRoot, 'apple', 'runner', 'AgentDeviceRunner'),
63+
ignoredDirectoryNames: RUNNER_SOURCE_IGNORED_DIR_NAMES,
64+
},
65+
{
66+
path: path.join(projectRoot, 'apple', 'snapshot-presentation'),
67+
ignoredDirectoryNames: SNAPSHOT_PRESENTATION_SOURCE_IGNORED_DIR_NAMES,
68+
},
5569
];
5670
const files = collectRunnerSourceFiles(sourceRoots);
5771
const hash = crypto.createHash('sha256');
@@ -66,7 +80,7 @@ function computeRunnerSourceFingerprint() {
6680

6781
function collectRunnerSourceFiles(roots) {
6882
const files = [];
69-
for (const root of roots) {
83+
for (const { path: root, ignoredDirectoryNames } of roots) {
7084
if (!fs.existsSync(root)) {
7185
continue;
7286
}
@@ -76,7 +90,7 @@ function collectRunnerSourceFiles(roots) {
7690
for (const entry of fs.readdirSync(current, { withFileTypes: true })) {
7791
const fullPath = path.join(current, entry.name);
7892
if (entry.isDirectory()) {
79-
if (entry.name === 'xcuserdata') continue;
93+
if (ignoredDirectoryNames.has(entry.name)) continue;
8094
stack.push(fullPath);
8195
continue;
8296
}

‎src/daemon/__tests__/request-router-screenshot.test.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ test('screenshot --overlay-refs captures a fresh snapshot when the session has n
447447
expect(runtime.binds).toHaveLength(1);
448448
});
449449

450-
test('screenshot --overlay-refs uses interactive iOS presentation for row-like other nodes', async () => {
450+
test('screenshot --overlay-refs uses presented iOS runner rows for overlay refs', async () => {
451451
const screenshotPath = path.join(os.tmpdir(), `agent-device-overlay-ios-${Date.now()}.png`);
452452
const { handler, sessionStore, runtime } = screenshotRouter(makeIosSession('default'), {
453453
onCapture: (input) => writeSolidPng(input.outPath, 402, 874),
@@ -522,7 +522,13 @@ test('screenshot --overlay-refs uses interactive iOS presentation for row-like o
522522
expect(runtime.captureSnapshot.mock.calls[0]?.[0].options).toMatchObject({
523523
interactiveOnly: true,
524524
});
525-
expect(sessionStore.get('default')?.snapshot?.nodes[4]?.type).toBe('Cell');
525+
expect(sessionStore.get('default')?.snapshot?.producer).toBe('apple-runner');
526+
expect(
527+
sessionStore.get('default')?.snapshot?.nodes.find((node) => node.ref === 'e5'),
528+
).toMatchObject({
529+
type: 'Cell',
530+
label: 'Receipt missing details, Receipt scanning failed. Enter details manually.',
531+
});
526532
});
527533

528534
test('screenshot --overlay-refs uses a fresh snapshot instead of stale session snapshot', async () => {

‎test/integration/provider-scenarios/settle-observation.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,9 @@ test('Provider-backed integration modal-dismiss press --settle attaches the unch
456456
// July 2026, org.reactnavigation.playground rne://stack-prevent-remove Input
457457
// screen; `snapshot -i --json` before and after `fill @e6 "hello" --settle`,
458458
// with the 31-key block reduced to 2 representative keys and rects rounded).
459+
// The retained TextField frames are normalized to the visible content frame after trimming, and
460+
// the left candidate-bar height is rounded from 69 to 68; those are intentional fixture
461+
// adjustments, not raw capture claims.
459462
// The load-bearing real-world facts they preserve:
460463
// - The keyboard renders in its OWN window; the "Next keyboard" and "Dictate"
461464
// candidate-bar buttons are SIBLINGS of the [Keyboard] container's wrapper,

0 commit comments

Comments
 (0)