Add opt-in game debug logs and bounded log sharing (#1061)

This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-10-27 22:22:33 -04:00
commit eceda6e840
21 files changed
+1608 -169

No files matched your search

@@ -3,9 +3,14 @@ package com.droiddeck.launcher.core
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import java.io.StringWriter
class LogRedactorTest {
@get:Rule val tmp = TemporaryFolder()
@Test fun labelledJwtIsRedacted() {
val out = LogRedactor.redact("Using JWT 25484942796017334")
assertFalse(out.contains("25484942796017334"))
@@ -226,6 +231,103 @@ class LogRedactorTest {
assertEquals(once, LogRedactor.redactForShare(once))
}
@Test fun anOversizedDirectInputIsWithheldBeforeRegex() {
val secret = "sessionid=abcdef123456"
val line = "x".repeat(LogRedactor.MAX_LINE_LENGTH) + secret
assertEquals(LogRedactor.OVERSIZED_LINE, LogRedactor.redact(line))
assertEquals(LogRedactor.OVERSIZED_LINE, LogRedactor.redactForShare(line))
}
@Test fun streamWithholdsAnOversizedLogicalLineWholeAndContinues() {
val secret = "sessionid=abcdef123456"
val src = tmp.newFile("oversized.log")
src.writeText(
"before\r" +
"x".repeat(LogRedactor.MAX_LINE_LENGTH - 3) + secret + "\r\n" +
"after $secret"
)
val out = StringWriter()
LogRedactor.scrubTo(src, out)
assertEquals(
"before\n${LogRedactor.OVERSIZED_LINE}\nafter sessionid=<redacted:token>\n",
out.toString(),
)
assertFalse(out.toString().contains("abcdef123456"))
}
@Test fun sharedStreamDistinguishesOversizedAndUnsupportedLines() {
val src = tmp.newFile("shared-lines.log")
src.writeText(
"x".repeat(LogRedactor.MAX_LINE_LENGTH + 1) + "\n" +
"private-prefix\u0000private-suffix\n" +
"after sessionid=abcdef123456\n"
)
val out = StringWriter()
assertTrue(LogRedactor.scrubForShare(src, out))
assertEquals(
"${LogRedactor.OVERSIZED_LINE}\n" +
"<unsupported or oversized line withheld>\n" +
"after sessionid=<redacted:token>\n",
out.toString(),
)
}
@Test fun aMaximumLengthLineBeforeCrLfIsStillScrubbed() {
val src = tmp.newFile("maximum.log")
val line = "x ".repeat(LogRedactor.MAX_LINE_LENGTH / 2)
src.writeText(line + "\r\n")
val out = StringWriter()
LogRedactor.scrubTo(src, out)
assertEquals(line + "\n", out.toString())
assertFalse(out.toString().contains(LogRedactor.OVERSIZED_LINE))
}
@Test fun streamingScrubStopsBetweenInputChunks() {
val src = tmp.newFile("cancelled.log")
src.writeText("first safe line\n" + "x".repeat(20_000) + " sessionid=abcdef123456\n")
val out = StringWriter()
var checks = 0
val complete = LogRedactor.scrubTo(src, out) { ++checks >= 4 }
assertFalse(complete)
assertFalse(out.toString().contains("abcdef123456"))
assertTrue(checks >= 4)
}
@Test fun manyLearnedAccountsKeepBoundariesAndLiteralNames() {
val users = tmp.newFile("loginusers.vdf")
users.writeText((0 until 40).joinToString("\n") {
"\"AccountName\" \"probe_account_$it\""
} + "\n\"PersonaName\" \"Player.+[40]\"\n")
try {
LogRedactor.learnAccounts(users)
assertEquals("owner=<redacted:account> persona=<redacted:account>",
LogRedactor.redact("owner=probe_account_39 persona=Player.+[40]"))
assertEquals("owner=probe_account_390", LogRedactor.redact("owner=probe_account_390"))
} finally {
LogRedactor.learnAccounts(tmp.root.resolve("missing-users"))
}
}
@Test fun manyLearnedAddressesKeepOtherAddresses() {
val link = tmp.newFile("droiddeck-net")
link.writeText((1..40).joinToString("\n") { "addr 203.0.113.$it 24" })
try {
LogRedactor.learnOwnAddresses(link)
assertEquals("local=<redacted:ip> server=203.0.113.200",
LogRedactor.redact("local=203.0.113.40 server=203.0.113.200"))
} finally {
LogRedactor.learnOwnAddresses(tmp.root.resolve("missing-network"))
}
}
@Test fun learnedAccountsComeFromBothClients() {
val root = java.nio.file.Files.createTempDirectory("redactor").toFile()
try {
@@ -4,6 +4,7 @@ import android.content.Context
import com.droiddeck.launcher.core.GameEnvironment
import com.droiddeck.launcher.runtime.LinuxRuntime
import org.json.JSONObject
import org.junit.After
import org.junit.Assert.*
import org.junit.Before
import org.junit.Test
@@ -12,6 +13,8 @@ import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config
import java.io.File
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [28], manifest = Config.NONE)
@@ -21,10 +24,137 @@ class GameEnvironmentStoreTest {
@Before fun setUp() {
context = RuntimeEnvironment.getApplication()
context.getSharedPreferences("session", Context.MODE_PRIVATE).edit()
.remove("logs")
.remove("gameDebugLogsEnabled")
.commit()
guest = File(LinuxRuntime.rootDir(context), "root/.config/droiddeck/game-environment.json")
File(context.filesDir, "game-environment.json").delete()
}
@After fun tearDown() {
context.getSharedPreferences("session", Context.MODE_PRIVATE).edit()
.remove("logs")
.remove("gameDebugLogsEnabled")
.commit()
}
@Test fun gameDebugLogsAreOffByDefault() {
assertFalse(SessionPrefs.gameDebugLogsEnabled(context))
GameEnvironmentStore.save(context, GameEnvironment.Config())
assertFalse(JSONObject(guest.readText()).getBoolean(GameEnvironmentStore.GAME_DEBUG_LOGS))
}
@Test fun gameDebugLogsRequireSessionLogsAndPreserveCustomDiagnostics() {
val config = GameEnvironment.Config(shared = mapOf("PROTON_LOG" to "0", "WINEDEBUG" to "+warn"))
GameEnvironmentStore.save(context, config)
SessionPrefs.setGameDebugLogsEnabled(context, true)
var published = JSONObject(guest.readText())
assertTrue(published.getBoolean(GameEnvironmentStore.GAME_DEBUG_LOGS))
assertEquals("0", published.getJSONObject("shared").getString("PROTON_LOG"))
assertEquals("+warn", published.getJSONObject("shared").getString("WINEDEBUG"))
assertEquals(config, GameEnvironmentStore.read(context))
SessionPrefs.setLogsEnabled(context, false)
published = JSONObject(guest.readText())
assertFalse(published.getBoolean(GameEnvironmentStore.GAME_DEBUG_LOGS))
assertTrue(SessionPrefs.gameDebugLogsEnabled(context))
SessionPrefs.setLogsEnabled(context, true)
assertTrue(JSONObject(guest.readText()).getBoolean(GameEnvironmentStore.GAME_DEBUG_LOGS))
}
@Test fun failedGameDebugOptOutLeavesTheEnabledPreferenceVisible() {
assertTrue(SessionPrefs.setGameDebugLogsEnabled(context, true))
assertTrue(SessionPrefs.gameDebugLogsEnabled(context))
val guestDirectory = guest.parentFile!!
guestDirectory.deleteRecursively()
guestDirectory.parentFile!!.mkdirs()
guestDirectory.writeText("blocks the guest configuration directory\n")
try {
assertFalse(SessionPrefs.setGameDebugLogsEnabled(context, false))
assertTrue(SessionPrefs.gameDebugLogsEnabled(context))
} finally {
guestDirectory.delete()
guestDirectory.mkdirs()
GameEnvironmentStore.publish(context)
}
assertTrue(JSONObject(guest.readText()).getBoolean(GameEnvironmentStore.GAME_DEBUG_LOGS))
}
@Test fun unchangedEffectiveDiagnosticsDoNotRequireGuestPublication() {
assertFalse(SessionPrefs.gameDebugLogsEnabled(context))
val guestDirectory = guest.parentFile!!
guestDirectory.deleteRecursively()
guestDirectory.parentFile!!.mkdirs()
guestDirectory.writeText("blocks the guest configuration directory\n")
try {
assertTrue(SessionPrefs.setLogsEnabled(context, false))
assertFalse(SessionPrefs.logsEnabled(context))
} finally {
guestDirectory.delete()
guestDirectory.mkdirs()
SessionPrefs.setLogsEnabled(context, true)
GameEnvironmentStore.publish(context)
}
}
@Test fun logPreferenceUpdatesUseThePublisherLock() {
GameEnvironmentStore.publish(context)
val entered = CountDownLatch(1)
val finished = CountDownLatch(1)
lateinit var thread: Thread
synchronized(GameEnvironmentStore) {
thread = Thread {
entered.countDown()
SessionPrefs.setGameDebugLogsEnabled(context, true)
finished.countDown()
}
thread.start()
assertTrue(entered.await(5, TimeUnit.SECONDS))
assertFalse(finished.await(100, TimeUnit.MILLISECONDS))
assertFalse(SessionPrefs.gameDebugLogsEnabled(context))
assertFalse(JSONObject(guest.readText()).getBoolean(GameEnvironmentStore.GAME_DEBUG_LOGS))
}
assertTrue(finished.await(5, TimeUnit.SECONDS))
thread.join()
assertTrue(SessionPrefs.gameDebugLogsEnabled(context))
assertTrue(JSONObject(guest.readText()).getBoolean(GameEnvironmentStore.GAME_DEBUG_LOGS))
}
@Test fun gameDebugLogsWaitForARetainedSessionFolder() {
assertNull(SessionPaths.current())
assertTrue(SessionPaths.currentSessionLogsRetained(context))
GameEnvironmentStore.publish(context)
SessionPrefs.setLogsEnabled(context, false)
val cacheSession = SessionPaths.beginOrCurrent(context, "game-debug-logs")
try {
assertFalse(SessionPaths.currentSessionLogsRetained(context))
SessionPrefs.setLogsEnabled(context, true)
SessionPrefs.setGameDebugLogsEnabled(context, true)
assertTrue(SessionPrefs.gameDebugLogsEnabled(context))
assertFalse(JSONObject(guest.readText()).getBoolean(GameEnvironmentStore.GAME_DEBUG_LOGS))
assertEquals(cacheSession, SessionPaths.take())
SessionPaths.release(context, cacheSession)
val retainedSession = SessionPaths.beginOrCurrent(context, "game-debug-logs")
assertTrue(SessionPaths.currentSessionLogsRetained(context))
GameEnvironmentStore.publish(context)
assertTrue(JSONObject(guest.readText()).getBoolean(GameEnvironmentStore.GAME_DEBUG_LOGS))
assertEquals(retainedSession, SessionPaths.current())
} finally {
SessionPaths.take()?.let { ended ->
SessionPaths.release(context, ended)
ended.deleteRecursively()
}
}
}
@Test fun savedSettingsAndPublishedSettingsPreserveUnsetsAndLiteralValues() {
val config = GameEnvironment.Config(
shared = mapOf("LITERAL" to "a=b 'quoted' $(echo test)", "EMPTY" to ""),
@@ -1,8 +1,10 @@
package com.droiddeck.launcher.session
import com.droiddeck.launcher.core.LogRedactor
import org.junit.Assert.assertArrayEquals
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Rule
import org.junit.Test
@@ -12,6 +14,9 @@ import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config
import java.io.File
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
import java.util.zip.ZipFile
@RunWith(RobolectricTestRunner::class)
@@ -147,6 +152,41 @@ class SessionLogShareTest {
assertTrue(zip(folder).values.none { it.contains(leaked) })
}
@Test fun aDirectoryListingFailureLeavesTheTreeUnrecordedButDoesNotStopSiblingScrubbing() {
val folder = tmp.newFolder("2026-10-06-06-listing")
val unavailable = File(folder, "unavailable").apply { mkdirs() }
val unavailableLog = File(unavailable, "session.log").apply { writeText("$secret\n") }
val availableLog = File(folder, "available/session.log").apply {
parentFile!!.mkdirs()
writeText("$secret\n")
}
assertFalse(SessionArtifacts.scrubAndMark(folder, listFiles = {
if (it == unavailable) null else it.listFiles()
}))
assertTrue(unavailableLog.readText().contains(leaked))
assertFalse(availableLog.readText().contains(leaked))
assertFalse(File(folder, ".scrubbed-r${LogRedactor.RULES_VERSION}").exists())
assertFalse(File(folder, SessionArtifacts.SCRUBBED_TREE_MARKER).exists())
}
@Test fun aFailedScrubStillRecordsTheCollectionEventWithoutCompletingTheFolder() {
val context: android.content.Context = RuntimeEnvironment.getApplication()
val folder = tmp.newFolder("2026-10-06-06-collect")
File(folder, "wayland.log").writeText("test compositor log\n")
File(folder, SessionArtifacts.SCRUBBED_TREE_MARKER).apply {
mkdirs()
resolve("blocker").writeText("force marker write failure\n")
}
SessionArtifacts.collect(context, folder, "test")
assertTrue(File(folder, "events.jsonl").readText().contains("session.artifacts_collected"))
assertFalse(File(folder, SessionArtifacts.COMPLETE_MARKER).exists())
assertFalse(File(folder, ".scrubbed-r${LogRedactor.RULES_VERSION}").exists())
}
@Test fun steamLogsPastTheSizeLimitStayOut() {
val folder = tmp.newFolder("2026-10-06-07-steam")
File(folder, "session.log").writeText("ok\n")
@@ -160,4 +200,322 @@ class SessionLogShareTest {
assertTrue("steam/console_log.txt" in names)
assertFalse("steam/cef_log.previous.txt" in names)
}
@Test fun streamingComparisonPreservesUnchangedFileAndReplacesChangedFile() {
val folder = tmp.newFolder("2026-10-06-08-steam")
val unchanged = File(folder, "unchanged.log")
unchanged.bufferedWriter().use { out -> repeat(5000) { out.write("safe diagnostic $it\n") } }
val originalModified = 1_600_000_000_000L
assertTrue(unchanged.setLastModified(originalModified))
val changed = File(folder, "changed.log")
changed.bufferedWriter().use { out ->
repeat(5000) { out.write("safe diagnostic $it\n") }
out.write("$secret\n")
}
assertTrue(SessionArtifacts.scrubAndMark(folder))
assertEquals(originalModified, unchanged.lastModified())
assertFalse(changed.readText().contains(leaked))
assertTrue(changed.readText().contains("sessionid=<redacted:token>"))
}
@Test fun historicalScrubDefersWithoutLeavingMarkersAndResumes() {
val folder = tmp.newFolder("2026-10-06-09-steam")
val log = File(folder, "session.log").apply { writeText("$secret\n") }
val rulesMarker = File(folder, ".scrubbed-r${LogRedactor.RULES_VERSION}").apply { writeText("stale\n") }
val treeMarker = File(folder, SessionArtifacts.SCRUBBED_TREE_MARKER).apply { writeText("rules ${LogRedactor.RULES_VERSION}\n") }
SessionState.running = true
try {
assertFalse(SessionArtifacts.scrubAndMark(folder, stopWhenSessionStarts = true))
} finally {
SessionState.running = false
}
assertFalse(rulesMarker.exists())
assertFalse(treeMarker.exists())
assertTrue(log.readText().contains(leaked))
assertTrue(SessionArtifacts.scrubAndMark(folder, stopWhenSessionStarts = true))
assertFalse(log.readText().contains(leaked))
assertTrue(File(folder, ".scrubbed-r${LogRedactor.RULES_VERSION}").isFile)
}
@Test fun historicalScrubCancellationDuringStreamingPreservesTheOriginal() {
val folder = tmp.newFolder("2026-10-06-10-steam")
val original = "first safe line\n" + "x".repeat(20_000) + " $secret\n"
val log = File(folder, "session.log").apply { writeText(original) }
var checks = 0
assertFalse(SessionArtifacts.scrubAndMark(folder, stopWhenSessionStarts = true) { ++checks >= 4 })
assertEquals(original, log.readText())
assertFalse(File(folder, ".session.log.scrub").exists())
assertFalse(File(folder, SessionArtifacts.SCRUBBED_TREE_MARKER).exists())
}
@Test fun historicalScrubCancellationBeforeComparisonPreservesTheOriginal() {
val folder = tmp.newFolder("2026-10-06-11-steam")
val original = "safe diagnostic\n"
val log = File(folder, "session.log").apply { writeText(original) }
val temporary = File(folder, ".session.log.scrub")
assertFalse(SessionArtifacts.scrubAndMark(folder, stopWhenSessionStarts = true) { temporary.length() > 0 })
assertEquals(original, log.readText())
assertFalse(temporary.exists())
assertFalse(File(folder, SessionArtifacts.SCRUBBED_TREE_MARKER).exists())
}
@Test fun historicalScrubDoesNotReplaceALogThatChangedBeforeCommit() {
val folder = tmp.newFolder("2026-10-06-12-steam")
val original = "sessionid=$leaked\n"
val appended = "writer finished after collection started\n"
val log = File(folder, "session.log").apply { writeText(original) }
assertFalse(SessionArtifacts.scrubAndMark(folder, beforeReplace = { it.appendText(appended) }))
assertEquals(original + appended, log.readText())
assertFalse(File(folder, ".session.log.scrub").exists())
assertFalse(File(folder, ".scrubbed-r${LogRedactor.RULES_VERSION}").exists())
assertFalse(File(folder, SessionArtifacts.SCRUBBED_TREE_MARKER).exists())
}
@Test fun comparisonCancellationWinsOverAnImmediateLengthMismatch() {
val left = tmp.newFile("left.log").apply { writeText("short\n") }
val right = tmp.newFile("right.log").apply { writeText("a different length\n") }
assertNull(SessionArtifacts.sameContents(left, right) { true })
}
@Test fun recoveryRetryKeepsItsSteamLogsWhenALaterSessionLeftNoFolder() {
val context: android.content.Context = RuntimeEnvironment.getApplication()
val folder = File(com.droiddeck.launcher.runtime.LinuxRuntime.logDir(context), "2026-10-08-01-steam").apply { mkdirs() }
val saved = File(folder, "steam/console_log.txt").apply {
parentFile!!.mkdirs()
writeText("session A\n")
}
File(folder, "ended-without-teardown.txt").writeText("recovery attempted before session B\n")
val runtime = File(com.droiddeck.launcher.runtime.LinuxRuntime.rootDir(context), "root/.local/share/Steam/logs/console_log.txt").apply {
parentFile!!.mkdirs()
writeText("session B\n")
}
SessionArtifacts.finishAbandoned(context)
assertEquals("session A\n", saved.readText())
assertEquals("session B\n", runtime.readText())
assertTrue(File(folder, "ended-without-teardown.txt").readText().contains("runtime capture did not finish"))
assertTrue(File(folder, SessionArtifacts.COMPLETE_MARKER).isFile)
}
@Test fun abandonedRecoveryDoesNotCopyLogsFromANewerCompletedSession() {
val context: android.content.Context = RuntimeEnvironment.getApplication()
val logs = com.droiddeck.launcher.runtime.LinuxRuntime.logDir(context)
val folder = File(logs, "2026-10-08-02-steam").apply { mkdirs() }
val saved = File(folder, "steam/console_log.txt").apply {
parentFile!!.mkdirs()
writeText("session A\n")
}
File(logs, "2026-10-08-03-steam").apply { mkdirs() }
.resolve(SessionArtifacts.COMPLETE_MARKER).writeText("finished session B\n")
File(com.droiddeck.launcher.runtime.LinuxRuntime.rootDir(context), "root/.local/share/Steam/logs/console_log.txt").apply {
parentFile!!.mkdirs()
writeText("session B\n")
}
SessionArtifacts.finishAbandoned(context)
assertEquals("session A\n", saved.readText())
assertTrue(File(folder, SessionArtifacts.COMPLETE_MARKER).isFile)
}
@Test fun startupRecoveryRunsBeforeVacMarkerArmWhileOrdinaryCleanupDefers() {
val context: android.content.Context = RuntimeEnvironment.getApplication()
val root = com.droiddeck.launcher.runtime.LinuxRuntime.rootDir(context)
val folder = File(com.droiddeck.launcher.runtime.LinuxRuntime.logDir(context), "2999-12-31-99-startup-recovery")
val marker = File(root, "root/.droiddeck-vac-diagnostics")
val launches = File(root, "root/.droiddeck-vac-launches")
val runtimeSteamLog = File(SessionPrefs.steamRoot(context, "arm64"), "logs/startup-recovery-vac.log")
val sessionLog = File(folder, "session.log")
val crashLog = File(folder, "crash.log")
val previousRunning = SessionState.running
val previousPhase = SessionState.phase
try {
folder.deleteRecursively()
folder.mkdirs()
SessionArtifacts.recordClient(folder, "arm64")
sessionLog.writeText("$secret\n")
marker.apply { parentFile!!.mkdirs(); writeText("0\narm64\n") }
launches.writeText("startup VAC evidence\n")
runtimeSteamLog.apply { parentFile!!.mkdirs(); writeText("startup VAC evidence\n") }
SessionState.running = true
SessionState.phase = SessionPhase.STARTING_GUEST
SessionArtifacts.finishAbandoned(context)
assertFalse(File(folder, "ended-without-teardown.txt").exists())
assertFalse(File(folder, SessionArtifacts.COMPLETE_MARKER).exists())
SessionArtifacts.finishAbandoned(context, beforeGuestStart = true)
assertEquals("startup VAC evidence\n", File(folder, "steam/startup-recovery-vac.log").readText())
assertTrue(File(folder, "vac.txt").readText().contains("startup VAC evidence"))
assertTrue(File(folder, ".recovery-runtime-captured").isFile)
assertTrue(crashLog.isFile && crashLog.length() > 0L)
assertTrue(sessionLog.readText().contains(leaked))
assertFalse(File(folder, SessionArtifacts.COMPLETE_MARKER).exists())
SessionState.running = false
SessionArtifacts.finishAbandoned(context)
assertFalse(sessionLog.readText().contains(leaked))
assertTrue(File(folder, SessionArtifacts.COMPLETE_MARKER).isFile)
} finally {
SessionState.running = previousRunning
SessionState.phase = previousPhase
folder.deleteRecursively()
runtimeSteamLog.delete()
marker.delete()
launches.delete()
}
}
@Test fun startupRecoveryExcludesCurrentFolderAndCapturesDeferredRuntime() {
val context: android.content.Context = RuntimeEnvironment.getApplication()
val root = com.droiddeck.launcher.runtime.LinuxRuntime.rootDir(context)
val logs = com.droiddeck.launcher.runtime.LinuxRuntime.logDir(context)
val day = SimpleDateFormat("yyyy-MM-dd", Locale.US).format(Date())
val olderFolder = File(logs, "$day-8999-older-recovery")
val folder = File(logs, "$day-9000-deferred-recovery")
val marker = File(root, "root/.droiddeck-vac-diagnostics")
val launches = File(root, "root/.droiddeck-vac-launches")
val runtimeSteamLog = File(SessionPrefs.steamRoot(context, "arm64"), "logs/deferred-recovery-vac.log")
val previousRunning = SessionState.running
val previousPhase = SessionState.phase
val previousLogsEnabled = SessionPrefs.logsEnabled(context)
var currentFolder: File? = null
try {
olderFolder.deleteRecursively()
olderFolder.mkdirs()
folder.deleteRecursively()
folder.mkdirs()
SessionArtifacts.recordClient(folder, "arm64")
File(folder, "ended-without-teardown.txt").writeText("recovery began before session start\n")
marker.apply { parentFile!!.mkdirs(); writeText("0\narm64\n") }
launches.writeText("deferred VAC evidence\n")
runtimeSteamLog.apply { parentFile!!.mkdirs(); writeText("deferred VAC evidence\n") }
SessionState.running = true
SessionState.phase = SessionPhase.STARTING_GUEST
SessionPrefs.setLogsEnabled(context, true)
currentFolder = SessionPaths.beginOrCurrent(context, "current-session")
SessionArtifacts.finishAbandoned(context, beforeGuestStart = true)
assertEquals("deferred VAC evidence\n", File(folder, "steam/deferred-recovery-vac.log").readText())
assertTrue(File(folder, "vac.txt").readText().contains("deferred VAC evidence"))
assertTrue(File(folder, ".recovery-runtime-captured").isFile)
assertFalse(File(folder, SessionArtifacts.COMPLETE_MARKER).exists())
assertFalse(File(olderFolder, "ended-without-teardown.txt").exists())
assertFalse(File(olderFolder, SessionArtifacts.COMPLETE_MARKER).exists())
assertFalse(File(currentFolder, "ended-without-teardown.txt").exists())
assertFalse(File(currentFolder, SessionArtifacts.COMPLETE_MARKER).exists())
SessionState.running = false
SessionArtifacts.finishAbandoned(context)
assertTrue(File(folder, SessionArtifacts.COMPLETE_MARKER).isFile)
assertTrue(File(olderFolder, SessionArtifacts.COMPLETE_MARKER).isFile)
assertFalse(File(currentFolder, SessionArtifacts.COMPLETE_MARKER).exists())
} finally {
SessionState.running = previousRunning
SessionState.phase = previousPhase
SessionPaths.take()?.let { SessionPaths.release(context, it) }
currentFolder?.deleteRecursively()
SessionPrefs.setLogsEnabled(context, previousLogsEnabled)
olderFolder.deleteRecursively()
folder.deleteRecursively()
runtimeSteamLog.delete()
marker.delete()
launches.delete()
}
}
@Test fun failedPreGuestRuntimeCaptureWritesNeitherCaptureNorCompleteMarker() {
val context: android.content.Context = RuntimeEnvironment.getApplication()
val root = com.droiddeck.launcher.runtime.LinuxRuntime.rootDir(context)
val folder = File(com.droiddeck.launcher.runtime.LinuxRuntime.logDir(context), "9999-12-31-01-vac-failure")
val marker = File(root, "root/.droiddeck-vac-diagnostics")
val launches = File(root, "root/.droiddeck-vac-launches")
val runtimeSteamLog = File(SessionPrefs.steamRoot(context, "arm64"), "logs/expired-recovery.log")
val crashLog = File(folder, "crash.log")
val previousRunning = SessionState.running
try {
folder.deleteRecursively()
folder.mkdirs()
SessionArtifacts.recordClient(folder, "arm64")
File(folder, "ended-without-teardown.txt").writeText("recovery began before session start\n")
val firstCrashSnapshot = "first crash snapshot\n".toByteArray()
crashLog.writeBytes(firstCrashSnapshot)
File(folder, "vac.txt").mkdirs()
marker.apply { parentFile!!.mkdirs(); writeText("0\narm64\n") }
launches.writeText("VAC evidence that cannot be reported\n")
runtimeSteamLog.apply { parentFile!!.mkdirs(); writeText("session A\n") }
SessionState.running = true
SessionArtifacts.finishAbandoned(context, beforeGuestStart = true)
assertFalse(File(folder, ".recovery-runtime-captured").exists())
assertTrue(File(folder, ".recovery-runtime-expired").isFile)
assertFalse(File(folder, SessionArtifacts.COMPLETE_MARKER).exists())
assertArrayEquals(firstCrashSnapshot, crashLog.readBytes())
File(folder, "vac.txt").deleteRecursively()
runtimeSteamLog.writeText("session B\n")
SessionArtifacts.finishAbandoned(context, beforeGuestStart = true)
assertEquals("session A\n", File(folder, "steam/expired-recovery.log").readText())
assertArrayEquals(firstCrashSnapshot, crashLog.readBytes())
assertTrue(File(folder, "ended-without-teardown.txt").readText().contains("runtime capture did not finish"))
assertFalse(File(folder, SessionArtifacts.COMPLETE_MARKER).exists())
SessionState.running = false
SessionArtifacts.finishAbandoned(context)
assertArrayEquals(firstCrashSnapshot, crashLog.readBytes())
assertTrue(File(folder, SessionArtifacts.COMPLETE_MARKER).isFile)
} finally {
SessionState.running = previousRunning
folder.deleteRecursively()
runtimeSteamLog.delete()
marker.delete()
launches.delete()
}
}
@Test fun emptyCrashSnapshotIsPreservedAcrossRecovery() {
val context: android.content.Context = RuntimeEnvironment.getApplication()
val folder = File(com.droiddeck.launcher.runtime.LinuxRuntime.logDir(context), "9999-12-31-02-empty-crash")
val crashLog = File(folder, "crash.log")
val previousRunning = SessionState.running
try {
folder.deleteRecursively()
folder.mkdirs()
crashLog.writeBytes(ByteArray(0))
SessionState.running = true
SessionArtifacts.finishAbandoned(context, beforeGuestStart = true)
assertTrue(crashLog.isFile)
assertEquals(0L, crashLog.length())
SessionState.running = false
SessionArtifacts.finishAbandoned(context)
assertTrue(crashLog.isFile)
assertEquals(0L, crashLog.length())
assertTrue(File(folder, SessionArtifacts.COMPLETE_MARKER).isFile)
} finally {
SessionState.running = previousRunning
folder.deleteRecursively()
}
}
}
@@ -2,6 +2,7 @@ package com.droiddeck.launcher.session
import com.droiddeck.launcher.runtime.LinuxRuntime
import java.io.File
import java.nio.charset.StandardCharsets
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
@@ -20,6 +21,49 @@ import org.robolectric.annotation.Config
class SessionLogShareZipTest {
private val app get() = RuntimeEnvironment.getApplication()
@Test fun aLargeSteamLogIsRedactedInTheSharedArchive() {
val session = File(LinuxRuntime.logDir(app), "2026-10-08-02-steam").apply { mkdirs() }
val raw = File(session, "steam-42.log")
val earlySecret = "early-sessionid-abcdef123456"
val trailingSecret = "late-refresh-token-abcdef123456"
try {
// One long line exercises the streaming limit; the final ordinary line must still be redacted.
raw.bufferedWriter().use { out ->
out.write("sessionid=$earlySecret")
val chunk = "x".repeat(8192)
repeat(8192) { out.write(chunk) }
out.write("\nrefresh_token=$trailingSecret\n")
}
assertTrue(raw.length() > 64L * 1024 * 1024)
val zip = SessionLogShare.zipFolder(app, session)!!
ZipFile(zip).use { archive ->
val entry = archive.getEntry("${session.name}/steam-42.log")!!
archive.getInputStream(entry).use { input ->
// Only inspect the bounded scrubbed prefix: the pre-fix raw archive is over 64 MiB.
val expected = "${com.droiddeck.launcher.core.LogRedactor.OVERSIZED_LINE}\n"
val prefix = ByteArray(expected.toByteArray(StandardCharsets.UTF_8).size)
var offset = 0
while (offset < prefix.size) {
val count = input.read(prefix, offset, prefix.size - offset)
assertTrue("zip entry ended before its scrubbed prefix", count > 0)
offset += count
}
assertEquals(expected, String(prefix, StandardCharsets.UTF_8))
input.bufferedReader().use { reader ->
val trailing = requireNotNull(reader.readLine())
assertFalse("trailing secret survived", trailing.contains(trailingSecret))
assertEquals("refresh_token=<redacted:token>", trailing)
assertEquals(null, reader.readLine())
}
}
}
} finally {
SessionLogShare.clear(app)
session.deleteRecursively()
}
}
@Test fun everyTextFileInTheZipIsScrubbedAndTheStoresAndToolsLogsComeAlong() {
val logs = LinuxRuntime.logDir(app)
val session = File(logs, "2026-10-08-01-steam").apply { mkdirs() }
@@ -2,10 +2,13 @@ package com.droiddeck.launcher.session
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import java.io.File
import java.io.IOException
import java.io.Writer
class SessionSteamLogsTest {
@get:Rule val tmp = TemporaryFolder()
@@ -59,4 +62,37 @@ class SessionSteamLogsTest {
assertEquals(listOf("web.txt"), names(copied))
assertFalse(File(out, "web.txt").readText().contains("abcdef123456"))
}
@Test fun aCopyFailurePreservesThePreviousSnapshotAndRemovesPartialStaging() {
val logs = tmp.newFolder("logs")
val session = tmp.newFolder("session")
val out = tmp.newFolder("out")
File(logs, "console_log.txt").writeText("new complete line\n")
val snapshot = File(out, "console_log.txt").apply { writeText("previous valid snapshot\n") }
lateinit var staging: File
val copied = SessionArtifacts.copySessionLogs(logs, session, out) { target ->
staging = target
val delegate = target.bufferedWriter()
object : Writer() {
private var failed = false
override fun write(buffer: CharArray, offset: Int, length: Int) {
if (!failed) {
delegate.write(buffer, offset, minOf(length, 4))
delegate.flush()
failed = true
}
throw IOException("injected writer failure")
}
override fun flush() = delegate.flush()
override fun close() = delegate.close()
}
}
assertTrue(copied.isEmpty())
assertEquals("previous valid snapshot\n", snapshot.readText())
assertFalse(staging.exists())
}
}
@@ -34,6 +34,7 @@ class SettingsResetTest {
SessionPrefs.setHdr(app, SessionService.MODE_DESKTOP, true)
SessionPrefs.setResolutionChoice(app, SessionService.MODE_STEAM, "1280x800")
SessionPrefs.setGuestHostname(app, "MyDeck")
assertTrue(SessionPrefs.setGameDebugLogsEnabled(app, true))
SessionPrefs.setHudShowFps(app, false)
SessionPrefs.setHudShowBattery(app, false)
SessionPrefs.setHudShowGraph(app, false)
@@ -54,6 +55,10 @@ class SettingsResetTest {
assertFalse(SessionPrefs.hdr(app, SessionService.MODE_DESKTOP))
assertFalse(SessionPrefs.resolutionChosen(app, SessionService.MODE_STEAM))
assertEquals(SessionPrefs.DEFAULT_GUEST_HOSTNAME, SessionPrefs.guestHostname(app))
assertFalse(SessionPrefs.gameDebugLogsEnabled(app))
val guest = java.io.File(com.droiddeck.launcher.runtime.LinuxRuntime.rootDir(app),
"root/.config/droiddeck/game-environment.json")
assertFalse(org.json.JSONObject(guest.readText()).getBoolean(GameEnvironmentStore.GAME_DEBUG_LOGS))
assertTrue(SessionPrefs.hudShowFps(app))
assertTrue(SessionPrefs.hudShowBattery(app))
assertTrue(SessionPrefs.hudShowGraph(app))
@@ -67,6 +72,22 @@ class SettingsResetTest {
assertFalse(prefs("steam_touch").contains("gyro"))
}
@Test fun aFailedDebugOptOutDoesNotHideTheEnabledPreference() {
assertTrue(SessionPrefs.setGameDebugLogsEnabled(app, true))
val directory = java.io.File(com.droiddeck.launcher.runtime.LinuxRuntime.rootDir(app),
"root/.config/droiddeck")
directory.deleteRecursively()
directory.writeText("blocks configuration publication")
try {
assertFalse(SettingsReset.resetAll(app, gameProfiles = false))
assertTrue(SessionPrefs.gameDebugLogsEnabled(app))
} finally {
directory.delete()
directory.mkdirs()
GameEnvironmentStore.publish(app)
}
}
@Test fun libraryAndRecordsAreKept() {
val folder = "/storage/emulated/0/Games/Foo"
SessionPrefs.setAddedGameName(app, folder, "Foo")