Keep PreToolUse allow monotonic

This commit is contained in:
Abhinav Vedmala
2026-05-04 15:15:45 -07:00
parent 7bc1c3610e
commit ea59e08790
7 changed files with 101 additions and 149 deletions
-72
View File
@@ -1440,78 +1440,6 @@ async fn permission_request_hook_allows_shell_command_without_user_approval() ->
Ok(())
}
#[tokio::test]
async fn pre_tool_use_allow_skips_shell_command_approval() -> Result<()> {
skip_if_no_network!(Ok(()));
let server = start_mock_server().await;
let call_id = "pretooluse-allow-shell-command";
let marker = std::env::temp_dir().join("pretooluse-allow-shell-command-marker");
let command = format!("rm -f {}", marker.display());
let args = serde_json::json!({ "command": command });
let responses = mount_sse_sequence(
&server,
vec![
sse(vec![
ev_response_created("resp-1"),
ev_function_call(call_id, "shell_command", &serde_json::to_string(&args)?),
ev_completed("resp-1"),
]),
sse(vec![
ev_response_created("resp-2"),
ev_assistant_message("msg-1", "pre tool use allowed it"),
ev_completed("resp-2"),
]),
],
)
.await;
let mut builder = test_codex()
.with_pre_build_hook(|home| {
if let Err(error) =
write_pre_tool_use_hook(home, Some("^Bash$"), "json_allow", "approved by hook")
{
panic!("failed to write pre tool use hook test fixture: {error}");
}
})
.with_config(|config| {
config
.features
.enable(Feature::CodexHooks)
.expect("test config should allow feature update");
});
let test = builder.build(&server).await?;
fs::write(&marker, "seed").context("create pre tool use marker")?;
test.submit_turn_with_approval_and_permission_profile(
"run the shell command after pre tool use approval",
AskForApproval::OnRequest,
PermissionProfile::Disabled,
)
.await?;
assert_eq!(responses.requests().len(), 2);
assert!(
!marker.exists(),
"pre tool use allow should execute without prompting"
);
assert!(
timeout(
Duration::from_secs(2),
wait_for_event(&test.codex, |event| matches!(
event,
EventMsg::ExecApprovalRequest(_)
))
)
.await
.is_err(),
"pre tool use allow should bypass the approval prompt"
);
Ok(())
}
#[tokio::test]
async fn pre_tool_use_ask_prompts_user_with_hook_reason() -> Result<()> {
skip_if_no_network!(Ok(()));