mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 12:56:06 +00:00
Keep failed session artifact collections incomplete
This commit is contained in:
3 files changed
+108
-11
No files matched your search
@@ -152,6 +152,40 @@ 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, 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")
|
||||
|
||||
@@ -6,6 +6,8 @@ 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 +61,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())
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user