@@ -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