Modern Apps git

← Modern-Apps.git

vpn: run native-guarded tests hermetically, no skips (#tests)

Commit
740f2df3420583f2438ea1a269440436ea6ee720
Author
Vayun Mathur <[email protected]>
When
2026-11-15 17:18 UTC (20 days ago)
Parents
8e4fa78
Twenty tests in VpnNativeTest, PumpLoopTest, TunnelSessionMoreTest,
TwoTunnelRouteTest, VpnTunnelServiceTest and FinalCoverageBatchTest
guarded every native call with Assume.assumeTrue(nativeAvailable()).
On any host where the Rust host library failed to build or load, CI
counted them as skipped and the WireGuard tunnel, pump-loop and
session code they cover was never exercised.

The host library is not optional: build-logic wireRustHostLibsForUnitTests
builds libvpn_wireguard via cargoBuildHost and puts it on
java.library.path for every unit-test task, exactly as communicate
fixed its JNI bridges. An unavailable library is therefore a build
failure, not a reason to skip. The guards now assert availability
with that message, so the tests always run (and fail loudly if the
host build ever breaks again).

Verified: :vpn:testDevUnitTest / createMergedCoverageReport green,
112 tests, 0 skipped (was 20 assumption-skips when the lib is absent).

Diff

vpn/src/test/java/com/vayunmathur/vpn/service/FinalCoverageBatchTest.kt
diff --git a/vpn/src/test/java/com/vayunmathur/vpn/service/FinalCoverageBatchTest.kt b/vpn/src/test/java/com/vayunmathur/vpn/service/FinalCoverageBatchTest.ktindex aca14ec8b1..f8c597bd30 100644--- a/vpn/src/test/java/com/vayunmathur/vpn/service/FinalCoverageBatchTest.kt+++ b/vpn/src/test/java/com/vayunmathur/vpn/service/FinalCoverageBatchTest.kt@@ -19,7 +19,6 @@ import kotlin.test.assertEquals import kotlinx.coroutines.delay import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withTimeout-import org.junit.Assume import org.junit.runner.RunWith import org.robolectric.Robolectric import org.robolectric.RobolectricTestRunner@@ -63,7 +62,7 @@ class FinalCoverageBatchTest {     }      @Test fun pumpTunAfterEstablishedHandshake() { runBlocking {-        Assume.assumeTrue(nativeAvailable())+        assertTrue(nativeAvailable(), "host vpn_wireguard lib unavailable: cargoBuildHost must produce libvpn_wireguard for JVM tests")         val svc = Robolectric.buildService(VpnTunnelService::class.java).create().get()         val privA = VpnNative.generatePrivateKey(); val pubA = VpnNative.derivePublicKey(privA)         val privB = VpnNative.generatePrivateKey(); val pubB = VpnNative.derivePublicKey(privB)@@ -108,7 +107,7 @@ class FinalCoverageBatchTest {     } }      @Test fun handleLoggingMalformedAndMergeCombos() { runBlocking {-        Assume.assumeTrue(nativeAvailable())+        assertTrue(nativeAvailable(), "host vpn_wireguard lib unavailable: cargoBuildHost must produce libvpn_wireguard for JVM tests")         val svc = Robolectric.buildService(VpnTunnelService::class.java).create().get()         val priv = VpnNative.generatePrivateKey()         val handle = VpnNative.newTunnel(priv, VpnNative.derivePublicKey(priv), "", 25)@@ -132,7 +131,7 @@ class FinalCoverageBatchTest {     } }      @Test fun connectWithValidKeysExercisesRunTunnel() { runBlocking {-        Assume.assumeTrue(nativeAvailable())+        assertTrue(nativeAvailable(), "host vpn_wireguard lib unavailable: cargoBuildHost must produce libvpn_wireguard for JVM tests")         val svc = Robolectric.buildService(VpnTunnelService::class.java).create().get()         val priv = VpnNative.generatePrivateKey(); val pub = VpnNative.derivePublicKey(priv)         // Empty address lists keep Builder.add* (hidden InetAddress APIs) out of buildTun;
vpn/src/test/java/com/vayunmathur/vpn/service/PumpLoopTest.kt
diff --git a/vpn/src/test/java/com/vayunmathur/vpn/service/PumpLoopTest.kt b/vpn/src/test/java/com/vayunmathur/vpn/service/PumpLoopTest.ktindex e48dd0c390..6cb131a769 100644--- a/vpn/src/test/java/com/vayunmathur/vpn/service/PumpLoopTest.kt+++ b/vpn/src/test/java/com/vayunmathur/vpn/service/PumpLoopTest.kt@@ -17,7 +17,6 @@ import kotlinx.coroutines.async import kotlinx.coroutines.delay import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withTimeout-import org.junit.Assume import org.junit.runner.RunWith import org.robolectric.Robolectric import org.robolectric.RobolectricTestRunner@@ -31,7 +30,7 @@ class PumpLoopTest {     private fun nativeAvailable(): Boolean = try { VpnNative.init(); true } catch (_: Throwable) { false }      @Test fun pumpLoopConsumesTunPacketAndStopsOnDisconnect() { runBlocking {-        Assume.assumeTrue(nativeAvailable())+        assertTrue(nativeAvailable(), "host vpn_wireguard lib unavailable: cargoBuildHost must produce libvpn_wireguard for JVM tests")         val svc = Robolectric.buildService(VpnTunnelService::class.java).create().get()         val priv = VpnNative.generatePrivateKey()         val handle = VpnNative.newTunnel(priv, VpnNative.derivePublicKey(priv), "", 25)@@ -69,7 +68,7 @@ class PumpLoopTest {     } }      @Test fun sessionRunDegradesWhenNoEndpoint() { runBlocking {-        Assume.assumeTrue(nativeAvailable())+        assertTrue(nativeAvailable(), "host vpn_wireguard lib unavailable: cargoBuildHost must produce libvpn_wireguard for JVM tests")         val svc = Robolectric.buildService(VpnTunnelService::class.java).create().get()         val priv = VpnNative.generatePrivateKey()         val handle = VpnNative.newTunnel(priv, VpnNative.derivePublicKey(priv), "", 25)
vpn/src/test/java/com/vayunmathur/vpn/service/TunnelSessionMoreTest.kt
diff --git a/vpn/src/test/java/com/vayunmathur/vpn/service/TunnelSessionMoreTest.kt b/vpn/src/test/java/com/vayunmathur/vpn/service/TunnelSessionMoreTest.ktindex 7d2748a239..585c1786bc 100644--- a/vpn/src/test/java/com/vayunmathur/vpn/service/TunnelSessionMoreTest.kt+++ b/vpn/src/test/java/com/vayunmathur/vpn/service/TunnelSessionMoreTest.kt@@ -14,7 +14,6 @@ import kotlin.test.assertTrue import kotlinx.coroutines.delay import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withTimeout-import org.junit.Assume import org.junit.runner.RunWith import org.robolectric.Robolectric import org.robolectric.RobolectricTestRunner@@ -59,7 +58,7 @@ class TunnelSessionMoreTest {     }      @Test fun resolveDomainFromSniAndCache() {-        Assume.assumeTrue(nativeAvailable())+        assertTrue(nativeAvailable(), "host vpn_wireguard lib unavailable: cargoBuildHost must produce libvpn_wireguard for JVM tests")         val s = session(service(), VpnConfig(peerEndpoint = "127.0.0.1:51820"))         val hello = clientHello("secure.example.com")         val pkt = tcpPacket(hello, 40000, 443)@@ -88,7 +87,7 @@ class TunnelSessionMoreTest {     // per-package catches do not intercept). BypassList itself is covered in VpnViewModelTest.      @Test fun flushJobAndStopSession() { runBlocking {-        Assume.assumeTrue(nativeAvailable())+        assertTrue(nativeAvailable(), "host vpn_wireguard lib unavailable: cargoBuildHost must produce libvpn_wireguard for JVM tests")         val svc = service()         val s = session(svc, VpnConfig(peerEndpoint = "127.0.0.1:51820"))         val dao = VpnTunnelServiceTest.FakeLogDao()@@ -119,7 +118,7 @@ class TunnelSessionMoreTest {     }      @Test fun startFlushJobLoopsAndFlushes() { runBlocking {-        Assume.assumeTrue(nativeAvailable())+        assertTrue(nativeAvailable(), "host vpn_wireguard lib unavailable: cargoBuildHost must produce libvpn_wireguard for JVM tests")         val svc = service()         val s = session(svc, VpnConfig(peerEndpoint = "127.0.0.1:51820"))         val dao = VpnTunnelServiceTest.FakeLogDao()
vpn/src/test/java/com/vayunmathur/vpn/service/TwoTunnelRouteTest.kt
diff --git a/vpn/src/test/java/com/vayunmathur/vpn/service/TwoTunnelRouteTest.kt b/vpn/src/test/java/com/vayunmathur/vpn/service/TwoTunnelRouteTest.ktindex 5b2fdad672..771f0ca01a 100644--- a/vpn/src/test/java/com/vayunmathur/vpn/service/TwoTunnelRouteTest.kt+++ b/vpn/src/test/java/com/vayunmathur/vpn/service/TwoTunnelRouteTest.kt@@ -17,7 +17,6 @@ import kotlin.test.assertTrue import kotlinx.coroutines.delay import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withTimeout-import org.junit.Assume import org.junit.runner.RunWith import org.robolectric.Robolectric import org.robolectric.RobolectricTestRunner@@ -63,7 +62,7 @@ class TwoTunnelRouteTest {     }      @Test fun handshakeAndDataRouteThroughRouteIncoming() { runBlocking {-        Assume.assumeTrue(nativeAvailable())+        assertTrue(nativeAvailable(), "host vpn_wireguard lib unavailable: cargoBuildHost must produce libvpn_wireguard for JVM tests")         val svc = service()         val (a, b) = tunnelPair()         val sessionA = svc.TunnelSession(VpnConfig(name = "A", peerEndpoint = "127.0.0.1:51820"), a.handle)@@ -103,7 +102,7 @@ class TwoTunnelRouteTest {     } }      @Test fun pumpTunFallbackAndStopSessionDrains() { runBlocking {-        Assume.assumeTrue(nativeAvailable())+        assertTrue(nativeAvailable(), "host vpn_wireguard lib unavailable: cargoBuildHost must produce libvpn_wireguard for JVM tests")         val svc = service()         val (a, _) = tunnelPair()         val s = svc.TunnelSession(VpnConfig(name = "A", peerEndpoint = "127.0.0.1:51820"), a.handle)@@ -135,7 +134,7 @@ class TwoTunnelRouteTest {     } }      @Test fun flushJobLoopFlushesSeededFlow() { runBlocking {-        Assume.assumeTrue(nativeAvailable())+        assertTrue(nativeAvailable(), "host vpn_wireguard lib unavailable: cargoBuildHost must produce libvpn_wireguard for JVM tests")         val svc = service()         val (a, _) = tunnelPair()         val s = svc.TunnelSession(VpnConfig(name = "A", peerEndpoint = "127.0.0.1:51820"), a.handle)@@ -159,7 +158,7 @@ class TwoTunnelRouteTest {     } }      @Test fun handleLoggingSniPacket() {-        Assume.assumeTrue(nativeAvailable())+        assertTrue(nativeAvailable(), "host vpn_wireguard lib unavailable: cargoBuildHost must produce libvpn_wireguard for JVM tests")         val svc = service()         val (a, _) = tunnelPair()         val s = svc.TunnelSession(VpnConfig(name = "A", peerEndpoint = "127.0.0.1:51820"), a.handle)
vpn/src/test/java/com/vayunmathur/vpn/service/VpnTunnelServiceTest.kt
diff --git a/vpn/src/test/java/com/vayunmathur/vpn/service/VpnTunnelServiceTest.kt b/vpn/src/test/java/com/vayunmathur/vpn/service/VpnTunnelServiceTest.ktindex 40781f2fae..097ce3b5ec 100644--- a/vpn/src/test/java/com/vayunmathur/vpn/service/VpnTunnelServiceTest.kt+++ b/vpn/src/test/java/com/vayunmathur/vpn/service/VpnTunnelServiceTest.kt@@ -19,7 +19,6 @@ import kotlin.test.assertNull import kotlin.test.assertTrue import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.runBlocking-import org.junit.Assume import org.junit.runner.RunWith import org.robolectric.Robolectric import org.robolectric.RobolectricTestRunner@@ -75,7 +74,7 @@ class VpnTunnelServiceTest {     }      @Test fun parseCsvCidrsAndLeakGuard() {-        Assume.assumeTrue(nativeAvailable())+        assertTrue(nativeAvailable(), "host vpn_wireguard lib unavailable: cargoBuildHost must produce libvpn_wireguard for JVM tests")         val s = session(service())         assertEquals(listOf("10.0.0.2" to 32), s.parseCsvCidrs("10.0.0.2/32"))         assertEquals(listOf("10.0.0.2" to 32, "fd00::2" to 128), s.parseCsvCidrs(" 10.0.0.2 , fd00::2 "))@@ -92,7 +91,7 @@ class VpnTunnelServiceTest {     }      @Test fun resolveEndpointVariants() {-        Assume.assumeTrue(nativeAvailable())+        assertTrue(nativeAvailable(), "host vpn_wireguard lib unavailable: cargoBuildHost must produce libvpn_wireguard for JVM tests")         val svc = service()         assertNotNull(session(svc, VpnConfig(peerEndpoint = "127.0.0.1:51820")).resolveEndpoint())         assertEquals(51820, session(svc, VpnConfig(peerEndpoint = "127.0.0.1:51820")).resolveEndpoint()!!.port)@@ -101,7 +100,7 @@ class VpnTunnelServiceTest {     }      @Test fun buildTunAndBuilderHelpersDoNotThrow() { runBlocking {-        Assume.assumeTrue(nativeAvailable())+        assertTrue(nativeAvailable(), "host vpn_wireguard lib unavailable: cargoBuildHost must produce libvpn_wireguard for JVM tests")         val s = session(service(), VpnConfig(name = "", address = "10.0.0.2/32", dns = "1.1.1.1, 8.8.8.8", peerAllowedIPs = "0.0.0.0/0"))         // VpnService.Builder's addAddress/establish call hidden InetAddress.parseNumericAddress,         // which the Robolectric stub android.jar lacks (NoSuchMethodError, an Error the production@@ -116,7 +115,7 @@ class VpnTunnelServiceTest {     } }      @Test fun loggingMergeAndFlush() { runBlocking {-        Assume.assumeTrue(nativeAvailable())+        assertTrue(nativeAvailable(), "host vpn_wireguard lib unavailable: cargoBuildHost must produce libvpn_wireguard for JVM tests")         val svc = service()         val s = session(svc)         val dao = FakeLogDao()@@ -144,7 +143,7 @@ class VpnTunnelServiceTest {     } }      @Test fun pumpHelpersWithRealChannels() { runBlocking {-        Assume.assumeTrue(nativeAvailable())+        assertTrue(nativeAvailable(), "host vpn_wireguard lib unavailable: cargoBuildHost must produce libvpn_wireguard for JVM tests")         val svc = service()         val s = session(svc)         s.logDao = FakeLogDao(); s.appResolver = AppResolver(ctx); s.tracker.clear()
vpn/src/test/java/com/vayunmathur/vpn/util/VpnNativeTest.kt
diff --git a/vpn/src/test/java/com/vayunmathur/vpn/util/VpnNativeTest.kt b/vpn/src/test/java/com/vayunmathur/vpn/util/VpnNativeTest.ktindex 764ba0330c..303ec047bd 100644--- a/vpn/src/test/java/com/vayunmathur/vpn/util/VpnNativeTest.kt+++ b/vpn/src/test/java/com/vayunmathur/vpn/util/VpnNativeTest.kt@@ -5,7 +5,6 @@ import kotlin.test.assertEquals import kotlin.test.assertNotNull import kotlin.test.assertNull import kotlin.test.assertTrue-import org.junit.Assume  class VpnNativeTest {     private fun nativeAvailable(): Boolean = try {@@ -13,7 +12,7 @@ class VpnNativeTest {     } catch (_: UnsatisfiedLinkError) { false } catch (_: NoClassDefFoundError) { false }      @Test fun keyGenerationAndDerivation() {-        Assume.assumeTrue("host vpn_wireguard lib unavailable", nativeAvailable())+        assertTrue(nativeAvailable(), "host vpn_wireguard lib unavailable: cargoBuildHost must produce libvpn_wireguard for JVM tests")         val priv = VpnNative.generatePrivateKey()         assertTrue(priv.isNotBlank())         val pub1 = VpnNative.derivePublicKey(priv)@@ -23,7 +22,7 @@ class VpnNativeTest {     }      @Test fun tunnelLifecycleAndStats() {-        Assume.assumeTrue("host vpn_wireguard lib unavailable", nativeAvailable())+        assertTrue(nativeAvailable(), "host vpn_wireguard lib unavailable: cargoBuildHost must produce libvpn_wireguard for JVM tests")         val priv = VpnNative.generatePrivateKey()         val pub = VpnNative.derivePublicKey(priv)         val handle = VpnNative.newTunnel(priv, pub, "", 25)@@ -42,7 +41,7 @@ class VpnNativeTest {     }      @Test fun invalidTunnelArgsReturnError() {-        Assume.assumeTrue("host vpn_wireguard lib unavailable", nativeAvailable())+        assertTrue(nativeAvailable(), "host vpn_wireguard lib unavailable: cargoBuildHost must produce libvpn_wireguard for JVM tests")         val handle = VpnNative.newTunnel("not-base64!!", "also-bad!!", "", 0)         assertTrue(handle <= 0, "bad keys should fail, got handle=$handle")         if (handle > 0) VpnNative.freeTunnel(handle)