Skip to content

fix(board): start gamesession after load so timer ticks + digit pad lands (#227) - #229

Merged
wei18 merged 1 commit into
mainfrom
fix/macos-board-timer-input
Jun 1, 2026
Merged

wei18 merged 1 commit into
mainfrom
fix/macos-board-timer-input

Conversation

@wei18

@wei18 wei18 commented Jun 1, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes #227 — macOS Sudoku board had a stuck `0:00` timer and unresponsive digit pad. Sr Dev diagnosed the root cause as: `BoardLoaderView.load()` constructed a `GameSession` and left it in `.idle`. Every digit-pad tap then failed the `.playing` gate inside the actor and was silently absorbed by `runSession`. The bug shipped on iOS too — PR #211's macOS 2-column layout just made the frozen timer impossible to miss.

Fix (Sr Dev's spec, applied verbatim)

  1. `GameViewModel.startOrResume()` — idempotent transition that maps `.idle → start()`, `.paused → resume()`, no-ops otherwise.
  2. `BoardLoaderView.load()` calls `startOrResume()` after `state = .loaded(viewModel)`.
  3. `BoardView` adds a 1-Hz `.task` ticker calling `GameViewModel.refreshElapsed()` while `status == .playing` so the timer label advances between mutations.

Diff: 4 files, +143 LOC. No platform-branch conditionals — fix applies to both iOS and macOS.

Regression net

New `GameViewModelStartTests` suite (4 tests) constructs `GameViewModel` via the LIVE init path with a real `GameSession` in `.idle`:

  • `startOrResume_advancesIdleToPlaying` — pins the transition the fix introduces
  • `placeDigit_landsAfterStartOrResume` — pins the user-visible "digit pad becomes responsive" contract
  • `startOrResume_isIdempotentWhilePlaying` — pins that double-call is safe
  • `startOrResume_resumesFromPaused` — pins the paused → playing branch

The existing `BoardViewTests.makeViewModel` uses the snapshot init seam with `status: .playing`, bypassing the actor — this is why the regression slipped through.

Verified

  • `swift build --package-path Packages/SudokuKit` → green
  • `swift test --filter GameViewModelStartTests` → 4/4 pass
  • `swift test --filter BoardViewTests` → 17/17 pass
  • `tuist build Sudoku --platform iOS` → green
  • CI: lint:swift_strict, iOS + macOS test suites, snapshot tests
  • User smoke test on macOS + iOS

Authorship note

Senior Developer subagent diagnosed the bug end-to-end (root cause with file:line citations to the actor gate, the silent absorption pattern, and the missing `.start()` call) but was blocked from applying the edit by tool permissions. Leader applied the spec'd diff verbatim and added the regression test. Both the diff and the test follow the Developer's specification.

Closes #227.

🤖 Generated with Claude Code

…ands (#227)

Root cause: `BoardLoaderView.load()` constructed a `GameSession` and left
it in `.idle`. Every digit-pad tap then failed the `.playing` gate inside
the actor and was silently absorbed by `runSession` (M10 error funnel), so
the user saw a dead board + a frozen 0:00 timer. The bug shipped on iOS
too — PR #211's new macOS 2-column layout (260pt control rail) just made
the frozen timer impossible to miss because the user's eye sits on it
while contemplating the board.

Fix (per Sr Dev's diagnosis on this issue)
------------------------------------------
1. `GameViewModel.startOrResume()` — idempotent transition that maps
   `.idle → start()`, `.paused → resume()`, and no-ops otherwise. Both
   live and snapshot paths handled.
2. `BoardLoaderView.load()` calls `startOrResume()` immediately after
   `state = .loaded(viewModel)`, so users never sit on an idle session.
3. `BoardView` adds a 1-Hz `.task` ticker that calls
   `GameViewModel.refreshElapsed()` while `status == .playing`. Without
   this the timer label only advanced after mutations (via
   `resyncFromSession`), leaving long contemplation gaps frozen.

Regression net
--------------
New `GameViewModelStartTests` suite (4 tests) constructs `GameViewModel`
via the LIVE init path with a real `GameSession` in `.idle` — exactly
what users hit. `BoardViewTests` could not catch this class of bug because
its `makeViewModel` uses the snapshot init seam with `status: .playing`,
bypassing the actor entirely.

Sr Dev diagnosed the bug end-to-end (file:line citations to the actor
gate, the silent absorption, and the missing `.start()` call) but was
blocked from applying the edit by tool permissions. Leader applied the
spec'd diff verbatim plus the regression test.

Verified
--------
- swift build --package-path Packages/SudokuKit → green
- swift test --filter GameViewModelStartTests → 4/4 pass
- swift test --filter BoardViewTests → 17/17 pass (existing tests unaffected)
- tuist build Sudoku --platform iOS → green

Closes #227.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@wei18
wei18 merged commit ec10f09 into main Jun 1, 2026
5 checks passed
@wei18
wei18 deleted the fix/macos-board-timer-input branch June 1, 2026 07:39
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.

macOS board: timer stuck at 0:00 + digit buttons unresponsive

1 participant