Skip to content

feat(minesweeper): achievement system — 11 achievements, evaluator, GC reporting - #734

Merged
wei18 merged 2 commits into
mainfrom
feat/700-ms-achievements
Jul 8, 2026
Merged

wei18 merged 2 commits into
mainfrom
feat/700-ms-achievements

Conversation

@wei18

@wei18 wei18 commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Refs #700 (stays open for the user-owned ASCRegister apply; code side complete).

What (2 commits, net ~+1760/−58: new Achievements subsystem + ASCRegister app-split + review fixes)

  • 11 achievements (owner-approved set, 650 pts): first_sweep, daily.complete_one, wins.complete_{10,50,200} (progressive percentComplete), expert.first_win, daily.full_spectrum, skill.no_flags, skill.lightning_expert (<180s), daily.streak_{7,30}.
  • MS-native evaluator (same owner-decided precedent as feat(minesweeper): wire PersonalRecordSink via makeCompletionSinks #699 — no TelemetryEvent/makeCompletionSinks): pure MinesweeperAchievementEvaluator over a MinesweeperWinFact, mounted ONLY on reveal()'s live .playing→.won transition; UTC MinesweeperDailyStreakMath; UserDefaults MinesweeperWinCountStore (per-game key prefix); best-effort GC reporting through errorReporter, local tally independent of GC presence.
  • ASCRegisterKit app-split: achievements(for: GCApp), MS registration material (gc.minesweeper.achievement.*, 33 keys × 7 locales), and an en-route fix of a latent Reconciler namespace bug that would have looked up wrong keys for any non-Sudoku app (Sudoku resolution provably unchanged; pinned by new ConfigConsistencyTests).
  • Review round fixes (both MAJORs found by the sonnet reviewer): loadInProgress now filters terminal records + a VM-level previousStatus != .won second line — resuming an already-won save can no longer re-inflate the win tally; everFlagged is now a persisted session/snapshot fact (backward-compatible decodeIfPresent, legacy saves OR-fallback on flagCount > 0) — backgrounding/resuming can no longer falsely grant "No Flags Needed". Local tally increments before the GC guard.

Verification

  • MinesweeperKit 222/222 (--no-parallel) · MinesweeperCoreKit 91/91 · ASCRegisterKit 160/160; 31 evaluator/store/streak tests + 8 review-guard tests (incl. real blob round-trip resume and the exact reviewer-identified resume path). swiftlint --strict 0. cloudkit/*.ckdb zero diff (the new snapshot field lives inside the opaque stateBlob).

Review

Dual review: haiku machine-verified the 11 IDs / 231 translation entries / scope discipline; sonnet's deep pass found 2 MAJORs (VM-instance latches vs game-scoped facts) + 1 MINOR — all fixed and delta re-verified ACCEPT by the original finder.

After merge (user-owned)

Register the achievements in ASC: extract the JSON from Packages/ASCRegisterKit/Sources/ASCRegister/Strings/gc-strings.xcstrings.patch (strip the comment header), then ASCRegister plan → apply with --app minesweeper and the MS ASC app id (creds in secrets/.env). Exact one-liner in the issue thread.

🤖 Generated with Claude Code

wei18 and others added 2 commits July 8, 2026 11:31
Adds Minesweeper's first Game Center achievement system per the
owner-approved set in #700 (Starter x2, Volume x3, Difficulty x2,
Skill x2, Streak x2 = 11 achievements, 650 pts total).

MS-native by owner decision (same precedent as #699): evaluation +
reporting sit beside submitDailyTimeIfWon() on the win path, NOT wired
through the shared TelemetryEvent / makeCompletionSinks pipeline (MS
cannot construct the Sudoku-typed TelemetryEvent).

MinesweeperUI:
- MinesweeperAchievementID: 11 short ids under the
  com.wei18.minesweeper.achievement. prefix, mirroring Sudoku's key
  shapes (daily.complete_one, wins.complete_10/50/200,
  daily.streak_7/30, ...).
- MinesweeperWinFact + MinesweeperAchievementEvaluator: pure,
  synchronous evaluation (progressive percentComplete for the volume
  tier; GameKit dedupes re-reported 100% achievements).
- MinesweeperDailyStreakMath: UTC consecutive-day counting from the
  day-stamped completedPuzzleIds already recorded by
  MinesweeperPersonalRecordStore (streak + full-spectrum facts).
- MinesweeperWinCountStore: device-local UserDefaults tally backing
  the volume achievements (both modes combined).
- MinesweeperGameViewModel: flagsPlacedThisGame latches on the flag
  INCREASE edge (place-then-remove still disqualifies No Flags
  Needed); evaluateAchievementsIfWon() fires ONLY on the live reveal()
  win transition — deliberately not on refresh(), which would inflate
  the non-idempotent win tally when re-opening a won board. Reporting
  is best-effort: errors funnel to errorReporter, never interrupt the
  win moment.

ASCRegisterKit (registration material; apply run stays user-owned):
- Config.achievements(for: GCApp) app-split mirroring
  leaderboards(for:); Sudoku's list byte-identical, pinned by tests.
- Reconciler/main: achievement actions now flow for --app minesweeper
  (previous leaderboard-only filter removed); localization lookup goes
  through AchievementConfig's app-scoped locKeyPrefix keys.
- gc-strings.xcstrings.patch: 33 MS achievement keys
  (gc.minesweeper.achievement.*, title/description/unearnedDescription)
  fully translated in all 7 locales (en source, zh-Hant primary,
  ja/zh-Hans/es/th/ko via the ai-translated-localization flow).

Achievement strings live only in the ASCRegister registration
material, not in the app catalogs (mirrors Sudoku: no gc.achievement
keys in Localizable.xcstrings), so the scan:l10n gate is unaffected.

Tests: 31 new (evaluator positive/negative per achievement incl.
progressive boundaries and the 179s/181s lightning edge; streak math;
win-count round-trip; ViewModel reporting incl. error-swallow and
no-inflation-on-refresh). MinesweeperKit 218/218 --no-parallel,
ASCRegisterKit 160/160, swiftlint --strict clean.

Refs #700 (ASC registration run pending; close after ASCRegister apply)

Co-Authored-By: Claude Fable 5 <[email protected]>
Code review on the achievement system found that two achievement facts
lived as ViewModel-instance state while the rules need whole-game-scope
facts, plus a tally/GC coupling nit. Three fixes:

MAJOR 1 — resumed won board re-inflated the win tally:
- MinesweeperSavedGameStore.loadInProgress now filters terminal records
  ("completed" / "failed") to nil, mirroring latestInProgress()'s status
  filter — a terminal save is not resumable (honest-failure philosophy;
  a missing status field stays tolerant/resumable).
- ViewModel defense in depth: reveal() only evaluates achievements when
  the pre-reveal status was not already .won, so a no-op reveal on a
  restored won board (which re-publishes the .won snapshot) can never
  re-run the non-idempotent tally increment.

MAJOR 2 — "No Flags Needed" mis-awarded after resume:
- The flag-history fact moves from a ViewModel-instance latch
  (flagsPlacedThisGame, lost on rebuild) into the session + snapshot:
  MinesweeperSession latches everFlagged on the flag-placement edge and
  MinesweeperSessionSnapshot persists it inside the existing stateBlob
  JSON (opaque blob — no CloudKit schema change). Back-compat: pre-#700
  blobs lack the key and decode false via decodeIfPresent; applySnapshot
  additionally ORs in flagCount > 0 so a legacy save with flags on the
  board stays disqualified (a legacy placed-then-removed flag is
  unrecoverable — accepted, saves are TestFlight-internal, same
  precedent as the wireStatus migration note).

MINOR — local tally no longer gated on Game Center presence:
- winCountStore.incrementAndGet() moved before the guard let gameCenter
  in evaluateAchievementsIfWon(): the tally is a device fact and must
  advance for offline/signed-out wins.

New guard tests (8):
- MinesweeperSavedGameStoreTerminalFilterTests.
  loadInProgressReturnsNilForTerminalRecords (MAJOR 1, store)
- MinesweeperAchievementReportingTests.
  restoredWonSessionDoesNotRecountOrRereport (MAJOR 1, ViewModel)
- MinesweeperAchievementReportingTests.
  flagBeforeResumeStillDisqualifiesNoFlags (MAJOR 2, full blob
  round-trip + fresh ViewModel)
- MinesweeperAchievementReportingTests.
  winWithoutGameCenterStillCountsLocally (MINOR)
- MinesweeperSessionEverFlaggedTests: placeThenRemoveKeepsEverFlagged /
  everFlaggedSurvivesRestore / legacyBlobDecodesEverFlaggedFalse /
  restoreLegacySaveWithFlagsOnBoardSetsEverFlagged (MAJOR 2, core)

Verified: MinesweeperKit 222/222 --no-parallel, MinesweeperCoreKit
91/91, swiftlint --strict clean on all changed files.

Refs #700

Co-Authored-By: Claude Fable 5 <[email protected]>
@wei18
wei18 enabled auto-merge (squash) July 8, 2026 10:20
@wei18
wei18 merged commit fcd9348 into main Jul 8, 2026
4 checks passed
@wei18
wei18 deleted the feat/700-ms-achievements branch July 8, 2026 10:20
wei18 added a commit that referenced this pull request Jul 8, 2026
Consolidates 17+ merged PRs (#701-#734): B1-B4 mirror/product decisions,
TF upload four-PR automation chain, GC/board-loader hardening, and the
MS achievement system, plus the open queue and two operational incidents.

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.

1 participant