Skip to content

iPhone tests: deterministic audits and timers, no re-run fallbacks - #447

Merged
alexkroman merged 8 commits into
mainfrom
claude/serene-albattani-ru7wt2
Nov 27, 2026
Merged

alexkroman merged 8 commits into
mainfrom
claude/serene-albattani-ru7wt2

Conversation

@alexkroman

@alexkroman alexkroman commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

What & why

This fixes several sources of random red on the iPhone jobs. Each one is fixed at its cause, never by re-running or retrying.

1. Accessibility audits (ios-audits, shard a)

Across the last 100 check.yml runs (Nov 25–27), 7 of the ~74 that finished failed on two audit findings. 4 of those were merge-queue runs, where a failure ejects the PR:

  • testSettings, 4 runs: "Dynamic Type unsupported" on Settings page 3's last rows.
  • testConsent, 3 runs: "Text clipped" on "The text just before your cursor".

auditScrolling paged with swipeUp(), a fling, so a slow runner audited each page at a slightly different scroll position.

Changes

  • Pages are reached with a slow drag that holds still before lifting (drag). scrollTo uses it too. The page limit goes from 16 to 24.
  • A ScalingCheck failure gives the measured heights, or says the text was never fully in view.
  • Fallbacks removed: the second tap in testConsent, the re-run after an audit timeout, and the second audit pass whose findings had to repeat.

What the fixed paging showed: this PR's first run put the consent row mid-screen (y 316.7), and the audit still flagged it. So that finding was never about the bar's edge: it had only passed when the fling left the row under the bar, where it was excused. #445, merged into this branch, already excuses the four consent rows by their exact text, based on the audit's own screenshot showing the row whole. Its comment now says the finding is consistent, not intermittent.

2. Unit-test timing races (ios-build, ios-sanitizers)

Test Failure Cause Fix
acceptedPress timed out after 40 s (run 45935799021) .connecting lasted a 200 ms real sleep, and the test's poll missed it the fake holds start() until the test calls releaseStart()
windowMinutesChanged timed out (same run, address sanitizer) the clock advanced before the expiry timer's task had started waiting advance only once a timer is waiting (WindowRig.step)
pressWhileClosing not seen failing; same race as acceptedPress polled for a .closing that lasted a 400 ms real sleep a hold, released by the test
recovers (keyboard random-sequence test) .press instead of .release, and a missing dictation id (run 45717226112, 24 s) ran on the real clock: a stalled runner let the 1.2 s press deadline pass between a tap and its answer keeps the rig's held time; the record ages against that time

#445 also fixed acceptedPress and windowMinutesChanged, a different way. This PR's versions replace both.

Shared changes

  • Holds instead of sleeps. A new Hold type replaces every real sleep in the fakes: start, close and the idle mode's close.
  • Clock waits are bounded. Heartbeat and resume-poll steps go through WindowRig.step/beat(). Every iPhone TestClock.waitUntilSleeping becomes parked(on:for:), the same wait capped like until. The engine's tests keep waitUntilSleeping, since their suites have a .timeLimit; it's marked with the cross-scan periphery:ignore.

3. App code: no wall-clock reads beside the injected clock

  • ListeningWindow takes now, as DictationCoordinator does, and no longer reads Date() for its records or its expiry. The app passes { Date() }.
  • The coordinator's recording start, recording length and phase timestamp use its injected now. The 80 ms meter throttle times itself on the injected clock, which is still ContinuousClock in the app.

The app's behavior is unchanged. A Swift 6 concurrency review found no issues.

Caveat: the coordinator tests now run on two time bases. The coordinator's now is frozen, while the window's moves with the test clock. No current test depends on this. A future test that feeds coordinator snapshots into a KeyboardModel would see identical at stamps, which the model uses as a notice's identity.

What to watch: DictationCoordinator.swift is at 396 of its 400-line limit, so a parallel PR that grows it could fail the size check.

How it was tested

Written in a Linux sandbox, which can't build or run the iPhone app or tests. CI on e8051d5 is green across every job: the iPhone audits, unit tests and both sanitizers, ios-static, live-tests, and the Mac jobs. Locally: swift-format, swiftlint lint --strict, the size, lint-lite and test-clock checks, and scripts/check.sh --portable all pass.

  • scripts/check.sh passes (or CI will, if I'm not on a Mac)
  • I read AGENTS.md and this doesn't reintroduce anything deliberately removed
  • Docs updated if behavior changed (doc comments on everything changed)

🤖 Generated with Claude Code

https://claude.ai/code/session_01DS5B1Thm9A5RTqE6KU3jvP

auditScrolling reached each page with swipeUp, a fling that travels as far
as the touch events' timing makes it, so a slow CI runner audited each page
at a slightly different scroll position. The two audits that still failed
intermittently both sat on that edge: testConsent's "Text clipped" on a row
whose y moved 181.7–184 between failures, by the bar's scroll-edge band, and
testSettings' "Dynamic Type unsupported" on the rows beside the tab bar at
the foot of the last page (7 of ~74 completed check.yml runs, Nov 25–27, 4
of them merge-queue ejections). Pages are now reached by a slow drag that
holds still before lifting (`drag`), so every run audits the same screens;
scrollTo uses the same drag.

Removed the fallbacks that re-ran something hoping for a different answer:
the second tap on testConsent's switch, the re-run of an audit pass XCTest
timed out on, and the second audit whose findings had to repeat.

A ScalingCheck failure now says what it measured: the text's height at the
default size and at the largest, or that it never came fully into view
there, since the log line is all a CI failure leaves most readers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DS5B1Thm9A5RTqE6KU3jvP
Two iPhone unit tests timed out at random after #439, each waiting its
whole 30 s `until` for a state that had already passed or never came:

- acceptedPress: FakeListeningSource held a press's start for 200 ms of
  wall time to make `.connecting` visible, while the test polled for it on
  the main actor. On a loaded runner the main actor was busy past 200 ms,
  `.connecting` gave way to `.recording` unseen, and the test failed at
  ~40 s (run 45935799021, ios-build). The fake now holds start() until the
  test calls releaseStart(), so the phase lasts until it has been checked.
- windowMinutesChanged: the test advanced the clock as soon as the record
  showed the shorter window, but the expiry timer is a task that parks on
  the clock when it next runs. Advanced first, it parked a minute past the
  step and never fired (same run, ios-sanitizers address).

WindowRig.step(_:once:) advances only once a timer due within the given
range has parked, bounded as `until` is; beat() is that for one heartbeat.
Every heartbeat and resume-poll step in the window tests uses them, the
unbounded waitUntilSleeping included, since these suites carry no
.timeLimit to end a sleeper that never arrives.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DS5B1Thm9A5RTqE6KU3jvP
@alexkroman alexkroman changed the title iPhone audits: page by a fixed drag, drop the re-run fallbacks iPhone tests: fixed-drag audit paging, no re-run fallbacks, unit-test timing races Nov 27, 2026
The window and the coordinator still read the device's time beside the
clock they are given, and the fakes still modelled slow steps with real
sleeps:

1. ListeningWindow takes `now`, as DictationCoordinator does, and stamps
   its records and measures its expiry from it rather than Date(). The app
   passes { Date() }; WindowRig passes the rig's build time moved on only
   by its TestClock, so a one-minute expiry sleeps a minute on the clock
   (to a Date's rounding) and windowMinutesChanged waits for a timer due
   59–60 s out, not 50–60. The window tests read the lease against rig.now.
2. FakeListeningSource's closeDelay and FakeIdle's closingDelay become
   holds the test releases (Hold, which the start hold now uses too).
   pressWhileClosing polled for `.closing` across a 400 ms real sleep, the
   same race acceptedPress had; reopenDuringClose and
   hopWaitsForTheIdleMode now also check the window waits while held,
   which a delay could only let pass unproven.
3. The coordinator's recordingSince, spoken duration and phase stamp use
   its injected `now`, and the meter's 80 ms throttle times itself on its
   injected clock (still ContinuousClock in the app) rather than Date(),
   which can jump back and freeze the meter.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DS5B1Thm9A5RTqE6KU3jvP
The keyboard fuzz's recovery test ("from any state, an appearance is a
clean keyboard that can dictate") ran on the wall clock so its dying app's
record could age by Date(). On a stalled runner (24 s for the test, run
45717226112) the 1.2 s press deadline passed between a tap and its started
ack: the ack landed on an expired press, and the second tap went out as a
new press with no dictation, the two failures that run recorded. It now
keeps the rig's held time, and KeyboardRig.record/listening age the record
against it (`now:`), so the lease still lapses and nothing else can.

Every remaining TestClock.waitUntilSleeping in the iPhone tests becomes
`parked(on:for:)`, the same wait bounded as `until` is: these suites carry
no .timeLimit, so a timer that never parked hung the run instead of failing
its test.

From the concurrency review of the previous commit: Hold documents that a
held step must be released on every path, and reopenDuringClose drops an
assertion that held whether or not the close was held.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DS5B1Thm9A5RTqE6KU3jvP
@alexkroman alexkroman changed the title iPhone tests: fixed-drag audit paging, no re-run fallbacks, unit-test timing races iPhone tests: deterministic audits and timers, no re-run fallbacks Nov 27, 2026
…g fixes

#445 excused "text clipped" on the consent sheet's four disclosure rows,
from the audit's own screenshot showing the row whole. With #447's fixed
drag, run 46010398262 (ios-audits a) put the row mid-screen at y 316.7 and
the audit still raised it: it was never about the bar's edge, the fling
only sometimes parked the row under the bar, where it was excused anyway.
The exception is the fix; its comment now says the finding is consistent.

#445 also fixed acceptedPress (the start delay on the rig's TestClock) and
windowMinutesChanged (waiting for an expiry parked 30–60 s out). This
branch's versions replace both — the start held until the test releases
it, the expiry exactly a minute on the window's injected clock — so the
four conflicted test files keep this branch's side; main's diff to them
was only those two fixes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DS5B1Thm9A5RTqE6KU3jvP
ios-static's build (run 46012952910) refused `Self.stopwatch(on: clock)`
in the level loop: "type 'any Clock<Duration>' cannot conform to 'Clock'"
— Xcode's compiler would not open the stored existential there, though it
opened the init's `clock` parameter in the same call. The generic is now
called only in init, as `stopwatches(on:)`, and returns a maker the loop
calls for each new stopwatch.

swiftlint analyze: DictationCoordinator+Publish.swift no longer needs
Foundation now that it stamps the phase with `now()`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DS5B1Thm9A5RTqE6KU3jvP
ios-sanitizers (address), run 46014211769: "cannot find type 'Date' in
scope" at WindowRig's `var now: Date`. The rig named no Foundation type
before this PR, and MemberImportVisibility wants each file to import what
it names itself.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DS5B1Thm9A5RTqE6KU3jvP
ios-static's periphery (run 46015518999) found TestClock's
waitUntilSleeping unused: this PR moved every iPhone test onto the bounded
parked(on:for:), and the iPhone scan indexes this shared stub with only the
iPhone tests. The engine's tests still call it (22 times), under suites
with a .timeLimit; marked with the repo's cross-scan periphery:ignore,
above the doc comment as the repo places it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DS5B1Thm9A5RTqE6KU3jvP
@alexkroman
alexkroman added this pull request to the merge queue Nov 27, 2026
Merged via the queue into main with commit 9101725 Nov 27, 2026
22 checks passed
@alexkroman
alexkroman deleted the claude/serene-albattani-ru7wt2 branch November 27, 2026 15:41
alexkroman pushed a commit that referenced this pull request Nov 27, 2026
…hange

The audit timeouts ("Audit failed to complete in time", -56) hit the first
test of a shard: testSetupWithKey in #451's queue run (46055375031), and
testConsent and testSetupWithKey in the runs that added the re-run #447
removed. That test pays for the runner installing the app afresh (~20 s
in #451's recording) and the cold first launch after it, and the audit
read the hierarchy while the app was still coming up.

The class's setUp now launches the app once and waits for its screen to
hold still before any test (`warmFirstLaunch`), so no test's screen is the
cold launch; and audit() snapshots until the screen holds still before it
reads it, as auditScrolling already did for every page but the first.
Both are bounded waits for a state, not a re-run: a screen that never
settles still gets audited, and a pass that times out still fails.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DS5B1Thm9A5RTqE6KU3jvP
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