Skip to content

test(gamecenter): cover DailyRankViewModel's own-rank second fetch + stale-response drop - #1008

Merged
wei18 merged 1 commit into
mainfrom
test/983-dailyrank-gaps
Aug 12, 2026
Merged

wei18 merged 1 commit into
mainfrom
test/983-dailyrank-gaps

Conversation

@wei18

@wei18 wei18 commented Aug 12, 2026

Copy link
Copy Markdown
Owner

Summary

  • Closes the two test gaps feat(gamecenter): shared Daily Rank screen (part of #983) #989's review flagged as verified only by code inspection (tracked in feat(gamecenter): friends leaderboard — surface the friendsAllTime slice in an app-owned view #983's latest comment):
    • DailyRankViewModel's aroundLocalPlayer: true second fetch — dedupe against the top slice, plus degradation (screen still renders the top slice) when that second fetch fails.
    • The commit(_:for:) selection-key guard — a fetch response for a tab/scope the user has since switched away from must be dropped, not committed over the current selection.
  • Extends FakeGameCenterClient (GameCenterTesting) with optional ownRankSlice/ownRankError overrides that only apply to aroundLocalPlayer: true calls; unscripted (nil, the default) behavior is byte-for-byte unchanged, so all ~26 existing consumers are unaffected.
  • Adds GatedLeaderboardGameCenter (own file, Tests/GameAppKitTests/GatedLeaderboardGameCenter.swift) — a small continuation-gated local GameCenterClient fake, following the existing StubGameCenter/MinimalGameCenter precedent already in this test target, that suspends one leaderboard id's fetch until the test releases it. Makes the tab-switch race deterministic (no sleeps/timing).
  • DailyRankViewModelTests.swift stayed just over the 400-line SwiftLint cap with the new tests inline, so the new fake was extracted to its own file rather than growing the test file further.

Verification (sanity-checked the guards are load-bearing)

Both new guard-dependent tests were confirmed to fail against a temporarily de-guarded production build, then the production file was restored byte-identical (confirmed via diff):

  • Deleting the commit(_:for:) selection-key guard → staleResponseDroppedAfterSwitchingAwayAndBack fails (stale .loaded(STALE) leaks into the "easy" tab's state).
  • Changing try? to try on the second fetch → secondFetchFailureDegradesToTopSliceOnlyRatherThanFailingScreen fails (screen falls through to .failed(.network) instead of degrading).

Test plan

  • swift test --package-path Packages/GameAppKit — 70/70 passed, including the 4 new/renamed tests in DailyRankViewModel — #983 states
  • swift test --package-path Packages/GameCenterKit --no-parallel — 43/43 passed (known parallel-hang worked around per project memory)
  • swift test --package-path Packages/SudokuKit --no-parallel --filter DailyRankViewTests — 7/7 passed (no regression from the FakeGameCenterClient extension)
  • swift test --package-path Packages/MinesweeperKit --no-parallel --filter DailyRankViewTests — 7/7 passed
  • swiftlint lint --strict on all 3 changed/added files — 0 violations
  • rg -n 'TODO|FIXME|stub|placeholder' on the diff — no matches
  • No production code changed (git diff touches only Tests/ and the test-support GameCenterTesting target)

part of #983

🤖 Generated with Claude Code

…stale-response drop

Closes the two test gaps #989's review flagged as verified only by code
inspection: the `aroundLocalPlayer: true` second-fetch path (dedupe against
the top slice + degrade to top-only when it fails) and the `commit(_:for:)`
selection-key guard that drops a fetch response for a tab/scope the user has
since switched away from.

- Extends `FakeGameCenterClient` with optional `ownRankSlice`/`ownRankError`
  overrides for the `aroundLocalPlayer: true` call only; unscripted (nil)
  behavior is unchanged, so every existing consumer is unaffected.
- Adds `GatedLeaderboardGameCenter`, a small continuation-gated local fake
  (matching the `StubGameCenter`/`MinimalGameCenter` precedent already used
  in this target) that suspends one leaderboard id's fetch until released,
  making the tab-switch race deterministic without sleeps.
- Extracted the new fake into its own file to keep DailyRankViewModelTests.swift
  under the 400-line SwiftLint cap.

Sanity-checked both new guard-dependent tests fail on a temporarily
un-guarded production build (guard deleted / `try?` → `try`), then restored
the production file unchanged.

part of #983

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@wei18
wei18 merged commit 3838a1e into main Aug 12, 2026
6 checks passed
@wei18
wei18 deleted the test/983-dailyrank-gaps branch August 12, 2026 03:01
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