Modern Apps git

← Modern-Apps.git

photos: the favorites-sync test asserts each write route separately

Commit
48fd89d0326ff34a4bbb2bb08747d2feda994b62
Author
Vayun Mathur <[email protected]>
When
2026-12-01 11:35 UTC (5 days ago)
Parents
8de225b
The full suite failed
newAndOtherwiseChangedRowsCarryTheirFavoriteFlag
deterministically โ€” a single-method run reproduces it, so
test isolation is excluded. The product partitions changed
rows (column-targeted updateSyncFields, deliberately: a
rebuilt-row upsert would null OCR/CLIP payloads the sync
projection excludes โ€” documented in AGENTS.md and the split
commit) from new rows (upsertAll). The test fake recorded
both into one upsertedBatches list, so .single() necessarily
failed against the two legitimate calls; the test still
encoded the pre-split contract.

The fake now records inserts and column-updates separately;
the test asserts exactly one batch per route (ids {3,5}
inserted, {1} column-updated) plus the original union and
all-favorite assertions โ€” strictly stronger, since it now
also fails if a known row is ever whole-row upserted. Two
sibling tests gained the matching no-column-update checks.
No product code changed. Verified: the class and the full
:photos:testDevUnitTest pass (418 tests, 0 failures); lint
errors are pre-existing on untouched files.

Diff

photos/src/test/java/com/vayunmathur/photos/util/PhotosFavoritesSyncTest.kt
diff --git a/photos/src/test/java/com/vayunmathur/photos/util/PhotosFavoritesSyncTest.kt b/photos/src/test/java/com/vayunmathur/photos/util/PhotosFavoritesSyncTest.ktindex 89d933b92a..b2b097c2fb 100644--- a/photos/src/test/java/com/vayunmathur/photos/util/PhotosFavoritesSyncTest.kt+++ b/photos/src/test/java/com/vayunmathur/photos/util/PhotosFavoritesSyncTest.kt@@ -42,6 +42,7 @@ class PhotosFavoritesSyncTest {         var all: List<Photo> = emptyList()         val deletedBatches = mutableListOf<List<Long>>()         val upsertedBatches = mutableListOf<List<Photo>>()+        val syncUpdatedBatches = mutableListOf<List<Photo>>()         val favoriteWrites = mutableListOf<Pair<List<Long>, Boolean>>()         override suspend fun getAll(): List<Photo> = all         override suspend fun getAllForSync(): List<Photo> = all@@ -51,10 +52,12 @@ class PhotosFavoritesSyncTest {         override suspend fun upsertAll(photos: List<Photo>) {             upsertedBatches += photos         }-        // Known-row sync writes are column-targeted in production; record-        // them with the inserts so assertions see every row the sync wrote.+        // Known-row sync writes are column-targeted in production, never+        // whole-row upserts (an upsert would null the row's OCR/CLIP+        // payloads). Record them separately from inserts so assertions can+        // verify each row took the right route, not just that it was written.         override suspend fun updateSyncFields(photos: List<Photo>) {-            upsertedBatches += photos+            syncUpdatedBatches += photos         }         override suspend fun setFavorite(ids: List<Long>, value: Boolean) {             favoriteWrites += ids to value@@ -147,6 +150,7 @@ class PhotosFavoritesSyncTest {          // No row rebuild (which would drop the CLIP embedding); one targeted write each way.         assertTrue(repository.upsertedBatches.isEmpty(), repository.upsertedBatches.toString())+        assertTrue(repository.syncUpdatedBatches.isEmpty(), repository.syncUpdatedBatches.toString())         assertEquals(             setOf(listOf(1L) to true, listOf(2L) to false),             repository.favoriteWrites.toSet(),@@ -165,7 +169,14 @@ class PhotosFavoritesSyncTest {          syncPhotos(context, repository, null, 0L) -        val upserted = repository.upsertedBatches.single().associateBy { it.id }+        // Exactly one batch per write route: new rows (3, 5) inserted whole,+        // the already-known changed row (1) written by column only, so its+        // OCR/CLIP payloads survive (see SyncWorker's partition).+        val inserted = repository.upsertedBatches.single()+        val updated = repository.syncUpdatedBatches.single()+        assertEquals(setOf(3L, 5L), inserted.map { it.id }.toSet())+        assertEquals(setOf(1L), updated.map { it.id }.toSet())+        val upserted = (inserted + updated).associateBy { it.id }         assertEquals(setOf(1L, 3L, 5L), upserted.keys)         // Videos are favourited the same way as photos.         assertTrue(upserted.values.all { it.isFavorite })@@ -180,6 +191,7 @@ class PhotosFavoritesSyncTest {         syncPhotos(context, repository, null, 0L)          assertTrue(repository.upsertedBatches.isEmpty())+        assertTrue(repository.syncUpdatedBatches.isEmpty())         assertTrue(repository.favoriteWrites.isEmpty())     }