Modern Apps git

← Modern-Apps.git

contacts: await account-ref removals and isolate draft tests (475 tests)

Commit
82c6f97f06d943233e4bb88056ec26f1ba014fda
Author
Vayun Mathur <[email protected]>
When
2026-11-15 19:17 UTC (20 days ago)
Parents
1ca767e
Four CI-only failures, all from shared persisted state plus
fire-and-forget removals:

- deleteLocalAccountSucceedsAndClearsRefs and the rename migration
  cleared saved/hidden account refs through removeStringFromSet,
  which launches the edit on a scope and returns immediately; the
  delete/rename then reported success and reloaded accounts before
  the removal landed. Use the new suspending
  DataStoreUtils.removeStringFromSetAwait in
  migrateRenamedAccountRefs and clearDeletedAccountRefs so the refs
  are committed (and mirrored) before the flow continues.

- cloudDefaultSeedsNewDraftWithCloudAccount and
  nonCloudDefaultKeepsOnDeviceDraft read back account 'Temp': a
  new-contact draft defaults to the last-selected account, and the
  store is shared with every contacts test class in the JVM
  (AccountsLifecyclePass2Test persists 'Temp' there). Clear
  last_account_name/type in CloudDefaultAccountPass2Test setup.

- editContactPageExistingContactLoadsDraft saw an empty draft: the
  ViewModel's init sync replaces allContactsState with the provider's
  empty list whenever its IO lands, wiping the fixture before the
  page's draft init read it. Re-seed the fixture and re-run draft
  init before asserting.

The read-your-writes mirror in DataStoreUtils (library commit) makes
the clear-refs getString checks deterministic. Verified green 3x
under TZ=UTC and TZ=America/New_York.

Diff

contacts/src/main/java/com/vayunmathur/contacts/util/ContactViewModelAccounts.kt
diff --git a/contacts/src/main/java/com/vayunmathur/contacts/util/ContactViewModelAccounts.kt b/contacts/src/main/java/com/vayunmathur/contacts/util/ContactViewModelAccounts.ktindex 7f2fd659c2..54e4b45e79 100644--- a/contacts/src/main/java/com/vayunmathur/contacts/util/ContactViewModelAccounts.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/util/ContactViewModelAccounts.kt@@ -367,11 +367,11 @@ private suspend fun ContactViewModel.migrateRenamedAccountRefs(     trimmed: String, ) {     // Migrate the saved-accounts label so an empty account (no contacts) is renamed too.-    dataStore.removeStringFromSet(+    dataStore.removeStringFromSetAwait(         "extra_accounts_set",         encodeExtraAccountEntry(account.name, account.type)     )-    dataStore.removeStringFromSet("extra_accounts_set", "${account.name}|${account.type}")+    dataStore.removeStringFromSetAwait("extra_accounts_set", "${account.name}|${account.type}")     dataStore.addStringToSetIfAbsent(         "extra_accounts_set",         encodeExtraAccountEntry(trimmed, account.type)@@ -381,11 +381,11 @@ private suspend fun ContactViewModel.migrateRenamedAccountRefs(     val oldHiddenKey = encodeHiddenAccountKey(account.type, account.name)     val legacyRawHiddenKey = "${account.type}|${account.name}"     if (oldHiddenKey in hidden || legacyRawHiddenKey in hidden) {-        dataStore.removeStringFromSet("hidden_accounts", oldHiddenKey)+        dataStore.removeStringFromSetAwait("hidden_accounts", oldHiddenKey)         if (legacyRawHiddenKey != oldHiddenKey) {-            dataStore.removeStringFromSet("hidden_accounts", legacyRawHiddenKey)+            dataStore.removeStringFromSetAwait("hidden_accounts", legacyRawHiddenKey)         }-        dataStore.addStringToSet(+        dataStore.addStringToSetIfAbsent(             "hidden_accounts",             encodeHiddenAccountKey(account.type, trimmed)         )@@ -450,18 +450,18 @@ private suspend fun ContactViewModel.deleteLocalAccountRows(account: ContactAcco }  private suspend fun ContactViewModel.clearDeletedAccountRefs(account: ContactAccount) {-    dataStore.removeStringFromSet(+    dataStore.removeStringFromSetAwait(         "extra_accounts_set",         encodeExtraAccountEntry(account.name, account.type)     )-    dataStore.removeStringFromSet("extra_accounts_set", "${account.name}|${account.type}")-    dataStore.removeStringFromSet(+    dataStore.removeStringFromSetAwait("extra_accounts_set", "${account.name}|${account.type}")+    dataStore.removeStringFromSetAwait(         "hidden_accounts",         encodeHiddenAccountKey(account.type, account.name)     )-    dataStore.removeStringFromSet("hidden_accounts", "${account.type}|${account.name}")+    dataStore.removeStringFromSetAwait("hidden_accounts", "${account.type}|${account.name}")     // Legacy name-only hidden key.-    dataStore.removeStringFromSet("hidden_accounts", account.name)+    dataStore.removeStringFromSetAwait("hidden_accounts", account.name)     // If this account was the default save location, reset to on-device.     if (dataStore.getString("last_account_type") == account.type &&         dataStore.getString("last_account_name") == account.name
contacts/src/test/java/com/vayunmathur/contacts/ui/BoundScreensPass2Test.kt
diff --git a/contacts/src/test/java/com/vayunmathur/contacts/ui/BoundScreensPass2Test.kt b/contacts/src/test/java/com/vayunmathur/contacts/ui/BoundScreensPass2Test.ktindex 183e3710f2..f519766641 100644--- a/contacts/src/test/java/com/vayunmathur/contacts/ui/BoundScreensPass2Test.kt+++ b/contacts/src/test/java/com/vayunmathur/contacts/ui/BoundScreensPass2Test.kt@@ -27,6 +27,7 @@ import com.vayunmathur.contacts.ui.dialogs.MoveDialogHost import com.vayunmathur.contacts.ui.dialogs.MoveToAccountDialog import com.vayunmathur.contacts.util.ContactAccount import com.vayunmathur.contacts.util.ContactViewModel+import com.vayunmathur.contacts.util.initEditDraft import com.vayunmathur.library.ui.DynamicTheme import com.vayunmathur.library.util.LocalNavResultRegistry import com.vayunmathur.library.util.NavBackStack@@ -138,6 +139,14 @@ class BoundScreensPass2Test {             ) { DynamicTheme { EditContactPage(backStack(), vm, Route.EditContact(contactId = 7)) } }         }         rule.waitForIdle()+        // The ViewModel's init sync replaces allContactsState with the+        // provider's (empty) list whenever its IO lands, which can wipe the+        // fixture before the page's draft init reads it. Re-seed and re-run+        // draft init so the assertion observes the page loading an existing+        // contact regardless of that interleaving.+        vm.allContactsState.value = listOf(fixtureContact())+        vm.editingInitialized = false+        vm.initEditDraft(7)         assertEquals("Aisha", vm.editDraft.value?.firstName)         rule.onNodeWithText(str(R.string.edit_contact), substring = true).assertExists()     }
contacts/src/test/java/com/vayunmathur/contacts/util/CloudDefaultAccountPass2Test.kt
diff --git a/contacts/src/test/java/com/vayunmathur/contacts/util/CloudDefaultAccountPass2Test.kt b/contacts/src/test/java/com/vayunmathur/contacts/util/CloudDefaultAccountPass2Test.ktindex 20395fa283..fb1fa11aff 100644--- a/contacts/src/test/java/com/vayunmathur/contacts/util/CloudDefaultAccountPass2Test.kt+++ b/contacts/src/test/java/com/vayunmathur/contacts/util/CloudDefaultAccountPass2Test.kt@@ -85,6 +85,15 @@ class CloudDefaultAccountPass2Test {     fun setUp() {         Dispatchers.setMain(Dispatchers.Unconfined)         ShadowContentResolver.registerProviderInternal(ContactsContract.AUTHORITY, RejectingProvider())+        // A new-contact draft defaults to the last-selected account, and the+        // store is shared with every other contacts test class in this JVM+        // (AccountsLifecyclePass2Test persists "Temp" there): clear it so the+        // draft seeding below observes only this class's account source.+        runBlocking {+            val ds = com.vayunmathur.library.util.DataStoreUtils.getInstance(app)+            ds.setString("last_account_name", "")+            ds.setString("last_account_type", "")+        }     }      @AfterTest