office: make sync slice-3 tests hermetic via fake transport (#tests)
- Commit
3950bd6abc88414a1323e71aea46672679f5e7ce- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-14 23:24 UTC (21 days ago)
- Parents
6a20b59
OfficeViewModelSyncSlice3Test relied on the relay being unreachable (devserver has no route to api.maproj.org), but through this host's proxy the real relay answers: registration succeeded and syncDoc adopted a live cursor (expected 0, was 17) - and the test device registered on production. Install OfficeSync's existing HttpTransport seam in setUp (fail every request, restore in tearDown), the same pattern Slice4Pass2OnlineHomeTest already uses, so the offline branches under test are exercised deterministically and no test traffic reaches the relay. Verified: :office:testDevUnitTest OfficeViewModelSyncSlice3Test 32/32 green.
Diff
office/src/test/java/com/vayunmathur/office/util/OfficeViewModelSyncSlice3Test.kt
diff --git a/office/src/test/java/com/vayunmathur/office/util/OfficeViewModelSyncSlice3Test.kt b/office/src/test/java/com/vayunmathur/office/util/OfficeViewModelSyncSlice3Test.ktindex a1fab21fbf..c6b1b4d76f 100644--- a/office/src/test/java/com/vayunmathur/office/util/OfficeViewModelSyncSlice3Test.kt+++ b/office/src/test/java/com/vayunmathur/office/util/OfficeViewModelSyncSlice3Test.kt@@ -57,9 +57,18 @@ class OfficeViewModelSyncSlice3Test { private val roboApp: android.app.Application get() = ApplicationProvider.getApplicationContext() + private var previousTransport: OfficeSync.HttpTransport? = null+ @BeforeTest fun setUp() { Dispatchers.setMain(UnconfinedTestDispatcher())+ // Hermetic: never touch the real relay. The fake transport fails+ // every request (null), so registration/pull exercise the+ // production offline branches instead of depending on whether+ // this host can reach api.maproj.org (via proxy it can, which+ // made syncDoc adopt a live cursor and registration succeed).+ previousTransport = OfficeSync.httpTransport+ OfficeSync.httpTransport = OfficeSync.HttpTransport { _, _ -> null } runBlocking { if (runCatching { OfficeSync.identity }.isFailure) { OfficeSync.identity = PqcIdentity.loadOrCreate(MemStore(), "slice3sync")@@ -69,6 +78,7 @@ class OfficeViewModelSyncSlice3Test { @AfterTest fun tearDown() {+ OfficeSync.httpTransport = previousTransport OfficeSync.stopLive() Dispatchers.resetMain() }