refactor(apple): give the foreground probe one result shape

Merged
TH
8h ago
+44-31

This PR applies the optional review items from #4256 and #4257 (https://github.com/callstack/agent-device/pull/4256#issuecomment-6683037208, https://github.com/callstack/agent-device/pull/4257#issuecomment-6683073163). It does not change behavior.

  • One probe result shape. SystemSurfaceForegroundProbe now always returns { foreground, sessionId? }, so the three narrowings in snapshot-route.ts are gone. Only a channel that passes sessionChanged swaps circuits, and a runner-session refusal still disables the bridge only for a circuit that names its session.
  • Realistic fakes. Test fakes without a runner session now answer 'unknown', as the real probe does. Because 'unknown' sends surface hosts to the bridge read, the fake runner refuses that check only when a test sets refuseSurfaceHostCheck.
  • Native wedge test. After the admitted read, the test holds one more read and calls at a time far past the old abandon stamp. It asserts bridge-read-in-flight.
  • lease.ts uses the existing errorMessage(error) helper.

The #4257 description is also corrected: 14 files, and the check receipt for its merged head.

Native evidence: The runner was built with AGENT_DEVICE_XCUITEST_INCLUDE_UNIT_TESTS=1 (Xcode 26.2) and run with xcodebuild test-without-building -only-testing:AgentDeviceRunnerUITests/RunnerTests/testAbandonedReadBecomesWedgedUntilItReturns on a dedicated iOS 26.2 Simulator. It executed 1 test with 0 failures. With both RunnerSnapshotBridgeAbandonedAt = 0 resets removed, the same test fails at the new bridge-read-in-flight assertion (line 100).

TS: packages/platform-apple and the lease handler tests pass (1581 tests).


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Validation: tested at ae570e9d06. pnpm check:affected --run --head ae570e9d06 passed with exactCommit=true (format, lint, typecheck, layering, fallow, native-dupes, build, vitest-related, unit, xctest-selection, packaged-runner-swift).