mirror of
https://github.com/openai/codex.git
synced 2026-12-06 01:10:58 +00:00
refactor: name filesystem violation predicate explicitly
Co-authored-by: Codex noreply@openai.com
This commit is contained in:
co-authored by
Codex noreply@openai.com
parent
93b08a2396
commit
5459b60d8a
@@ -2,7 +2,6 @@ use super::*;
|
||||
use codex_protocol::config_types::WindowsSandboxLevel;
|
||||
use codex_protocol::models::PermissionProfile;
|
||||
use codex_sandboxing::SandboxType;
|
||||
use codex_sandboxing::is_likely_sandbox_denied;
|
||||
use core_test_support::PathBufExt;
|
||||
use core_test_support::PathExt;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
@@ -48,6 +48,7 @@ use codex_sandboxing::SandboxManager;
|
||||
use codex_sandboxing::SandboxTransformRequest;
|
||||
use codex_sandboxing::SandboxType;
|
||||
use codex_sandboxing::SandboxablePreference;
|
||||
use codex_sandboxing::is_filesystem_sandbox_violation;
|
||||
use codex_sandboxing::record_filesystem_sandbox_violation;
|
||||
use codex_shell_command::bash::parse_shell_lc_plain_commands;
|
||||
use codex_shell_command::bash::parse_shell_lc_single_command_prefix;
|
||||
@@ -1113,7 +1114,8 @@ fn map_exec_result(
|
||||
})));
|
||||
}
|
||||
|
||||
if record_filesystem_sandbox_violation(sandbox, &output).is_some() {
|
||||
if is_filesystem_sandbox_violation(sandbox, &output) {
|
||||
record_filesystem_sandbox_violation(sandbox, &output);
|
||||
return Err(ToolError::Codex(CodexErr::Sandbox(SandboxErr::Denied {
|
||||
output: Box::new(output),
|
||||
network_policy_decision: None,
|
||||
|
||||
@@ -30,6 +30,8 @@ pub use violation::FileSystemSandboxViolation;
|
||||
pub use violation::FileSystemSandboxViolationReason;
|
||||
pub use violation::NetworkSandboxViolation;
|
||||
pub use violation::SandboxViolationEvent;
|
||||
pub use violation::classify_filesystem_sandbox_violation;
|
||||
pub use violation::is_filesystem_sandbox_violation;
|
||||
pub use violation::record_filesystem_sandbox_violation;
|
||||
pub use violation::record_network_sandbox_violation;
|
||||
pub use violation::record_sandbox_violation;
|
||||
|
||||
@@ -147,14 +147,8 @@ pub fn classify_filesystem_sandbox_violation(
|
||||
None
|
||||
}
|
||||
|
||||
/// Preserve the legacy boolean sandbox-denial check for call sites that only need a retry decision.
|
||||
///
|
||||
/// We don't have a fully deterministic way to tell if a command failed because
|
||||
/// of the sandbox: a command in the user's zshrc file might hit an error, but
|
||||
/// the command itself might fail or succeed for other reasons. For now, we
|
||||
/// conservatively check for well known command failure exit codes and also look
|
||||
/// for common sandbox denial keywords in the command output.
|
||||
pub fn is_likely_sandbox_denied(
|
||||
/// Return whether a sandboxed process result represents a filesystem sandbox violation.
|
||||
pub fn is_filesystem_sandbox_violation(
|
||||
sandbox_type: SandboxType,
|
||||
exec_output: &ExecToolCallOutput,
|
||||
) -> bool {
|
||||
|
||||
@@ -36,7 +36,7 @@ fn preserves_legacy_boolean_denial_keywords() {
|
||||
let output = make_exec_output(/*exit_code*/ 1, "", keyword, "");
|
||||
|
||||
assert_eq!(
|
||||
is_likely_sandbox_denied(SandboxType::LinuxSeccomp, &output),
|
||||
is_filesystem_sandbox_violation(SandboxType::LinuxSeccomp, &output),
|
||||
true,
|
||||
"{keyword}"
|
||||
);
|
||||
@@ -54,19 +54,19 @@ fn preserves_legacy_boolean_denial_ordering() {
|
||||
let non_sandbox_with_keyword =
|
||||
make_exec_output(/*exit_code*/ 1, "", "Operation not permitted", "");
|
||||
|
||||
assert!(!is_likely_sandbox_denied(
|
||||
assert!(!is_filesystem_sandbox_violation(
|
||||
SandboxType::LinuxSeccomp,
|
||||
&quick_reject_without_keyword
|
||||
));
|
||||
assert!(is_likely_sandbox_denied(
|
||||
assert!(is_filesystem_sandbox_violation(
|
||||
SandboxType::LinuxSeccomp,
|
||||
&quick_reject_with_keyword
|
||||
));
|
||||
assert!(!is_likely_sandbox_denied(
|
||||
assert!(!is_filesystem_sandbox_violation(
|
||||
SandboxType::LinuxSeccomp,
|
||||
&zero_exit_with_keyword
|
||||
));
|
||||
assert!(!is_likely_sandbox_denied(
|
||||
assert!(!is_filesystem_sandbox_violation(
|
||||
SandboxType::None,
|
||||
&non_sandbox_with_keyword
|
||||
));
|
||||
@@ -137,7 +137,7 @@ fn classifies_linux_sigsys_exit() {
|
||||
fn preserves_boolean_denial_semantics_for_non_sandbox_mode() {
|
||||
let output = make_exec_output(/*exit_code*/ 1, "", "Operation not permitted", "");
|
||||
|
||||
assert!(!is_likely_sandbox_denied(SandboxType::None, &output));
|
||||
assert!(!is_filesystem_sandbox_violation(SandboxType::None, &output));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user