refactor(ios-runner): charge the text-entry budget the plan the runner posts

Merged
TH
2mo ago
+619-328

Second commit

705ef4bc0 answers the review on #2955's own terms: one step executor serves both synthesized routes. runSynthesizedTextPlan takes the plan, the text, a post closure and the route's warmup read-back, slices the next characters per step, and takes every wait the plan carries. isSpaced and warmupSplit are gone; the phase log's burst/warmup/paced naming derives from the steps themselves. RunnerTests+TextTyping.swift loses 38 net lines and the fill route no longer re-derives anything from delaySeconds.

Closes #2955. The delivery budget from #2904 was a parallel projection: projectedSeconds re-derived the spaced split, the warmup peel and the warmup wait — all decided elsewhere — and under-charged even its own model, counting a select-and-type post as one synthesize call when the bridge runs two (Cmd-A record + text record).

SynthesizedTextPlan now carries the posts a command makes (character counts, whether a post selects first, the wait after it). The budget charges the sum over those steps, and both synthesized routes execute that same array: the loop sleeps the plan's own pauses instead of re-deriving delaySeconds > 0 (twice more, at that). The type route decides the budget once, outside the per-chunk closure, and its budget refusal and synthesizer .fallback arm share one application-wide typing path. The pace moved from the ObjC bridge (whose getter Swift read back through a second source of truth) into TextEntryTiming and is passed to the bridge, so no call site can type at a pace its own budget did not charge. synthesizedAcknowledgeWindowSeconds was production dead weight; it moved into the tests. The fixture's never-asserted edits= counter is gone.

Numbers: fill's admitted length at --delay-ms 0 moves 214 → 212 — honesty about the select-all record the old hint overpromised (at 80 ms both models say 57). The recovery hint now fits the host's 400-char diagnostic bound it previously overflowed by 60, silently losing its last sentence via redactDiagnosticData.

Validation

Head 705ef4bc0. pnpm check:affected --run passed locally (xctest-selection: 0 dark tests; packaged-runner-swift ok) and pnpm check:fallow --base origin/main reports no issues in the changed files.

Local XCUITest evidence on head 705ef4bc0:

  • iOS simulator lane: all 35 text-entry tests across RunnerTests+TextEntryPolicyTests, RunnerTests+SynthesizedTextEntryTests and RunnerTests+TextTypingTests passed (TEST EXECUTE SUCCEEDED), including the two new executor contract tests.
  • macOS host lane: the 21 of those 35 that compile on macOS all passed (TEST EXECUTE SUCCEEDED); the other 14 are os(iOS)-guarded.
  • The pace test's app-side observation and the over-budget refusal, from the runner log on head:
    AGENT_DEVICE_RUNNER_TEXT_ENTRY_ROUTE route=synthesized-first-responder-replacement
    AGENT_DEVICE_RUNNER_TEXT_ENTRY_ROUTE route=synthesized-first-responder-replacement reason=delivery-budget-refused chars=213 budgetChars=212
    AGENT_DEVICE_RUNNER_TEXT_ENTRY_ROUTE route=xctest-application-fallback reason=delivery-budget chars=1 commandChars=213
    AGENT_DEVICE_RUNNER_TEXT_ENTRY_ROUTE route=xctest-application-fallback reason=delivery-budget chars=212 commandChars=213
    
    testSynthesizedReplacementPacesAnAppOwnedFieldAtItsAcknowledgeWindow passed on that first line's route (16.4 s); testOverBudgetTypeWithoutResolvableElementTypesApplicationWide passed reading the field back after the second pair (16.7 s).

Regression evidence (mutation discipline, head 43ea03ca0):

  • synthesizeCallCount → 1 → testSynthesizedPlanChargesAReplacingPostTwoSynthesizeCalls red at both asserts.
  • peelsWarmupCharacter: false (budget ignores the peel) → testOverBudgetTypeWithoutResolvableElementTypesApplicationWide red: route synthesized-first-responder ≠ xctest-application-fallback — proving the peel charge is what makes the over-budget branch reachable.
  • New pins are policy floors, not formula copies: spaced marginal cost ≥ pace+overhead+delay (full delay; 1e-9 only absorbs float accumulation between the two subtracted sums); plan steps cover the text exactly once (lengths 2/3/11/240 × delays 0/0.08); the executor hands each step its own slice, gives a warmup step the read-back with exactly its own characters, and reports only delivered characters when a post stops the plan; append chunks admitted at fill's own advertised budget; hint ≤ 400 chars.

One regression the executor consolidation found and fixed: reading withElement's frame after a post that refused the text turned testBareDelayedTypeFailsWhenTappedInputDisappearsMidCommand into a snapshot error, because the input is gone by then. A stopped plan now answers with its typed failure before touching the target.

Risk: admission tightened by 2 chars for fill at delay 0 (refuses 213–214 that previously shipped and could time out mid-command). type .none burst admission unchanged. Docs need no change; commands.md:491 describes the hint's shape, which is preserved.