Files
codex/codex-rs/exec/tests/suite/agents_md.rs
T
Dylan Hurd 3aaa23a437 Reduce overhead in CLI integration tests (#62153)
## Why

SSE-only mocks return 404 on WebSocket upgrades by default, causing
retries before the tests reach the HTTP stream. In parallel runs, each
CLI subprocess can also start a Tokio worker per host CPU.

## What changed

- Share an SSE mock that returns HTTP 426 on WebSocket upgrades to
  trigger immediate HTTP fallback. Reuse it in the fallback test.
- Set `TOKIO_WORKER_THREADS=2` for CLI subprocesses launched by the
  affected test helpers. Run streaming and resume cases that don't need
  the repository checkout in temporary working directories.
- Test promptless `codex exec fork` option validation without creating a
  source thread. In the successful promptless fork case, keep stdin
  open and rely on the test runner's timeout to catch a blocked read.

GitOrigin-RevId: 94c20d4b2fd7cc65bc0f2a1cd0318ac188f59f22
2026-11-18 01:48:42 +00: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_sse_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_sse_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(())
}