feat(snapshot): publish the viewport a snapshot's rects are measured in

Merged
TH
2mo ago
+1219-32

Summary

A snapshot response now carries a response-level viewport: { width, height } — the box the node rects are measured in, in the same coordinate space and orientation as the nodes beside it — so consumers scale and clip against the screen they were shown instead of inferring one from the largest rect (Closes #3182).

Producers answer per their own surface: the Android helper reads the real display extent behind the tree (getMaximumWindowMetrics on API 30+, getRealMetrics below) around each dump and publishes it only when both reads agree; the Apple runner publishes the box the fold validated, which the engine now returns rather than each caller re-deriving; absent means the producer measured nothing, never a zero — snapshotViewportSizeFrom is the sole construction path and the type is branded. The daemon state, digest view, serialization, client, and remote-proxy parity set all carry it.

// snapshot --json
{ "viewport": { "width": 402, "height": 874 }, "nodes": [ ... ] }

45 files: kernel/contracts types, Android helper (Java DisplayExtent) + capture plumbing, Apple presentation, daemon/client/digest seams, tests per seam, docs.

Validation

Tested at 5a05a3ea4: pnpm check:affected --run green (1036 files / 8404 tests, plus helper JVM suite, format, lint, typecheck, layering, fallow, build). All CI lanes green on that head: CI, Android, iOS, macOS, Linux, Size.

Live evidence through the daemon CLI on an API 35 emulator with 3-button navigation (#issuecomment-5988412865): portrait viewport equals wm size and the PNG, with Back/Home/Recents inside (the old app-display read ended above the nav bar); landscape swap with sessionReused/transport=persistent-session; Android --raw publishes the viewport while Apple --raw omits it; empty-screen captures still report it on both.

The Android smoke failure was this PR's, not a flake: the state-seam spread dropped WeakMap-keyed clickability evidence, so Maestro's clickable-first ordering fell back and tapped an inert duplicate. Fixed at the seam with a regression test that fails without it.