fix(debug): Use human-readable UTC timestamp in debug session directory names

Parse creation time from the embedded filename timestamp instead of relying on filesystem attributes, which are non-deterministic and caused flaky test failures in CI.
This commit is contained in:
darken
2026-03-09 11:57:42 +00:00
committed by Matthias Urhahn
parent 7f8daddfe0
commit de89c51457
4 changed files with 89 additions and 75 deletions
@@ -256,13 +256,27 @@ class DebugSessionManager @Inject constructor(
return prefix + file.name.removeSuffix(".zip")
}
private val TIMESTAMP_FORMAT = java.time.format.DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmss'Z'")
.withZone(java.time.ZoneOffset.UTC)
@VisibleForTesting
internal fun parseCreatedAt(file: File): Instant = try {
val attrs = Files.readAttributes(file.toPath(), BasicFileAttributes::class.java)
attrs.creationTime().toInstant()
} catch (e: Exception) {
log(TAG, WARN) { "Failed to read creation time for ${file.name}: ${e.message}" }
Instant.ofEpochMilli(file.lastModified())
internal fun parseCreatedAt(file: File): Instant {
val name = file.name.removeSuffix(".zip")
val parts = name.split("_")
// Format: capod_{version}_{yyyyMMddTHHmmssZ}_{suffix}
if (parts.size >= 3) {
try {
return TIMESTAMP_FORMAT.parse(parts[2], Instant::from)
} catch (_: Exception) {
}
}
return try {
val attrs = Files.readAttributes(file.toPath(), BasicFileAttributes::class.java)
attrs.creationTime().toInstant()
} catch (e: Exception) {
log(TAG, WARN) { "Failed to read creation time for ${file.name}: ${e.message}" }
Instant.ofEpochMilli(file.lastModified())
}
}
private fun computeDiskSize(file: File): Long {
@@ -98,7 +98,8 @@ class RecorderModule @Inject constructor(
}
private fun createSessionDir(): File {
val timestamp = System.currentTimeMillis()
val timestamp = java.time.ZonedDateTime.now(java.time.ZoneOffset.UTC)
.format(java.time.format.DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmss'Z'"))
val installIdPrefix = installId.id.take(8)
val dirName = "capod_${BuildConfigWrap.VERSION_NAME}_${timestamp}_$installIdPrefix"