Skip to content

Take the engine and iPhone tests off the wall clock - #380

Merged
alexkroman merged 12 commits into
mainfrom
fix/tests-off-the-wall-clock
Nov 25, 2026
Merged

alexkroman merged 12 commits into
mainfrom
fix/tests-off-the-wall-clock

Conversation

@alexkroman

Copy link
Copy Markdown
Collaborator

Takes the engine and iPhone unit tests off the wall clock wherever a slow CI runner could fail them spuriously.

What prompted this

SelectionSpeechRouterLifecycleTests.heldReadStartsAfterTheDelay failed on #376's CI run with CancellationError: it polled waitUntil (a real 5 s timeout) for a read driven by a real 300 ms hold timer, and the runner's main actor stalled for seconds. The same pattern was elsewhere: real production timers awaited with bounded polls, elapsed-time assertions, and fixed sleeps standing in for an event.

Production seams (all default to real time, so behavior is unchanged)

  • StreamingPCMPlayer(clock:): drain()'s deadline and polls run on it. New drainPollCeiling names the existing 100 ms cap.
  • KeyboardRelayInjector(clock:): the delivery poll, re-signal and 3 s timeout run on it. The deadline is now measured on a monotonic clock rather than Date().
  • KeyboardModel.clock: handshake ticks, notice dwell/clock, term check, leave grace and heartbeat sleep on it.

Engine tests

  • The hold-timer tests now step a TestClock. That covers the held read itself and speakHeldPress, which all 34 Rewrite/Compose/Command tests go through (they only became holds when the real 300 ms timer fired). styleReachesTheAnswer also steps its 400 ms cue gap.
  • Stepping exposed a race the real delay hid: a press could open the mic before the session's replayed idle reached the router, which then took it for its own request's end. The new wirePhases(of:to:) waits for that replay before pressing.
  • StreamingPCMPlayerTests bound the drain in virtual time instead of timing it.
  • LongReadTests, SelectionSpeakerTests (meter), ChunkedRequestBodyTests and SpeechTransportTests wait for the event itself instead of a fixed sleep.
  • .timeLimit(.minutes(1)) is added to suites whose new waits are unbounded, so a stuck wait fails instead of hanging.

iPhone tests

  • The relay timeout test steps all 12 polls instead of asserting >= 2.5 s elapsed. The delivered tests take the result once written instead of after 300 ms.
  • The press-timer, notice-dwell, held-error, term-dwell and leave-grace tests advance the model's clock.
  • The watchdog and hop-return tests wait for the sleeper to park before advancing (the race Fix flaky hop-return cap test under the address sanitizer #353 fixed for the cap). The resume poll steps on its sleeper.
  • Two "nothing happened" window checks use the inbox's FIFO order and record sequence instead of a sleep. The lexicon stamp is bracketed instead of compared to "< 5 s ago".

Left on purpose

  • "Sleep, then expect nothing happened" checks where no deterministic signal exists without exposing private tasks: Lifecycle ×5, Rewrite, Compose, Command, and two DictationCoordinatorTests. These can't fail spuriously; a slow runner only weakens them.
  • Poll steps inside helpers, the 60 s "hang" fakes, the deliberate DictationPerformanceTests budget, and the hardware/live harnesses (BLURT_LIVE_AUDIO_TESTS, .drivesThisMac, BLURT_PLANNER_EVAL, all gated off by default).

Verification

  • swift build --build-tests -Xswiftc -warnings-as-errors: clean.
  • Full swift test: 1304 tests in 192 suites pass. Every touched suite passed 5 runs in a row.
  • scripts/ios-test.sh, 3 runs: 365 tests pass, BlurtiOSCore coverage 96.12%. The two-process contract suite dropped from ~3.5 s to 0.12 s.
  • swift-format (strict) and swiftlint are clean on every changed file. check-invariants.sh passes.

🤖 Generated with Claude Code

alexkroman-assembly and others added 3 commits November 24, 2026 15:12
Timing a real 300 ms timer against a 5 s poll failed on a loaded CI runner
whose main actor stalled for seconds (CancellationError from waitUntil).
The TestClock proves the same thing deterministically: the timer waits the
hold delay exactly, nothing starts before it fires, the read starts after.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…them

Timers the tests waited on behind a bounded poll, and elapsed-time
assertions, could fail spuriously on a loaded CI runner, as
heldReadStartsAfterTheDelay did. They now step a TestClock or wait for the
event itself:

- StreamingPCMPlayer takes a clock (default ContinuousClock, so production
  is unchanged); its tests bound the drain in virtual time instead of
  timing it, by the new drainPollCeiling rather than seconds of margin.
- The rewrite, compose and command suites became holds only when the real
  300 ms hold timer fired. speakHeldPress now steps the router's TestClock,
  and so does styleReachesTheAnswer, for its hold and the answer's cue gap.
  Stepping exposed a race the delay hid: a press whose mic opened before
  the phase stream's replayed idle took that idle for its own end.
  wirePhases waits for the replay before pressing.
- pacesByPlayback waits for the room check that holds the next piece back,
  the meter test's sink plays until the meter has heard it, the writer
  cancellation test waits for bytes in the pipe, and the URLSession
  cancellation waits for the first audio rather than 50 ms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…real time

BlurtiOSTests waited real seconds for production timers and asserted on
elapsed wall time, so a loaded runner whose main actor stalled could fail
them spuriously. Two production seams, both defaulting to real time:

- KeyboardRelayInjector takes a `clock:` (ContinuousClock by default); the
  delivery poll, re-signal and timeout run on it. The relay tests drive it
  with TestClock: the timeout test steps every poll and checks the result is
  still waiting before the last, instead of asserting >= 2.5 s elapsed; the
  delivered tests take the result once written rather than after 300 ms.
- KeyboardModel.clock: the handshake ticks, notice dwell and clock, term
  check, leave grace and heartbeat sleep on it. The press-timer, notice
  dwell, held error, term dwell and leave-grace tests advance it instead of
  sleeping or polling against the real timer.

Elsewhere: the coordinator's watchdog and hop-return cap tests wait for the
sleeper to park before advancing (the race #353 fixed for the cap), and
prove a stood-down timer by its sleeper leaving the clock; the resume poll
steps on its sleeper instead of 10 ms sleeps; two "nothing happened" window
checks use the inbox's FIFO order and the record sequence instead of a
sleep; the lexicon stamp is bracketed rather than compared to "< 5 s ago".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@alexkroman
alexkroman enabled auto-merge November 24, 2026 23:27
@alexkroman
alexkroman disabled auto-merge November 25, 2026 00:06
@alexkroman
alexkroman added this pull request to the merge queue Nov 25, 2026
…eld-read test

#375 gave the relay a ResultAddress presser; the injected clock now sits
beside it, and the delivered test steps the clock while asserting the
controller. #370 independently moved the held-read test onto a TestClock
with its own press helper; its version is kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@alexkroman
alexkroman removed this pull request from the merge queue due to a manual request Nov 25, 2026
alexkroman-assembly and others added 5 commits November 24, 2026 17:01
… hold

Every KeyboardRig model read the wall clock, so on an ASan or loaded CI
runner more than the 350 ms hold threshold could pass between a tap's
micDown and micUp, and the tap's lift sent a release (the × test saw
[press, release, cancel]). The rig now holds time still unless a test
moves it. The one fuzz test that ages records by Date() opts back into
the wall clock.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…edes #357's widened wall-clock one

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With main, the suite's struct body reached 253 lines (type_body_length
250). The suite already splits by topic (+Latch, +Undo); the stepped retry
and deadline get their own file, which keeps this PR clear of the gate
tests #378 also moves.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	App/BlurtiOS/BlurtiOSCore/KeyboardRelayInjector.swift
# Conflicts:
#	App/BlurtiOS/BlurtiOSTests/ProtocolTests.swift
@alexkroman
alexkroman enabled auto-merge November 25, 2026 02:54
-warn-long-function-bodies / -warn-long-expression-type-checking measure
how long the compiler took, which varies with a CI runner's load; with
every warning an error they made the build nondeterministic. They failed
#384's merge-queue compile on a test that took 729 ms against the 500 ms
limit, while the run beside it passed. Every remaining strict setting gives
the same answer on every machine.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@alexkroman
alexkroman added this pull request to the merge queue Nov 25, 2026
@alexkroman
alexkroman removed this pull request from the merge queue due to a manual request Nov 25, 2026
@alexkroman
alexkroman enabled auto-merge November 25, 2026 03:57
@alexkroman
alexkroman added this pull request to the merge queue Nov 25, 2026
Merged via the queue into main with commit c9bcd0f Nov 25, 2026
15 checks passed
@alexkroman
alexkroman deleted the fix/tests-off-the-wall-clock branch November 25, 2026 05:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants