Skip to content

refactor(gamecenter): drop SudokuEngine.Difficulty from the shared protocol - #953

Merged
wei18 merged 3 commits into
mainfrom
refactor/gamecenter-difficulty-947
Jul 27, 2026
Merged

wei18 merged 3 commits into
mainfrom
refactor/gamecenter-difficulty-947

Conversation

@wei18

@wei18 wei18 commented Jul 27, 2026

Copy link
Copy Markdown
Owner

Closes #947

What

GameCenterClient.submitScore(puzzleId:elapsedSeconds:difficulty:leaderboardKind:) required a SudokuEngine.Difficulty argument and the protocol file did public import SudokuEngine, forcing every conformer — Minesweeper's, any future game's — through Sudoku's enum and re-exporting SudokuEngine visibility downstream (SE-0409).

Survey found the difficulty parameter was already dead at the protocol boundary: GameCenterSink.submitScoreIfEligible resolves Difficulty -> LeaderboardKind itself before calling client.submitScore(...), and both conformers (LiveGameCenterClient, FakeGameCenterClient) discarded the parameter entirely (_ = (puzzleId, difficulty) in LiveGameCenterClient, dropped from the recorded operation in FakeGameCenterClient). So the smallest fix is simply removing the unused parameter — no pre-resolved-ID or LeaderboardSlot type was needed.

How

  • Dropped difficulty: Difficulty from the GameCenterClient.submitScore(puzzleId:elapsedSeconds:difficulty:leaderboardKind:) requirement.
  • Removed public import SudokuEngine from GameCenterClient.swift, LiveGameCenterClient.swift, and FakeGameCenterClient.swift (now fully unused there).
  • Updated the call site in GameCenterSink.swift and every conformer/fake: LiveGameCenterClient, FakeGameCenterClient, UITestSignedOutGameCenterClient (GameAppKit), plus test fakes in GameRootViewModelLeaveTests, GameRootViewModelTests, TerminalPersistJoinTests, and the assertions in LiveGameCenterClientSubmitTests.
  • LeaderboardIDs.swift / SudokuEngine/GameCenterIdentifiers.swift (the actual id-string source of truth) are untouched — out of scope, and touching them would risk the production leaderboard IDs.
  • AchievementEvaluator.swift's separate public import SudokuEngine is untouched — it's a different public type, not the GameCenterClient protocol the issue names, and redesigning it is out of scope (issue explicitly warns against redesigning the whole GC surface).

Leaderboard-ID equivalence (production safety)

No code that computes leaderboard ID strings changed. Evidence — every (difficulty, kind) -> id pair, asserted by tests unmodified in their assertions (only the now-removed difficulty: argument was dropped from call sites) and green on this branch:

Difficulty LeaderboardKind Leaderboard ID Asserted by
.easy .dailyEasy com.wei18.sudoku.leaderboard.easy.daily.v1 SubmitScoreTests.leaderboardIDSuffixedV1, LiveGameCenterClientSubmitTests.elapsedSecondsConvertsToCentiseconds, SudokuLeaderboardRoutingTests.dailyEasyMapsToEasyLeaderboard
.medium .dailyMedium com.wei18.sudoku.leaderboard.medium.daily.v1 SubmitScoreTests.leaderboardIDSuffixedV1, LiveGameCenterClientSubmitTests.zeroElapsedSecondsConvertsToZero, SudokuLeaderboardRoutingTests.dailyMediumMapsToMediumLeaderboard
.hard .dailyHard com.wei18.sudoku.leaderboard.hard.daily.v1 SubmitScoreTests.leaderboardIDSuffixedV1, LiveGameCenterClientSubmitTests.twoHourCapMatchesDesignRange, SudokuLeaderboardRoutingTests.dailyHardMapsToHardLeaderboard

Minesweeper's MinesweeperLeaderboardID (easy/medium/hard segments, .v1 suffix, com.wei18.minesweeper.leaderboard.*) is untouched — it never went through the difficulty-typed overload; MS always called the raw submitScore(leaderboardId:elapsedSeconds:) path.

All three suites above ran green on this branch (post-refactor); since LeaderboardIDs.swift / GameCenterIdentifiers.swift have zero diff, the same assertions hold byte-identically against main.

Verification

swift test --no-parallel --package-path Packages/GameCenterKit
# Test run with 69 tests in 14 suites passed after 0.529 seconds.

swift test --package-path Packages/GameAppKit
# Test run with 58 tests in 11 suites passed after 0.108 seconds.

swift test --package-path Packages/MinesweeperKit
# Test run with 370 tests in 63 suites passed after 4.535 seconds.

swift test --package-path Packages/SudokuKit --filter "SudokuLeaderboardRoutingTests|BoardViewTests|BoardCompletionOverlayTests"
# Test run with 29 tests in 3 suites passed after 2.308 seconds.
# (full-suite run hit the known pre-existing local segfault flake near
#  ToastController/SettingsView, unrelated to this diff — filtered to the
#  touched areas per repo convention)

mise run lint:swift_strict <9 changed files>
# 0 violations

Deviations from the issue's proposed direction

The issue proposed a pre-resolved leaderboard-ID String or a LeaderboardSlot/LeaderboardTarget type. That wasn't needed: the difficulty parameter was provably dead at the protocol boundary (both real conformers discarded it, and the caller already resolves the mapping before calling submitScore), so removing it was the smallest fix that satisfies the issue's goal (no SudokuEngine leak, no live ID change) without adding a new type.

🤖 Generated with Claude Code

wei18 and others added 2 commits July 28, 2026 00:05
…otocol (#947)

`GameCenterClient.submitScore(puzzleId:elapsedSeconds:difficulty:leaderboardKind:)`
forced every conformer (Minesweeper, any future game) through Sudoku's
`Difficulty` enum via `public import SudokuEngine`, even though both
conformers (`LiveGameCenterClient`, `FakeGameCenterClient`) already
discarded the parameter — the caller (`GameCenterSink`) resolves
`Difficulty -> LeaderboardKind` before crossing the protocol boundary.
Drop the dead parameter and the `public import SudokuEngine` it required;
`LeaderboardIDs` / `GameCenterIdentifiers` (the actual id strings) are
untouched, so no leaderboard ID changes.

Co-Authored-By: Claude Fable 5 <[email protected]>
CR round 1 on PR #953: both DEBUG near-win noop `GameCenterClient` conformers
still declared the removed `difficulty:` parameter, so they no longer satisfied
the protocol.

macOS `swift build` / `swift test` cannot catch this — both actors live inside
`#if os(iOS)`, so the host-platform build never compiles them. Reproduced and
verified with `xcodebuild -scheme SudokuUI -destination 'generic/platform=iOS
Simulator'`: BUILD FAILED with "does not conform to protocol 'GameCenterClient'"
on both types before this change, BUILD SUCCEEDED after.

Co-Authored-By: Claude <[email protected]>
CR round 1 on PR #953: the protocol-level leak is gone, but
`AchievementEvaluator` in the same package still carries
`public import SudokuEngine` with `evaluateForCompletion(…difficulty:…)`, so
GameCenterKit still re-exports the type at module level. That is a packaging
problem (the evaluator is effectively Sudoku-specific and also coupled to the
Sudoku-typed Persistence surface), not a conformer constraint — filed as #955.

Co-Authored-By: Claude <[email protected]>
@wei18
wei18 merged commit e4ae1ff into main Jul 27, 2026
5 checks passed
@wei18
wei18 deleted the refactor/gamecenter-difficulty-947 branch July 27, 2026 16:36
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.

refactor(gamecenter): GameCenterClient protocol leaks SudokuEngine.Difficulty to all games

1 participant