chore: move codex-exec unit tests into sibling files (#16581)

## Why

`codex-rs/exec/src/lib.rs` already keeps unit tests in a sibling
`lib_tests.rs` module so the implementation stays top-heavy and easier
to read. This applies that same layout to the rest of
`codex-rs/exec/src` so each production file keeps its entry points and
helpers ahead of test code.

## What

- Move inline unit tests out of `cli.rs`, `main.rs`,
`event_processor_with_human_output.rs`, and
`event_processor_with_jsonl_output.rs` into sibling `*_tests.rs` files.
- Keep test modules wired through `#[cfg(test)]` plus `#[path = "..."]
mod tests;`, matching the `lib.rs` pattern.
- Preserve the existing test coverage and assertions while making this a
source-layout-only refactor.

## Verification

- `cargo test -p codex-exec`
This commit is contained in:
Michael Bolin
2026-04-02 10:01:40 -07:00
committed by GitHub
parent a098834148
commit 95b0b5a204
10 changed files with 904 additions and 903 deletions

View File

@@ -621,59 +621,5 @@ impl EventProcessor for EventProcessorWithJsonOutput {
}
#[cfg(test)]
mod tests {
use super::*;
use pretty_assertions::assert_eq;
use tempfile::tempdir;
#[test]
fn failed_turn_does_not_overwrite_output_last_message_file() {
let tempdir = tempdir().expect("create tempdir");
let output_path = tempdir.path().join("last-message.txt");
std::fs::write(&output_path, "keep existing contents").expect("seed output file");
let mut processor = EventProcessorWithJsonOutput::new(Some(output_path.clone()));
let collected = processor.collect_thread_events(ServerNotification::ItemCompleted(
codex_app_server_protocol::ItemCompletedNotification {
item: ThreadItem::AgentMessage {
id: "msg-1".to_string(),
text: "partial answer".to_string(),
phase: None,
memory_citation: None,
},
thread_id: "thread-1".to_string(),
turn_id: "turn-1".to_string(),
},
));
assert_eq!(collected.status, CodexStatus::Running);
assert_eq!(processor.final_message(), Some("partial answer"));
let status = processor.process_server_notification(ServerNotification::TurnCompleted(
codex_app_server_protocol::TurnCompletedNotification {
thread_id: "thread-1".to_string(),
turn: codex_app_server_protocol::Turn {
id: "turn-1".to_string(),
items: Vec::new(),
status: TurnStatus::Failed,
error: Some(codex_app_server_protocol::TurnError {
message: "turn failed".to_string(),
additional_details: None,
codex_error_info: None,
}),
},
},
));
assert_eq!(status, CodexStatus::InitiateShutdown);
assert_eq!(processor.final_message(), None);
EventProcessor::print_final_output(&mut processor);
assert_eq!(
std::fs::read_to_string(&output_path).expect("read output file"),
"keep existing contents"
);
}
}
#[path = "event_processor_with_jsonl_output_tests.rs"]
mod tests;