Modern Apps git

← Modern-Apps.git

build: count companion-task coverage; emergency test in the elapsed domain

Commit
5992cedd3b74bedae30f6afe67dec653981bce89
Author
Vayun Mathur <[email protected]>
When
2026-11-22 04:24 UTC (14 days ago)
Parents
46858d7
Merged coverage ignored the Native companions' JaCoCo
(plain Test tasks write build/jacoco/<task>Native.exec, not
the AGP exec dir), understating coverage for all 31 split
modules. Both convention plugins now include
build/jacoco/*Native.exec - proof on library:ocr: LINE
covered 27 -> 54, the quarantined OcrEngine going 0/24 -> 18
covered lines.

Emergency's SOS test asserted the call alarm in wall time,
but production deliberately arms ELAPSED_REALTIME_WAKEUP
(wall changes must not move an emergency call, 27125493a).
The assertion now lives in the elapsed domain and pins the
alarm type; production untouched.

Verified: emergency 88 tests green, library:ocr and
emergency merged-coverage reports build.

Diff

build-logic/src/main/kotlin/common-conventions-app.gradle.kts
diff --git a/build-logic/src/main/kotlin/common-conventions-app.gradle.kts b/build-logic/src/main/kotlin/common-conventions-app.gradle.ktsindex 8f395fac4c..45eea3c635 100644--- a/build-logic/src/main/kotlin/common-conventions-app.gradle.kts+++ b/build-logic/src/main/kotlin/common-conventions-app.gradle.kts@@ -585,14 +585,22 @@ val jacocoAntClasspath: FileCollection = objects.fileCollection().from(  tasks.register<JacocoReport>(MERGED_COVERAGE_TASK) {     group = "verification"-    description = "Merged JaCoCo report for the dev variant: unit-test .exec plus " +-        "androidTest .ec files (whichever exist), with generated-code excludes."+    description = "Merged JaCoCo report for the dev variant: unit-test .exec, " ++        "<task>Native companion .exec, plus androidTest .ec files (whichever " ++        "exist), with generated-code excludes."     dependsOn("testDevUnitTest")     setJacocoClasspath(jacocoAntClasspath)     classDirectories.from(mergedCoverageClassDirs(APP_UNIT_TEST_VARIANT))     executionData.from(         files(layout.buildDirectory.dir("outputs/unit_test_code_coverage/devUnitTest"))             .asFileTree.matching { include("*.exec") },+        // The <task>Native companions (see RustNative.kt splitNativeLoadingTests)+        // are plain Gradle Test tasks, not AGP unit-test tasks, so their JaCoCo+        // agent writes build/jacoco/<task>Native.exec instead of AGP's+        // outputs/unit_test_code_coverage dir. Without this the quarantined+        // (native-loading / isolated) classes report 0% in every split module.+        files(layout.buildDirectory.dir("jacoco"))+            .asFileTree.matching { include("*Native.exec") },         files(layout.buildDirectory.dir("outputs/coverage-manual"))             .asFileTree.matching { include("*.ec") },     )
build-logic/src/main/kotlin/common-conventions-library.gradle.kts
diff --git a/build-logic/src/main/kotlin/common-conventions-library.gradle.kts b/build-logic/src/main/kotlin/common-conventions-library.gradle.ktsindex 6ea6d311db..4cf632a030 100644--- a/build-logic/src/main/kotlin/common-conventions-library.gradle.kts+++ b/build-logic/src/main/kotlin/common-conventions-library.gradle.kts@@ -169,14 +169,22 @@ val jacocoAntClasspath: FileCollection = objects.fileCollection().from(  tasks.register<JacocoReport>(MERGED_COVERAGE_TASK) {     group = "verification"-    description = "Merged JaCoCo report for the debug variant: unit-test .exec plus " +-        "androidTest .ec files (whichever exist), with generated-code excludes."+    description = "Merged JaCoCo report for the debug variant: unit-test .exec, " ++        "<task>Native companion .exec, plus androidTest .ec files (whichever " ++        "exist), with generated-code excludes."     dependsOn("testDebugUnitTest")     setJacocoClasspath(jacocoAntClasspath)     classDirectories.from(mergedCoverageClassDirs(LIBRARY_UNIT_TEST_VARIANT))     executionData.from(         files(layout.buildDirectory.dir("outputs/unit_test_code_coverage/debugUnitTest"))             .asFileTree.matching { include("*.exec") },+        // The <task>Native companions (see RustNative.kt splitNativeLoadingTests)+        // are plain Gradle Test tasks, not AGP unit-test tasks, so their JaCoCo+        // agent writes build/jacoco/<task>Native.exec instead of AGP's+        // outputs/unit_test_code_coverage dir. Without this the quarantined+        // (native-loading / isolated) classes report 0% in every split module.+        files(layout.buildDirectory.dir("jacoco"))+            .asFileTree.matching { include("*Native.exec") },         files(layout.buildDirectory.dir("outputs/coverage-manual"))             .asFileTree.matching { include("*.ec") },     )
emergency/src/test/java/com/vayunmathur/emergency/platform/RepositoryAndServiceTest.kt
diff --git a/emergency/src/test/java/com/vayunmathur/emergency/platform/RepositoryAndServiceTest.kt b/emergency/src/test/java/com/vayunmathur/emergency/platform/RepositoryAndServiceTest.ktindex d466f99bf5..7ec2721462 100644--- a/emergency/src/test/java/com/vayunmathur/emergency/platform/RepositoryAndServiceTest.kt+++ b/emergency/src/test/java/com/vayunmathur/emergency/platform/RepositoryAndServiceTest.kt@@ -286,7 +286,11 @@ class SosServiceAndReceiverTest {         val alarms = ctx.getSystemService(android.app.AlarmManager::class.java)         val controller = Robolectric.buildService(SosCountdownService::class.java)         val service = controller.create().get()-        val before = System.currentTimeMillis()+        // Production arms ELAPSED_REALTIME_WAKEUP at+        // SystemClock.elapsedRealtime() + remainingMs (see SosCountdownService+        // .scheduleCall), so the shadow's triggerAtMs lives in the elapsed+        // domain — read the same shadow-backed clock here, not the wall clock.+        val beforeElapsed = android.os.SystemClock.elapsedRealtime()         val intent = Intent().putExtra("service.extra.remaining_time_ms", 60_000L)         service.onStartCommand(intent, 0, 1)         ShadowLooper.idleMainLooper()@@ -295,7 +299,11 @@ class SosServiceAndReceiverTest {         // grant is unavailable on device.         val scheduled = Shadows.shadowOf(alarms).scheduledAlarms         assertTrue(scheduled.isNotEmpty())-        assertTrue(scheduled.first().triggerAtMs >= before + 50_000)+        assertEquals(+            android.app.AlarmManager.ELAPSED_REALTIME_WAKEUP,+            scheduled.first().getType(),+        )+        assertTrue(scheduled.first().triggerAtMs >= beforeElapsed + 50_000)         controller.destroy()         ShadowLooper.idleMainLooper()     }