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
This commit is contained in:
2026-07-09 23:51:55 -05:00
parent f049898be1
commit 17985cb04c
@@ -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"
}
}