refactor(apple): put the Apple app states at one source and reuse the contract failure

Merged
TH
2mo ago
+58-39

Summary

Follow-up to #2929 that resolves the duplication that PR surfaced, without touching the runner wire.

  • State lists point the right way. APPLE_APPLICATION_STATES is now the single declaration of the XCApplication.State names, and IOS_TARGET_ACTIVATION_PRIOR_STATES derives from it by dropping runningForeground. Before, the full list spread from the prior-state subset, so the narrower concept owned the names the appState command answers with. Behavior and order are unchanged; the decoder's raw table and the native SDK pins still verify the mapping.
  • The Apple binder stops restating contracts. AppStateInteractorResolver is now an alias of LocalInteractorOperationResolver, and the advertised-without-an-implementation failure is built by invalidRuntimeContract instead of a second copy of the code, reason, and hint. That failure branch had no test; it now has one pinning the typed reason, which is what keeps it outside every closed reason set that licenses answering from the session record (ADR 0019 §2).
  • AppleApplicationState stops re-exporting through contracts/app-state-runtime; the kernel is its declaration site and both consumers read it there.

Evaluated and skipped from the same review, with reasons:

  • Send targetActivation.priorState as a name instead of an integer. Not safe on this repo's seams: runner-artifact.ts accepts an operator-supplied .xctestrun (iosXctestrunFile) and AGENT_DEVICE_IOS_RUNNER_DERIVED_PATH overrides the derived path, and neither spends the runner-source fingerprint that guards cache reuse and lease adoption. A daemon can therefore reach a runner it did not build, and the numeric table plus the native raw-value pins (#2726) are what catch SDK drift on that path.
  • Require appBundleId in the Apple input to drop a session check. The two checks are not redundant: one refuses explicit --platform requests before device resolution, the other decides after resolveCommandDevice for selector-targeted requests.
  • Share one Swift helper across the app-state switches. The switches answer different questions (wire naming, alert-observation eligibility, foreground-host policy); merging them couples unrelated policies.

9 files, +58/−39. No CLI, MCP, docs, or wire change.

Validation

Tested at d76aeb214.

  • pnpm check:affected --run: all runnable checks passed (format, lint, typecheck, layering, di-seams, fallow, mcp-metadata, build, package, integration-node, macos-coverage, vitest-related, integration-progress, replay-compat, daemon-wire-compat, affected-selector, and the model/tooling suites).
  • pnpm test:unit: 1403 files / 11374 tests passed.
  • pnpm check:fallow --base origin/main: no issues in the 9 changed files.
  • pnpm check:production-exports: 68 findings, identical to the origin/main baseline (no new unused export).
  • pnpm check:daemon-wire-compat: protocol unchanged vs v0.21.14.
  • New test is a real regression proof: replacing the contract-bug throw with a silent {} fails only that test.

No device-facing behavior changed, so no device runs apply.