Repository navigation
test(sudoku): freeze the session clock in the Ready-window test - #1092
Merged
Merged
Conversation
BoardLeaveOrPauseStateTests' "live startOrResume() lands in the reachable Ready window" built GameSession(puzzle:) on LiveMonotonicClock. GameSession.elapsedSeconds floors `clock.now - runningSince` (Int(_:) truncation), so when a loaded batch runner stalls >= 1.0 s between start() and startOrResume()'s resync, elapsedSeconds reads 1 and the state leaves .leaveReady. That is the intermittent failure at the elapsedSeconds and leaveOrPauseState expectations. The test now builds its session with a test-local FrozenMonotonicClock. Assertions unchanged; no production code touched. Part of #1082. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Owner
Author
Fresh-context T6 acceptance: #1082 (head
|
| # | Check | Verdict | Evidence |
|---|---|---|---|
| A | Diff scope | PASS | git show --stat 097bb70d and git diff --stat origin/main...097bb70d both show 1 file, BoardLeaveOrPauseStateTests.swift, 15 insertions and 1 deletion. No production file, no Package.swift, no .xcstrings. |
| B | Root-cause claims | PASS | origin/main:GameSession.swift:77 is return accumulatedSeconds + Int(clock.now - runningSince) and :101 is runningSince = clock.now, both verbatim. GameViewModel.resyncFromSession() assigns self.elapsedSeconds = snap.elapsedSeconds at :722. Int(Double) on a non-negative value is floor. FrozenMonotonicClock satisfies MonotonicClock (var now: TimeInterval { get }, Sendable). |
| C | No assertion widened | PASS | Every #expect is byte-identical to origin/main. Only line numbers moved: +1 for the import and +6 for the comment. |
| D | Evidence logs | PASS | Repro: step 1.0 is red at the elapsed and state expectations, 0.999 records no issue. M1: only :83 red. M2: the Ready-window test is red at :133, and the siblings at :66 and :83 too. Batches 1–5: 188 tests / 43 suites with 1 issue each, and the issue is always ToastTests.swift:57 (#1087). BoardLeaveOrPauseState recorded 0 issues. The repro patch is not in the commit. |
| E | Independent green run | PASS | HEAD = 097bb70d5f5e…, clean tree. swift test --filter BoardLeaveOrPauseStateTests gave Test run with 7 tests in 1 suite passed after 0.010 seconds. |
| F | PR body references | PASS | Closes #1082 is the only closing keyword. #1062 (MERGED) and #1087 (OPEN) are plain references, and both exist. |
| G | TODO/FIXME/stub/placeholder in the diff | PASS | 0 hits. |
總判定:ACCEPT
wei18
added a commit
that referenced
this pull request
Sep 15, 2026
Merge origin/main (c2959d0) into session/brisk-stork-isio. Main advanced by two commits after the first #1080 merge (68f840a): - aeb80f0 test(sudoku): freeze the session clock in the Ready-window test (#1092) - c2959d0 chore(l10n): remove proven-orphan keys and relabel live stale keys in both catalogs (#1093) A read-only `git merge-tree` dry run was clean. The five files main touched (both app catalogs, the SudokuAppCompositionTests L10n fixture, BoardLeaveOrPauseStateTests.swift, mise-tasks/scan/l10n) do not overlap with any file this branch changes. L10n check: this branch adds no localized string literals. None of the 14 Sudoku keys #1093 removed is referenced by branch-added code. part of #1024 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
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.
Summary
Closes #1082. Test-only:
BoardLeaveOrPauseStateTests"live startOrResume() lands in the reachable Ready window" now builds itsGameSessionon a test-local frozenMonotonicClock. Assertions are unchanged (noelapsedSeconds <= 1widening), and no production code is touched.Root cause (confirmed, not assumed)
GameSession.elapsedSecondsisaccumulatedSeconds + Int(clock.now - runningSince)(SudokuCoreKit/.../GameSession.swift:77).Int(Double)truncates, which for non-negative spans is floor.start()setsrunningSince = clock.now(:101).GameViewModel.startOrResume()then callsresyncFromSession(), which readssession.snapshot().elapsedSeconds(GameViewModel.swift:719-723).LiveMonotonicClock, once ≥ 1.0 s of real time passes betweenstart()and that resync, the value reads 1. The path crosses several actor / MainActor hops, and only a loaded batch runner stalls that long.:123then fails (elapsedSeconds → 1) and:126fails (the state leaves.leaveReady), which is exactly the pair seen in the fix(monetization): restore cold-launch gate resolution + consent-before-request ordering #1062 batch runs.Red repro (temporary, not committed). A test-local clock whose first read (inside
start()) returns 0 and every later read returnsstep. I parameterized the test overstep ∈ [0.999, 1.0]:step → 0.999recorded no issue, so the threshold is exactly 1.0 s. The repro's temporaryimport Foundationshifted lines by one, which is why this output says:124/:127instead of:123/:126.Change
private struct FrozenMonotonicClock: MonotonicClock { let now: TimeInterval = 0 }, local to the test file.GameSession(puzzle: puzzle, clock: FrozenMonotonicClock())in the Ready-window test only.GameSession+GameViewModelpath, not live time, so nobody swaps it back toLiveMonotonicClock.Verification
Mutation. Each run below was
swift test --filter BoardLeaveOrPauseStateTestswith a temporary edit toBoardView+AccessibilityHeader.swiftleaveOrPauseState. Every edit was reverted, so the final diff touches only the test file.elapsedSeconds == 0clause. Only the sibling snapshot-seam test goes red: "playing, elapsed > 0, pencil-only resolves to pause" at:83(.leaveReady≠.pause). The Ready-window test stays green. This is expected: the frozen clock pins elapsed at 0, so M1 does not change this test's input.elapsedSeconds != 0. The Ready-window test goes red at:133(.pause≠.leaveReady). The two snapshot-seam siblings go red too (:66,:83).Stability. The SudokuKit board batch ran 5 consecutive times, one at a time, with the exact board
--filterstring from #1062's phase-2d comment:Test run with 188 tests in 43 suites failed after 9.485 seconds with 1 issue.ToastTests.autoDismiss_firesAfterDuration(#1087)Test run with 188 tests in 43 suites failed after 11.504 seconds with 1 issue.ToastTests.autoDismiss_firesAfterDuration(#1087)Test run with 188 tests in 43 suites failed after 8.131 seconds with 1 issue.ToastTests.autoDismiss_firesAfterDuration(#1087)Test run with 188 tests in 43 suites failed after 10.312 seconds with 1 issue.ToastTests.autoDismiss_firesAfterDuration(#1087)Test run with 188 tests in 43 suites failed after 12.095 seconds with 1 issue.ToastTests.autoDismiss_firesAfterDuration(#1087)The batch is red in all 5 runs, with 1 failure (1 issue) per run. The failure is the separately tracked #1087 wall-clock flake (
ToastTests.swift:57), not this test.BoardLeaveOrPauseStateTestsrecorded no issue in any run. Under batch load the Ready-window test took 6.8–10.4 s of wall time per run. That is far past the 1.0 s floor, so on the live clock it would have failed.Lint.
swiftlint lint --stricton the changed file reported 0 violations. The lefthook pre-commit hooks (gitleaks, hygiene, swiftlint) passed.Follow-up (not done here)
FakeMonotonicClocknow exists as private copies in SudokuCoreKit's and PersistenceKit's test targets, plus this frozen variant. Consolidating them into a shared test-support target is a possible follow-up and is out of scope for this PR.🤖 Generated with Claude Code