Files
codex/codex-rs/app-server-daemon/src/diagnostics_tests.rs
T
Eric Traut 08b07eef12 Preserve daemon diagnostics and include updater logs in reports (#49843)
## Why

Detached launches truncate stderr logs, losing details from previous failures. Updater handoffs can also leave existing writers with stale offsets after truncation.

## What changed

- Record daemon lifecycle and update stages with timings, outcomes, and typed OS errors, omitting error messages and context.
- Preserve the last 256 KiB of nonempty stderr logs before truncation and use append handles to prevent gaps during handoff. Preservation failures do not block launch.
- Attach current and previous updater log tails when log inclusion is enabled for a report, with a 512 KiB total limit and legacy filename fallback. Skip missing, empty, and nonregular files.

## Testing

Add regression coverage for diagnostic error redaction, bounded log preservation, append behavior during handoff, attachment selection, and updater logs in captured report uploads.

GitOrigin-RevId: 918317022ab9dcfd1b13d676872706c77e9ffbb2
2026-10-01 03:24:18 +00:00

56 lines
1.5 KiB
Rust

use super::Failure;
use pretty_assertions::assert_eq;
#[test]
fn failure_omits_error_messages_and_context() {
let error = anyhow::Error::new(std::io::Error::new(
std::io::ErrorKind::PermissionDenied,
"secret child output",
))
.context("secret protocol data");
assert_eq!(
Failure::from(&error),
Failure {
kind: "PermissionDenied".to_string(),
os_code: None
},
);
let error = anyhow::anyhow!("secret child output");
assert_eq!(
Failure::from(&error),
Failure {
kind: "other".to_string(),
os_code: None
},
);
}
#[test]
fn result_record_preserves_json_shape_and_redacts_error_text() {
let error = anyhow::Error::new(std::io::Error::new(
std::io::ErrorKind::PermissionDenied,
"secret child output",
));
let record = super::Record {
timestamp_ms: 123,
process_pid: 456,
payload: super::Payload::<()>::Result {
stage: "process_spawn",
outcome: super::Outcome::Failed,
elapsed_ms: 789,
failure: Some(Failure::from(&error)),
},
};
assert_eq!(
serde_json::to_value(record).unwrap(),
serde_json::json!({
"timestampMs": 123,
"processPid": 456,
"stage": "process_spawn",
"outcome": "failed",
"elapsedMs": 789,
"failure": { "kind": "PermissionDenied", "os_code": null },
}),
);
}