fix(di): start AppFunctionStateSync from the Application, not createdAtStart

The google-flavor AppFunctionsModule registered AppFunctionStateSync
with createdAtStart = true. Eager creation needs the androidContext
binding and immediately spawns the prefs-observing sync coroutine —
so any Koin graph built outside a running app failed with
NoDefinitionFoundException for android.content.Context. That broke
KoinVerificationTest.verifyTypedBootstrapLoadsModuleGraph (the typed
koinApplication<AndroidKoinApp>() bootstrap instantiates eager
singletons), failing the shard-app CI job on this branch.

The definition is now a plain @Single (the graph stays lazily
constructible) and GoogleMeshUtilApplication.onCreate resolves it once
after startKoin has bound androidContext — same production behavior,
explicit instead of implicit. It was the repo's only createdAtStart.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: James Rich <james.a.rich@gmail.com>
This commit is contained in:
James Rich
2026-06-12 06:43:09 -05:00
parent 2820efefca
commit 0a4c22b3d3
2 changed files with 14 additions and 1 deletions

View File

@@ -18,6 +18,7 @@ package org.meshtastic.app
import androidx.appfunctions.service.AppFunctionConfiguration
import org.koin.java.KoinJavaComponent.getKoin
import org.meshtastic.app.ai.appfunctions.AppFunctionStateSync
import org.meshtastic.app.ai.appfunctions.MeshtasticAppFunctions
/**
@@ -30,6 +31,14 @@ class GoogleMeshUtilApplication :
MeshUtilApplication(),
AppFunctionConfiguration.Provider {
override fun onCreate() {
super.onCreate()
// Start the AppFunctions enabled-state sync. Resolved here (after startKoin has bound
// androidContext) rather than via createdAtStart so that Koin graphs built outside a
// running app — verification tests, previews — stay lazily constructible.
getKoin().get<AppFunctionStateSync>()
}
override val appFunctionConfiguration: AppFunctionConfiguration
get() =
AppFunctionConfiguration.Builder()

View File

@@ -32,7 +32,11 @@ class AppFunctionsModule {
@Single
fun meshtasticAppFunctions(provider: AiFunctionProvider): MeshtasticAppFunctions = MeshtasticAppFunctions(provider)
@Single(createdAtStart = true)
// NOT createdAtStart: eager creation needs the androidContext binding and spawns the sync
// coroutine, which breaks (and is wrong for) any Koin graph built outside a running app —
// e.g. KoinVerificationTest's typed-bootstrap check. GoogleMeshUtilApplication starts it
// explicitly at app startup instead.
@Single
fun appFunctionStateSync(
context: Context,
prefs: AppFunctionsPrefs,