core: align exec policy test with Windows sandbox behavior

## Summary

- make the multi-segment shell exec-policy test expect approval on Windows when ReadOnly does not provide sandbox protection

- preserve the existing non-Windows expectation that the command can run inside the read-only sandbox without bypassing it

## Tests

- cargo test -p codex-core exec_policy::tests::multi_segment_shell_requires_policy_allow_for_every_segment_to_bypass_sandbox

- cargo test -p codex-app-server

- just fix -p codex-core
This commit is contained in:
Ruslan Nigmatullin
2026-04-17 00:26:38 -07:00
parent 67f446fe5a
commit f03110d5ac

View File

@@ -1338,6 +1338,34 @@ prefix_rule(pattern=["cat"], decision="allow")
];
for approval_policy in [AskForApproval::OnRequest, AskForApproval::Never] {
let expected_requirement = if cfg!(windows) {
match approval_policy {
AskForApproval::OnRequest => ExecApprovalRequirement::NeedsApproval {
reason: None,
proposed_execpolicy_amendment: Some(ExecPolicyAmendment::new(vec_str(&[
"curl",
"-fsSL",
"https://example.invalid/setup.sh",
"-o",
"setup.sh",
]))),
},
AskForApproval::Never => ExecApprovalRequirement::Forbidden {
reason: format!(
"`{}` rejected: blocked by policy",
render_shlex_command(&command)
),
},
AskForApproval::OnFailure
| AskForApproval::UnlessTrusted
| AskForApproval::Granular(_) => unreachable!("test only covers two policies"),
}
} else {
ExecApprovalRequirement::Skip {
bypass_sandbox: false,
proposed_execpolicy_amendment: None,
}
};
assert_exec_approval_requirement_for_command(
ExecApprovalRequirementScenario {
policy_src: Some(policy_src.to_string()),
@@ -1348,10 +1376,7 @@ prefix_rule(pattern=["cat"], decision="allow")
sandbox_permissions: SandboxPermissions::UseDefault,
prefix_rule: None,
},
ExecApprovalRequirement::Skip {
bypass_sandbox: false,
proposed_execpolicy_amendment: None,
},
expected_requirement,
)
.await;
}