mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 05:16:01 +00:00
Add enhanced one-session diagnostic bundles
This commit is contained in:
1 parent
b563b8d1eb
commit
5614bd5d5a
32 files changed
+3100
-141
No files matched your search
@@ -316,6 +316,60 @@ class LogRedactorTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun oversizedAccountMetadataIsRejectedWithoutForgettingKnownNames() {
|
||||
val users = tmp.newFile("known-loginusers.vdf")
|
||||
val oversized = tmp.newFile("oversized-loginusers.vdf")
|
||||
users.writeText("\"AccountName\" \"previous_player\"")
|
||||
java.io.RandomAccessFile(oversized, "rw").use {
|
||||
it.setLength(LogRedactor.MAX_LEARN_INPUT_BYTES.toLong() + 1)
|
||||
}
|
||||
try {
|
||||
assertTrue(LogRedactor.learnAccounts(users))
|
||||
assertFalse(LogRedactor.learnAccounts(oversized))
|
||||
assertEquals("<redacted:account>", LogRedactor.redact("previous_player"))
|
||||
} finally {
|
||||
LogRedactor.learnAccounts()
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun repeatedIncompleteAccountLearningKeepsOnlyABoundedRecentSet() {
|
||||
val users = tmp.newFile("changing-loginusers.vdf")
|
||||
val oversized = tmp.newFile("unreadable-loginusers.vdf")
|
||||
java.io.RandomAccessFile(oversized, "rw").use {
|
||||
it.setLength(LogRedactor.MAX_LEARN_INPUT_BYTES.toLong() + 1)
|
||||
}
|
||||
try {
|
||||
LogRedactor.learnAccounts()
|
||||
repeat(3) { batch ->
|
||||
users.writeText((0 until 1024).joinToString("\n") {
|
||||
"\"AccountName\" \"round${batch}player${it.toString().padStart(4, '0')}\""
|
||||
})
|
||||
assertFalse(LogRedactor.learnAccounts(users, oversized))
|
||||
}
|
||||
assertEquals("<redacted:account>", LogRedactor.redact("round2player0000"))
|
||||
assertEquals("<redacted:account>", LogRedactor.redact("round1player0000"))
|
||||
assertEquals("round0player0000", LogRedactor.redact("round0player0000"))
|
||||
} finally {
|
||||
LogRedactor.learnAccounts()
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun oversizedAddressMetadataIsRejectedWithoutForgettingKnownAddresses() {
|
||||
val link = tmp.newFile("known-network")
|
||||
val oversized = tmp.newFile("oversized-network")
|
||||
link.writeText("addr 203.0.113.40 24\n")
|
||||
java.io.RandomAccessFile(oversized, "rw").use {
|
||||
it.setLength(LogRedactor.MAX_LEARN_INPUT_BYTES.toLong() + 1)
|
||||
}
|
||||
try {
|
||||
assertTrue(LogRedactor.learnOwnAddresses(link))
|
||||
assertFalse(LogRedactor.learnOwnAddresses(oversized))
|
||||
assertEquals("<redacted:ip>", LogRedactor.redact("203.0.113.40"))
|
||||
} finally {
|
||||
LogRedactor.learnOwnAddresses(tmp.root.resolve("missing-network"))
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun manyLearnedAddressesKeepOtherAddresses() {
|
||||
val link = tmp.newFile("droiddeck-net")
|
||||
link.writeText((1..40).joinToString("\n") { "addr 203.0.113.$it 24" })
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import android.content.Context
|
||||
import com.droiddeck.launcher.runtime.LinuxRuntime
|
||||
import org.json.JSONObject
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
import java.io.File
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [28], manifest = Config.NONE)
|
||||
class EnhancedDiagnosticsTest {
|
||||
private lateinit var context: Context
|
||||
private lateinit var guest: File
|
||||
|
||||
@Before fun setUp() {
|
||||
context = RuntimeEnvironment.getApplication()
|
||||
SessionPaths.take()?.let { SessionPaths.release(context, it) }
|
||||
context.getSharedPreferences("session", Context.MODE_PRIVATE).edit()
|
||||
.remove("logs")
|
||||
.remove("gameDebugLogsEnabled")
|
||||
.remove("enhancedDiagnosticsNext")
|
||||
.remove("enhancedDiagnosticsActiveSessions")
|
||||
.commit()
|
||||
guest = File(LinuxRuntime.rootDir(context), "root/.config/droiddeck/game-environment.json")
|
||||
}
|
||||
|
||||
@After fun tearDown() {
|
||||
SessionPaths.take()?.let { folder ->
|
||||
SessionPaths.release(context, folder)
|
||||
folder.deleteRecursively()
|
||||
}
|
||||
context.getSharedPreferences("session", Context.MODE_PRIVATE).edit()
|
||||
.remove("logs")
|
||||
.remove("gameDebugLogsEnabled")
|
||||
.remove("enhancedDiagnosticsNext")
|
||||
.remove("enhancedDiagnosticsActiveSessions")
|
||||
.commit()
|
||||
GameEnvironmentStore.publish(context)
|
||||
}
|
||||
|
||||
@Test fun armedSessionIsRetainedAndConsumesTheOneShotPreference() {
|
||||
context.getSharedPreferences("session", Context.MODE_PRIVATE).edit().putBoolean("logs", false).commit()
|
||||
assertTrue(EnhancedDiagnostics.setArmed(context, true))
|
||||
|
||||
val folder = SessionPaths.beginOrCurrent(context, "enhanced-test")
|
||||
|
||||
assertEquals(SessionFiles.logDirectory(context), folder.parentFile)
|
||||
assertFalse(EnhancedDiagnostics.isArmed(context))
|
||||
assertTrue(EnhancedDiagnostics.isActive(context, folder))
|
||||
val manifest = JSONObject(File(folder, EnhancedDiagnostics.MANIFEST_FILE).readText())
|
||||
assertEquals(1, manifest.getInt("schema"))
|
||||
assertEquals("enhanced", manifest.getString("profile"))
|
||||
assertEquals(folder.name, manifest.getString("sessionId"))
|
||||
assertTrue(manifest.getBoolean("exportBundlesBounded"))
|
||||
assertFalse(manifest.getBoolean("rawCaptureByteBounded"))
|
||||
}
|
||||
|
||||
@Test fun activeProfileForcesGameDiagnosticsWithoutChangingUserPreferences() {
|
||||
context.getSharedPreferences("session", Context.MODE_PRIVATE).edit()
|
||||
.putBoolean("logs", false)
|
||||
.putBoolean("gameDebugLogsEnabled", false)
|
||||
.commit()
|
||||
assertTrue(EnhancedDiagnostics.setArmed(context, true))
|
||||
SessionPaths.beginOrCurrent(context, "enhanced-game-logs")
|
||||
|
||||
GameEnvironmentStore.publish(context)
|
||||
|
||||
assertTrue(JSONObject(guest.readText()).getBoolean(GameEnvironmentStore.GAME_DEBUG_LOGS))
|
||||
assertFalse(SessionPrefs.logsEnabled(context))
|
||||
assertFalse(SessionPrefs.gameDebugLogsEnabled(context))
|
||||
}
|
||||
|
||||
@Test fun cancellingTheOneShotLeavesOrdinaryLogRetentionUnchanged() {
|
||||
context.getSharedPreferences("session", Context.MODE_PRIVATE).edit().putBoolean("logs", false).commit()
|
||||
assertTrue(EnhancedDiagnostics.setArmed(context, true))
|
||||
assertTrue(EnhancedDiagnostics.setArmed(context, false))
|
||||
|
||||
val folder = SessionPaths.beginOrCurrent(context, "ordinary-test")
|
||||
|
||||
assertEquals(File(context.cacheDir, "session-logs"), folder.parentFile)
|
||||
assertFalse(EnhancedDiagnostics.isActive(context, folder))
|
||||
}
|
||||
|
||||
@Test fun guestCannotForgeEnhancedDiagnosticsByWritingAMarker() {
|
||||
val folder = SessionPaths.beginOrCurrent(context, "forged-marker")
|
||||
File(folder, EnhancedDiagnostics.MANIFEST_FILE).writeText(
|
||||
"""{"schema":1,"profile":"enhanced"}""",
|
||||
)
|
||||
|
||||
assertFalse(EnhancedDiagnostics.isActive(context, folder))
|
||||
assertNull(EnhancedDiagnostics.manifest(context, folder))
|
||||
}
|
||||
|
||||
@Test fun trustedStateSurvivesGuestMarkerDeletionAndSessionRecovery() {
|
||||
assertTrue(EnhancedDiagnostics.setArmed(context, true))
|
||||
val folder = SessionPaths.beginOrCurrent(context, "deleted-marker")
|
||||
assertTrue(File(folder, EnhancedDiagnostics.MANIFEST_FILE).delete())
|
||||
|
||||
assertTrue(EnhancedDiagnostics.isActive(context, File(folder.path)))
|
||||
assertEquals(folder.name, EnhancedDiagnostics.manifest(context, folder)?.getString("sessionId"))
|
||||
assertEquals(folder, SessionPaths.take())
|
||||
assertTrue(EnhancedDiagnostics.isActive(context, folder))
|
||||
}
|
||||
|
||||
@Test fun informationalMarkerFailureDoesNotRearmTheNextSession() {
|
||||
val parent = SessionFiles.logDirectory(context).apply { mkdirs() }
|
||||
val folder = File(parent, "2026-11-04-99-marker-failure").apply { mkdirs() }
|
||||
File(folder, EnhancedDiagnostics.MANIFEST_FILE).mkdirs()
|
||||
assertTrue(EnhancedDiagnostics.setArmed(context, true))
|
||||
|
||||
assertTrue(EnhancedDiagnostics.consumeInto(context, folder))
|
||||
|
||||
assertTrue(EnhancedDiagnostics.isActive(context, folder))
|
||||
assertFalse(EnhancedDiagnostics.isArmed(context))
|
||||
folder.deleteRecursively()
|
||||
}
|
||||
|
||||
@Test fun aReusedSessionPathDoesNotInheritTrustedState() {
|
||||
assertTrue(EnhancedDiagnostics.setArmed(context, true))
|
||||
val original = SessionPaths.beginOrCurrent(context, "reused-path")
|
||||
assertTrue(EnhancedDiagnostics.isActive(context, original))
|
||||
assertEquals(original, SessionPaths.take())
|
||||
original.deleteRecursively()
|
||||
|
||||
val replacement = SessionPaths.beginOrCurrent(context, "reused-path")
|
||||
|
||||
assertEquals(original.path, replacement.path)
|
||||
assertFalse(EnhancedDiagnostics.isActive(context, replacement))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,331 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import android.content.Intent
|
||||
import org.json.JSONObject
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Assume.assumeFalse
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
import java.io.RandomAccessFile
|
||||
import java.nio.file.Files
|
||||
import java.util.zip.ZipFile
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [33])
|
||||
class EnhancedSessionLogShareTest {
|
||||
@get:Rule val tmp = TemporaryFolder()
|
||||
private val app get() = RuntimeEnvironment.getApplication()
|
||||
|
||||
@Test fun diagnosticsAreSplitIntoManifestedArchivesWithOneSessionIdentity() {
|
||||
val session = tmp.newFolder("2026-11-04-01-steam")
|
||||
session.resolve("session.log").writeText("startup ok\n")
|
||||
session.resolve("wayland.log").writeText("frame import ok\n")
|
||||
session.resolve("steam-42.log").writeText("dxvk: present ok\n")
|
||||
|
||||
val zips = EnhancedSessionLogShare.create(app, session)
|
||||
|
||||
assertEquals(
|
||||
setOf("session", "graphics", "games"),
|
||||
zips.map { it.nameWithoutExtension.substringAfterLast('-') }.toSet(),
|
||||
)
|
||||
val expected = mapOf(
|
||||
"session" to "${session.name}/session.log",
|
||||
"graphics" to "${session.name}/wayland.log",
|
||||
"games" to "${session.name}/steam-42.log",
|
||||
)
|
||||
zips.forEach { zip ->
|
||||
val category = zip.nameWithoutExtension.substringAfterLast('-')
|
||||
ZipFile(zip).use { archive ->
|
||||
assertTrue(archive.getEntry(expected.getValue(category)) != null)
|
||||
val manifest = JSONObject(archive.getInputStream(archive.getEntry("diagnostics-manifest.json"))
|
||||
.bufferedReader().readText())
|
||||
assertEquals(1, manifest.getInt("schema"))
|
||||
assertEquals(session.name, manifest.getString("sessionId"))
|
||||
assertEquals(category, manifest.getString("category"))
|
||||
assertEquals("captured", manifest.getJSONArray("entries").getJSONObject(0).getString("status"))
|
||||
}
|
||||
}
|
||||
SessionLogShare.clear(app)
|
||||
}
|
||||
|
||||
@Test fun oversizedFilesKeepBoundedBeginningAndTailAndDeclareTruncation() {
|
||||
val session = tmp.newFolder("2026-11-04-02-game")
|
||||
session.resolve("steam-7.log").writeText("begin\n" + "middle\n".repeat(100) + "tail\n")
|
||||
val limits = EnhancedShareLimits(maxFilesPerArchive = 8, maxBytesPerFile = 96, maxBytesTotal = 512)
|
||||
|
||||
val games = EnhancedSessionLogShare.create(app, session, limits = limits)
|
||||
.single { it.name.endsWith("-games.zip") }
|
||||
|
||||
ZipFile(games).use { archive ->
|
||||
val text = archive.getInputStream(archive.getEntry("${session.name}/steam-7.log")).bufferedReader().readText()
|
||||
assertTrue(text.startsWith("begin"))
|
||||
assertTrue(text.contains("diagnostic file truncated"))
|
||||
assertTrue(text.endsWith("tail\n"))
|
||||
val manifest = JSONObject(archive.getInputStream(archive.getEntry("diagnostics-manifest.json"))
|
||||
.bufferedReader().readText())
|
||||
assertEquals("truncated", manifest.getJSONArray("entries").getJSONObject(0).getString("status"))
|
||||
assertTrue(manifest.getJSONArray("entries").getJSONObject(0).getLong("capturedBytes") <= 96)
|
||||
}
|
||||
SessionLogShare.clear(app)
|
||||
}
|
||||
|
||||
@Test fun symbolicLinksAreNotReadAndTheirOmissionIsRecorded() {
|
||||
assumeFalse(System.getProperty("os.name").startsWith("Windows"))
|
||||
val session = tmp.newFolder("2026-11-04-03-steam")
|
||||
session.resolve("session.log").writeText("safe\n")
|
||||
val outside = tmp.newFile("private.log").apply { writeText("do-not-share\n") }
|
||||
val link = session.toPath().resolve("wayland.log")
|
||||
runCatching { Files.createSymbolicLink(link, outside.toPath()) }.getOrElse { return }
|
||||
|
||||
val graphics = EnhancedSessionLogShare.create(app, session).single { it.name.endsWith("-graphics.zip") }
|
||||
|
||||
ZipFile(graphics).use { archive ->
|
||||
assertFalse(archive.entries().toList().any { it.name.endsWith("wayland.log") })
|
||||
val manifest = JSONObject(archive.getInputStream(archive.getEntry("diagnostics-manifest.json"))
|
||||
.bufferedReader().readText())
|
||||
val entries = manifest.getJSONArray("entries")
|
||||
assertTrue((0 until entries.length()).map { entries.getJSONObject(it) }
|
||||
.any { it.optString("reason") == "unsafe-or-unavailable-source" })
|
||||
}
|
||||
SessionLogShare.clear(app)
|
||||
}
|
||||
|
||||
@Test fun enhancedShareUsesOneMultipleAttachmentIntent() {
|
||||
val session = tmp.newFolder("2026-11-04-04-steam")
|
||||
session.resolve("session.log").writeText("safe\n")
|
||||
val zips = EnhancedSessionLogShare.create(app, session)
|
||||
|
||||
val chooser = SessionLogShare.shareEnhancedIntent(app, zips)
|
||||
val send = chooser.getParcelableExtra<Intent>(Intent.EXTRA_INTENT)!!
|
||||
|
||||
assertEquals(Intent.ACTION_SEND_MULTIPLE, send.action)
|
||||
assertEquals("application/zip", send.type)
|
||||
assertEquals(3, send.getParcelableArrayListExtra<android.net.Uri>(Intent.EXTRA_STREAM)!!.size)
|
||||
assertEquals(3, send.clipData!!.itemCount)
|
||||
SessionLogShare.clear(app)
|
||||
}
|
||||
|
||||
@Test fun graphicsArchiveIncludesOnlyBoundedFrameTraceSummariesFromTheSessionLog() {
|
||||
val session = tmp.newFolder("2026-11-04-05-steam")
|
||||
session.resolve("session.log").writeText(
|
||||
"normal startup line\n" +
|
||||
"DROIDDECK_FRAME_TRACE xdamage=4 commits=2\n" +
|
||||
"unrelated account=test-user\n" +
|
||||
"DROIDDECK_FRAME_TRACE xdamage=9 commits=8\n" +
|
||||
"DROIDDECK_PROCESS_TRACE pid=42 gpuLibs=libvulkan.so\n",
|
||||
)
|
||||
|
||||
val graphics = EnhancedSessionLogShare.create(app, session).single { it.name.endsWith("-graphics.zip") }
|
||||
|
||||
ZipFile(graphics).use { archive ->
|
||||
val trace = archive.getInputStream(archive.getEntry("${session.name}/graphics/frame-trace.log"))
|
||||
.bufferedReader().readText()
|
||||
assertEquals(
|
||||
"DROIDDECK_FRAME_TRACE xdamage=4 commits=2\n" +
|
||||
"DROIDDECK_FRAME_TRACE xdamage=9 commits=8\n",
|
||||
trace,
|
||||
)
|
||||
assertFalse(trace.contains("normal startup"))
|
||||
assertFalse(trace.contains("test-user"))
|
||||
val process = archive.getInputStream(archive.getEntry("${session.name}/graphics/process-trace.log"))
|
||||
.bufferedReader().readText()
|
||||
assertEquals("DROIDDECK_PROCESS_TRACE pid=42 gpuLibs=libvulkan.so\n", process)
|
||||
}
|
||||
SessionLogShare.clear(app)
|
||||
}
|
||||
|
||||
@Test fun truncationNeverSharesASecretWhoseLabelWasCutOffAtTheBoundary() {
|
||||
val session = tmp.newFolder("2026-11-04-06-game")
|
||||
val secret = "abcdef1234567890"
|
||||
session.resolve("steam-8.log").writeText(
|
||||
"padding-refresh_token=$secret" + "x".repeat(512) + "\nvisible tail\n",
|
||||
)
|
||||
val limits = EnhancedShareLimits(maxFilesPerArchive = 8, maxBytesPerFile = 128, maxBytesTotal = 512)
|
||||
|
||||
val games = EnhancedSessionLogShare.create(app, session, limits = limits)
|
||||
.single { it.name.endsWith("-games.zip") }
|
||||
|
||||
val shared = ZipFile(games).use { archive ->
|
||||
archive.getInputStream(archive.getEntry("${session.name}/steam-8.log")).bufferedReader().readText()
|
||||
}
|
||||
assertFalse(shared.contains(secret))
|
||||
assertTrue(shared.contains("diagnostic file truncated"))
|
||||
assertTrue(shared.endsWith("visible tail\n"))
|
||||
SessionLogShare.clear(app)
|
||||
}
|
||||
|
||||
@Test fun discoveryStopsAtItsBoundAndDeclaresTheTruncatedInventory() {
|
||||
val session = tmp.newFolder("2026-11-04-07-steam")
|
||||
repeat(20) { session.resolve("log-$it.txt").writeText("line $it\n") }
|
||||
val limits = EnhancedShareLimits(
|
||||
maxFilesPerArchive = 8,
|
||||
maxDiscoveredFiles = 2,
|
||||
maxBytesPerFile = 1024,
|
||||
maxBytesTotal = 4096,
|
||||
)
|
||||
|
||||
val zips = EnhancedSessionLogShare.create(app, session, limits = limits)
|
||||
|
||||
val captured = zips.sumOf { zip ->
|
||||
ZipFile(zip).use { archive -> archive.entries().toList().count { it.name != "diagnostics-manifest.json" } }
|
||||
}
|
||||
assertTrue(captured <= 2)
|
||||
zips.forEach { zip ->
|
||||
ZipFile(zip).use { archive ->
|
||||
val manifest = JSONObject(archive.getInputStream(archive.getEntry("diagnostics-manifest.json"))
|
||||
.bufferedReader().readText())
|
||||
val entries = manifest.getJSONArray("entries")
|
||||
assertTrue((0 until entries.length()).map { entries.getJSONObject(it) }
|
||||
.any { it.optString("origin") == "discovery" && it.optString("status") == "truncated" })
|
||||
}
|
||||
}
|
||||
SessionLogShare.clear(app)
|
||||
}
|
||||
|
||||
@Test fun aGuestForgedActivationMarkerIsNeverExportedAsTrustedMetadata() {
|
||||
val session = tmp.newFolder("2026-11-04-08-steam")
|
||||
session.resolve("session.log").writeText("safe\n")
|
||||
session.resolve(EnhancedDiagnostics.MANIFEST_FILE).writeText("{\"profile\":\"forged\"}\n")
|
||||
|
||||
val zips = EnhancedSessionLogShare.create(app, session)
|
||||
|
||||
zips.forEach { zip ->
|
||||
ZipFile(zip).use { archive ->
|
||||
assertFalse(archive.entries().toList().any { it.name.endsWith(EnhancedDiagnostics.MANIFEST_FILE) })
|
||||
}
|
||||
}
|
||||
SessionLogShare.clear(app)
|
||||
}
|
||||
|
||||
@Test fun hardLinksAreRejectedInsteadOfFollowingASecondNameToItsContent() {
|
||||
assumeFalse(System.getProperty("os.name").startsWith("Windows"))
|
||||
val session = tmp.newFolder("2026-11-04-09-steam")
|
||||
session.resolve("session.log").writeText("safe\n")
|
||||
val outside = tmp.newFile("outside-hardlink.log").apply { writeText("private hard-link content\n") }
|
||||
runCatching { Files.createLink(session.toPath().resolve("wayland.log"), outside.toPath()) }.getOrElse { return }
|
||||
|
||||
val graphics = EnhancedSessionLogShare.create(app, session).single { it.name.endsWith("-graphics.zip") }
|
||||
|
||||
ZipFile(graphics).use { archive ->
|
||||
assertFalse(archive.entries().toList().any { it.name.endsWith("wayland.log") })
|
||||
val all = archive.entries().toList().joinToString("\n") { entry ->
|
||||
archive.getInputStream(entry).bufferedReader().readText()
|
||||
}
|
||||
assertFalse(all.contains("private hard-link content"))
|
||||
}
|
||||
SessionLogShare.clear(app)
|
||||
}
|
||||
|
||||
@Test fun guestControlledAndControlCharacterNamesNeverEnterTheArchiveOrManifest() {
|
||||
val session = tmp.newFolder("2026-11-04-10-steam")
|
||||
session.resolve("private-window-title.log").writeText("safe diagnostic\n")
|
||||
session.resolve("wayland\nsecret.log").writeText("must not be named\n")
|
||||
|
||||
val sessionZip = EnhancedSessionLogShare.create(app, session).single { it.name.endsWith("-session.zip") }
|
||||
|
||||
ZipFile(sessionZip).use { archive ->
|
||||
val names = archive.entries().toList().map { it.name }
|
||||
assertTrue(names.any { it.contains("/entry-") && it.endsWith(".log") })
|
||||
assertFalse(names.any { it.contains("private-window-title") || it.contains('\n') })
|
||||
val manifest = archive.getInputStream(archive.getEntry("diagnostics-manifest.json")).bufferedReader().readText()
|
||||
assertFalse(manifest.contains("private-window-title"))
|
||||
assertFalse(manifest.contains("wayland\\nsecret"))
|
||||
}
|
||||
SessionLogShare.clear(app)
|
||||
}
|
||||
|
||||
@Test fun oneCategoryCannotConsumeTheOtherCategoriesByteReservations() {
|
||||
val session = tmp.newFolder("2026-11-04-11-steam")
|
||||
session.resolve("session.log").writeText("session\n".repeat(100))
|
||||
session.resolve("wayland.log").writeText("graphics\n".repeat(100))
|
||||
session.resolve("steam-11.log").writeText("game\n".repeat(100))
|
||||
val limits = EnhancedShareLimits(maxBytesPerFile = 1024, maxBytesTotal = 300)
|
||||
|
||||
val zips = EnhancedSessionLogShare.create(app, session, limits = limits)
|
||||
|
||||
zips.forEach { zip ->
|
||||
ZipFile(zip).use { archive ->
|
||||
assertTrue(archive.entries().toList().any { it.name != "diagnostics-manifest.json" })
|
||||
}
|
||||
}
|
||||
SessionLogShare.clear(app)
|
||||
}
|
||||
|
||||
@Test fun filteredTraceScanFindsLateSummariesAndMarksThePartialSource() {
|
||||
val session = tmp.newFolder("2026-11-04-12-steam")
|
||||
val source = session.resolve("session.log")
|
||||
RandomAccessFile(source, "rw").use { file ->
|
||||
file.setLength(17L * 1024 * 1024)
|
||||
file.seek(file.length() - 80)
|
||||
file.write("\nDROIDDECK_PROCESS_TRACE pid=99 gpuLibs=libGLES.so\n".toByteArray())
|
||||
}
|
||||
|
||||
val graphics = EnhancedSessionLogShare.create(app, session).single { it.name.endsWith("-graphics.zip") }
|
||||
|
||||
ZipFile(graphics).use { archive ->
|
||||
val trace = archive.getInputStream(archive.getEntry("${session.name}/graphics/process-trace.log"))
|
||||
.bufferedReader().readText()
|
||||
assertTrue(trace.contains("pid=99"))
|
||||
val manifest = JSONObject(archive.getInputStream(archive.getEntry("diagnostics-manifest.json"))
|
||||
.bufferedReader().readText())
|
||||
val entries = manifest.getJSONArray("entries")
|
||||
assertTrue((0 until entries.length()).map { entries.getJSONObject(it) }.any {
|
||||
it.optString("origin") == "guest-process-trace" && it.optString("status") == "truncated"
|
||||
})
|
||||
}
|
||||
SessionLogShare.clear(app)
|
||||
}
|
||||
|
||||
@Test fun diagnosticLookingGuestNamesCannotExposeEmbeddedSecrets() {
|
||||
val session = tmp.newFolder("2026-11-04-13-game")
|
||||
val tokenName = "dxvk-refresh_token_abcdef123456.log"
|
||||
val accountName = "battle.net-secretvalue.log"
|
||||
session.resolve(tokenName).writeText("dxvk diagnostic\n")
|
||||
session.resolve(accountName).writeText("battle net diagnostic\n")
|
||||
|
||||
val games = EnhancedSessionLogShare.create(app, session).single { it.name.endsWith("-games.zip") }
|
||||
|
||||
ZipFile(games).use { archive ->
|
||||
val names = archive.entries().toList().map { it.name }
|
||||
assertFalse(names.any { it.contains("refresh_token") || it.contains("secretvalue") })
|
||||
assertTrue(names.count { it.substringAfterLast('/').startsWith("entry-") } >= 2)
|
||||
val manifest = archive.getInputStream(archive.getEntry("diagnostics-manifest.json")).bufferedReader().readText()
|
||||
assertFalse(manifest.contains("refresh_token"))
|
||||
assertFalse(manifest.contains("secretvalue"))
|
||||
}
|
||||
SessionLogShare.clear(app)
|
||||
}
|
||||
|
||||
@Test fun gamesArchiveIncludesOnlyGameLifecycleSummariesFromTheSessionLog() {
|
||||
val session = tmp.newFolder("2026-11-04-14-game")
|
||||
session.resolve("session.log").writeText(
|
||||
"DROIDDECK_DIAGNOSTICS event=game_start appId=42 pid=123\n" +
|
||||
"unrelated launch detail\n" +
|
||||
"DROIDDECK_DIAGNOSTICS event=game_exit appId=42 status=139\n",
|
||||
)
|
||||
|
||||
val games = EnhancedSessionLogShare.create(app, session).single { it.name.endsWith("-games.zip") }
|
||||
|
||||
ZipFile(games).use { archive ->
|
||||
val lifecycle = archive.getInputStream(archive.getEntry("${session.name}/games/game-lifecycle.log"))
|
||||
.bufferedReader().readText()
|
||||
assertEquals(
|
||||
"DROIDDECK_DIAGNOSTICS event=game_start appId=42 pid=123\n" +
|
||||
"DROIDDECK_DIAGNOSTICS event=game_exit appId=42 status=139\n",
|
||||
lifecycle,
|
||||
)
|
||||
assertFalse(lifecycle.contains("unrelated launch detail"))
|
||||
val manifest = JSONObject(archive.getInputStream(archive.getEntry("diagnostics-manifest.json"))
|
||||
.bufferedReader().readText())
|
||||
assertTrue(manifest.toString().contains("guest-game-lifecycle"))
|
||||
}
|
||||
SessionLogShare.clear(app)
|
||||
}
|
||||
}
|
||||
@@ -86,8 +86,9 @@ class SessionLogShareTest {
|
||||
File(folder, "events.jsonl").writeText("$secret\n")
|
||||
|
||||
val out = zip(folder)
|
||||
for (name in listOf("app.log", "session.log", "steam/deep/nested.txt", ".hidden.txt", "events.jsonl"))
|
||||
for (name in listOf("app.log", "session.log", "events.jsonl"))
|
||||
assertFalse(name, out.getValue(name).contains(leaked))
|
||||
assertTrue(out.values.none { it.contains(leaked) })
|
||||
}
|
||||
|
||||
@Test fun aRecordUnderOtherRedactorRulesVouchesForNothing() {
|
||||
@@ -187,7 +188,7 @@ class SessionLogShareTest {
|
||||
assertFalse(File(folder, ".scrubbed-r${LogRedactor.RULES_VERSION}").exists())
|
||||
}
|
||||
|
||||
@Test fun steamLogsPastTheSizeLimitStayOut() {
|
||||
@Test fun steamLogsPastTheSizeLimitAreBoundedAndDeclared() {
|
||||
val folder = tmp.newFolder("2026-10-06-07-steam")
|
||||
File(folder, "session.log").writeText("ok\n")
|
||||
File(folder, "steam").mkdirs()
|
||||
@@ -196,9 +197,11 @@ class SessionLogShareTest {
|
||||
val line = ByteArray(1024) { 'x'.code.toByte() }.also { it[it.size - 1] = '\n'.code.toByte() }
|
||||
repeat(9 * 1024) { out.write(line) }
|
||||
}
|
||||
val names = zip(folder).keys
|
||||
assertTrue("steam/console_log.txt" in names)
|
||||
assertFalse("steam/cef_log.previous.txt" in names)
|
||||
val output = zip(folder)
|
||||
assertTrue("steam/console_log.txt" in output)
|
||||
assertTrue("steam/cef_log.previous.txt" in output)
|
||||
assertTrue(output.getValue("steam/cef_log.previous.txt").contains("diagnostic file truncated"))
|
||||
assertTrue(output.getValue("diagnostics-manifest.json").contains("\"status\": \"truncated\""))
|
||||
}
|
||||
|
||||
@Test fun streamingComparisonPreservesUnchangedFileAndReplacesChangedFile() {
|
||||
|
||||
@@ -2,7 +2,6 @@ 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
|
||||
@@ -38,23 +37,11 @@ class SessionLogShareZipTest {
|
||||
val zip = SessionLogShare.zipFolder(app, session)!!
|
||||
ZipFile(zip).use { archive ->
|
||||
val entry = archive.getEntry("${session.name}/steam-42.log")!!
|
||||
archive.getInputStream(entry).use { input ->
|
||||
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())
|
||||
}
|
||||
}
|
||||
val shared = archive.getInputStream(entry).bufferedReader().readText()
|
||||
assertTrue(shared.contains("diagnostic file truncated"))
|
||||
assertFalse("early secret survived", shared.contains(earlySecret))
|
||||
assertFalse("trailing secret survived", shared.contains(trailingSecret))
|
||||
assertTrue(shared.contains("refresh_token=<redacted:token>"))
|
||||
}
|
||||
} finally {
|
||||
SessionLogShare.clear(app)
|
||||
|
||||
@@ -35,6 +35,7 @@ class SettingsResetTest {
|
||||
SessionPrefs.setResolutionChoice(app, SessionService.MODE_STEAM, "1280x800")
|
||||
SessionPrefs.setGuestHostname(app, "MyDeck")
|
||||
assertTrue(SessionPrefs.setGameDebugLogsEnabled(app, true))
|
||||
assertTrue(EnhancedDiagnostics.setArmed(app, true))
|
||||
SessionPrefs.setHudShowFps(app, false)
|
||||
SessionPrefs.setHudShowBattery(app, false)
|
||||
SessionPrefs.setHudShowGraph(app, false)
|
||||
@@ -58,6 +59,7 @@ class SettingsResetTest {
|
||||
assertFalse(SessionPrefs.resolutionChosen(app, SessionService.MODE_STEAM))
|
||||
assertEquals(SessionPrefs.DEFAULT_GUEST_HOSTNAME, SessionPrefs.guestHostname(app))
|
||||
assertFalse(SessionPrefs.gameDebugLogsEnabled(app))
|
||||
assertFalse(EnhancedDiagnostics.isArmed(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))
|
||||
|
||||
Reference in new issue
Block a user