mirror of
https://github.com/openai/codex.git
synced 2026-11-15 21:50:46 +00:00
## What changed - Build and assert `PermissionProfile` values directly in memory consolidation tests using filesystem and network permissions. - Remove the `SandboxPolicy` dependency from rollout trace test fixtures while preserving their `DangerFullAccess` value. - Update sandbox documentation to describe legacy `sandbox_mode` conversion to `PermissionProfile` and nested filesystem rules, and reference `SandboxMode` in the CLI documentation. GitOrigin-RevId: ac1be62625b1bfd98dde5f762b379eb840f9186b
111 lines
3.9 KiB
Rust
111 lines
3.9 KiB
Rust
use super::agent;
|
|
use codex_config::Constrained;
|
|
use codex_core::config::Permissions;
|
|
use codex_model_provider::create_model_provider;
|
|
use codex_protocol::models::ManagedFileSystemPermissions;
|
|
use codex_protocol::models::PermissionProfile;
|
|
use codex_protocol::permissions::FileSystemPolicyProjection;
|
|
use codex_protocol::permissions::FileSystemSandboxPolicy;
|
|
use codex_protocol::permissions::NetworkSandboxPolicy;
|
|
use codex_protocol::protocol::AskForApproval;
|
|
use core_test_support::responses::start_mock_server;
|
|
use core_test_support::test_codex::test_codex;
|
|
use pretty_assertions::assert_eq;
|
|
use std::sync::Arc;
|
|
use tempfile::TempDir;
|
|
|
|
#[tokio::test]
|
|
async fn consolidation_uses_canonical_parent_enforcement() -> anyhow::Result<()> {
|
|
let server = start_mock_server().await;
|
|
let home = Arc::new(TempDir::new()?);
|
|
let test = test_codex()
|
|
.with_home(home)
|
|
.build_with_auto_env(&server)
|
|
.await?;
|
|
let provider = create_model_provider(
|
|
test.config.model_provider.clone(),
|
|
Some(test.thread_manager.auth_manager()),
|
|
);
|
|
|
|
let root = crate::memory_root(&test.config.codex_home);
|
|
let managed_worker_profile = PermissionProfile::from_runtime_permissions(
|
|
&FileSystemSandboxPolicy::workspace_write(
|
|
std::slice::from_ref(&root),
|
|
/*exclude_tmpdir_env_var*/ true,
|
|
/*exclude_slash_tmp*/ true,
|
|
),
|
|
NetworkSandboxPolicy::Restricted,
|
|
);
|
|
|
|
for (parent_permission_profile, expected_permission_profile) in [
|
|
(PermissionProfile::Disabled, PermissionProfile::Disabled),
|
|
(
|
|
PermissionProfile::External {
|
|
network: NetworkSandboxPolicy::Restricted,
|
|
},
|
|
PermissionProfile::External {
|
|
network: NetworkSandboxPolicy::Restricted,
|
|
},
|
|
),
|
|
(
|
|
PermissionProfile::External {
|
|
network: NetworkSandboxPolicy::Enabled,
|
|
},
|
|
PermissionProfile::External {
|
|
network: NetworkSandboxPolicy::Enabled,
|
|
},
|
|
),
|
|
(
|
|
PermissionProfile::Managed {
|
|
file_system: ManagedFileSystemPermissions::Unrestricted,
|
|
network: NetworkSandboxPolicy::Enabled,
|
|
},
|
|
managed_worker_profile,
|
|
),
|
|
] {
|
|
let agent_config =
|
|
agent::get_config(&test.config, parent_permission_profile, provider.as_ref())
|
|
.expect("agent config should be created");
|
|
|
|
assert_eq!(
|
|
(
|
|
agent_config.permissions.permission_profile().enforcement(),
|
|
agent_config.permissions.network_sandbox_policy(),
|
|
agent_config.permissions.approval_policy.value(),
|
|
),
|
|
(
|
|
expected_permission_profile.enforcement(),
|
|
expected_permission_profile.network_sandbox_policy(),
|
|
AskForApproval::Never,
|
|
),
|
|
);
|
|
assert_eq!(
|
|
agent_config
|
|
.permissions
|
|
.effective_permission_profile()
|
|
.file_system_sandbox_policy()
|
|
.resolve_for_enforcement(root.as_path(), FileSystemPolicyProjection::Native)?,
|
|
expected_permission_profile
|
|
.file_system_sandbox_policy()
|
|
.resolve_for_enforcement(root.as_path(), FileSystemPolicyProjection::Native)?,
|
|
);
|
|
}
|
|
|
|
let mut constrained_config = test.config.clone();
|
|
constrained_config.permissions = Permissions::from_approval_and_profile(
|
|
Constrained::allow_only(AskForApproval::Never),
|
|
Constrained::allow_only(PermissionProfile::read_only()),
|
|
)?;
|
|
assert!(
|
|
agent::get_config(
|
|
&constrained_config,
|
|
PermissionProfile::workspace_write(),
|
|
provider.as_ref(),
|
|
)
|
|
.is_none()
|
|
);
|
|
|
|
test.codex.shutdown_and_wait().await?;
|
|
Ok(())
|
|
}
|