Modern Apps git

← Modern-Apps.git

openassistant: batch unit tests - only model-loading classes quarantine

Commit
e760d88e104c660a48d645e66043f09b77258e4e
Author
Vayun Mathur <[email protected]>
When
2026-11-21 22:10 UTC (14 days ago)
Parents
7af02ce
Split audit: 3 classes actually load libmodelrunner and 9
pollute via AssistantViewModel/InferenceService/repository
singletons; 30 classes batch at 20. 255/255 green both ways,
49s -> 25-28s. New native- or ViewModel/service-backed
classes must join the lists (documented).

Diff

openassistant/build.gradle.kts
diff --git a/openassistant/build.gradle.kts b/openassistant/build.gradle.ktsindex 292e0e16b7..a961411fb5 100644--- a/openassistant/build.gradle.kts+++ b/openassistant/build.gradle.kts@@ -22,6 +22,67 @@ android {     } } +// This module has no Rust of its own, but :library:ml registers+// libmodelrunner (rustNativeLib), so every unit test here has kept+// forkEvery = 1. Only the classes below actually load that library:+// they execute a path that touches MlNative.isAvailable+// (System.loadLibrary("modelrunner") via NativeLoader), through+// Gemma4Handle.inDirectory (MamlChatEngine's real model opener),+// Gemma4VisionHandle / Gemma4AudioHandle.inDirectory (the multimodal+// towers MamlChatEngine opens for image/audio turns, even when its+// text model is a fake), or InferenceService's onCreate pre-warm with+// the default (real) engine factory. Tests that merely reference+// Gemma4Handle.Turn / ToolDeclaration, call the pure+// declareGemma4Tools / parseGemma4ToolCall helpers, or inject a fake+// text model / fake engine never load the library and stay in the+// main task. Quarantine the loaders and the shared-JVM polluters+// below into testDevUnitTestNative (forkEvery = 1); the remaining+// classes batch 20-per-JVM in testDevUnitTest, which depends on the+// quarantine task so the usual invocation still runs everything.+rustNativeTests {+    nativeClasses.addAll(+        listOf(+            "com.vayunmathur.openassistant.platform.MamlAndAssistTest",+            "com.vayunmathur.openassistant.platform.MamlChatEngineFakeModelTest",+            "com.vayunmathur.openassistant.util.InferenceServiceTest",+        )+    )+    // Shared-JVM polluters keep forkEvery = 1 in the same companion task:+    // DataStoreUtils is a process-wide singleton whose init eagerly+    // collects the preferences DataStore, and AssistantViewModel turns+    // repository flows into viewModelScope stateIn collectors+    // (SharingStarted.WhileSubscribed) that are never cleared when the+    // test never calls onCleared; its init also launches+    // viewModelScope IO coroutines that call+    // DataStoreUtils.getInstance, start InferenceService, and delete+    // files under the external files dir. Same hazard for tests that+    // launch MainActivity (which builds the ViewModel), use the+    // OpenAssistantRepository.get process-wide singleton (and its+    // cached Room database) directly, or build the real+    // InferenceService: its serviceScope job loop, onCreate engine+    // pre-warm, DataStore-backed system-prompt read, and the+    // process-wide InferenceService.halt / newTitle statics outlive+    // the test, and InferenceServiceModelLoadTest deletes and+    // rewrites the shared model directory. Audit rule: any test+    // instantiating AssistantViewModel (or launching MainActivity,+    // which builds one), using OpenAssistantRepository.get directly,+    // or building InferenceService belongs here. All other classes+    // batch.+    isolatedClasses.addAll(+        listOf(+            "com.vayunmathur.openassistant.MainActivityAndDeviceToolsTest",+            "com.vayunmathur.openassistant.data.RepositoryAndSettingsBindingTest",+            "com.vayunmathur.openassistant.ui.BubbleInputSurfaceExtraTest",+            "com.vayunmathur.openassistant.ui.LiteRTChatUiTest",+            "com.vayunmathur.openassistant.util.AssistantViewModelFakeDataTest",+            "com.vayunmathur.openassistant.util.AssistantViewModelTest",+            "com.vayunmathur.openassistant.util.InferenceServiceFakeEngineTest",+            "com.vayunmathur.openassistant.util.InferenceServiceHostMarkerTest",+            "com.vayunmathur.openassistant.util.InferenceServiceModelLoadTest",+        )+    )+}+ dependencies {      // room