Skip to content

Commit c8ec2a4

Browse files
committed
fix(snapshot): admit empty scoped modal captures from complete evidence
1 parent 495c210 commit c8ec2a4

2 files changed

Lines changed: 45 additions & 6 deletions

File tree

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,43 @@ test('snapshot accepts only structured healthy empty scope results', async () =>
432432
});
433433
});
434434

435+
test('scoped modal capture admits complete unscoped evidence without inventing a verdict', async () => {
436+
const note = { code: 'regular-geometry-clipped', clippedNodeCount: 1, droppedNodeCount: 1 };
437+
const qualityPayload = {
438+
nodes: [
439+
{ index: 0, type: 'Alert', label: 'Tracking', rect: { x: 0, y: 0, width: 320, height: 240 } },
440+
],
441+
truncated: false,
442+
};
443+
const capture = (wire: Record<string, unknown>) =>
444+
createAppleInteractor(IOS_SIMULATOR, {}, createLiveTestHostEnvironment(), {
445+
hasLiveSession: () => true,
446+
runCommand: async () => wire,
447+
});
448+
const wire = {
449+
nodes: [],
450+
presentedSurface: 'presented',
451+
qualityPayload,
452+
snapshotQualityNotes: [note],
453+
};
454+
const scoped = presentedSnapshot(await capture(wire).snapshot({ scope: 'missing' }));
455+
assert.deepEqual(scoped.nodes, []);
456+
assert.equal(scoped.quality, undefined);
457+
assert.deepEqual(scoped.qualityNotes, [note]);
458+
for (const rejected of [
459+
{ ...wire, qualityPayload: undefined },
460+
{ ...wire, qualityPayload: { ...qualityPayload, nodes: [] } },
461+
{ ...wire, qualityPayload: { ...qualityPayload, truncated: true } },
462+
{ ...wire, snapshotQuality: { state: 'sparse', backend: 'tree' } },
463+
{ ...wire, presentedSurface: undefined },
464+
]) {
465+
await assert.rejects(capture(rejected).snapshot({ scope: 'missing' }), {
466+
code: 'COMMAND_FAILED',
467+
});
468+
}
469+
await assert.rejects(capture(wire).snapshot(), { code: 'COMMAND_FAILED' });
470+
});
471+
435472
// #1634 P2: the backend pin must actually reach the wire — the daemon test
436473
// stops at the dispatch context and the Swift test starts at the parsed
437474
// command, so this is the assertion that fails if the interactor stops

‎packages/platform-apple/src/interactor.ts‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { withDiagnosticTimer } from '@agent-device/host-kit/diagnostics';
2626
import { isMacOs, isTvOsDevice, type DeviceInfo } from '@agent-device/kernel/device';
2727
import { AppError } from '@agent-device/kernel/errors';
2828
import { withMethodScope } from '@agent-device/kernel/scoped-provider';
29-
import type { Point, SnapshotQualityVerdict } from '@agent-device/kernel/snapshot';
29+
import type { Point } from '@agent-device/kernel/snapshot';
3030
import type {
3131
Interactor,
3232
RunnerCallOptions,
@@ -327,7 +327,7 @@ function assertReportedRunnerSnapshotNodes(
327327
result: AppleRunnerSnapshotResult,
328328
) {
329329
if ((result.nodes?.length ?? 0) > 0) return;
330-
if (acceptsEmptyScopedSnapshot(options, result.quality)) return;
330+
if (acceptsEmptyScopedSnapshot(options, result)) return;
331331
if (device.kind !== 'simulator') return;
332332
throw new AppError('COMMAND_FAILED', 'XCTest snapshot returned 0 nodes on iOS simulator.');
333333
}
@@ -361,12 +361,14 @@ function presentRunnerSnapshotForDevice(
361361

362362
function acceptsEmptyScopedSnapshot(
363363
options: SnapshotOptions | undefined,
364-
quality: SnapshotQualityVerdict | undefined,
364+
result: AppleRunnerSnapshotResult,
365365
): boolean {
366+
if (normalizeSnapshotScope(options?.scope) === null) return false;
367+
if (result.quality) return result.quality.state !== 'sparse';
366368
return (
367-
normalizeSnapshotScope(options?.scope) !== null &&
368-
quality !== undefined &&
369-
quality.state !== 'sparse'
369+
result.presentedSurface === 'presented' &&
370+
result.qualityPayload?.truncated === false &&
371+
result.qualityPayload.nodes.length > 0
370372
);
371373
}
372374

0 commit comments

Comments
 (0)