Skip to content

feat(minesweeper): add MS-specific personal-record store, wired at daily win - #706

Merged
wei18 merged 1 commit into
mainfrom
feat/699-ms-personal-record-store
Jul 6, 2026
Merged

wei18 merged 1 commit into
mainfrom
feat/699-ms-personal-record-store

Conversation

@wei18

@wei18 wei18 commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Closes #699 — B2 from the 2026-07-05 uiux audit; mechanism (MS-native store, NOT the shared TelemetryEvent/makeCompletionSinks pipeline) owner-approved 2026-07-05, per the two prior per-game precedents. Pipeline generalization stays with #479.

What (+953/−68, MinesweeperKit + cloudkit/minesweeper.ckdb only — no shared code touched)

  • MinesweeperPersonalRecord + MinesweeperPersonalRecordStore (new, MinesweeperPersistence): CRUD over the injected PrivateCKGateway seam (lazy CK — no eager CKContainer), mirroring PersistenceKit's PersonalRecordStore: .ifUnchanged optimistic concurrency with bounded 3-attempt retry (PersonalRecord best-time can clobber under multi-device race after #544 last-write-wins #552 lesson preserved), dedup-by-puzzleId, min-best merge. Record-type name PersonalRecord reuse is safe — each app owns its own CKContainer (same precedent as SavedGame).
  • cloudkit/minesweeper.ckdb: adds the PersonalRecord record type, field-for-field identical to sudoku.ckdb's. Additive only.
  • Wired beside the GC submit in submitDailyTimeIfWon() (extracted to +SubmitOnWin.swift to stay under the 400-line lint ceiling). Store threaded optional end-to-end like savedGameStore. Failed writes funnel through errorReporter, never interrupt the win.
  • guard let gameCenter → if let gameCenter: deliberate — personal records must not depend on GC's presence; the 9 existing GC submit tests pin the old behavior (all green).
  • Initial scope is daily-only — a reviewed, deliberate divergence from Sudoku (which also records practice). MS practice recordNames are singletons and can't serve as the dedup puzzleId; widening to practice = feat(minesweeper): record practice personal bests (needs per-game unique practice id) #705. Doc comment separates the two contracts explicitly.

Verification

  • MinesweeperKit full suite: 191/191 (impl) re-verified by reviewer; post-amend filtered run 30/30 (PersonalRecord × 4 suites + GC submit suite)
  • swiftlint --strict: 0 violations · pre-commit hooks green
  • Race tests exercise the real conflict path via ConflictOnceGateway/AlwaysConflictGateway decorators (sawConflict asserted)

Review

Highest-risk tier: sonnet + opus dual review (data-writing CloudKit path), plus Leader spot-audit of container separation + lazy CK. Sonnet: no findings beyond a PR-note. Opus: 1 MAJOR (the practice-scope divergence — resolved by owner decision: ship daily-only, #705 follow-up; misleading comment reworded) + 2 MINOR (race-test name implied a guarantee it doesn't test — renamed; redundant : Sendable on actor — kept, faithful mirror of Sudoku).

Post-merge (NOT in this PR)

  • Leader: push the schema to Development (ck:schema, needs secrets/.env on the main checkout).
  • Owner: Production schema deploy is the CloudKit Console button ("Deploy Schema Changes to Production…") — prod fields are add-only; the app writes PersonalRecord records that will fail silently behind the error funnel until prod has the record type.

🤖 Generated with Claude Code

…ily win

Minesweeper had no personal-best record at all. Per owner decision on #699,
this adds an MS-specific `MinesweeperPersonalRecordStore` (mirroring
PersistenceKit's `PersonalRecordStore` shape: `.ifUnchanged` optimistic
retry, `recordingCompletion` dedup-by-puzzleId, min-best merge) rather than
generalizing the shared `TelemetryEvent`/`PersonalRecordSink`/
`makeCompletionSinks` pipeline to Minesweeper's types — the same precedent
already set by `MinesweeperSavedGameStore` and the direct
`gameCenter.submitScore` call for GC best-times. Generalizing the shared
pipeline is left to #479.

- `MinesweeperPersonalRecord` / `MinesweeperPersonalRecordStore` (new,
  MinesweeperPersistence): CRUD over the shared `PrivateCKGateway` seam,
  reusing `PrivateCKConstants.personalRecordRecordType` ("PersonalRecord")
  — safe because MS and Sudoku each own a separate CKContainer (same
  precedent as `SavedGame`).
- `cloudkit/minesweeper.ckdb`: adds the `PersonalRecord` record type
  (fields mirror `cloudkit/sudoku.ckdb`). Additive only.
- Wired at the same daily-only trigger as the Game Center submit, right
  beside it in `MinesweeperGameViewModel.submitDailyTimeIfWon()` (moved to
  MinesweeperGameViewModel+SubmitOnWin.swift to keep the main file under
  the 400-line lint ceiling). Threaded optional end-to-end:
  `Live.swift` -> `LiveRouteFactory` -> `MinesweeperBoardView` /
  `MinesweeperBoardLoaderView` -> `MinesweeperGameViewModel`. A failed
  write funnels through `errorReporter`, never interrupts gameplay.
- Tests mirror PersistenceKit's `PersonalRecordTests` /
  `PersonalRecordMergeTests` / `PersonalRecordRaceTests` patterns with MS
  types, plus a VM-level submit-on-win suite (dedup, daily-only gate,
  swallowed-write-error, nil-store no-op).

No shared code (PersistenceKit / GameAppKit / TelemetryKit) touched.
Development CloudKit schema push + eventual Production "Deploy Schema
Changes to Production" console click are follow-ups, not done here.

closes #699

Co-Authored-By: Claude Fable 5 <[email protected]>
@wei18
wei18 enabled auto-merge (squash) July 6, 2026 03:37
@wei18
wei18 merged commit 7cf34be into main Jul 6, 2026
4 checks passed
@wei18
wei18 deleted the feat/699-ms-personal-record-store branch July 6, 2026 03:37
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.

feat(minesweeper): wire PersonalRecordSink via makeCompletionSinks

1 participant