refactor(apple): put the Apple app states at one source and reuse the contract failure
Merged
TH
2mo ago+58+58+01234567890123456789-39-39-01234567890123456789
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_STATESis now the single declaration of theXCApplication.Statenames, andIOS_TARGET_ACTIVATION_PRIOR_STATESderives from it by droppingrunningForeground. Before, the full list spread from the prior-state subset, so the narrower concept owned the names theappStatecommand 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.
AppStateInteractorResolveris now an alias ofLocalInteractorOperationResolver, and the advertised-without-an-implementation failure is built byinvalidRuntimeContractinstead 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). AppleApplicationStatestops re-exporting throughcontracts/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.priorStateas a name instead of an integer. Not safe on this repo's seams:runner-artifact.tsaccepts an operator-supplied.xctestrun(iosXctestrunFile) andAGENT_DEVICE_IOS_RUNNER_DERIVED_PATHoverrides 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
appBundleIdin the Apple input to drop a session check. The two checks are not redundant: one refuses explicit--platformrequests before device resolution, the other decides afterresolveCommandDevicefor 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 theorigin/mainbaseline (no new unused export).pnpm check:daemon-wire-compat: protocol unchanged vsv0.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.