mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 04:46:08 +00:00
Add opt-in game debug logs and bounded log sharing
This commit is contained in:
1 parent
798386d02a
commit
6521c3c3ad
19 files changed
+825
-74
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"))
|
||||
@@ -148,6 +153,71 @@ 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 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 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
|
||||
@@ -21,10 +22,78 @@ 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 gameDebugLogsWaitForARetainedSessionFolder() {
|
||||
assertNull(SessionPaths.current())
|
||||
assertTrue(SessionPaths.currentSessionLogsRetained(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 ""),
|
||||
|
||||
@@ -131,4 +131,124 @@ 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 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, 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 previousRunning = SessionState.running
|
||||
val previousPhase = SessionState.phase
|
||||
try {
|
||||
folder.deleteRecursively()
|
||||
folder.mkdirs()
|
||||
SessionArtifacts.recordClient(folder, "arm64")
|
||||
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, SessionArtifacts.COMPLETE_MARKER).isFile)
|
||||
} finally {
|
||||
SessionState.running = previousRunning
|
||||
SessionState.phase = previousPhase
|
||||
folder.deleteRecursively()
|
||||
runtimeSteamLog.delete()
|
||||
marker.delete()
|
||||
launches.delete()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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() }
|
||||
|
||||
@@ -32,6 +32,7 @@ class SettingsResetTest {
|
||||
SessionPrefs.setHdr(app, SessionService.MODE_DESKTOP, true)
|
||||
SessionPrefs.setResolutionChoice(app, SessionService.MODE_STEAM, "1280x800")
|
||||
SessionPrefs.setGuestHostname(app, "MyDeck")
|
||||
SessionPrefs.setGameDebugLogsEnabled(app, true)
|
||||
ControllerPrefs.setOpacity(app, 40)
|
||||
AppUiPrefs.setScale(app, 150)
|
||||
FrameGen.set(app, FrameGen.Mode(FrameGen.ENGINE_WINFG, 3))
|
||||
@@ -45,6 +46,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))
|
||||
assertEquals(100, ControllerPrefs.read(app).opacity)
|
||||
assertEquals(AppUiPrefs.DEFAULT_SCALE, AppUiPrefs.scale(app))
|
||||
assertEquals(FrameGen.Mode.OFF.engine, FrameGen.engine(app))
|
||||
|
||||
Reference in new issue
Block a user