Repository navigation
test(e2e): close the N19 clear-cache resumeCandidate load race + harden the Cancel half - #957
Merged
Merged
Conversation
…en the Cancel half (#956) Re-diagnosed the intermittent test_clearCacheCancelAndFailureToast_N19 failure: the issue's original "fixed backdrop coordinate" hypothesis was wrong. Repeat-running under contention reproduced the flake at ~15-50%, always at the same assertion ("should raise the failure toast"), with the Cancel/backdrop-dismiss half always succeeding. Root cause: a race in SettingsViewModel.clearCache() — deleteAbandoned only runs `if let candidate = resumeCandidate`, and resumeCandidate is populated by bootstrap()'s async persistence.latestInProgress() fetch. If that hadn't resolved by the time the test tapped Confirm, clearCache() silently fell through to the unconditional success toast instead of the failure one. Closes the race product-side: SettingsViewModel.isCacheStateReady flips true once bootstrap() settles either way; SettingsStorageSection renders a zero-size, non-localized settings.storage.cacheReady sibling marker only while it's true (mirrors DailyHubView's sudoku.dailyHub.root pattern, no container id per the #937 lesson, no L10n work needed). Threaded through SettingsScreen -> GameAppKit.SettingsView (both apps share the composition). The E2E test now waits for that anchor before touching the row at all. Also hardens the Cancel/backdrop half per the issue's directions: waits for the confirm button to be isHittable (not merely exists) before every tap, re-queries a fresh handle after reopening instead of reusing the pre-Cancel one, and taps the popover's own PopoverDismissRegion backdrop element (discovered via idb ui_describe_all) instead of a fixed normalized-offset coordinate. Split the clear-cache helper into NegativeNavigationE2ESupport+ClearCache.swift to keep the main file under the 400-line SwiftLint ceiling, and updated docs/screen-contracts.md accordingly. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This was referenced Jul 28, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #956
Root cause (corrected from the issue's original hypothesis)
The issue suspected the Cancel half's fixed backdrop-tap coordinate. That
turned out to be wrong: repeat-running
test_clearCacheCancelAndFailureToast_N19under contention reproduced the flake at a consistent ~15-50% rate, always
at the SAME assertion (
should raise the failure toast), and theCancel/backdrop-dismiss half succeeded in every single reproduction.
The real bug is a precondition race in
SettingsViewModel.clearCache()(
Packages/GameAppKit/Sources/GameAppKit/SettingsViewModel.swift):deleteAbandonedonly runsif let candidate = resumeCandidate, andresumeCandidateis populated bybootstrap()'s asyncpersistence.latestInProgress()fetch, fired fromSettingsView's.task.If that fetch hadn't resolved by the time the test tapped Confirm — worse
under host CPU contention —
clearCache()silently fell through to theunconditional SUCCESS toast branch instead of the failure one, so the
failure toast the test waits for never appeared.
What changed
Product (closes the race):
SettingsViewModel.isCacheStateReady: Bool— flipstrueoncebootstrap()has resolvedresumeCandidateeither way.SettingsStorageSectionrenders a zero-size, non-localized E2Eprecondition anchor (
settings.storage.cacheReady) as a.backgroundSIBLING marker (not a container id — test(e2e): cover sudoku hub failure flows N3-N5 (#935) #937 lesson) only while
isCacheStateReadyistrue, mirroringDailyHubView'ssudoku.dailyHub.rootpattern. No user-visible text, so no L10n work.SettingsStorageSection→SettingsScreen→GameAppKit.SettingsView(both apps share this composition — mirrorprinciple). Default
trueon the intermediate inits keeps everypreview/snapshot/unit-test call site unchanged.
Test (
App/UITestsShared/NegativeNavigationE2ESupport+ClearCache.swift):settings.storage.cacheReady(15s, matching this file's ownceiling for "an app-level async load settled" waits) BEFORE tapping the
Clear cache row at all — closes the race structurally instead of hoping
the timing works out.
confirmed correct by repeat-running (every pre-fix failure was at the
toast assertion, never here): wait for the confirm button to be
genuinely
isHittable(not merelyexists) before every tap, andre-query a FRESH handle after reopening instead of reusing the
pre-Cancel one.
PopoverDismissRegionbackdropaccessibility element (discovered via idb
ui_describe_all— adiscrete, full-screen element the system already exposes) instead of a
fixed normalized-offset coordinate, per direction (b) — self-adapts to
layout instead of guessing a safe point.
NegativeNavigationE2ESupport+ClearCache.swiftto keep themain file under the 400-line SwiftLint ceiling (same pattern as the
existing
+Restore.swiftsplit).Docs:
docs/screen-contracts.md— SETTINGS storage row inventory +CLEAR-CACHE-DIALOG note updated with the real root cause and the new
anchor, replacing the incorrect backdrop-coordinate framing.
Considered and rejected
Resolving the DEBUG fake's
latestInProgress()synchronously/eagerly,bypassing the Task hop for the E2E path specifically — rejected. The race
is in the VIEW MODEL's
.task/Task scheduling, not the fake's own latency,so a synchronous fake would still be a Task hop behind the confirm tap; it
wouldn't remove the race. It would also make the E2E path exercise a
different load sequence than production, which defeats the point of a
host-driven E2E test in the first place.
Verification
Diagnosis (pre-fix): reproduced 7/16 under deliberate dual-suite
concurrent-build contention; also 3/16 in a clean single-suite sequential
run with no deliberate contention (1 Sudoku, 2 Minesweeper) — confirming
it's a genuine race, not purely a contention artifact.
Post-fix, 10x
-only-testing:sequential per app (raw counts, notcherry-picked):
assertion — the bug is structurally closed. All 3 residual failures
are at the NEW
isCacheStateReadyanchor wait (a bounded 15s wait),measured during a period of load average 18-22 (
uptime) — thissession was running ~12 concurrent Claude Code agents at the time. A
bounded wait can be exceeded by an unbounded contention source; that's
a different failure class than test(e2e): stabilize the N19 clear-cache backdrop-tap flake #956 and not something a larger timeout
structurally fixes.
Final confirmation pass at settled load (
uptime: load averages 6.31 8.1911.17 — single digits):
mise run test:ui all→ both suites clean —Sudoku-E2E 19/19 ("Executed 19 tests, with 0 failures"), Minesweeper-E2E
15/15 ("Executed 15 tests, with 0 failures"),
test_clearCacheCancelAndFailureToast_N19passing in both (21.4s / 19.8s). This converts the contention attribution
above into a measurement: at normal load both suites are clean; all 3
residual failures across the 20x batches happened only during a load spike
(18-22).
mise run lint:swift_stricton all changed files → 0 violations.Unit/snapshot tests unaffected:
swift test --package-path Packages/SettingsKit(51/51),
swift test --package-path Packages/SudokuKit --filter SettingsView(22/22, including snapshots — the zero-size marker doesn't change rendered
pixels),
swift test --package-path Packages/MinesweeperKit --filter SettingsView(9/9).
🤖 Generated with Claude Code