Modern Apps git

← Modern-Apps.git

launcher: unflake the seeding tests and re-pin the drawer loading contract

Commit
e1c01b0b823835f32a26b864ab9d6799e628b846
Author
Vayun Mathur <[email protected]>
When
2026-12-01 12:33 UTC (5 days ago)
Parents
75a6d08
Two failures were test-isolation defects: the seeding
tests polled with a blind 300x sleep without ever verifying
the persisted KEY_SEEDED flag, and tearDown reflected
onCleared, which does not cancel viewModelScope — a prior
test's seed coroutine leaked into the next over the shared
repository and DataStore. tearDown now cancels the scope and
the flush polls the flag until it reads the expected value.
Production seeding already matches its documented contract
(a deliberately cleared home screen is not reseeded).

The drawer test was a stale contract: the loading wave
pinned a standalone progress indicator, then the scaffold
pull-to-refresh wave removed it for progress text (the
drawer is a non-scaffold overlay; the convention — fatal
ScaffoldLoading lint — makes the local affordance progress
text, and the test was demanding lint-illegal UI). It now
asserts 'Loading…' shown, no empty-state text, and no
progress-indicator node. No production code changed.
Verified: full :launcher:testDevUnitTest 405 tests, 0
failures, twice (second with cleanTest + no-build-cache);
the 1 lint error is pre-existing on untouched main code.

Diff

launcher/src/test/java/com/vayunmathur/launcher/platform/LauncherViewModelOpsTest.kt
diff --git a/launcher/src/test/java/com/vayunmathur/launcher/platform/LauncherViewModelOpsTest.kt b/launcher/src/test/java/com/vayunmathur/launcher/platform/LauncherViewModelOpsTest.ktindex 08802445d2..8c1ce41200 100644--- a/launcher/src/test/java/com/vayunmathur/launcher/platform/LauncherViewModelOpsTest.kt+++ b/launcher/src/test/java/com/vayunmathur/launcher/platform/LauncherViewModelOpsTest.kt@@ -27,6 +27,7 @@ import kotlin.test.assertNotNull import kotlin.test.assertNull import kotlin.test.assertTrue import kotlin.test.fail+import kotlinx.coroutines.cancel import kotlinx.coroutines.launch import kotlinx.coroutines.test.runTest import org.junit.runner.RunWith@@ -65,6 +66,12 @@ class LauncherViewModelOpsTest {                 .getDeclaredMethod("onCleared").apply { isAccessible = true }             cleared.invoke(vm)         }+        // Invoking onCleared reflectively does not cancel viewModelScope (only+        // ViewModelStore clearing does that), so without this the old VM's+        // coroutines — the workspace collector, and any seed coroutine still+        // suspended in its seeded-flag DataStore write — leak into the next+        // test, which shares the repository singleton and the DataStore.+        vm.viewModelScope.cancel()         shadowOf(Looper.getMainLooper()).idle()         // Deliberately NOT holder.close(): this database is also the         // LauncherRepository singleton's db (swapped in setUp), and other@@ -78,15 +85,27 @@ class LauncherViewModelOpsTest {      */     private fun resetSeededFlag() {         vm.viewModelScope.launch { vm.ds.setBoolean(KEY_SEEDED, false) }-        flushDataStoreWrites()+        awaitSeededFlag(false)     } -    /** Gives queued DataStore writes time to land (idle turns plus sleeps). */-    private fun flushDataStoreWrites() {+    /**+     * Waits until the persisted seeded flag actually reads [expected], rather+     * than sleeping a fixed budget and hoping the asynchronous DataStore write+     * landed inside it. Under full-suite load the blind sleep raced both ways:+     * a reset that had not landed made the next seed a no-op (seeded-rows+     * timeout), and a seed's flag write that had not landed made a deliberate+     * clear look like a first run (reseeded rows).+     */+    private fun awaitSeededFlag(expected: Boolean) {         repeat(300) {             shadowOf(Looper.getMainLooper()).idle()+            val actual = kotlinx.coroutines.runBlocking {+                vm.ds.getBooleanAwait(KEY_SEEDED, false)+            }+            if (actual == expected) return             Thread.sleep(10)         }+        fail("seeded flag never became $expected")     }      private fun await(description: String, cond: () -> Boolean) {@@ -554,7 +573,9 @@ class LauncherViewModelOpsTest {         setMonitorApps((0 until 7).map { appEntry("com.example.s$it", label = "Seed$it") })         vm.seedIfEmptyImpl()         await("seeded rows") { all().isNotEmpty() }-        flushDataStoreWrites()+        // Rows land before the seed coroutine's flag write does; the clear+        // below is only meaningful once that write has actually landed.+        awaitSeededFlag(true)         // The user removes every item: the table is empty again, which is         // exactly the state a first run starts in. Empty alone cannot tell         // the two apart.@@ -583,9 +604,9 @@ class LauncherViewModelOpsTest {         )         await("manual row added") { all().isNotEmpty() }         vm.seedIfEmptyImpl()-        // The recording write is asynchronous; give it time to land before+        // The recording write is asynchronous; it must actually land before         // the clear below, or the second call could still read it as unset.-        flushDataStoreWrites()+        awaitSeededFlag(true)         all().map { it.id }.forEach { vm.remove(it) }         await("home cleared") { all().isEmpty() }         vm.seedIfEmptyImpl()
launcher/src/test/java/com/vayunmathur/launcher/ui/LauncherDrawerUiTest.kt
diff --git a/launcher/src/test/java/com/vayunmathur/launcher/ui/LauncherDrawerUiTest.kt b/launcher/src/test/java/com/vayunmathur/launcher/ui/LauncherDrawerUiTest.ktindex 25e3754042..2d4a5af9ed 100644--- a/launcher/src/test/java/com/vayunmathur/launcher/ui/LauncherDrawerUiTest.kt+++ b/launcher/src/test/java/com/vayunmathur/launcher/ui/LauncherDrawerUiTest.kt@@ -86,15 +86,21 @@ class LauncherDrawerUiTest {      @Test fun loadingReadsLoadingApps() {         show(state = DrawerUiState(apps = emptyList(), loading = true))-        // Loading now renders the canonical indicator, not a text label:-        // the indicator is on screen and neither text state is.+        // The drawer is an overlay over the home screen, not a scaffold screen+        // (see the SCAFFOLD SEARCH EXCEPTION in DrawerContent), so its loading+        // state is the scaffold-consistent local affordance the root AGENTS.md+        // prescribes for non-scaffold surfaces — progress text in the empty-state+        // slot — never a standalone progress indicator (fatal ScaffoldLoading+        // lint; the indicator was removed from DrawerContent by the scaffold+        // pull-to-refresh wave). Assert that text, and that neither the empty+        // state nor any progress indicator is shown instead.+        rule.onNodeWithText("Loading…").assertIsDisplayed()+        rule.onNodeWithText("No apps found").assertDoesNotExist()         rule.onNode(             androidx.compose.ui.test.SemanticsMatcher.keyIsDefined(                 androidx.compose.ui.semantics.SemanticsProperties.ProgressBarRangeInfo,             ),-        ).assertExists()-        rule.onNodeWithText("Loading apps").assertDoesNotExist()-        rule.onNodeWithText("No apps found").assertDoesNotExist()+        ).assertDoesNotExist()     }      @Test fun listLayoutRendersRows() {