Repository navigation
test(gamecenter): cover DailyRankViewModel's own-rank second fetch + stale-response drop - #1008
Merged
Merged
Conversation
…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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DailyRankViewModel'saroundLocalPlayer: truesecond fetch — dedupe against the top slice, plus degradation (screen still renders the top slice) when that second fetch fails.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.FakeGameCenterClient(GameCenterTesting) with optionalownRankSlice/ownRankErroroverrides that only apply toaroundLocalPlayer: truecalls; unscripted (nil, the default) behavior is byte-for-byte unchanged, so all ~26 existing consumers are unaffected.GatedLeaderboardGameCenter(own file,Tests/GameAppKitTests/GatedLeaderboardGameCenter.swift) — a small continuation-gated localGameCenterClientfake, following the existingStubGameCenter/MinimalGameCenterprecedent 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.swiftstayed 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):commit(_:for:)selection-key guard →staleResponseDroppedAfterSwitchingAwayAndBackfails (stale.loaded(STALE)leaks into the "easy" tab's state).try?totryon the second fetch →secondFetchFailureDegradesToTopSliceOnlyRatherThanFailingScreenfails (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 inDailyRankViewModel — #983 statesswift 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 theFakeGameCenterClientextension)swift test --package-path Packages/MinesweeperKit --no-parallel --filter DailyRankViewTests— 7/7 passedswiftlint lint --stricton all 3 changed/added files — 0 violationsrg -n 'TODO|FIXME|stub|placeholder'on the diff — no matchesgit difftouches onlyTests/and the test-supportGameCenterTestingtarget)part of #983
🤖 Generated with Claude Code