From 85b0497716cd634fb021e5a5704edafa219e6817 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 29 Sep 2026 13:52:04 +0000 Subject: [PATCH] test(prefs): account for the Community List fragments slot The new kind-33302 backup slot never existed in the legacy SharedPreferences file, so it stays out of the one-shot migration table. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01PmuzkD5qdqgv6dMeRMoC5N --- .../commons/model/preferences/LatestEventCacheStore.kt | 6 ++++-- .../commons/model/preferences/LatestEventCacheStoreTest.kt | 5 +++-- .../commons/model/preferences/LegacyKeyTableTest.kt | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/model/preferences/LatestEventCacheStore.kt b/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/model/preferences/LatestEventCacheStore.kt index bde302eeec..5238625689 100644 --- a/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/model/preferences/LatestEventCacheStore.kt +++ b/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/model/preferences/LatestEventCacheStore.kt @@ -41,6 +41,8 @@ import okio.IOException */ enum class LatestEventSlot( val prefKey: String, + /** False for a slot added after the SharedPreferences era: there is nothing to migrate. */ + val existedInLegacyPrefs: Boolean = true, ) { CONTACT_LIST("latestContactList"), USER_METADATA("latestUserMetadata"), @@ -63,7 +65,7 @@ enum class LatestEventSlot( CONCORD_LIST("latestConcordList"), /** The kind-33302 Community List fragments (CORD-02 ยง8), one event JSON per line. */ - CONCORD_LIST_FRAGMENTS("latestConcordListFragments"), + CONCORD_LIST_FRAGMENTS("latestConcordListFragments", existedInLegacyPrefs = false), TRUST_PROVIDER_LIST("latestTrustProviderList"), KEY_PACKAGE_RELAY_LIST("latestKeyPackageRelayList"), FAVORITE_ALGO_FEEDS_LIST("latestFavoriteAlgoFeedsList"), @@ -97,7 +99,7 @@ class LatestEventCacheStore( val legacyTable = LegacyKeyTable( "migrated.latestEvents", - LatestEventSlot.entries.map { LegacyStringKey(it.prefKey, it.key) }, + LatestEventSlot.entries.filter { it.existedInLegacyPrefs }.map { LegacyStringKey(it.prefKey, it.key) }, ) } diff --git a/commons/src/jvmTest/kotlin/com/vitorpamplona/amethyst/commons/model/preferences/LatestEventCacheStoreTest.kt b/commons/src/jvmTest/kotlin/com/vitorpamplona/amethyst/commons/model/preferences/LatestEventCacheStoreTest.kt index 32d0003c47..549d12b5f1 100644 --- a/commons/src/jvmTest/kotlin/com/vitorpamplona/amethyst/commons/model/preferences/LatestEventCacheStoreTest.kt +++ b/commons/src/jvmTest/kotlin/com/vitorpamplona/amethyst/commons/model/preferences/LatestEventCacheStoreTest.kt @@ -107,10 +107,11 @@ class LatestEventCacheStoreTest { assertEquals("latestUserMetadata", LatestEventSlot.USER_METADATA.prefKey) assertEquals("latestContactList", LatestEventSlot.CONTACT_LIST.prefKey) assertEquals("latestNIP65RelayList", LatestEventSlot.NIP65_RELAY_LIST.prefKey) - assertEquals(26, LatestEventSlot.entries.size) + assertEquals("latestConcordListFragments", LatestEventSlot.CONCORD_LIST_FRAGMENTS.prefKey) + assertEquals(27, LatestEventSlot.entries.size) assertEquals( "prefKeys must be unique", - 26, + 27, LatestEventSlot.entries .map { it.prefKey } .toSet() diff --git a/commons/src/jvmTest/kotlin/com/vitorpamplona/amethyst/commons/model/preferences/LegacyKeyTableTest.kt b/commons/src/jvmTest/kotlin/com/vitorpamplona/amethyst/commons/model/preferences/LegacyKeyTableTest.kt index 8b5787bc83..e5343a4287 100644 --- a/commons/src/jvmTest/kotlin/com/vitorpamplona/amethyst/commons/model/preferences/LegacyKeyTableTest.kt +++ b/commons/src/jvmTest/kotlin/com/vitorpamplona/amethyst/commons/model/preferences/LegacyKeyTableTest.kt @@ -209,7 +209,7 @@ class LegacyKeyTableTest { ) assertEquals(FollowListSlot.entries.size, TopNavFollowListStore.legacyTable.keys.size) - assertEquals(LatestEventSlot.entries.size, LatestEventCacheStore.legacyTable.keys.size) + assertEquals(LatestEventSlot.entries.count { it.existedInLegacyPrefs }, LatestEventCacheStore.legacyTable.keys.size) } /** Several tables share one store, so their markers must not collide. */