Skip to content

Commit 1211a90

Browse files
authored
core tests: migrate hook turns to profiles (#20041)
## Summary - Removes `SandboxPolicy` from the hooks test suite. - Submits hook-related turns with explicit `PermissionProfile` values for disabled, read-only, and workspace-write cases. - Preserves the managed-network hook test by configuring and submitting a workspace-write profile with enabled network, allowing the existing requirements-backed proxy path to remain covered. ## Verification - `cargo check -p codex-core --tests` - `just fmt`
1 parent 1fed948 commit 1211a90

1 file changed

Lines changed: 39 additions & 29 deletions

File tree

codex-rs/core/tests/suite/hooks.rs

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ use codex_core::config::Constrained;
77
use codex_features::Feature;
88
use codex_protocol::items::parse_hook_prompt_fragment;
99
use codex_protocol::models::ContentItem;
10+
use codex_protocol::models::PermissionProfile;
1011
use codex_protocol::models::ResponseItem;
12+
use codex_protocol::permissions::NetworkSandboxPolicy;
1113
use codex_protocol::protocol::AskForApproval;
1214
use codex_protocol::protocol::EventMsg;
1315
use codex_protocol::protocol::Op;
1416
use codex_protocol::protocol::RolloutItem;
1517
use codex_protocol::protocol::RolloutLine;
16-
use codex_protocol::protocol::SandboxPolicy;
1718
use codex_protocol::user_input::UserInput;
1819
use core_test_support::managed_network_requirements_loader;
1920
use core_test_support::responses::ev_apply_patch_function_call;
@@ -48,6 +49,24 @@ const BLOCKED_PROMPT_CONTEXT: &str = "Remember the blocked lighthouse note.";
4849
const PERMISSION_REQUEST_HOOK_MATCHER: &str = "^Bash$";
4950
const PERMISSION_REQUEST_ALLOW_REASON: &str = "should not be used for allow";
5051

52+
fn restrictive_workspace_write_profile() -> PermissionProfile {
53+
PermissionProfile::workspace_write_with(
54+
&[],
55+
NetworkSandboxPolicy::Restricted,
56+
/*exclude_tmpdir_env_var*/ true,
57+
/*exclude_slash_tmp*/ true,
58+
)
59+
}
60+
61+
fn network_workspace_write_profile() -> PermissionProfile {
62+
PermissionProfile::workspace_write_with(
63+
&[],
64+
NetworkSandboxPolicy::Enabled,
65+
/*exclude_tmpdir_env_var*/ false,
66+
/*exclude_slash_tmp*/ false,
67+
)
68+
}
69+
5170
fn write_stop_hook(home: &Path, block_prompts: &[&str]) -> Result<()> {
5271
let script_path = home.join("stop_hook.py");
5372
let log_path = home.join("stop_hook_log.jsonl");
@@ -1322,10 +1341,10 @@ async fn permission_request_hook_allows_shell_command_without_user_approval() ->
13221341

13231342
fs::write(&marker, "seed").context("create permission request marker")?;
13241343

1325-
test.submit_turn_with_policies(
1344+
test.submit_turn_with_approval_and_permission_profile(
13261345
"run the shell command after hook approval",
13271346
AskForApproval::OnRequest,
1328-
codex_protocol::protocol::SandboxPolicy::DangerFullAccess,
1347+
PermissionProfile::Disabled,
13291348
)
13301349
.await?;
13311350

@@ -1407,15 +1426,10 @@ async fn permission_request_hook_allows_apply_patch_with_write_alias() -> Result
14071426
let test = builder.build(&server).await?;
14081427
let target_path = test.workspace_path(&patch_path);
14091428

1410-
test.submit_turn_with_policies(
1429+
test.submit_turn_with_approval_and_permission_profile(
14111430
"apply the patch after hook approval",
14121431
AskForApproval::OnRequest,
1413-
SandboxPolicy::WorkspaceWrite {
1414-
writable_roots: vec![],
1415-
network_access: false,
1416-
exclude_tmpdir_env_var: true,
1417-
exclude_slash_tmp: true,
1418-
},
1432+
restrictive_workspace_write_profile(),
14191433
)
14201434
.await?;
14211435

@@ -1494,10 +1508,10 @@ async fn permission_request_hook_sees_raw_exec_command_input() -> Result<()> {
14941508

14951509
fs::write(&marker, "seed").context("create exec command permission request marker")?;
14961510

1497-
test.submit_turn_with_policies(
1511+
test.submit_turn_with_approval_and_permission_profile(
14981512
"run the exec command after hook approval",
14991513
AskForApproval::OnRequest,
1500-
codex_protocol::protocol::SandboxPolicy::new_read_only_policy(),
1514+
PermissionProfile::read_only(),
15011515
)
15021516
.await?;
15031517

@@ -1558,13 +1572,8 @@ allow_local_binding = true
15581572
.await;
15591573

15601574
let approval_policy = AskForApproval::OnFailure;
1561-
let sandbox_policy = SandboxPolicy::WorkspaceWrite {
1562-
writable_roots: vec![],
1563-
network_access: true,
1564-
exclude_tmpdir_env_var: false,
1565-
exclude_slash_tmp: false,
1566-
};
1567-
let sandbox_policy_for_config = sandbox_policy.clone();
1575+
let permission_profile = network_workspace_write_profile();
1576+
let permission_profile_for_config = permission_profile.clone();
15681577
let test = test_codex()
15691578
.with_home(Arc::clone(&home))
15701579
.with_pre_build_hook(|home| {
@@ -1580,8 +1589,9 @@ allow_local_binding = true
15801589
.expect("test config should allow feature update");
15811590
config.permissions.approval_policy = Constrained::allow_any(approval_policy);
15821591
config
1583-
.set_legacy_sandbox_policy(sandbox_policy_for_config)
1584-
.expect("set sandbox policy");
1592+
.permissions
1593+
.set_permission_profile(permission_profile_for_config)
1594+
.expect("set permission profile");
15851595
})
15861596
.build(&server)
15871597
.await?;
@@ -1598,10 +1608,10 @@ allow_local_binding = true
15981608
.as_ref()
15991609
.expect("expected runtime managed network proxy addresses");
16001610

1601-
test.submit_turn_with_policies(
1611+
test.submit_turn_with_approval_and_permission_profile(
16021612
"run the shell command after network hook approval",
16031613
approval_policy,
1604-
sandbox_policy,
1614+
permission_profile,
16051615
)
16061616
.await?;
16071617

@@ -1695,10 +1705,10 @@ async fn permission_request_hook_sees_retry_context_after_sandbox_denial() -> Re
16951705
let marker_path = test.workspace_path(marker);
16961706
let _ = fs::remove_file(&marker_path);
16971707

1698-
test.submit_turn_with_policies(
1708+
test.submit_turn_with_approval_and_permission_profile(
16991709
"retry the shell command after sandbox denial",
17001710
AskForApproval::OnFailure,
1701-
codex_protocol::protocol::SandboxPolicy::new_read_only_policy(),
1711+
PermissionProfile::read_only(),
17021712
)
17031713
.await?;
17041714

@@ -1769,9 +1779,9 @@ async fn pre_tool_use_blocks_shell_command_before_execution() -> Result<()> {
17691779
fs::remove_file(&marker).context("remove leftover pre tool use marker")?;
17701780
}
17711781

1772-
test.submit_turn_with_policy(
1782+
test.submit_turn_with_permission_profile(
17731783
"run the blocked shell command",
1774-
codex_protocol::protocol::SandboxPolicy::DangerFullAccess,
1784+
PermissionProfile::Disabled,
17751785
)
17761786
.await?;
17771787

@@ -2013,9 +2023,9 @@ async fn pre_tool_use_blocks_shell_when_defined_in_config_toml() -> Result<()> {
20132023
fs::remove_file(&marker).context("remove leftover config.toml marker")?;
20142024
}
20152025

2016-
test.submit_turn_with_policy(
2026+
test.submit_turn_with_permission_profile(
20172027
"run the blocked shell command from config toml",
2018-
codex_protocol::protocol::SandboxPolicy::DangerFullAccess,
2028+
PermissionProfile::Disabled,
20192029
)
20202030
.await?;
20212031

0 commit comments

Comments
 (0)