From 17985cb04c1a06fbbf6abab053978570dadc56e3 Mon Sep 17 00:00:00 2001 From: Jason Ross Date: Thu, 9 Jul 2026 23:51:55 -0500 Subject: [PATCH] test(migrator): resolve latest exported AccountDatabase schema dynamically Resolves the highest-versioned AccountDatabase schema JSON under assets instead of hardcoding a version filename, so a schema bump is validated automatically instead of silently checked against a stale version. Fails loudly if no schema asset is found. Closes #477 --- .../data/local/AccountDataMigratorTest.kt | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/app/src/androidTest/kotlin/org/libremail/data/local/AccountDataMigratorTest.kt b/app/src/androidTest/kotlin/org/libremail/data/local/AccountDataMigratorTest.kt index 8db0847..4ecb8a1 100644 --- a/app/src/androidTest/kotlin/org/libremail/data/local/AccountDataMigratorTest.kt +++ b/app/src/androidTest/kotlin/org/libremail/data/local/AccountDataMigratorTest.kt @@ -275,7 +275,7 @@ class AccountDataMigratorTest { fun migratorDdlMatchesExportedAccountDatabaseSchema() { val schema = JSONObject( InstrumentationRegistry.getInstrumentation().context.assets - .open("org.libremail.data.local.AccountDatabase/2.json") + .open(latestAccountDatabaseSchemaAsset()) .bufferedReader().use { it.readText() }, ).getJSONObject("database") val entities = schema.getJSONArray("entities") @@ -312,4 +312,28 @@ class AccountDataMigratorTest { ) assertTrue("the signatures index must be present in the exported schema", checkedIndex) } + + /** + * The highest-versioned exported AccountDatabase schema shipped as an androidTest asset — i.e. the + * current schema. Resolved dynamically so a schema-version bump is validated automatically and no + * one has to remember to bump a hardcoded filename here (issue #477). Fails loudly if the schema + * assets are missing/mislocated rather than silently validating against nothing. + */ + private fun latestAccountDatabaseSchemaAsset(): String { + val assets = InstrumentationRegistry.getInstrumentation().context.assets + val latest = assets.list(ACCOUNT_DATABASE_SCHEMA_DIR).orEmpty() + .filter { it.endsWith(".json") } + .mapNotNull { it.removeSuffix(".json").toIntOrNull() } + .maxOrNull() + assertNotNull( + "No exported AccountDatabase schema JSON under assets/$ACCOUNT_DATABASE_SCHEMA_DIR — is " + + "schemas/ still wired as an androidTest asset srcDir in app/build.gradle.kts?", + latest, + ) + return "$ACCOUNT_DATABASE_SCHEMA_DIR/$latest.json" + } + + private companion object { + const val ACCOUNT_DATABASE_SCHEMA_DIR = "org.libremail.data.local.AccountDatabase" + } } -- 2.47.3