mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
Preserve hook trust bypass in codex exec threads (#26434)
Addresses #26383 and #26452 ## Summary `codex exec --dangerously-bypass-hook-trust` printed the bypass warning, but valid untrusted hooks still did not run. Exec applied the flag to its initial config, then lost it when app-server reloaded config for the new or resumed thread. ## Fix Forward `bypass_hook_trust: true` through the existing thread request config override for both start and resume. The override is omitted when the flag is not enabled, preserving normal trust behavior. ## Testing Added: - A test confirming start and resume preserve the override. - An end-to-end exec test confirming a `SessionStart` hook runs and creates a marker file.
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
#![cfg(not(target_os = "windows"))]
|
||||
#![allow(clippy::expect_used)]
|
||||
|
||||
use core_test_support::responses;
|
||||
use core_test_support::test_codex_exec::test_codex_exec;
|
||||
use serde_json::json;
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn exec_hook_trust_bypass_runs_session_start_hook() -> anyhow::Result<()> {
|
||||
let test = test_codex_exec();
|
||||
let marker_path = test.home_path().join("session-start-ran");
|
||||
let command = format!("touch {}", marker_path.display());
|
||||
std::fs::write(
|
||||
test.home_path().join("hooks.json"),
|
||||
serde_json::to_vec_pretty(&json!({
|
||||
"hooks": {
|
||||
"SessionStart": [{
|
||||
"hooks": [{
|
||||
"type": "command",
|
||||
"command": command,
|
||||
}],
|
||||
}],
|
||||
},
|
||||
}))?,
|
||||
)?;
|
||||
|
||||
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;
|
||||
|
||||
test.cmd_with_server(&server)
|
||||
.arg("--skip-git-repo-check")
|
||||
.arg("--dangerously-bypass-hook-trust")
|
||||
.arg("run the session start hook")
|
||||
.assert()
|
||||
.success();
|
||||
|
||||
assert!(marker_path.exists(), "session start hook did not run");
|
||||
Ok(())
|
||||
}
|
||||
@@ -5,6 +5,7 @@ mod apply_patch;
|
||||
mod approval_policy;
|
||||
mod auth_env;
|
||||
mod ephemeral;
|
||||
mod hooks;
|
||||
mod mcp_required_exit;
|
||||
mod originator;
|
||||
mod output_schema;
|
||||
|
||||
Reference in New Issue
Block a user