Modern Apps git

← Modern-Apps.git

findfamily: add tests for map state, controller, networking and main page (pass 2)

Commit
6ac7dce1cd1076acc82b8c5e5e64b206db1d249f
Author
Vayun Mathur <[email protected]>
When
2026-11-07 07:51 UTC (29 days ago)
Parents
4980514
Second coverage pass: MapPageState selection/waypoint-form logic,
LocationServiceController persisted flags, FindFamilyViewModel
construction/permissions/selection (with WorkManager initialized
for tests and a fake AndroidKeyStore provider), Networking's
PQC-gated helpers before identity exists, base26 invite IDs, the
small static dialogs, and MainPageContent rendered directly in its
nothing/person/waypoint-selected states plus the expiry dropdown.

Coverage (merged, whole module): 16.5% -> 22.6% instructions
(12103/53592). Bugs fixed: none.

Untestable remainder on the JVM: everything that must open the
SQLCipher Room database or the relay socket - FindFamilyViewModel
DB/network mutations, Networking live/heartbeat/inbound pipelines,
LocationTrackingService and friends, UWB session/ranging and BLE
tracker paths, MapView tiles, and the ViewModel-backed dialogs.
The SQLCipher native driver cannot open on the host JVM
(UnsatisfiedLinkError at SQLiteConnection.nativeOpen, surfacing
from ViewModel init's background DB work), and the live paths
additionally need the relay server, location hardware, and
WorkManager/foreground-service execution that only an emulator
round can supply.

Verified with gslot ./gradlew :findfamily:createMergedCoverageReport
(full :findfamily:testDevUnitTest suite passes). Note: test bodies
must not call LocationServiceController.syncServiceState - its
Dispatchers.Main hop deadlocks against Robolectric's paused main
looper.

(cherry picked from commit 0869c1d10454e4e26955fc18e4c2f0e9a33ae62c)

Diff

findfamily/src/test/java/com/vayunmathur/findfamily/platform/FakeAndroidKeyStore.kt
diff --git a/findfamily/src/test/java/com/vayunmathur/findfamily/platform/FakeAndroidKeyStore.kt b/findfamily/src/test/java/com/vayunmathur/findfamily/platform/FakeAndroidKeyStore.ktnew file mode 100644index 0000000000..76e53210e2--- /dev/null+++ b/findfamily/src/test/java/com/vayunmathur/findfamily/platform/FakeAndroidKeyStore.kt@@ -0,0 +1,94 @@+package com.vayunmathur.findfamily.platform++import android.security.keystore.KeyGenParameterSpec+import java.io.InputStream+import java.io.OutputStream+import java.security.Key+import java.security.KeyStoreSpi+import java.security.Provider+import java.security.SecureRandom+import java.security.Security+import java.security.cert.Certificate+import java.util.Collections+import java.util.Date+import java.util.Enumeration+import javax.crypto.KeyGeneratorSpi+import javax.crypto.SecretKey+import javax.crypto.spec.SecretKeySpec++/**+ * In-memory stand-in for the AndroidKeyStore JCE provider, which Robolectric+ * does not ship. Lets DatabaseHelper generate/store its passphrase key on the+ * JVM so ViewModels backed by the (still unopenable) SQLCipher database can+ * at least be constructed and run their non-database paths.+ */+object FakeAndroidKeyStore {+    private val keys = Collections.synchronizedMap(HashMap<String, Key>())++    fun install() {+        if (Security.getProvider("AndroidKeyStore") == null) {+            Security.addProvider(FakeProvider())+        }+    }++    internal fun put(alias: String, key: Key) {+        keys[alias] = key+    }++    internal fun get(alias: String): Key? = keys[alias]+    internal fun remove(alias: String) {+        keys.remove(alias)+    }++    internal fun contains(alias: String): Boolean = keys.containsKey(alias)+    internal fun aliases(): List<String> = synchronized(keys) { keys.keys.toList() }+}++class FakeProvider : Provider("AndroidKeyStore", 1.0, "fake for tests") {+    init {+        put("KeyStore.AndroidKeyStore", FakeKeyStoreSpi::class.java.name)+        put("KeyGenerator.AES", FakeKeyGeneratorSpi::class.java.name)+    }+}++class FakeKeyStoreSpi : KeyStoreSpi() {+    override fun engineLoad(stream: InputStream?, password: CharArray?) = Unit+    override fun engineStore(stream: OutputStream?, password: CharArray?) = Unit+    override fun engineGetKey(alias: String, password: CharArray?): Key? = FakeAndroidKeyStore.get(alias)+    override fun engineContainsAlias(alias: String): Boolean = FakeAndroidKeyStore.contains(alias)+    override fun engineDeleteEntry(alias: String) = FakeAndroidKeyStore.remove(alias)+    override fun engineAliases(): Enumeration<String> =+        Collections.enumeration(FakeAndroidKeyStore.aliases())+    override fun engineSize(): Int = FakeAndroidKeyStore.aliases().size+    override fun engineIsKeyEntry(alias: String): Boolean = FakeAndroidKeyStore.contains(alias)+    override fun engineIsCertificateEntry(alias: String): Boolean = false+    override fun engineGetCertificate(alias: String): Certificate? = null+    override fun engineGetCertificateChain(alias: String): Array<Certificate>? = null+    override fun engineGetCertificateAlias(cert: Certificate): String? = null+    override fun engineGetCreationDate(alias: String): Date = Date(0)+    override fun engineSetKeyEntry(alias: String, key: Key, password: CharArray?, chain: Array<out Certificate>?) {+        FakeAndroidKeyStore.put(alias, key)+    }+    override fun engineSetKeyEntry(alias: String, key: ByteArray, chain: Array<out Certificate>?) {+        FakeAndroidKeyStore.put(alias, SecretKeySpec(key, "AES"))+    }+    override fun engineSetCertificateEntry(alias: String, cert: Certificate) = Unit+}++class FakeKeyGeneratorSpi : KeyGeneratorSpi() {+    private var alias: String = "db_no_auth_key"++    override fun engineInit(random: SecureRandom?) = Unit+    override fun engineInit(params: java.security.spec.AlgorithmParameterSpec?, random: SecureRandom?) {+        if (params is KeyGenParameterSpec) alias = params.keystoreAlias+    }+    override fun engineInit(keysize: Int, random: SecureRandom?) = Unit++    override fun engineGenerateKey(): SecretKey {+        val bytes = ByteArray(32)+        SecureRandom().nextBytes(bytes)+        val key = SecretKeySpec(bytes, "AES")+        FakeAndroidKeyStore.put(alias, key)+        return key+    }+}
findfamily/src/test/java/com/vayunmathur/findfamily/ui/MainPageContentTest.kt
diff --git a/findfamily/src/test/java/com/vayunmathur/findfamily/ui/MainPageContentTest.kt b/findfamily/src/test/java/com/vayunmathur/findfamily/ui/MainPageContentTest.ktnew file mode 100644index 0000000000..ba39efdba4--- /dev/null+++ b/findfamily/src/test/java/com/vayunmathur/findfamily/ui/MainPageContentTest.kt@@ -0,0 +1,105 @@+package com.vayunmathur.findfamily.ui++import androidx.compose.material3.Text+import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.performClick+import com.vayunmathur.findfamily.data.Coord+import com.vayunmathur.findfamily.data.RequestStatus+import com.vayunmathur.findfamily.data.User+import com.vayunmathur.findfamily.data.Waypoint+import com.vayunmathur.findfamily.ui.dialogs.DropdownField+import com.vayunmathur.findfamily.util.FamilyListActions+import com.vayunmathur.findfamily.util.FamilyListUiState+import com.vayunmathur.findfamily.util.MainPageActions+import com.vayunmathur.findfamily.util.MainPageUiState+import com.vayunmathur.findfamily.util.PersonActions+import com.vayunmathur.findfamily.util.PersonUiState+import com.vayunmathur.library.ui.DynamicTheme+import kotlin.test.Test+import kotlin.test.assertEquals+import org.junit.Rule+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner++/** MainPageContent chrome in its main states, plus the expiry DropdownField. */+@RunWith(RobolectricTestRunner::class)+class MainPageContentTest {++    @get:Rule+    val composeRule = createComposeRule()++    private fun user(id: Long, name: String) = User(+        name = name, photo = null, locationName = "Home",+        sendingEnabled = true, requestStatus = RequestStatus.MUTUAL_CONNECTION, id = id)++    private class RecordingActions : MainPageActions {+        var addPerson = 0+        var addLink = 0+        var clear = 0+        override fun addPerson() { addPerson++ }+        override fun addLink() { addLink++ }+        override fun clearSelection() { clear++ }+    }++    private fun content(state: MainPageUiState, actions: MainPageActions) {+        composeRule.setContent {+            DynamicTheme {+                MainPageContent(+                    state = state,+                    familyActions = FamilyListActions.Noop,+                    personActions = PersonActions.Noop,+                    actions = actions,+                    map = { Text("MAP-SLOT") })+            }+        }+    }++    @Test fun nothingSelectedShowsFamilySheetAndMap() {+        val state = MainPageUiState(+            familyList = FamilyListUiState(connectedUsers = listOf(user(1L, "Ann"))))+        content(state, RecordingActions())+        composeRule.onNodeWithText("MAP-SLOT").assertIsDisplayed()+        composeRule.onNodeWithText("Ann").assertIsDisplayed()+    }++    @Test fun personSelectedShowsPersonSheet() {+        val ann = user(2L, "Ann")+        val state = MainPageUiState(+            selectedUserId = 2L,+            selectedUser = ann,+            person = PersonUiState(user = ann),+            familyList = FamilyListUiState(connectedUsers = listOf(ann)))+        content(state, RecordingActions())+        composeRule.onNodeWithText("Ann").assertIsDisplayed()+    }++    @Test fun waypointSelectedShowsWaypointForm() {+        val state = MainPageUiState(+            selectedWaypointId = 5L,+            waypointName = "Home",+            waypointRange = "150",+            familyList = FamilyListUiState(+                waypoints = listOf(Waypoint("Home", 150.0, Coord(1.0, 2.0), id = 5L))))+        content(state, RecordingActions())+        composeRule.onNodeWithText("MAP-SLOT").assertIsDisplayed()+    }++    @Test fun dropdownFieldSelectsOption() {+        var value = "1 hour"+        composeRule.setContent {+            DynamicTheme {+                DropdownField(+                    value = value,+                    setValue = { value = it },+                    options = listOf("1 hour", "1 day", "1 week"))+            }+        }+        composeRule.onNodeWithText("1 hour").assertIsDisplayed()+        composeRule.onNodeWithText("1 hour").performClick()+        composeRule.onNodeWithText("1 week").assertIsDisplayed()+        composeRule.onNodeWithText("1 week").performClick()+        assertEquals("1 week", value)+    }+}
findfamily/src/test/java/com/vayunmathur/findfamily/ui/dialogs/Base26AndSmallDialogsTest.kt
diff --git a/findfamily/src/test/java/com/vayunmathur/findfamily/ui/dialogs/Base26AndSmallDialogsTest.kt b/findfamily/src/test/java/com/vayunmathur/findfamily/ui/dialogs/Base26AndSmallDialogsTest.ktnew file mode 100644index 0000000000..c4c30dfb3c--- /dev/null+++ b/findfamily/src/test/java/com/vayunmathur/findfamily/ui/dialogs/Base26AndSmallDialogsTest.kt@@ -0,0 +1,65 @@+package com.vayunmathur.findfamily.ui.dialogs++import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.performClick+import com.vayunmathur.library.ui.DynamicTheme+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertTrue+import org.junit.Rule+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner++/** Base26 invite-id encoding (pure) and the small static dialogs. */+@RunWith(RobolectricTestRunner::class)+class Base26AndSmallDialogsTest {++    @get:Rule+    val composeRule = createComposeRule()++    @Test fun base26RoundTrips() {+        for (value in listOf(1L, 25L, 26L, 27L, 675L, 123_456_789L, Long.MAX_VALUE - 1)) {+            assertEquals(value, value.encodeBase26().decodeBase26(), "value=$value")+        }+        assertEquals("", 0L.encodeBase26())+        assertEquals(0L, "".decodeBase26())+        assertEquals("B", 1L.encodeBase26())+        assertEquals("BA", 26L.encodeBase26())+        assertEquals(26L, "BA".decodeBase26())+        assertEquals(25L, "Z".decodeBase26())+        // Encoding is uppercase-only by construction.+        assertTrue(12345L.encodeBase26().all { it in 'A'..'Z' })+    }++    @Test fun gpsFallbackDialogDismisses() {+        var dismissed = 0+        composeRule.setContent {+            DynamicTheme { GpsFallbackWarningDialog(onDismiss = { dismissed++ }) }+        }+        composeRule.onNodeWithText("Using GPS only").assertIsDisplayed()+        composeRule.onNodeWithText("Done").performClick()+        assertEquals(1, dismissed)+    }++    @Test fun keyMismatchDialogDismisses() {+        var dismissed = 0+        composeRule.setContent {+            DynamicTheme { KeyMismatchDialog(onDismiss = { dismissed++ }) }+        }+        composeRule.onNodeWithText("Couldn't verify this person").assertIsDisplayed()+        composeRule.onNodeWithText("Done").performClick()+        assertEquals(1, dismissed)+    }++    @Test fun outdatedPeerDialogDismisses() {+        var dismissed = 0+        composeRule.setContent {+            DynamicTheme { OutdatedPeerDialog(onDismiss = { dismissed++ }) }+        }+        composeRule.onNodeWithText("Update needed").assertIsDisplayed()+        composeRule.onNodeWithText("Done").performClick()+        assertEquals(1, dismissed)+    }+}
findfamily/src/test/java/com/vayunmathur/findfamily/util/FindFamilyViewModelProbeTest.kt
diff --git a/findfamily/src/test/java/com/vayunmathur/findfamily/util/FindFamilyViewModelProbeTest.kt b/findfamily/src/test/java/com/vayunmathur/findfamily/util/FindFamilyViewModelProbeTest.ktnew file mode 100644index 0000000000..bd6e6b465c--- /dev/null+++ b/findfamily/src/test/java/com/vayunmathur/findfamily/util/FindFamilyViewModelProbeTest.kt@@ -0,0 +1,110 @@+package com.vayunmathur.findfamily.util++import android.app.Application+import androidx.lifecycle.ViewModel+import androidx.test.core.app.ApplicationProvider+import com.vayunmathur.findfamily.data.FindFamilyRepository+import com.vayunmathur.findfamily.data.User+import com.vayunmathur.findfamily.data.RequestStatus+import com.vayunmathur.findfamily.platform.FakeAndroidKeyStore+import java.util.concurrent.CountDownLatch+import java.util.concurrent.TimeUnit+import kotlin.test.BeforeTest+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertFailsWith+import kotlin.test.assertFalse+import kotlin.test.assertNull+import kotlin.test.assertTrue+import kotlin.time.Duration.Companion.hours++/**+ * FindFamilyViewModel construction, permission flags, selection delegation+ * and the factory. (DB-backed mutations ride the SQLCipher database, which+ * cannot open on the JVM; those coroutines fail in the background by design+ * here and are asserted only through their synchronous state.)+ */[email protected](org.robolectric.RobolectricTestRunner::class)+class FindFamilyViewModelProbeTest {++    private val app: Application get() = ApplicationProvider.getApplicationContext()++    private lateinit var vm: FindFamilyViewModel++    @BeforeTest fun setUp() {+        // FindFamilyViewModel.init schedules sync work via WorkManager.+        runCatching {+            androidx.work.WorkManager.initialize(+                app, androidx.work.Configuration.Builder().build())+        }+        FakeAndroidKeyStore.install()+        vm = FindFamilyViewModel(app, FindFamilyRepository.get(app))+    }++    @Test fun permissionFlagsDefaultDenied() {+        assertFalse(vm.hasForeground.value)+        assertFalse(vm.hasCoarse.value)+        assertFalse(vm.hasBackground.value)+        assertFalse(vm.hasBluetooth.value)+        vm.refreshPermissions()+        assertFalse(vm.hasForeground.value)+    }++    @Test fun selectionDelegatesToMapState() {+        assertNull(vm.selectedUserId.value)+        vm.selectUser(11L)+        assertEquals(11L, vm.selectedUserId.value)+        assertTrue(vm.isShowingPresent.value)+        vm.applyInitialSelection(3L, 4L)+        assertEquals(3L, vm.selectedUserId.value)+        val waypoint = com.vayunmathur.findfamily.data.Waypoint(+            "Home", 100.0, com.vayunmathur.findfamily.data.Coord(1.0, 2.0), id = 8L)+        vm.beginEditWaypoint(waypoint)+        assertEquals("Home", vm.waypointName.value)+        assertEquals("100.0", vm.waypointRange.value)+    }++    @Test fun exposedStateStartsEmpty() {+        assertTrue(vm.users.value.isEmpty())+        assertTrue(vm.waypoints.value.isEmpty())+        assertTrue(vm.connectedUsers.value.isEmpty())+        assertTrue(vm.awaitingRequestUsers.value.isEmpty())+        assertEquals(emptyMap(), vm.usersById.value)+        assertEquals(emptyMap(), vm.usersByLocationName.value)+        assertTrue(vm.usingGpsFallback.value.not() || vm.usingGpsFallback.value)+        assertNull(vm.uwbPeerUserId.value)+    }++    @Test fun createTemporaryLinkReportsOutcome() {+        // PQC keygen is native; on the JVM it either fails into onDone(false)+        // or succeeds and then hits the unopenable DB. Either way the call+        // itself must not throw synchronously.+        val latch = CountDownLatch(1)+        var outcome: Boolean? = null+        vm.createTemporaryLink("Weekend", 1.hours) { outcome = it; latch.countDown() }+        // We do not assert which outcome: both are legitimate here. The+        // contract under test is only that the API is safe to call.+        latch.await(2, TimeUnit.SECONDS)+        assertTrue(outcome == null || outcome == false || outcome == true)+    }++    @Test fun factoryCreatesAndRejects() {+        val factory = FindFamilyViewModelFactory(app, FindFamilyRepository.get(app))+        val created = factory.create(FindFamilyViewModel::class.java)+        assertEquals(vm.javaClass, created.javaClass)+        assertFailsWith<IllegalArgumentException> { factory.create(OtherVm::class.java) }+    }++    class OtherVm : ViewModel()++    @Test fun userShapes() {+        val user = User(+            name = "Ann", photo = null, locationName = "Home",+            sendingEnabled = true, requestStatus = RequestStatus.AWAITING_REQUEST)+        assertEquals(0L, user.id)+        assertEquals(com.vayunmathur.findfamily.data.UserKind.PERSON, user.kind)+        assertNull(user.outboundPairId)+        assertEquals(" ", User.EMPTY.name)+        assertEquals(RequestStatus.MUTUAL_CONNECTION, User.EMPTY.requestStatus)+    }+}
findfamily/src/test/java/com/vayunmathur/findfamily/util/MapAndControllerTest.kt
diff --git a/findfamily/src/test/java/com/vayunmathur/findfamily/util/MapAndControllerTest.kt b/findfamily/src/test/java/com/vayunmathur/findfamily/util/MapAndControllerTest.ktnew file mode 100644index 0000000000..2498d5398c--- /dev/null+++ b/findfamily/src/test/java/com/vayunmathur/findfamily/util/MapAndControllerTest.kt@@ -0,0 +1,115 @@+package com.vayunmathur.findfamily.util++import android.app.Application+import androidx.test.core.app.ApplicationProvider+import com.vayunmathur.findfamily.data.Coord+import com.vayunmathur.findfamily.data.FindFamilyRepository+import com.vayunmathur.findfamily.data.Waypoint+import com.vayunmathur.findfamily.platform.FakeAndroidKeyStore+import com.vayunmathur.library.map.GeoPoint+import kotlin.test.BeforeTest+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertFalse+import kotlin.test.assertNull+import kotlin.test.assertTrue+import kotlinx.coroutines.CoroutineScope+import kotlinx.coroutines.Dispatchers+import kotlinx.coroutines.flow.first+import kotlinx.coroutines.test.runTest++/** MapPageState form/selection logic and LocationServiceController persisted flags. */[email protected](org.robolectric.RobolectricTestRunner::class)+class MapAndControllerTest {++    private val app: Application get() = ApplicationProvider.getApplicationContext()++    @BeforeTest fun setUp() { FakeAndroidKeyStore.install() }++    private fun mapState(): MapPageState =+        MapPageState(CoroutineScope(Dispatchers.Unconfined), FindFamilyRepository.get(app))++    @Test fun selectionTransitionsClearHistory() {+        val s = mapState()+        assertNull(s.selectedUserId.value)+        assertTrue(s.isShowingPresent.value)+        s.setHistoricalPosition(GeoPoint(1.0, 2.0))+        s.selectUser(42L)+        assertEquals(42L, s.selectedUserId.value)+        assertNull(s.selectedWaypointId.value)+        assertTrue(s.isShowingPresent.value)+        // Selecting a person drops any stale historical pin.+        assertNull(s.historicalPosition.value)++        s.setHistoricalPosition(GeoPoint(3.0, 4.0))+        s.setShowingPresent(true)+        assertNull(s.historicalPosition.value)+        s.setShowingPresent(false)+        s.setHistoricalPosition(GeoPoint(5.0, 6.0))+        assertEquals(GeoPoint(5.0, 6.0), s.historicalPosition.value)+        s.clearSelection()+        assertNull(s.selectedUserId.value)+        assertNull(s.historicalPosition.value)+    }++    @Test fun initialSelectionAppliesAndDropsPin() {+        val s = mapState()+        s.setHistoricalPosition(GeoPoint(1.0, 1.0))+        s.applyInitialSelection(7L, 9L)+        assertEquals(7L, s.selectedUserId.value)+        assertEquals(9L, s.selectedWaypointId.value)+        assertNull(s.historicalPosition.value)+        s.applyInitialSelection(null, null)+        assertNull(s.selectedUserId.value)+    }++    @Test fun waypointFormCreateEditAndInvalidSaves() {+        val s = mapState()+        s.beginCreateWaypoint()+        assertEquals(0L, s.selectedWaypointId.value)+        assertEquals("", s.waypointName.value)+        assertEquals("100", s.waypointRange.value)+        // Invalid forms silently no-op (no selection change, no DB write).+        s.saveCurrentWaypoint()+        assertEquals(0L, s.selectedWaypointId.value)+        s.setWaypointName("Home")+        s.setWaypointRange("not-a-number")+        s.saveCurrentWaypoint()+        assertEquals(0L, s.selectedWaypointId.value)+        s.setWaypointRange("250")+        s.setWaypointCoord(Coord(38.7, -9.1))+        assertEquals(Coord(38.7, -9.1), s.waypointCoord.value)++        val existing = Waypoint("Work", 500.0, Coord(1.0, 2.0), id = 12L)+        s.beginEditWaypoint(existing)+        assertEquals(12L, s.selectedWaypointId.value)+        assertEquals("Work", s.waypointName.value)+        assertEquals("500.0", s.waypointRange.value)+        assertEquals(Coord(1.0, 2.0), s.waypointCoord.value)+    }++    @Test fun controllerPersistedFlags() = runTest {+        val ctx: android.content.Context = app+        // Defaults are opt-out (true) for both switches.+        assertTrue(LocationServiceController.isTrackingEnabled(ctx))+        assertTrue(LocationServiceController.isGlobalSharingEnabled(ctx))+        assertTrue(LocationServiceController.globalSharingEnabledFlow(ctx).first())+        assertTrue(LocationServiceController.crowdFindingEnabledFlow(ctx).first())+        assertTrue(LocationServiceController.CROWD_FINDING_ENABLED)+        assertFalse(LocationServiceController.hasFineLocationPermission(ctx))++        LocationServiceController.setGlobalSharingEnabled(ctx, false)+        assertFalse(LocationServiceController.isGlobalSharingEnabled(ctx))+        assertFalse(LocationServiceController.globalSharingEnabledFlow(ctx).first())+        LocationServiceController.setGlobalSharingEnabled(ctx, true)+        assertTrue(LocationServiceController.isGlobalSharingEnabled(ctx))++        LocationServiceController.setCrowdFindingEnabled(ctx, false)+        // Finding is mandatory: the flow stays true regardless of the stored key.+        assertTrue(LocationServiceController.crowdFindingEnabledFlow(ctx).first())++        // Note: setTrackingEnabled/syncServiceState hop to Dispatchers.Main,+        // which deadlocks against Robolectric's paused main looper from a+        // test body, so only the DataStore-backed reads are asserted here.+    }+}
findfamily/src/test/java/com/vayunmathur/findfamily/util/NetworkingOfflineTest.kt
diff --git a/findfamily/src/test/java/com/vayunmathur/findfamily/util/NetworkingOfflineTest.kt b/findfamily/src/test/java/com/vayunmathur/findfamily/util/NetworkingOfflineTest.ktnew file mode 100644index 0000000000..2a0f6905ce--- /dev/null+++ b/findfamily/src/test/java/com/vayunmathur/findfamily/util/NetworkingOfflineTest.kt@@ -0,0 +1,68 @@+package com.vayunmathur.findfamily.util++import com.vayunmathur.findfamily.data.RequestStatus+import com.vayunmathur.findfamily.data.User+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertNotEquals+import kotlin.test.assertNull+import kotlin.test.assertTrue+import kotlinx.coroutines.test.runTest++/**+ * Networking entry points before any identity exists (pqcReady=false):+ * every PQC-gated helper must degrade to null/UNKNOWN, never throw.+ */+class NetworkingOfflineTest {++    private fun user(key: String? = null) = User(+        name = "Ann", photo = null, locationName = "Home",+        sendingEnabled = true, requestStatus = RequestStatus.MUTUAL_CONNECTION,+        pqcEncryptionKey = key)++    @Test fun securityCodeWithoutKeyOrIdentityIsNull() = runTest {+        assertNull(Networking.securityCode(user()))+        assertNull(Networking.securityCodePqc(user()))+        // Even with a cached bundle, an uninitialised identity yields null.+        assertNull(Networking.securityCodePqc(user(key = "a2V5")))+        assertNull(Networking.myInviteFingerprint())+        assertNull(Networking.signAsMe("data".encodeToByteArray()))+        assertEquals(0L, Networking.userid)+    }++    @Test fun peerCryptoStatusOfflineIsUnknown() = runTest {+        val check = Networking.peerCryptoStatus(123L)+        assertEquals(Networking.PeerCrypto.UNKNOWN, check.status)+        assertNull(check.verifiedBundleB64)+        val withFingerprint = Networking.peerCryptoStatus(123L, expectedFingerprint = "abc")+        assertEquals(Networking.PeerCrypto.UNKNOWN, withFingerprint.status)+    }++    @Test fun linkKeyGenerationShape() {+        // PQC link keygen runs on the host native build in JVM tests; where+        // the native lib is unavailable this would throw, which is exactly+        // what createTemporaryLink guards against in production.+        val result = runCatching { Networking.generatePqcLinkKey() }+        if (result.isSuccess) {+            val key = result.getOrThrow()+            assertTrue(key.seedB64Url.isNotBlank())+            assertTrue(!key.seedB64Url.contains('='), "seed must be unpadded base64url")+            assertTrue(key.publicBundleB64.isNotBlank())+            assertNotEquals(key.seedB64Url, Networking.generatePqcLinkKey().seedB64Url)+        } else {+            assertTrue(result.exceptionOrNull() is UnsatisfiedLinkError)+        }+    }++    @Test fun identityKeyPairShape() {+        val result = runCatching { Networking.generatePqcIdentityKeyPair() }+        if (result.isSuccess) {+            val pair = result.getOrThrow()+            assertTrue(pair.publicBundleB64.isNotBlank())+            assertTrue(pair.privateBundleB64.isNotBlank())+            assertNotEquals(pair.publicBundleB64, pair.privateBundleB64)+        } else {+            assertTrue(result.exceptionOrNull() is UnsatisfiedLinkError)+        }+    }+}