fix(ios): make both rect guards refuse the sentinel and let the fold answer clipped carriers

Merged
TH
2mo ago
+365-46

Follow-up to #2908, which merged before this review round finished. Carries the four findings against #2891; nothing merged is reverted.

Summary

Both guards refuse the box a failed read leaves behind. The TypeScript isPositiveFiniteRect accepted CGRect.infinite: its four components are finite, and so are both extents, so a check that reads only components or only extents waves it through. It also accepted finite components whose extents overflow. The Swift isPositiveFinite already refused the sentinel by identity, but it too accepted the overflowing shape. Both now refuse non-finite components, non-finite extents, and CG_RECT_INFINITE by value, so the sentinel is unusable on both sides of the boundary instead of only where an Apple frame is parsed. Every other box is classified the same as before; the narrowing is stated in the ADR rather than in prose.

A box is checked where it is made. Box(checked:) is the in-module path from a CGRect to a declared fact, and the viewport factories turn refusal into .missing(reason: .invalid). There is no longer a way to hold a Box that the shared guard would refuse.

The fold answers a carrier its own clip already decided. Application and Window are exempt from visibility, so a retained carrier can reach the fold with a degenerate clipped frame and no source bit. The merged flatMap published nil there, which reads as "containment is undecided" about a node the policy already refuses. clippedHittability keeps the source's own false first, answers from the clipped frame second, and withholds only when containment is the open question.

The golden table says what it runs. The sentinel row now executes in both languages, a row with finite components and a non-finite extent pins the overflow refusal in both, a nonfinite row is labelled as pinning the guard rather than a producer, and a row declaring false in both languages is rejected by both readers instead of being silently skipped.

SnapshotBridgeRuntime.m is deliberately unchanged. Refusing to serialize a box there would turn "the source reported an unusable frame" into "the source reported no frame", which is a different claim about the device, and that file has no test seam to notice the difference.

Validation

Tested SHA 1e1fa90d84, on top of origin/main at fa1082dd14.

  • pnpm test:ios-snapshot-differential: Swift 17 tests, node 6, 0 failures. The sentinel row now runs in both languages.
  • pnpm check:xctest-selection: 321 declared RunnerTests methods, 0 reachable by no lane. check:layering and the eager-closure budget pass, and presentIosRunnerSnapshot keeps its zero fold call count.
  • Runner test target built with AGENT_DEVICE_XCUITEST_INCLUDE_UNIT_TESTS=1 on an iPhone 17 / iOS 26.2 simulator: Executed 9 tests, with 0 failures, including both new cases and testRegularFoldKeepsWindowCarriersButNeverHittableOutsideClip, the reported-viewport neighbour of the new fold policy.
  • Reverts fail where they should: dropping the Swift sentinel refusal fails ActionabilityPolicyTests, dropping the TypeScript one fails rect.test.ts and tree.test.ts, and a false/false row fails both table readers.
  • Live A/B on one simulator, open com.apple.Preferences, this head against an fa1082dd14 runner on separate derived paths: snapshot --json and snapshot -i --json return the same ordered payload โ€” 58 nodes (52 true, 6 false, none absent) and 18 (16, 2, none absent). Only snapshotDiagnostics timings and refsGeneration differ.
  • ios-lifecycle.test.ts passes at this head and at clean fa1082dd14; the earlier failure did not reproduce.
  • A fourth adversarial round closed the fold policy and its proof and found four claims wider than the code, all corrected in the last commit.
  • `pnpm check:affected --run__:AFFECTED_PLACEHOLDER__

Not checked live: a .missing viewport cannot be forced on a device, so the absent-bit and fold paths are unit-covered only.