games-wordmaker: reset competitive state synchronously on mode switch
- Commit
78044c14e82f7458f15f1a0f11ece8ad5132b7de- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-17 02:44 UTC (19 days ago)
- Parents
00dc2ab
Product: setGameMode reset the competitive session (active/result/deadline) only after the suspending DataStore mode write, so the stale reset could land after loadNextCompetitiveLevel() started in the new mode and clear its active flag, leaving a generated board permanently inactive (the 30s poll timeouts in retryLoad and the tap-submission test). The reset now happens synchronously before the persisted write. Test: dailyBonusAndFoundWordsDoNotLeakIntoCasualSets asserted the casual found/bonus sets immediately after polling only gameMode; those sets are combines over gameMode and switch asynchronously, so await their observed contents too. Verified: TZ=UTC ViewModelDeepTest and GameLoaderPageDeepTest green.
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 be199b6b83..2c5cfe86e9 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@@ -333,14 +333,18 @@ class WordMakerViewModel(application: Application) : AndroidViewModel(applicatio } override fun setGameMode(mode: GameMode) {+ // Reset to the neutral state synchronously, before the persisted+ // mode write suspends: doing it after the write let this stale+ // reset land after a loadNextCompetitiveLevel() started in the+ // new mode, clearing its active flag (and leaving its board+ // permanently "inactive", which the retry/tap flows poll for).+ _competitiveActive.value = false+ _competitiveResult.value = null+ _competitiveDeadline.value = 0L+ // The error belongs to the mode that produced it, not to the one being entered.+ _error.value = null viewModelScope.launch { levelDataStore.setGameMode(mode)- // Both modes return to a neutral state: competitive opens its lobby, casual resumes play.- _competitiveActive.value = false- _competitiveResult.value = null- _competitiveDeadline.value = 0L- // The error belongs to the mode that produced it, not to the one being entered.- _error.value = null } }
games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/platform/ViewModelDeepTest.kt
diff --git a/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/platform/ViewModelDeepTest.kt b/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/platform/ViewModelDeepTest.ktindex 6238d86cba..559cae5947 100644--- a/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/platform/ViewModelDeepTest.kt+++ b/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/platform/ViewModelDeepTest.kt@@ -215,8 +215,13 @@ class ViewModelDeepTest { assertTrue(total >= 1) pollUntil { "ZQXDAILYDEEP" in vm.bonusWords.value } // The same word found today does not appear once back in casual mode.+ // foundWords/bonusWords are combines over gameMode, so they switch+ // asynchronously after gameMode itself: await the observed sets,+ // not just the mode (an immediate assert reads the daily sets). vm.setGameMode(GameMode.CASUAL) pollUntil { vm.gameMode.value == GameMode.CASUAL }+ pollUntil { "ZQXDAILYDEEP" !in vm.foundWords.value }+ pollUntil { "ZQXDAILYDEEP" !in vm.bonusWords.value } assertFalse("ZQXDAILYDEEP" in vm.foundWords.value) assertFalse("ZQXDAILYDEEP" in vm.bonusWords.value) // Daily win is idempotent within the day for the streak.