From 2ba90e1d1833920854e885df8dbc9d3bbd50b8d4 Mon Sep 17 00:00:00 2001 From: darken Date: Mon, 31 Aug 2026 18:41:18 +0200 Subject: [PATCH] feat(debug): Flip the debug flag when the recorder starts writing The flag was only written from committed recorder module state, which publishes after the recording header has been read. That read is bounded at 5s, so for up to five seconds the file logger is live while the flag still says false, and diagnostics keyed off it are missing from exactly the window a reporter uses to reproduce a screen-off issue. The module-state writer stays: it covers a resumed session and any path that reaches isRecording=false without going through Recorder.stop(). A rolled-back start self-corrects, because the rollback stops the recorder before publishing the failure. BaseTest resets the flag per test instance because it is JVM-global. It goes into init rather than the companion teardown, which uses JUnit 5's @AfterAll and never fires under the JUnit 4 Robolectric runner. --- .../eu/darken/capod/common/debug/recording/core/Recorder.kt | 6 ++++++ app/src/test/java/testhelpers/BaseTest.kt | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/app/src/main/java/eu/darken/capod/common/debug/recording/core/Recorder.kt b/app/src/main/java/eu/darken/capod/common/debug/recording/core/Recorder.kt index f61be52e..56337470 100644 --- a/app/src/main/java/eu/darken/capod/common/debug/recording/core/Recorder.kt +++ b/app/src/main/java/eu/darken/capod/common/debug/recording/core/Recorder.kt @@ -1,6 +1,7 @@ package eu.darken.capod.common.debug.recording.core import eu.darken.capod.common.TimeSource +import eu.darken.capod.common.debug.Bugs import eu.darken.capod.common.debug.logging.FileLogger import eu.darken.capod.common.debug.logging.Logging import eu.darken.capod.common.debug.logging.Logging.Priority.INFO @@ -33,6 +34,10 @@ class Recorder @Inject constructor( it.start() Logging.install(it) log(TAG, INFO) { "Now logging to file!" } + // Flipped here rather than only from the committed module state: that publishes after + // the recording header has been read, and everything written in that window would miss + // the debug-only diagnostics that key off this flag. + Bugs.isDebug.value = true } } @@ -52,6 +57,7 @@ class Recorder @Inject constructor( } finally { fileLogger = null this@Recorder.path = null + Bugs.isDebug.value = false } } } diff --git a/app/src/test/java/testhelpers/BaseTest.kt b/app/src/test/java/testhelpers/BaseTest.kt index d19e1710..ce7ae1b3 100644 --- a/app/src/test/java/testhelpers/BaseTest.kt +++ b/app/src/test/java/testhelpers/BaseTest.kt @@ -1,5 +1,6 @@ package testhelpers +import eu.darken.capod.common.debug.Bugs import eu.darken.capod.common.debug.logging.Logging import eu.darken.capod.common.debug.logging.Logging.Priority.VERBOSE import eu.darken.capod.common.debug.logging.log @@ -12,6 +13,10 @@ open class BaseTest { init { Logging.clearAll() Logging.install(JUnitLogger()) + // JVM-global and written by anything that starts a debug recording. Reset per test instance + // and not in a companion teardown: the JUnit 5 @AfterAll below never fires under the JUnit 4 + // Robolectric runner that the recorder tests use. + Bugs.isDebug.value = false testClassName = this.javaClass.simpleName }