mirror of
https://github.com/openai/codex.git
synced 2026-09-10 20:26:47 +00:00
## What changed - Add `--approve-for-me` to interactive and exec commands to route approval requests through automatic review. - Configure the mode with `approval_policy="on-request"` and the `workspace-write` sandbox. - Propagate the option across root, `exec`, `resume`, and `fork` argument handling while preserving later subcommand permission overrides. ## Testing - Cover parsing, permission conflicts, root/subcommand precedence, resume handling, and the effective exec approval and sandbox modes. GitOrigin-RevId: ae969e8c18f925f943049fefff56255f10b25659
79 lines
2.4 KiB
Rust
79 lines
2.4 KiB
Rust
#![cfg(not(target_os = "windows"))]
|
|
#![allow(clippy::unwrap_used)]
|
|
|
|
use core_test_support::responses;
|
|
use core_test_support::test_codex_exec::test_codex_exec;
|
|
|
|
async fn run_exec_with_config(config_toml: &str, extra_args: &[&str]) -> anyhow::Result<String> {
|
|
let test = test_codex_exec();
|
|
std::fs::write(test.home_path().join("config.toml"), config_toml)?;
|
|
|
|
let server = responses::start_mock_server().await;
|
|
let body = responses::sse(vec![
|
|
responses::ev_response_created("response_1"),
|
|
responses::ev_assistant_message("response_1", "done"),
|
|
responses::ev_completed("response_1"),
|
|
]);
|
|
responses::mount_sse_once(&server, body).await;
|
|
|
|
let mut cmd = test.cmd_with_server(&server);
|
|
let output = cmd
|
|
.arg("--skip-git-repo-check")
|
|
.args(extra_args)
|
|
.arg("check approval mode")
|
|
.output()?;
|
|
|
|
assert!(output.status.success(), "exec run failed: {output:?}");
|
|
|
|
Ok(String::from_utf8(output.stderr)?)
|
|
}
|
|
|
|
async fn run_exec_with_auto_review_config(extra_args: &[&str]) -> anyhow::Result<String> {
|
|
run_exec_with_config(
|
|
r#"
|
|
approval_policy = "on-request"
|
|
approvals_reviewer = "auto_review"
|
|
"#,
|
|
extra_args,
|
|
)
|
|
.await
|
|
}
|
|
|
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
|
async fn exec_preserves_on_request_for_auto_review_config() -> anyhow::Result<()> {
|
|
let stderr = run_exec_with_auto_review_config(&[]).await?;
|
|
assert!(
|
|
stderr.contains("approval: on-request"),
|
|
"stderr missing preserved auto-review approval mode: {stderr}"
|
|
);
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
|
async fn exec_approve_for_me_flag_sets_approval_mode_and_sandbox() -> anyhow::Result<()> {
|
|
let stderr = run_exec_with_config("", &["--approve-for-me"]).await?;
|
|
assert!(
|
|
stderr.contains("approval: on-request"),
|
|
"stderr missing --approve-for-me approval mode: {stderr}"
|
|
);
|
|
assert!(
|
|
stderr.contains("sandbox: workspace-write"),
|
|
"stderr missing --approve-for-me sandbox mode: {stderr}"
|
|
);
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
|
async fn exec_bypass_preserves_never_for_auto_review_config() -> anyhow::Result<()> {
|
|
let stderr =
|
|
run_exec_with_auto_review_config(&["--dangerously-bypass-approvals-and-sandbox"]).await?;
|
|
assert!(
|
|
stderr.contains("approval: never"),
|
|
"stderr missing bypass approval mode: {stderr}"
|
|
);
|
|
|
|
Ok(())
|
|
}
|