Allow --output-last-message to print to stdout

This commit is contained in:
pakrym-oai
2025-10-01 18:02:18 -07:00
parent c07fb71186
commit f8f66adeac
9 changed files with 198 additions and 77 deletions

View File

@@ -1,5 +1,6 @@
// Aggregates all former standalone integration tests as modules.
mod apply_patch;
mod output_last_message;
mod output_schema;
mod resume;
mod sandbox;

View File

@@ -0,0 +1,106 @@
#![cfg(not(target_os = "windows"))]
#![allow(clippy::expect_used, clippy::unwrap_used)]
use core_test_support::responses;
use core_test_support::test_codex_exec::test_codex_exec;
use wiremock::matchers::any;
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn exec_includes_output_last_message_in_request() -> anyhow::Result<()> {
let test = test_codex_exec();
let last_message_path = test.cwd_path().join("last_message.txt");
let server = responses::start_mock_server().await;
let body = responses::sse(vec![
serde_json::json!({
"type": "response.created",
"response": {"id": "resp1"}
}),
responses::ev_assistant_message("m1", "fixture hello"),
responses::ev_completed("resp1"),
]);
responses::mount_sse_once_match(&server, any(), body).await;
test.cmd_with_server(&server)
.arg("--skip-git-repo-check")
// keep using -C in the test to exercise the flag as well
.arg("-C")
.arg(test.cwd_path())
.arg("--output-last-message")
.arg(&last_message_path)
.arg("tell me a joke")
.assert()
.success();
assert_eq!(
std::fs::read_to_string(&last_message_path)?,
"fixture hello"
);
Ok(())
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn exec_includes_output_last_message_in_request_json() -> anyhow::Result<()> {
let test = test_codex_exec();
let last_message_path = test.cwd_path().join("last_message.txt");
let server = responses::start_mock_server().await;
let body = responses::sse(vec![
serde_json::json!({
"type": "response.created",
"response": {"id": "resp1"}
}),
responses::ev_assistant_message("m1", "fixture hello"),
responses::ev_completed("resp1"),
]);
responses::mount_sse_once_match(&server, any(), body).await;
test.cmd_with_server(&server)
.arg("--skip-git-repo-check")
// keep using -C in the test to exercise the flag as well
.arg("-C")
.arg(test.cwd_path())
.arg("--output-last-message")
.arg(&last_message_path)
.arg("--json")
.arg("tell me a joke")
.assert()
.success();
assert_eq!(
std::fs::read_to_string(&last_message_path)?,
"fixture hello"
);
Ok(())
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn exec_includes_output_last_message_in_request_stdout() -> anyhow::Result<()> {
let test = test_codex_exec();
let server = responses::start_mock_server().await;
let body = responses::sse(vec![
serde_json::json!({
"type": "response.created",
"response": {"id": "resp1"}
}),
responses::ev_assistant_message("m1", "fixture hello"),
responses::ev_completed("resp1"),
]);
responses::mount_sse_once_match(&server, any(), body).await;
test.cmd_with_server(&server)
.arg("--skip-git-repo-check")
// keep using -C in the test to exercise the flag as well
.arg("-C")
.arg(test.cwd_path())
.arg("tell me a joke")
.arg("--output-last-message")
.assert()
.success()
.stdout("fixture hello\n");
Ok(())
}