Skip to content

Commit f8b6cfe

Browse files
committed
fix(platform-apple): publish the viewport only when the fold validated it (#3182)
The runner fold published the largest root even on a raw projection, where the engine validates no box at all — reinstating the largest-rect guess #3182 exists to retire under the name of a measured fact, on a payload the regular projection refuses outright. Publication now follows the validated projection, and the absence cases are pinned off the runnerFatal early return.
1 parent c42c083 commit f8b6cfe

2 files changed

Lines changed: 48 additions & 25 deletions

File tree

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

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -348,25 +348,41 @@ test('a capture with no usable viewport box publishes no viewport, never a zero
348348
runnerFatal: true,
349349
});
350350
assert.equal('viewport' in rootless, false);
351+
352+
// The guard itself, off the early return: raw is the projection that validates no box, so it is the
353+
// one that reaches publication still holding an unchecked root. A zero-extent Application there
354+
// must answer with absence rather than the failed read's dimensions.
355+
const rawZero = presentAppleRunnerSnapshot(
356+
'device-1',
357+
{ raw: true },
358+
{
359+
nodes: [{ index: 0, type: 'Application', rect: { x: 0, y: 0, width: 0, height: 0 } }],
360+
},
361+
);
362+
assert.equal('viewport' in rawZero, false);
351363
});
352364

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,
365+
test('a raw projection publishes no viewport, because nothing validated its box (#3182)', () => {
366+
// The engine validates the viewport only for the regular projection. Publishing the largest root
367+
// under `raw` would hand the caller the same largest-rect guess #3182 exists to retire, labelled
368+
// as a measured fact — and the regular path would refuse this very payload.
369+
const presented = presentAppleRunnerSnapshot(
370+
'device-1',
371+
{ raw: true },
372+
{
373+
nodes: [
374+
{ index: 0, type: 'Other', rect: { x: 0, y: 0, width: 120, height: 44 } },
375+
{
376+
index: 1,
377+
parentIndex: 0,
378+
type: 'Button',
379+
label: 'Open',
380+
rect: { x: 16, y: 900, width: 80, height: 32 },
381+
hittable: true,
366382
},
367-
},
368-
],
369-
runnerFatal: true,
370-
});
383+
],
384+
},
385+
);
386+
371387
assert.equal('viewport' in presented, false);
372388
});

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,14 @@ function readSystemSurfaceProvenance(value: unknown): IosSystemSurfaceProvenance
8888

8989
/**
9090
* What one Apple runner capture leaves behind after presentation: the presented tree, and the box
91-
* its rects are measured in (#3182). The viewport is the evidence the fold already resolved — the
92-
* app's own box when the runner read one, otherwise the largest window root in the payload, which on
93-
* tvOS is the screen every `XCUIApplication` rect is measured on — and it is published through the
91+
* its rects are measured in (#3182). The viewport is the evidence the regular fold validated against —
92+
* the app's own box when the runner read one, otherwise the largest window root in the payload, which
93+
* on tvOS is the screen every `XCUIApplication` rect is measured on — and it is published through the
9494
* same guard every other producer passes, so an unusable box stays absent instead of reaching a
95-
* reader as zero. This is the host-side owner ADR 0004 gives the viewport question; the runner
96-
* itself never grows a second wire key for a fact the host already derives from the payload's roots.
95+
* reader as zero. A raw projection and a runner-declared failure publish no box: neither had a
96+
* viewport checked against its tree, so the roots alone would be a guess. This is the host-side owner
97+
* ADR 0004 gives the viewport question; the runner itself never grows a second wire key for a fact
98+
* the host already derives from the payload's roots.
9799
*/
98100
export type AppleRunnerSnapshotPresentation = Readonly<{
99101
nodes: RawSnapshotNode[];
@@ -107,9 +109,8 @@ export function presentAppleRunnerSnapshot(
107109
): AppleRunnerSnapshotPresentation {
108110
const nodes = result.nodes ?? [];
109111
const viewportEvidence = runnerViewportEvidence(nodes, result.qualityPayload?.nodes);
110-
const viewport = viewportSize(viewportEvidence);
111112
if (result.runnerFatal === true || (nodes.length === 0 && result.qualityPayload === undefined)) {
112-
return { nodes, ...(viewport ? { viewport } : {}) };
113+
return { nodes };
113114
}
114115

115116
const request = createIosSnapshotRequest({
@@ -119,6 +120,12 @@ export function presentAppleRunnerSnapshot(
119120
scope: options?.scope,
120121
customActions: options?.customActions,
121122
});
123+
// The engine only validates a box for the regular projection (`presentIosRunnerSnapshot` reads the
124+
// viewport evidence for `regular` and skips it for `raw`), so raw is the one projection where this
125+
// host still holds a root it never checked. Publishing it would reinstate the largest-rect guess
126+
// #3182 exists to retire, under the name of a measured fact.
127+
const validatedViewport =
128+
request.projection === 'regular' ? viewportSize(viewportEvidence) : undefined;
122129

123130
const input: IosSnapshotInput = {
124131
stage: 'presented',
@@ -146,7 +153,7 @@ export function presentAppleRunnerSnapshot(
146153
try {
147154
return {
148155
nodes: presentIosRunnerSnapshot(input, request).nodes,
149-
...(viewport ? { viewport } : {}),
156+
...(validatedViewport ? { viewport: validatedViewport } : {}),
150157
};
151158
} catch (error) {
152159
throwSnapshotPresentationError(error, result);

0 commit comments

Comments
 (0)