Skip to content

Commit 024a3a8

Browse files
committed
test(platform-apple): pin the viewport an Apple capture publishes (#3182)
The capture publishes the fold's app-window evidence, follows the quality payload the fold prefers, refuses zero/infinite boxes as absence, and the desktop runner publishes none because window-space rects answer to no single box.
1 parent 8297839 commit 024a3a8

2 files changed

Lines changed: 131 additions & 0 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import assert from 'node:assert/strict';
2+
import { test } from 'vitest';
3+
import { IOS_SIMULATOR, MACOS_DEVICE } from './device-fixtures.ts';
4+
import { createAppleInteractor } from '../interactor.ts';
5+
import { runnerResultFor } from './recording-runner-provider.ts';
6+
7+
// #3182: an Apple capture publishes the box its rects are measured in — the app-window evidence the
8+
// presentation fold already resolves — without the runner growing a second wire key for it.
9+
10+
test('an Apple runner capture publishes the app-window box its rects are measured in (#3182)', async () => {
11+
const interactor = createAppleInteractor(
12+
IOS_SIMULATOR,
13+
{},
14+
{ hasLiveSession: () => true, runCommand: async () => runnerResultFor({ command: 'snapshot' }) },
15+
);
16+
17+
const result = await interactor.snapshot();
18+
if ('stage' in result) throw new Error('Apple runner snapshot must be presented');
19+
20+
assert.deepEqual(result.viewport, { width: 390, height: 844 });
21+
});
22+
23+
// The desktop runner's nodes are absolute in window space (#2891), which no single box describes —
24+
// a published viewport would claim a screen the coordinates do not answer to.
25+
test('a macOS app capture publishes no viewport (#3182)', async () => {
26+
const nodes = [
27+
{
28+
index: 0,
29+
type: 'Application',
30+
label: 'System Settings',
31+
rect: { x: 3200, y: -180, width: 1440, height: 900 },
32+
},
33+
];
34+
const interactor = createAppleInteractor(
35+
MACOS_DEVICE,
36+
{},
37+
{ hasLiveSession: () => true, runCommand: async () => ({ nodes }) },
38+
);
39+
40+
const result = await interactor.snapshot({ interactiveOnly: true });
41+
if ('stage' in result) throw new Error('Apple runner snapshot must be presented');
42+
43+
assert.equal(result.nodes?.length, 1);
44+
assert.equal('viewport' in result, false);
45+
});

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

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,3 +284,89 @@ test('a malformed keyboard payload is restated by the kernel reader, never forwa
284284
assert.deepEqual(read, { kind: 'unmeasurable', reason }, `payload ${JSON.stringify(payload)}`);
285285
}
286286
});
287+
288+
// #3182: the response publishes the box the fold already resolved for the presentation, never a
289+
// second box and never a zero. The viewport the validator receives and the viewport the capture
290+
// publishes must be the same evidence — if the fold validated against one box and the response
291+
// published another, a consumer scaling rects against `viewport` would scale against a screen the
292+
// numbers were never checked against.
293+
test('the published viewport is the root box the presentation validated against (#3182)', () => {
294+
const screen: RawSnapshotNode = {
295+
index: 0,
296+
type: 'Application',
297+
rect: { x: 0, y: 0, width: 390, height: 844 },
298+
};
299+
const button: RawSnapshotNode = {
300+
index: 1,
301+
parentIndex: 0,
302+
type: 'Button',
303+
label: 'Open',
304+
rect: { x: 16, y: 400, width: 80, height: 32 },
305+
hittable: true,
306+
};
307+
308+
const presented = presentAppleRunnerSnapshot('device-1', undefined, {
309+
nodes: [screen, button],
310+
});
311+
312+
assert.deepEqual(presented.viewport, { width: 390, height: 844 });
313+
});
314+
315+
test('the published viewport follows the quality payload the fold prefers (#3182)', () => {
316+
// A scoped capture can carry an unscoped quality payload whose Application root is the screen;
317+
// the fold resolves the viewport from those roots, and the response must publish that same box.
318+
const scopedRoot: RawSnapshotNode = {
319+
index: 0,
320+
type: 'Application',
321+
rect: { x: 0, y: 100, width: 390, height: 400 },
322+
};
323+
const qualityRoot: RawSnapshotNode = {
324+
index: 0,
325+
type: 'Application',
326+
rect: { x: 0, y: 0, width: 390, height: 844 },
327+
};
328+
329+
const presented = presentAppleRunnerSnapshot('device-1', undefined, {
330+
nodes: [scopedRoot],
331+
qualityPayload: { nodes: [qualityRoot], truncated: false, scope: null },
332+
});
333+
334+
assert.deepEqual(presented.viewport, { width: 390, height: 844 });
335+
});
336+
337+
test('a capture with no usable viewport box publishes no viewport, never a zero (#3182)', () => {
338+
// `runnerFatal` skips presentation, so this exercises the publication seam alone: a zero-extent
339+
// root is the failed Apple read, and the guard must answer with absence.
340+
const fatalZero = presentAppleRunnerSnapshot('device-1', undefined, {
341+
nodes: [{ index: 0, type: 'Application', rect: { x: 0, y: 0, width: 0, height: 0 } }],
342+
runnerFatal: true,
343+
});
344+
assert.equal('viewport' in fatalZero, false);
345+
346+
const rootless = presentAppleRunnerSnapshot('device-1', undefined, {
347+
nodes: [{ index: 0, type: 'Other' }],
348+
runnerFatal: true,
349+
});
350+
assert.equal('viewport' in rootless, false);
351+
});
352+
353+
test('the infinite viewport a failed Apple read crosses the wire as never publishes (#3182)', () => {
354+
// `CGRectInfinite` is finite in every component and maximal in extent: without the shared guard
355+
// it would publish the largest box on the wire as the screen.
356+
const presented = presentAppleRunnerSnapshot('device-1', undefined, {
357+
nodes: [
358+
{
359+
index: 0,
360+
type: 'Application',
361+
rect: {
362+
x: -Number.MAX_VALUE / 2,
363+
y: -Number.MAX_VALUE / 2,
364+
width: Number.MAX_VALUE,
365+
height: Number.MAX_VALUE,
366+
},
367+
},
368+
],
369+
runnerFatal: true,
370+
});
371+
assert.equal('viewport' in presented, false);
372+
});

0 commit comments

Comments
 (0)