Files
pakrym-oai e752f7b4ae [codex] Use expect in integration tests (#28441)
The workspace denies `clippy::expect_used` in production. Although
`clippy.toml` allows `expect` in tests, Bazel Clippy compiles
integration-test helper code in a way that does not receive that
exemption, which encouraged verbose `unwrap_or_else(... panic!(...))`
and equivalent `match`/`let else` forms.

This allows `clippy::expect_used` once at each integration-test crate
root (including aggregated suites and test-support libraries), then
replaces manual panic-based Result and Option unwraps with
`expect`/`expect_err`. Standalone `tests/*.rs` files remain their own
crate roots. Intentional assertion and unexpected-variant panics remain
unchanged, and the production `expect_used = "deny"` lint remains in
place.

The cleanup is mechanical and net-negative in line count.
2026-06-15 21:53:47 -07:00

75 lines
2.5 KiB
Rust

#![allow(clippy::unwrap_used)]
use core_test_support::responses;
use core_test_support::test_codex_exec::test_codex_exec;
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn exec_includes_workspace_agents_md_in_request() -> anyhow::Result<()> {
let test = test_codex_exec();
std::fs::write(test.cwd_path().join("AGENTS.md"), "workspace instructions")?;
let server = responses::start_mock_server().await;
let body = responses::sse(vec![
responses::ev_response_created("resp1"),
responses::ev_assistant_message("m1", "fixture hello"),
responses::ev_completed("resp1"),
]);
let response_mock = responses::mount_sse_once(&server, body).await;
test.cmd_with_server(&server)
.arg("--skip-git-repo-check")
.arg("tell me something")
.assert()
.success();
let user_messages = response_mock.single_request().message_input_texts("user");
assert!(
user_messages
.iter()
.any(|text| text.contains("workspace instructions")),
"request should include workspace AGENTS.md instructions: {user_messages:?}"
);
Ok(())
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn exec_prefers_workspace_agents_override_md() -> anyhow::Result<()> {
let test = test_codex_exec();
std::fs::write(test.cwd_path().join("AGENTS.md"), "base instructions")?;
std::fs::write(
test.cwd_path().join("AGENTS.override.md"),
"override instructions",
)?;
let server = responses::start_mock_server().await;
let body = responses::sse(vec![
responses::ev_response_created("resp1"),
responses::ev_assistant_message("m1", "fixture hello"),
responses::ev_completed("resp1"),
]);
let response_mock = responses::mount_sse_once(&server, body).await;
test.cmd_with_server(&server)
.arg("--skip-git-repo-check")
.arg("tell me something")
.assert()
.success();
let user_messages = response_mock.single_request().message_input_texts("user");
assert!(
user_messages
.iter()
.any(|text| text.contains("override instructions")),
"request should include AGENTS.override.md instructions: {user_messages:?}"
);
assert!(
user_messages
.iter()
.all(|text| !text.contains("base instructions")),
"request should exclude shadowed AGENTS.md instructions: {user_messages:?}"
);
Ok(())
}