Modern Apps git

← Modern-Apps.git

appstore: make Accrescent repodata fetcher injectable for tests

Commit
e25623f5153384d70df65efbfd4aeed36b677d2e
Author
Vayun Mathur <[email protected]>
When
2026-11-14 23:08 UTC (21 days ago)
Parents
08c31c0
AccrescentRepositoryOfflineTest asserted no-network behaviour
against the real gRPC API and repodata host, and
InstallCoordinatorAccrescentTest seeded trust rows that a live
repodata refresh then replaced with the real allowlist (which
does not vouch for the fake app ids, so trusted installs were
refused with 'does not vouch'). Both only pass with no network.

Make AccrescentRepoDataFetcher open and let AccrescentRepository
take one as a constructor parameter (default unchanged). The
offline test now uses an in-process channel with no server (every
RPC fails UNAVAILABLE) plus a fetcher that fails; the installer
test injects the failing fetcher so its seeded trust survives the
install-time refresh, exactly as it does when the refresh fails
on a real offline device. Assertions unchanged.

Verified: targeted :appstore:testDevUnitTest run (see final
full-suite run).

Diff

appstore/src/main/java/com/vayunmathur/appstore/data/accrescent/AccrescentRepoData.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/data/accrescent/AccrescentRepoData.kt b/appstore/src/main/java/com/vayunmathur/appstore/data/accrescent/AccrescentRepoData.ktindex 4bf64db75c..ffeb1c0c58 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/data/accrescent/AccrescentRepoData.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/data/accrescent/AccrescentRepoData.kt@@ -45,11 +45,11 @@ data class RepoApp(  * [Result.failure] — fail closed — so a tampered, unsigned or rolled-back document yields no  * usable allowlist and therefore nothing installable.  */-class AccrescentRepoDataFetcher(private val context: Context) {+open class AccrescentRepoDataFetcher(private val context: Context) {      private val json = Json { ignoreUnknownKeys = true; isLenient = true } -    suspend fun fetch(): Result<RepoData> {+    open suspend fun fetch(): Result<RepoData> {         return try {             val (jsonStatus, _, jsonBytes) =                 NetworkClient.performRequestBytesFull(AccrescentRepo.REPODATA_JSON_URL)
appstore/src/main/java/com/vayunmathur/appstore/data/accrescent/AccrescentRepository.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/data/accrescent/AccrescentRepository.kt b/appstore/src/main/java/com/vayunmathur/appstore/data/accrescent/AccrescentRepository.ktindex 8c339a60b7..f406d24fd7 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/data/accrescent/AccrescentRepository.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/data/accrescent/AccrescentRepository.kt@@ -43,8 +43,8 @@ class AccrescentRepository(     context: Context,     db: AppDatabase,     private val api: AccrescentApi = AccrescentApi(),+    private val repoDataFetcher: AccrescentRepoDataFetcher = AccrescentRepoDataFetcher(context), ) {-    private val repoDataFetcher = AccrescentRepoDataFetcher(context)     private val trustStore = AccrescentTrustStore(db.accrescentTrustDao())     private val deviceAttributes = DeviceAttributesProvider(context)     private val appContext = context.applicationContext
appstore/src/test/java/com/vayunmathur/appstore/data/accrescent/AccrescentRepositoryOfflineTest.kt
diff --git a/appstore/src/test/java/com/vayunmathur/appstore/data/accrescent/AccrescentRepositoryOfflineTest.kt b/appstore/src/test/java/com/vayunmathur/appstore/data/accrescent/AccrescentRepositoryOfflineTest.ktindex adde72e5ea..f368394afd 100644--- a/appstore/src/test/java/com/vayunmathur/appstore/data/accrescent/AccrescentRepositoryOfflineTest.kt+++ b/appstore/src/test/java/com/vayunmathur/appstore/data/accrescent/AccrescentRepositoryOfflineTest.kt@@ -35,7 +35,16 @@ class AccrescentRepositoryOfflineTest {             .setDriver(BundledSQLiteDriver())             .allowMainThreadQueries()             .build()-        repo = AccrescentRepository(ctx, db)+        // Hermetic offline: an in-process channel with no server behind it+        // (every RPC fails UNAVAILABLE) plus a repodata fetcher that fails,+        // whatever network the host running the tests happens to have.+        val deadChannel = io.grpc.inprocess.InProcessChannelBuilder+            .forName("accrescent-offline-no-server").directExecutor().build()+        val failingFetcher = object : AccrescentRepoDataFetcher(ctx) {+            override suspend fun fetch(): Result<RepoData> =+                Result.failure(java.io.IOException("offline test double"))+        }+        repo = AccrescentRepository(ctx, db, AccrescentApi { deadChannel }, failingFetcher)     }      @AfterTest
appstore/src/test/java/com/vayunmathur/appstore/data/installer/InstallCoordinatorAccrescentTest.kt
diff --git a/appstore/src/test/java/com/vayunmathur/appstore/data/installer/InstallCoordinatorAccrescentTest.kt b/appstore/src/test/java/com/vayunmathur/appstore/data/installer/InstallCoordinatorAccrescentTest.ktindex 5a4cd5e09b..85555d74b7 100644--- a/appstore/src/test/java/com/vayunmathur/appstore/data/installer/InstallCoordinatorAccrescentTest.kt+++ b/appstore/src/test/java/com/vayunmathur/appstore/data/installer/InstallCoordinatorAccrescentTest.kt@@ -110,11 +110,21 @@ class InstallCoordinatorAccrescentTest {             .allowMainThreadQueries()             .build()         scope = CoroutineScope(Dispatchers.Unconfined)+        // The repodata refresh must fail closed and leave the trust rows+        // each test seeds: with live network it would succeed and replace+        // them with the real allowlist, which does not vouch for the fake+        // app ids below.+        val failingFetcher = object :+            com.vayunmathur.appstore.data.accrescent.AccrescentRepoDataFetcher(context) {+            override suspend fun fetch():+                Result<com.vayunmathur.appstore.data.accrescent.RepoData> =+                Result.failure(java.io.IOException("offline test double"))+        }         coordinator = InstallCoordinator(             context = context,             db = db,             play = PlayRepository(context),-            accrescent = AccrescentRepository(context, db, AccrescentApi { channel }),+            accrescent = AccrescentRepository(context, db, AccrescentApi { channel }, failingFetcher),             scope = scope,             ownSigningCertificates = { emptySet() },         )