wordmaker: a competitive hint can no longer corrupt the saved casual game
- Commit
d0ef4aa1f7904bcba8483099aff47933cc4b7b4e- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-01 05:47 UTC (5 days ago)
- Parents
4151c77
revealHint was the only ViewModel mutator dispatching on a daily Boolean instead of the three-way GameMode, so a competitive call fell through to the casual addRevealedHint/addFoundWord writes (plus the 30 s cooldown): requesting a hint in competitive play persisted the revealed cell and the completed words into the casual DataStore sets, and a later casual restore showed a hint cell and found words never earned on the casual board. The 'hints cannot be earned in competitive play' rule was enforced only by hiding the button, not at the layer that writes. revealHint now returns immediately in COMPETITIVE, before the cooldown or any write; daily/casual behaviour unchanged. New regression test failed pre-fix at the cooldown assertion. Dictionary membership, board generation, casual/daily isolation and restore determinism were audited and cleared. Verified: :games:wordmaker:testDevUnitTest 161 tests and :games:wordmaker:lint BUILD SUCCESSFUL (warnings are pre-existing in library files).
Diff
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/platform/WordMakerViewModel.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/platform/WordMakerViewModel.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/platform/WordMakerViewModel.ktindex 65b5b5cd4a..30398d0c9f 100644--- a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/platform/WordMakerViewModel.kt+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/platform/WordMakerViewModel.kt@@ -469,6 +469,12 @@ class WordMakerViewModel(application: Application) : AndroidViewModel(applicatio } override fun revealHint(crosswordData: CrosswordData, foundWords: Set<String>, revealedHints: Set<Pair<Int, Int>>) {+ // Hints cannot be earned in competitive play (the button is hidden there and the+ // revealed-hints flow shows none). Refuse here rather than only hiding the button:+ // the writes below are mode-dispatched as daily-or-casual, so a competitive call+ // would otherwise persist its hint cell and any word it completes into the saved+ // casual game, which then restores with progress the player never earned there.+ if (gameMode.value == GameMode.COMPETITIVE) return val revealed = foundWords.flatMapTo(mutableSetOf()) { word -> crosswordData.letterPositions[word]?.flatten().orEmpty() } + revealedHints
games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/platform/WordMakerViewModelTest.kt
diff --git a/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/platform/WordMakerViewModelTest.kt b/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/platform/WordMakerViewModelTest.ktindex 2eb48bb844..c7b659cf22 100644--- a/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/platform/WordMakerViewModelTest.kt+++ b/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/platform/WordMakerViewModelTest.kt@@ -236,6 +236,36 @@ class WordMakerViewModelTest { pollUntil { vm.gameMode.value == GameMode.CASUAL } assertFalse(vm.bonusWords.value.contains("ZQXCOMPWORD")) }+ @Test fun revealHintInCompetitiveModeDoesNotTouchCasualState() {+ val vm = vm()+ // Start from a pristine casual level, then enter a competitive level.+ vm.setGameMode(GameMode.CASUAL)+ pollUntil { vm.gameMode.value == GameMode.CASUAL }+ vm.saveLevel(1)+ pollUntil { vm.currentLevel.value == 1 && vm.foundWords.value.isEmpty() && vm.revealedHints.value.isEmpty() }+ vm.setGameMode(GameMode.COMPETITIVE)+ pollUntil { vm.gameMode.value == GameMode.COMPETITIVE }+ vm.loadNextCompetitiveLevel()+ pollUntil { vm.competitiveActive.value && vm.crosswordData.value != null }+ // Hints cannot be earned in competitive play, so asking for one there+ // must be a no-op. The inputs below leave exactly one cell of the+ // CAT/ACT board unrevealed, so a hint that (wrongly) ran would reveal+ // that cell and complete both words in whichever store it wrote to.+ val board = CrosswordData.fromString("CAT\n C \n T ")!!+ val allCells = board.letterPositions.values.flatMap { it.flatten() }.toSet()+ vm.revealHint(board, emptySet(), allCells - (0 to 0))+ // No cooldown is started and nothing lands in the saved casual game:+ // a casual game restored later must not show a hint cell or found+ // words the player never earned on that board.+ assertEquals(0L, vm.hintCooldownEnd.value)+ Thread.sleep(500)+ val storedFound = kotlinx.coroutines.runBlocking { vm.levelDataStore.foundWords.first() }+ val storedHints = kotlinx.coroutines.runBlocking { vm.levelDataStore.revealedHints.first() }+ assertTrue(storedFound.isEmpty(), "competitive hint wrote casual found words: $storedFound")+ assertTrue(storedHints.isEmpty(), "competitive hint wrote casual revealed hints: $storedHints")+ vm.setGameMode(GameMode.CASUAL)+ pollUntil { vm.gameMode.value == GameMode.CASUAL }+ } @Test fun hintAvailableImmediatelyOnLaunch() { // No hint has been used yet, so there is no cooldown to serve: the // UiState contract uses 0 for "available now" and the wheel enables