Skip to content

fix(board): state-aware leave/pause control shared across both apps - #868

Merged
wei18 merged 1 commit into
mainfrom
fix/849-leave-pause-state
Jul 17, 2026
Merged

wei18 merged 1 commit into
mainfrom
fix/849-leave-pause-state

Conversation

@wei18

@wei18 wei18 commented Jul 17, 2026

Copy link
Copy Markdown
Owner

What

Closes #849 (owner report: Sudoku 永遠寫 Pause 但按下去只有 Leave Game?; MS 同一控制項是狀態式) — shared BoardLeaveOrPauseState + BoardLeaveOrPauseButton in GameShellUI (zero-dep), both board views delegate; drift dead.

Semantics (CR-hardened, round 2)

  • Sudoku Ready = status == .playing && elapsedSeconds == 0 && !canUndo — reachable only at the mount instant, because Sudoku's clock starts at board load (MS starts at first reveal). The code comment documents the clock-model asymmetry honestly instead of claiming MS parity. The 1Hz elapsed ticker re-derives the control, so Leave→Pause flips within ≤1s; pencil-marking players always see a working Pause (round 1's !canUndo-only gate hid Pause during pencil-only play with a running clock — caught by CR, and the round-2 fix provably restores the pre-fix(board): 'Pause' control label drifts between apps and overpromises — Sudoku always says Pause but only offers Leave #849 pencilNotes baseline byte-for-byte).
  • Resume-mount race fixed: initialCanUndo threaded from the snapshot's undoMoves at construction — no transient Leave flash on resume.
  • Pause-overlay parity verified pre-existing (both apps share PauseOverlayView with identical strings) — no shape change needed.

Review

Dual CR. Mechanical: 8/8 PASS. Adversarial round 1: REQUEST_CHANGES (the Ready-signal clock trap + resume race + fixture infidelity); round 2: APPROVE with the byte-identical baseline restoration as primary evidence. Mid-flight rebase onto ecea204 unioned #860's digit-pad baselines + #862's BoardView+Completion changes (verified by reviewer).

Verification

SudokuKit Board 78/78 --no-parallel · MinesweeperKit 345/345 --no-parallel · GameShellKit 32/32 · GameAppKit 43/43 · scan:l10n green (no new strings — all three labels pre-existed ×7 locales) · swiftlint --strict clean · 18 baseline re-records total, every delta explained.

🤖 Generated with Claude Code

Sudoku's board toolbar always showed "Pause" (bars icon), even before any
digit was placed, even though tapping it only ever opened the "Leave Game?"
sheet — no real pause feature exists yet. Minesweeper's equivalent control
was already state-aware: "Leave" + X pre-first-reveal, "Pause" + bars once
playing. Per #849 adjudication, extract the shared state→label/icon mapping
into `BoardLeaveOrPauseState` / `BoardLeaveOrPauseButton` (GameShellUI, zero
deps) and have both board views derive their own Ready-state signal from it.

Sudoku has no `.idle` board render (`startOrResume()` fires during
`BoardLoaderView`, before the toolbar ever mounts), so its semantically
equivalent Ready signal is "no move made yet on a live session" —
`status == .playing && !canUndo` (`canUndo` mirrors the session's undo
stack, which only digit placement/erase populates, never pencil notes).
Both apps gained a small view-local `showReadyLeaveOverlay` /
`showIdleLeaveOverlay` flag so tapping Leave-ready opens the shared
"Leave Game?" sheet without an illegal pause transition; Resume just hides
the flag. Sheet behavior itself is unchanged.

No new localized strings: `leave.game.leave`, `Pause`, `Resume` already
carry all 7 locales in both catalogs.

Snapshot churn (17 baselines, all reviewed as legitimate):
- 7 fresh/no-move-yet boards now show Leave+X instead of Pause+bars (the
  intended #849 fix): BoardViewBannerTests ads-enabled iPhone light/dark,
  BoardViewTests empty iPhone light/dark-ja/Mac light/dark,
  BoardViewPencilNotesTests (notes-only boards have no digit-undo history).
- 10 fixtures with placed digits (InProgress ×5, AlmostComplete ×4,
  ArmedDigit ×1) needed their `canUndo` fixture value corrected to match
  their visible board content (previously always false regardless of
  placed digits) — toolbar itself is pixel-identical (stays Pause), the
  Undo/Redo buttons flip from incorrectly-disabled to correctly-enabled.

Rebased onto ecea204 (#859/#860/#862): #860's DigitPadView contrast/a11y
rewrite re-recorded 8 of the same iPhone-compact baselines this change
touches. Took upstream as the merge base for the 8 PNG conflicts, then
re-recorded on the fully rebased tree so each baseline reflects the union
of both changes (verified pixel-diffed, e.g. the empty-board banner fixture
now shows both this fix's Leave/X toolbar and #860's digit-pad ink fix in
one frame). No source conflicts — #862's `BoardView+Completion.swift` /
`BoardLoaderView.swift` changes didn't touch the lines this PR edits.

CR round 2 (3 findings, all addressed):

Finding 1 (clock-model honesty): the original comment claimed straight MS
parity, but Sudoku's clock starts at `GameSession.start()` — called by
`BoardLoaderView` before the toolbar ever mounts — while MS's clock starts
only on first reveal/flag. Empirically verified (`GameSessionElapsedTests
.startAtZero`, SudokuCoreKit, plus a new live-session test here) that
`elapsedSeconds == 0` IS the real state at the instant `startOrResume()`
returns, so the Ready window is reachable — just far narrower than MS's:
gated `.leaveReady` on `elapsedSeconds == 0 && !canUndo` (was `!canUndo`
alone), and rewrote the code comment to state the clock-model asymmetry
plainly instead of claiming parity. This also fixes the real bug the
finding flagged: a pencil-marking player (`toggleNote` never touches
`undoStack`) or anyone who's simply let a second tick by now correctly
sees Pause, not Leave, once the clock has genuinely started accruing time.
Verified pause-overlay shape parity separately: both apps mount the exact
same shared `PauseOverlayView` with identical default strings
(`leave.game.title` "Leave Game?" / `leave.game.leave` "Leave") for a
genuine pause AND the Ready-state Leave-confirm — this is pre-existing,
shared, cross-app behavior, not something #849 introduced, so no shape
change was needed.

Finding 2 (resume-mount race): `BoardLoaderView.mountLoaded` renders
`BoardView` (`state = .loaded(viewModel)`) before `await
viewModel.startOrResume()`'s resync lands, so a resumed mid-game
`GameViewModel` could momentarily read the constructor's default
`canUndo == false` and flash `.leaveReady` for one frame. Added
`initialCanUndo` to the live `GameViewModel` init and threaded
`!snapshot.undoMoves.isEmpty` through at construction in
`BoardLoaderView.mountLoaded` — no transient wrong label.

Finding 3 (fixture fidelity): `BoardViewTests.makeViewModel`'s `canUndo`
derivation (`!userCells.isEmpty || elapsedSeconds > 0`) couldn't express
the pencil-only/running-clock scenario Finding 1 fixes, and wasn't faithful
to production's `!undoStack.isEmpty`. Changed the default to
`!userCells.isEmpty` alone (elapsedSeconds decoupled), with an explicit
`canUndo` override where the two must diverge (the `almostCompleteClues`
fixtures encode their near-solved state as puzzle givens, not `userCells`).
Added test coverage in `BoardLeaveOrPauseStateTests` pinning: a running
clock with no move made (pencil-only) resolves to `.pause`; a running clock
with a move resolves to `.pause`; the live-session Ready window is
reachable; and a resumed construction with `initialCanUndo` has no
transient `.leaveReady`.

One additional legitimate re-record from this round: BoardViewPencilNotesTests
now correctly shows Pause (was incorrectly showing Leave under the old
canUndo-only gate, since a pencil-only board has real elapsed time but no
undo history — exactly Finding 1's motivating bug).

Closes #849

Co-Authored-By: Claude Fable 5 <[email protected]>
@wei18
wei18 enabled auto-merge (squash) July 17, 2026 13:42
@wei18
wei18 merged commit 3b203a7 into main Jul 17, 2026
5 checks passed
@wei18
wei18 deleted the fix/849-leave-pause-state branch July 17, 2026 13:42
wei18 added a commit that referenced this pull request Jul 21, 2026
…lt (#930)

* docs(screen-contracts): sync STATS/MS-loader/week-strip/Close-button drift to as-built

Nav audit (flow-audit-hubs/board/periphery.md) found docs/screen-contracts.md
frozen at #684 (2026-07-05) while a dozen merged PRs changed navigation
underneath it. This pass fixes gaps 1-4:

- add ## STATS contract (Statistics Home entry, #773/#844) + wire it into
  HOME's element inventory/interactions (was completely undocumented)
- rewrite MS-BOARD-LOAD-FAILED into 4 tiers covering the new
  MinesweeperDailyOpenGuardView (#842) / MinesweeperDailyReplayLoaderView
  (#841) / MinesweeperFreshBoardLoaderView (#910) loaders the docs claimed
  didn't exist ("direct mount, no loader" was wrong); update MS-DAILY-HUB's
  per-interaction table to route through them
- add the week-strip (DailyStripView, #826) to SUD/MS-DAILY-HUB element
  inventory + interactions, and fix SUD/MS-COMPLETION-REVIEW's stale
  "completed-card tap only" entry points
- add the Close button (#719) to SUD/MS-BOARD-LOAD-FAILED's element
  inventory, previously Retry-only
- add SUD-BOARD's .leaveReady branch (#849/#868) to its interaction table,
  mirroring MS-BOARD's existing #681 note; extend PAUSE-OVERLAY's Resume row
  to name both apps' view-local flags

No .swift changes — docs only. Every new/edited row re-verified against
current source via rg before writing.

Co-Authored-By: Claude Fable 5 <[email protected]>

* docs(nav): finish as-built sync — CTA copy, GC entry points, MS reminder, route enums

Continues the previous commit (gaps 1-4) with gaps 5-8 from the same nav
audit:

- drop stale Practice hub CTA divergence: both apps read "New Game" since
  #885 (was "Draw new puzzle" Sudoku / "Start" MS); also note the MS Start
  tap now routes through MinesweeperFreshBoardLoaderView (#910)
- add MS-COMPLETION-OVERLAY's reminder affordance (#814, mirrors Sudoku's
  #287) — was documented as Sudoku-only; update REMINDER-PRIMER's entry
  points to match
- add the SETTINGS Game Center row as a real second entry point into
  GC-DASHBOARD / GC-SIGNED-OUT-ALERT (#685/#714), and give SETTINGS' own
  interaction table the row it was missing
- fix GC-SIGNED-OUT-ALERT's code anchor: the alert moved from
  MakeGameApp+Modifiers.swift to GameRoot.swift:113-123 under #685
- navigation-flows.md: add the `.stats` case to both route enum
  reproductions, widen MS `.completion` with its `day` param (#826), add a
  dated note for Sudoku's `.leaveReady` state (#849/#868, mirrors MS's
  #681 note), and fix N14's stale GC-alert anchor to match

No .swift changes — docs only. Every new/edited row re-verified against
current source via rg before writing.

Co-Authored-By: Claude Fable 5 <[email protected]>

* docs(contracts): correct three drifted anchors found in review

CR round 1 — all three were coordinates pointing at the wrong code, not
wrong claims about behavior:

- HOME footnote 2: sidebarItems(from:) is at HomeScreen.swift:115-127,
  not :103-116 (that range covered the previous init + the extension header).
- MS-BOARD-LOAD-FAILED tier 2: the whole anchor set had drifted. content
  switch is :145-205 (not :141-192), exitToHub :207-214 (not :198-205),
  resolve :244-265 (not :207-231 — that range is actually exitToHub +
  check() + resolve levels doc comment). Added check() explicitly. File is
  266 lines, not 267.
- MS-COMPLETION-OVERLAY #814 note: the daily-only gate for THIS live
  overlay is MinesweeperBoardView.swift:1110-1121, which gates on mode AND
  an actual win. LiveRouteFactory.swift:308 carries a near-identical
  mode == .daily line but belongs to the pushed .completion re-view route;
  the note now spells out the distinction so the next reader does not
  re-anchor to the wrong one.

Co-Authored-By: Claude Fable 5 <[email protected]>

---------

Co-authored-by: Claude Fable 5 <[email protected]>
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.

fix(board): 'Pause' control label drifts between apps and overpromises — Sudoku always says Pause but only offers Leave

1 participant