mirror of
https://github.com/openai/codex.git
synced 2026-10-21 17:48:44 +00:00
chore: merge origin/main into symlink hardening
Co-authored-by: Codex noreply@openai.com
This commit is contained in:
@@ -40,6 +40,7 @@ codex-utils-absolute-path = { workspace = true }
|
||||
codex-utils-cli = { workspace = true }
|
||||
codex-utils-oss = { workspace = true }
|
||||
libc = { workspace = true }
|
||||
codex-utils-sandbox-summary = { workspace = true }
|
||||
owo-colors = { workspace = true }
|
||||
serde = { workspace = true, features = ["derive"] }
|
||||
serde_json = { workspace = true }
|
||||
|
||||
@@ -16,6 +16,10 @@ pub struct Cli {
|
||||
#[command(subcommand)]
|
||||
pub command: Option<Command>,
|
||||
|
||||
/// Error out when config.toml contains fields that are not recognized by this version of Codex.
|
||||
#[arg(long = "strict-config", global = true, default_value_t = false)]
|
||||
pub strict_config: bool,
|
||||
|
||||
#[clap(flatten)]
|
||||
pub shared: ExecSharedCliOptions,
|
||||
|
||||
@@ -46,7 +50,7 @@ pub struct Cli {
|
||||
pub removed_full_auto: bool,
|
||||
|
||||
/// Path to a JSON Schema file describing the model's final response shape.
|
||||
#[arg(long = "output-schema", value_name = "FILE")]
|
||||
#[arg(long = "output-schema", value_name = "FILE", global = true)]
|
||||
pub output_schema: Option<PathBuf>,
|
||||
|
||||
#[clap(skip)]
|
||||
@@ -155,6 +159,7 @@ fn mark_exec_global_args(cmd: clap::Command) -> clap::Command {
|
||||
.mut_arg("dangerously_bypass_approvals_and_sandbox", |arg| {
|
||||
arg.global(true)
|
||||
})
|
||||
.mut_arg("bypass_hook_trust", |arg| arg.global(true))
|
||||
}
|
||||
|
||||
#[derive(Debug, clap::Subcommand)]
|
||||
@@ -257,7 +262,7 @@ impl FromArgMatches for ResumeArgs {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[derive(Args, Debug)]
|
||||
pub struct ReviewArgs {
|
||||
/// Review staged, unstaged, and untracked changes.
|
||||
#[arg(
|
||||
|
||||
@@ -36,7 +36,7 @@ fn resume_parses_prompt_after_global_flags() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resume_accepts_output_last_message_flag_after_subcommand() {
|
||||
fn resume_accepts_output_flags_after_subcommand() {
|
||||
const PROMPT: &str = "echo resume-with-output-file";
|
||||
let cli = Cli::parse_from([
|
||||
"codex-exec",
|
||||
@@ -44,6 +44,8 @@ fn resume_accepts_output_last_message_flag_after_subcommand() {
|
||||
"session-123",
|
||||
"-o",
|
||||
"/tmp/resume-output.md",
|
||||
"--output-schema",
|
||||
"/tmp/schema.json",
|
||||
PROMPT,
|
||||
]);
|
||||
|
||||
@@ -51,6 +53,7 @@ fn resume_accepts_output_last_message_flag_after_subcommand() {
|
||||
cli.last_message_file,
|
||||
Some(PathBuf::from("/tmp/resume-output.md"))
|
||||
);
|
||||
assert_eq!(cli.output_schema, Some(PathBuf::from("/tmp/schema.json")));
|
||||
let Some(Command::Resume(args)) = cli.command else {
|
||||
panic!("expected resume command");
|
||||
};
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use std::io::IsTerminal;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use codex_app_server_protocol::CommandExecutionStatus;
|
||||
@@ -11,11 +10,9 @@ use codex_app_server_protocol::ThreadTokenUsage;
|
||||
use codex_app_server_protocol::TurnStatus;
|
||||
use codex_core::config::Config;
|
||||
use codex_model_provider_info::WireApi;
|
||||
use codex_protocol::models::PermissionProfile;
|
||||
use codex_protocol::num_format::format_with_separators;
|
||||
use codex_protocol::permissions::NetworkSandboxPolicy;
|
||||
use codex_protocol::protocol::SessionConfiguredEvent;
|
||||
use codex_utils_absolute_path::canonicalize_preserving_symlinks;
|
||||
use codex_utils_sandbox_summary::summarize_permission_profile;
|
||||
use owo_colors::OwoColorize;
|
||||
use owo_colors::Style;
|
||||
|
||||
@@ -219,7 +216,7 @@ impl EventProcessor for EventProcessorWithHumanOutput {
|
||||
session_configured_event: &SessionConfiguredEvent,
|
||||
) {
|
||||
const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
eprintln!("OpenAI Codex v{VERSION} (research preview)\n--------");
|
||||
eprintln!("OpenAI Codex v{VERSION}\n--------");
|
||||
for (key, value) in config_summary_entries(config, session_configured_event) {
|
||||
eprintln!("{} {}", format!("{key}:").style(self.bold), value);
|
||||
}
|
||||
@@ -423,6 +420,7 @@ fn config_summary_entries(
|
||||
config: &Config,
|
||||
session_configured_event: &SessionConfiguredEvent,
|
||||
) -> Vec<(&'static str, String)> {
|
||||
let permission_profile = config.permissions.effective_permission_profile();
|
||||
let mut entries = vec![
|
||||
("workdir", config.cwd.display().to_string()),
|
||||
("model", session_configured_event.model.clone()),
|
||||
@@ -437,8 +435,9 @@ fn config_summary_entries(
|
||||
(
|
||||
"sandbox",
|
||||
summarize_permission_profile(
|
||||
config.permissions.permission_profile.get(),
|
||||
config.cwd.as_path(),
|
||||
&permission_profile,
|
||||
&config.cwd,
|
||||
config.effective_workspace_roots().as_slice(),
|
||||
),
|
||||
),
|
||||
];
|
||||
@@ -465,83 +464,6 @@ fn config_summary_entries(
|
||||
entries
|
||||
}
|
||||
|
||||
fn summarize_permission_profile(permission_profile: &PermissionProfile, cwd: &Path) -> String {
|
||||
match permission_profile {
|
||||
PermissionProfile::Disabled => "danger-full-access".to_string(),
|
||||
PermissionProfile::External { network } => {
|
||||
let mut summary = "external-sandbox".to_string();
|
||||
append_network_summary(&mut summary, *network);
|
||||
summary
|
||||
}
|
||||
PermissionProfile::Managed { .. } => {
|
||||
let file_system_policy = permission_profile.file_system_sandbox_policy();
|
||||
let network_policy = permission_profile.network_sandbox_policy();
|
||||
if file_system_policy.has_full_disk_write_access() {
|
||||
let mut summary = "workspace-write [/]".to_string();
|
||||
append_network_summary(&mut summary, network_policy);
|
||||
return summary;
|
||||
}
|
||||
|
||||
let writable_roots = file_system_policy.get_writable_roots_with_cwd(cwd);
|
||||
if writable_roots.is_empty() {
|
||||
let mut summary = "read-only".to_string();
|
||||
append_network_summary(&mut summary, network_policy);
|
||||
return summary;
|
||||
}
|
||||
|
||||
let mut summary = "workspace-write".to_string();
|
||||
let writable_entries = writable_roots
|
||||
.iter()
|
||||
.map(|root| writable_root_label(root.root.as_path(), cwd))
|
||||
.collect::<Vec<_>>();
|
||||
summary.push_str(&format!(" [{}]", writable_entries.join(", ")));
|
||||
append_network_summary(&mut summary, network_policy);
|
||||
summary
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn append_network_summary(summary: &mut String, network_policy: NetworkSandboxPolicy) {
|
||||
if network_policy.is_enabled() {
|
||||
summary.push_str(" (network access enabled)");
|
||||
}
|
||||
}
|
||||
|
||||
fn writable_root_label(root: &Path, cwd: &Path) -> String {
|
||||
if paths_match_after_canonicalization(root, cwd) {
|
||||
return "workdir".to_string();
|
||||
}
|
||||
if paths_match_after_canonicalization(root, Path::new("/tmp")) {
|
||||
return "/tmp".to_string();
|
||||
}
|
||||
if std::env::var_os("TMPDIR")
|
||||
.filter(|tmpdir| !tmpdir.is_empty())
|
||||
.is_some_and(|tmpdir| paths_match_after_canonicalization(root, Path::new(&tmpdir)))
|
||||
{
|
||||
return "$TMPDIR".to_string();
|
||||
}
|
||||
display_path_label(root)
|
||||
}
|
||||
|
||||
fn paths_match_after_canonicalization(left: &Path, right: &Path) -> bool {
|
||||
match (
|
||||
canonicalize_preserving_symlinks(left),
|
||||
canonicalize_preserving_symlinks(right),
|
||||
) {
|
||||
(Ok(left), Ok(right)) if left == right => true,
|
||||
_ => display_path_label(left) == display_path_label(right),
|
||||
}
|
||||
}
|
||||
|
||||
fn display_path_label(path: &Path) -> String {
|
||||
path.strip_prefix("/private/tmp")
|
||||
.ok()
|
||||
.map(|suffix| Path::new("/tmp").join(suffix))
|
||||
.unwrap_or_else(|| path.to_path_buf())
|
||||
.to_string_lossy()
|
||||
.to_string()
|
||||
}
|
||||
|
||||
fn reasoning_text(
|
||||
summary: &[String],
|
||||
content: &[String],
|
||||
|
||||
@@ -2,24 +2,29 @@ use codex_app_server_protocol::ServerNotification;
|
||||
use codex_app_server_protocol::ThreadItem;
|
||||
use codex_app_server_protocol::Turn;
|
||||
use codex_app_server_protocol::TurnStatus;
|
||||
use codex_core::config::ConfigBuilder;
|
||||
use codex_protocol::SessionId;
|
||||
use codex_protocol::ThreadId;
|
||||
use codex_protocol::models::PermissionProfile;
|
||||
use codex_protocol::permissions::FileSystemAccessMode;
|
||||
use codex_protocol::permissions::FileSystemPath;
|
||||
use codex_protocol::permissions::FileSystemSandboxEntry;
|
||||
use codex_protocol::permissions::FileSystemSandboxPolicy;
|
||||
use codex_protocol::permissions::NetworkSandboxPolicy;
|
||||
use codex_protocol::protocol::AskForApproval;
|
||||
use codex_protocol::protocol::SessionConfiguredEvent;
|
||||
use codex_utils_absolute_path::test_support::PathBufExt;
|
||||
use codex_utils_absolute_path::test_support::test_path_buf;
|
||||
use codex_utils_sandbox_summary::summarize_permission_profile;
|
||||
use owo_colors::Style;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
use super::EventProcessorWithHumanOutput;
|
||||
use super::config_summary_entries;
|
||||
use super::final_message_from_turn_items;
|
||||
use super::paths_match_after_canonicalization;
|
||||
use super::reasoning_text;
|
||||
use super::should_print_final_message_to_stdout;
|
||||
use super::should_print_final_message_to_tty;
|
||||
use super::summarize_permission_profile;
|
||||
use crate::event_processor::EventProcessor;
|
||||
|
||||
#[test]
|
||||
@@ -101,10 +106,13 @@ fn reasoning_text_uses_raw_content_when_enabled() {
|
||||
|
||||
#[test]
|
||||
fn summarizes_disabled_permission_profile_as_danger_full_access() {
|
||||
let cwd = test_path_buf("/tmp").abs();
|
||||
|
||||
assert_eq!(
|
||||
summarize_permission_profile(
|
||||
&PermissionProfile::Disabled,
|
||||
test_path_buf("/tmp").as_path()
|
||||
&cwd,
|
||||
std::slice::from_ref(&cwd),
|
||||
),
|
||||
"danger-full-access"
|
||||
);
|
||||
@@ -112,12 +120,15 @@ fn summarizes_disabled_permission_profile_as_danger_full_access() {
|
||||
|
||||
#[test]
|
||||
fn summarizes_external_permission_profile() {
|
||||
let cwd = test_path_buf("/tmp").abs();
|
||||
|
||||
assert_eq!(
|
||||
summarize_permission_profile(
|
||||
&PermissionProfile::External {
|
||||
network: NetworkSandboxPolicy::Enabled,
|
||||
},
|
||||
test_path_buf("/tmp").as_path(),
|
||||
&cwd,
|
||||
std::slice::from_ref(&cwd),
|
||||
),
|
||||
"external-sandbox (network access enabled)"
|
||||
);
|
||||
@@ -144,30 +155,89 @@ fn summarizes_managed_workspace_write_permission_profile() {
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
summarize_permission_profile(&profile, cwd.as_path()),
|
||||
summarize_permission_profile(&profile, &cwd, &[cwd.clone(), cache_root.clone()]),
|
||||
format!("workspace-write [workdir, {}]", cache_root.display())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn summarizes_managed_read_only_permission_profile() {
|
||||
let cwd = test_path_buf("/tmp/project").abs();
|
||||
let profile = PermissionProfile::from_runtime_permissions(
|
||||
&FileSystemSandboxPolicy::restricted(Vec::new()),
|
||||
NetworkSandboxPolicy::Restricted,
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
summarize_permission_profile(&profile, test_path_buf("/tmp/project").as_path()),
|
||||
summarize_permission_profile(&profile, &cwd, std::slice::from_ref(&cwd)),
|
||||
"read-only"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn distinct_missing_paths_do_not_match_after_canonicalization() {
|
||||
assert!(!paths_match_after_canonicalization(
|
||||
test_path_buf("/tmp/codex-missing-left").as_path(),
|
||||
test_path_buf("/tmp/codex-missing-right").as_path(),
|
||||
));
|
||||
#[tokio::test]
|
||||
async fn config_summary_entries_include_runtime_workspace_roots() {
|
||||
let codex_home = tempfile::tempdir().expect("create codex home");
|
||||
let cwd = tempfile::tempdir().expect("create cwd");
|
||||
let extra_root = tempfile::tempdir().expect("create extra root");
|
||||
let mut config = ConfigBuilder::default()
|
||||
.codex_home(codex_home.path().to_path_buf())
|
||||
.fallback_cwd(Some(cwd.path().to_path_buf()))
|
||||
.build()
|
||||
.await
|
||||
.expect("build default config");
|
||||
let cwd = cwd.path().to_path_buf().abs();
|
||||
let extra_root = extra_root.path().to_path_buf().abs();
|
||||
let expected_extra_root_name = extra_root
|
||||
.file_name()
|
||||
.expect("extra root should have file name")
|
||||
.to_string_lossy()
|
||||
.to_string();
|
||||
config.cwd = cwd.clone();
|
||||
config.workspace_roots = vec![cwd.clone(), extra_root];
|
||||
config
|
||||
.permissions
|
||||
.set_workspace_roots(config.workspace_roots.clone());
|
||||
config
|
||||
.permissions
|
||||
.set_permission_profile(PermissionProfile::workspace_write_with(
|
||||
&[],
|
||||
NetworkSandboxPolicy::Restricted,
|
||||
/*exclude_tmpdir_env_var*/ true,
|
||||
/*exclude_slash_tmp*/ true,
|
||||
))
|
||||
.expect("set permission profile");
|
||||
|
||||
let session_configured_event = SessionConfiguredEvent {
|
||||
session_id: SessionId::new(),
|
||||
thread_id: ThreadId::new(),
|
||||
forked_from_id: None,
|
||||
parent_thread_id: None,
|
||||
thread_source: None,
|
||||
thread_name: None,
|
||||
model: "gpt-5.4".to_string(),
|
||||
model_provider_id: config.model_provider_id.clone(),
|
||||
service_tier: None,
|
||||
approval_policy: AskForApproval::Never,
|
||||
approvals_reviewer: config.approvals_reviewer,
|
||||
permission_profile: config.permissions.effective_permission_profile(),
|
||||
active_permission_profile: None,
|
||||
cwd,
|
||||
reasoning_effort: None,
|
||||
initial_messages: None,
|
||||
network_proxy: None,
|
||||
rollout_path: None,
|
||||
};
|
||||
|
||||
let summary_entries = config_summary_entries(&config, &session_configured_event);
|
||||
let sandbox_summary = summary_entries
|
||||
.iter()
|
||||
.find_map(|(key, value)| (*key == "sandbox").then_some(value))
|
||||
.expect("sandbox summary entry");
|
||||
assert!(
|
||||
sandbox_summary.starts_with("workspace-write [workdir, ")
|
||||
&& sandbox_summary.contains(&expected_extra_root_name),
|
||||
"expected runtime workspace root in sandbox summary: {summary_entries:?}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -223,6 +223,7 @@ impl EventProcessorWithJsonOutput {
|
||||
arguments,
|
||||
result: result.map(|result| McpToolCallItemResult {
|
||||
content: result.content,
|
||||
meta: result.meta,
|
||||
structured_content: result.structured_content,
|
||||
}),
|
||||
error: error.map(|error| McpToolCallItemError {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use super::*;
|
||||
use pretty_assertions::assert_eq;
|
||||
use serde_json::json;
|
||||
use tempfile::tempdir;
|
||||
|
||||
#[test]
|
||||
@@ -57,3 +58,54 @@ fn failed_turn_does_not_overwrite_output_last_message_file() {
|
||||
"keep existing contents"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mcp_tool_call_result_preserves_meta_in_jsonl_event() {
|
||||
let mut processor = EventProcessorWithJsonOutput::new(/*last_message_path*/ None);
|
||||
|
||||
let collected = processor.collect_thread_events(ServerNotification::ItemCompleted(
|
||||
codex_app_server_protocol::ItemCompletedNotification {
|
||||
item: ThreadItem::McpToolCall {
|
||||
id: "mcp-1".to_string(),
|
||||
server: "search service".to_string(),
|
||||
tool: "web_run".to_string(),
|
||||
status: McpToolCallStatus::Completed,
|
||||
arguments: json!({"search_query": [{"q": "OpenAI Codex CLI documentation"}]}),
|
||||
mcp_app_resource_uri: None,
|
||||
plugin_id: None,
|
||||
result: Some(Box::new(codex_app_server_protocol::McpToolCallResult {
|
||||
content: vec![json!({"type": "text", "text": "search result"})],
|
||||
structured_content: None,
|
||||
meta: Some(json!({"raw_messages": [{"ref_id": "turn0search0"}]})),
|
||||
})),
|
||||
error: None,
|
||||
duration_ms: Some(42),
|
||||
},
|
||||
thread_id: "thread-1".to_string(),
|
||||
turn_id: "turn-1".to_string(),
|
||||
completed_at_ms: 0,
|
||||
},
|
||||
));
|
||||
|
||||
assert_eq!(collected.status, CodexStatus::Running);
|
||||
assert_eq!(collected.events.len(), 1);
|
||||
|
||||
let ThreadEvent::ItemCompleted(ItemCompletedEvent { item }) = &collected.events[0] else {
|
||||
panic!("expected item.completed event");
|
||||
};
|
||||
let ThreadItemDetails::McpToolCall(item) = &item.details else {
|
||||
panic!("expected MCP tool call item");
|
||||
};
|
||||
let result = item.result.as_ref().expect("expected MCP tool result");
|
||||
assert_eq!(
|
||||
result.meta,
|
||||
Some(json!({"raw_messages": [{"ref_id": "turn0search0"}]}))
|
||||
);
|
||||
|
||||
let serialized = serde_json::to_value(&collected.events[0]).expect("serialize event");
|
||||
assert_eq!(
|
||||
serialized["item"]["result"]["_meta"],
|
||||
json!({"raw_messages": [{"ref_id": "turn0search0"}]})
|
||||
);
|
||||
assert!(serialized["item"]["result"].get("meta").is_none());
|
||||
}
|
||||
|
||||
@@ -266,6 +266,9 @@ pub struct McpToolCallItemResult {
|
||||
// representations). Using `JsonValue` keeps the payload wire-shaped and
|
||||
// easy to export.
|
||||
pub content: Vec<JsonValue>,
|
||||
#[serde(rename = "_meta", skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
pub meta: Option<JsonValue>,
|
||||
pub structured_content: Option<JsonValue>,
|
||||
}
|
||||
|
||||
|
||||
+138
-74
@@ -15,7 +15,6 @@ pub use cli::Command;
|
||||
pub use cli::ReviewArgs;
|
||||
use codex_app_server_client::DEFAULT_IN_PROCESS_CHANNEL_CAPACITY;
|
||||
use codex_app_server_client::EnvironmentManager;
|
||||
use codex_app_server_client::EnvironmentManagerArgs;
|
||||
use codex_app_server_client::ExecServerRuntimePaths;
|
||||
use codex_app_server_client::InProcessAppServerClient;
|
||||
use codex_app_server_client::InProcessClientStartArgs;
|
||||
@@ -25,8 +24,6 @@ use codex_app_server_protocol::ConfigWarningNotification;
|
||||
use codex_app_server_protocol::JSONRPCErrorError;
|
||||
use codex_app_server_protocol::McpServerElicitationAction;
|
||||
use codex_app_server_protocol::McpServerElicitationRequestResponse;
|
||||
use codex_app_server_protocol::PermissionProfileModificationParams;
|
||||
use codex_app_server_protocol::PermissionProfileSelectionParams;
|
||||
use codex_app_server_protocol::RequestId;
|
||||
use codex_app_server_protocol::ReviewStartParams;
|
||||
use codex_app_server_protocol::ReviewStartResponse;
|
||||
@@ -42,6 +39,7 @@ use codex_app_server_protocol::ThreadReadResponse;
|
||||
use codex_app_server_protocol::ThreadResumeParams;
|
||||
use codex_app_server_protocol::ThreadResumeResponse;
|
||||
use codex_app_server_protocol::ThreadSortKey;
|
||||
use codex_app_server_protocol::ThreadSource;
|
||||
use codex_app_server_protocol::ThreadSourceKind;
|
||||
use codex_app_server_protocol::ThreadStartParams;
|
||||
use codex_app_server_protocol::ThreadStartResponse;
|
||||
@@ -55,6 +53,7 @@ use codex_app_server_protocol::TurnStartedNotification;
|
||||
use codex_arg0::Arg0DispatchPaths;
|
||||
use codex_cloud_requirements::cloud_requirements_loader_for_storage;
|
||||
use codex_config::ConfigLoadError;
|
||||
use codex_config::ConfigLoadOptions;
|
||||
use codex_config::LoaderOverrides;
|
||||
use codex_config::format_config_error_with_source;
|
||||
use codex_core::StateDbHandle;
|
||||
@@ -63,8 +62,9 @@ use codex_core::config::Config;
|
||||
use codex_core::config::ConfigBuilder;
|
||||
use codex_core::config::ConfigOverrides;
|
||||
use codex_core::config::find_codex_home;
|
||||
use codex_core::config::load_config_as_toml_with_cli_and_loader_overrides;
|
||||
use codex_core::config::load_config_as_toml_with_cli_and_load_options;
|
||||
use codex_core::config::resolve_oss_provider;
|
||||
use codex_core::config::resolve_profile_v2_config_path;
|
||||
use codex_core::find_thread_meta_by_name_str;
|
||||
use codex_core::format_exec_policy_error_with_source;
|
||||
use codex_core::path_utils;
|
||||
@@ -80,9 +80,9 @@ use codex_otel::set_parent_from_context;
|
||||
use codex_otel::traceparent_context_from_env;
|
||||
use codex_protocol::SessionId;
|
||||
use codex_protocol::ThreadId;
|
||||
use codex_protocol::config_types::ApprovalsReviewer;
|
||||
use codex_protocol::config_types::SandboxMode;
|
||||
use codex_protocol::models::ActivePermissionProfile;
|
||||
use codex_protocol::models::ActivePermissionProfileModification;
|
||||
use codex_protocol::models::PermissionProfile;
|
||||
use codex_protocol::protocol::AskForApproval;
|
||||
use codex_protocol::protocol::ReviewRequest;
|
||||
@@ -135,7 +135,7 @@ pub use exec_events::TurnStartedEvent;
|
||||
pub use exec_events::Usage;
|
||||
pub use exec_events::WebSearchItem;
|
||||
use serde_json::Value;
|
||||
use std::collections::HashMap;
|
||||
use std::future::Future;
|
||||
use std::io::IsTerminal;
|
||||
use std::io::Read;
|
||||
use std::path::Path;
|
||||
@@ -243,6 +243,7 @@ pub async fn run_main(cli: Cli, arg0_paths: Arg0DispatchPaths) -> anyhow::Result
|
||||
|
||||
let Cli {
|
||||
command,
|
||||
strict_config,
|
||||
shared,
|
||||
skip_git_repo_check,
|
||||
ephemeral,
|
||||
@@ -262,9 +263,10 @@ pub async fn run_main(cli: Cli, arg0_paths: Arg0DispatchPaths) -> anyhow::Result
|
||||
model: model_cli_arg,
|
||||
oss,
|
||||
oss_provider,
|
||||
config_profile,
|
||||
config_profile_v2,
|
||||
sandbox_mode: sandbox_mode_cli_arg,
|
||||
dangerously_bypass_approvals_and_sandbox,
|
||||
bypass_hook_trust,
|
||||
cwd,
|
||||
add_dir,
|
||||
} = shared;
|
||||
@@ -317,19 +319,25 @@ pub async fn run_main(cli: Cli, arg0_paths: Arg0DispatchPaths) -> anyhow::Result
|
||||
std::process::exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
#[allow(clippy::print_stderr)]
|
||||
let user_config_path = config_profile_v2
|
||||
.as_ref()
|
||||
.map(|profile_v2| resolve_profile_v2_config_path(&codex_home, profile_v2));
|
||||
let loader_overrides = LoaderOverrides {
|
||||
user_config_path,
|
||||
user_config_profile: config_profile_v2,
|
||||
ignore_user_config,
|
||||
ignore_user_and_project_exec_policy_rules: ignore_rules,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let config_toml = match load_config_as_toml_with_cli_and_loader_overrides(
|
||||
let config_toml = match load_config_as_toml_with_cli_and_load_options(
|
||||
&codex_home,
|
||||
Some(&config_cwd),
|
||||
cli_kv_overrides.clone(),
|
||||
loader_overrides.clone(),
|
||||
ConfigLoadOptions {
|
||||
loader_overrides: loader_overrides.clone(),
|
||||
strict_config,
|
||||
},
|
||||
)
|
||||
.await
|
||||
{
|
||||
@@ -368,11 +376,7 @@ pub async fn run_main(cli: Cli, arg0_paths: Arg0DispatchPaths) -> anyhow::Result
|
||||
let run_cloud_requirements = cloud_requirements.clone();
|
||||
|
||||
let model_provider = if oss {
|
||||
let resolved = resolve_oss_provider(
|
||||
oss_provider.as_deref(),
|
||||
&config_toml,
|
||||
config_profile.clone(),
|
||||
);
|
||||
let resolved = resolve_oss_provider(oss_provider.as_deref(), &config_toml);
|
||||
|
||||
if let Some(provider) = resolved {
|
||||
Some(provider)
|
||||
@@ -397,42 +401,51 @@ pub async fn run_main(cli: Cli, arg0_paths: Arg0DispatchPaths) -> anyhow::Result
|
||||
None // No model specified, will use the default.
|
||||
};
|
||||
|
||||
// Load configuration and determine approval policy
|
||||
let overrides = ConfigOverrides {
|
||||
model,
|
||||
review_model: None,
|
||||
config_profile,
|
||||
// Default to never ask for approvals in headless mode. Feature flags can override.
|
||||
// Default to never ask for approvals in headless mode. Rebuild below if
|
||||
// the fully resolved reviewer is AutoReview.
|
||||
approval_policy: Some(AskForApproval::Never),
|
||||
approvals_reviewer: None,
|
||||
sandbox_mode,
|
||||
permission_profile: None,
|
||||
default_permissions: None,
|
||||
cwd: resolved_cwd,
|
||||
workspace_roots: None,
|
||||
model_provider: model_provider.clone(),
|
||||
service_tier: None,
|
||||
codex_self_exe: arg0_paths.codex_self_exe.clone(),
|
||||
codex_linux_sandbox_exe: arg0_paths.codex_linux_sandbox_exe.clone(),
|
||||
main_execve_wrapper_exe: arg0_paths.main_execve_wrapper_exe.clone(),
|
||||
zsh_path: None,
|
||||
default_zsh_path: None,
|
||||
base_instructions: None,
|
||||
developer_instructions: None,
|
||||
personality: None,
|
||||
compact_prompt: None,
|
||||
include_apply_patch_tool: None,
|
||||
show_raw_agent_reasoning: oss.then_some(true),
|
||||
tools_web_search_request: None,
|
||||
ephemeral: ephemeral.then_some(true),
|
||||
bypass_hook_trust: bypass_hook_trust.then_some(true),
|
||||
additional_writable_roots: add_dir,
|
||||
};
|
||||
|
||||
let config = ConfigBuilder::default()
|
||||
.cli_overrides(cli_kv_overrides)
|
||||
.harness_overrides(overrides)
|
||||
.loader_overrides(loader_overrides)
|
||||
.cloud_requirements(cloud_requirements)
|
||||
.build()
|
||||
.await?;
|
||||
let build_config = |overrides| {
|
||||
ConfigBuilder::default()
|
||||
.codex_home(codex_home.to_path_buf())
|
||||
.cli_overrides(cli_kv_overrides.clone())
|
||||
.harness_overrides(overrides)
|
||||
.loader_overrides(loader_overrides.clone())
|
||||
.strict_config(strict_config)
|
||||
.cloud_requirements(cloud_requirements.clone())
|
||||
.build()
|
||||
};
|
||||
let config = build_exec_config(
|
||||
overrides,
|
||||
dangerously_bypass_approvals_and_sandbox || removed_full_auto,
|
||||
build_config,
|
||||
)
|
||||
.await?;
|
||||
|
||||
#[allow(clippy::print_stderr)]
|
||||
match check_execpolicy_for_warnings(&config.config_layer_stack).await {
|
||||
@@ -479,6 +492,8 @@ pub async fn run_main(cli: Cli, arg0_paths: Arg0DispatchPaths) -> anyhow::Result
|
||||
None
|
||||
}
|
||||
};
|
||||
codex_core::otel_init::record_process_start(otel.as_ref(), "codex_exec");
|
||||
codex_core::otel_init::install_sqlite_telemetry(otel.as_ref(), "codex_exec");
|
||||
|
||||
let otel_logger_layer = otel.as_ref().and_then(|o| o.logger_layer());
|
||||
|
||||
@@ -509,18 +524,23 @@ pub async fn run_main(cli: Cli, arg0_paths: Arg0DispatchPaths) -> anyhow::Result
|
||||
arg0_paths.codex_linux_sandbox_exe.clone(),
|
||||
)?;
|
||||
let state_db = codex_core::init_state_db(&config).await;
|
||||
let environment_manager = if run_loader_overrides.ignore_user_config {
|
||||
EnvironmentManager::from_env(Some(local_runtime_paths)).await?
|
||||
} else {
|
||||
EnvironmentManager::from_codex_home(config.codex_home.clone(), Some(local_runtime_paths))
|
||||
.await?
|
||||
};
|
||||
let in_process_start_args = InProcessClientStartArgs {
|
||||
arg0_paths,
|
||||
config: std::sync::Arc::new(config.clone()),
|
||||
cli_overrides: run_cli_overrides,
|
||||
loader_overrides: run_loader_overrides,
|
||||
strict_config,
|
||||
cloud_requirements: run_cloud_requirements,
|
||||
feedback: CodexFeedback::new(),
|
||||
log_db: None,
|
||||
state_db: state_db.clone(),
|
||||
environment_manager: std::sync::Arc::new(
|
||||
EnvironmentManager::new(EnvironmentManagerArgs::new(local_runtime_paths)).await,
|
||||
),
|
||||
environment_manager: std::sync::Arc::new(environment_manager),
|
||||
config_warnings,
|
||||
session_source: SessionSource::Exec,
|
||||
enable_codex_api_key_env: true,
|
||||
@@ -551,6 +571,41 @@ pub async fn run_main(cli: Cli, arg0_paths: Arg0DispatchPaths) -> anyhow::Result
|
||||
.await
|
||||
}
|
||||
|
||||
async fn build_exec_config<BuildConfig, BuildFuture>(
|
||||
overrides: ConfigOverrides,
|
||||
preserve_headless_approval_policy: bool,
|
||||
build_config: BuildConfig,
|
||||
) -> std::io::Result<Config>
|
||||
where
|
||||
BuildConfig: Fn(ConfigOverrides) -> BuildFuture,
|
||||
BuildFuture: Future<Output = std::io::Result<Config>>,
|
||||
{
|
||||
let build_without_headless_approval_policy = || {
|
||||
build_config(ConfigOverrides {
|
||||
approval_policy: None,
|
||||
..overrides.clone()
|
||||
})
|
||||
};
|
||||
match build_config(overrides.clone()).await {
|
||||
Ok(config)
|
||||
if config.approvals_reviewer == ApprovalsReviewer::AutoReview
|
||||
&& !preserve_headless_approval_policy =>
|
||||
{
|
||||
build_without_headless_approval_policy().await
|
||||
}
|
||||
Ok(config) => Ok(config),
|
||||
Err(headless_error) if !preserve_headless_approval_policy => {
|
||||
match build_without_headless_approval_policy().await {
|
||||
Ok(config) if config.approvals_reviewer == ApprovalsReviewer::AutoReview => {
|
||||
Ok(config)
|
||||
}
|
||||
Ok(_) | Err(_) => Err(headless_error),
|
||||
}
|
||||
}
|
||||
Err(headless_error) => Err(headless_error),
|
||||
}
|
||||
}
|
||||
|
||||
async fn run_exec_session(args: ExecRunArgs) -> anyhow::Result<()> {
|
||||
let ExecRunArgs {
|
||||
in_process_start_args,
|
||||
@@ -621,7 +676,7 @@ async fn run_exec_session(args: ExecRunArgs) -> anyhow::Result<()> {
|
||||
let mut items: Vec<UserInput> = imgs
|
||||
.into_iter()
|
||||
.chain(args.images.iter().cloned())
|
||||
.map(|path| UserInput::LocalImage { path })
|
||||
.map(|path| UserInput::LocalImage { path, detail: None })
|
||||
.collect();
|
||||
items.push(UserInput::Text {
|
||||
text: prompt_text.clone(),
|
||||
@@ -641,7 +696,7 @@ async fn run_exec_session(args: ExecRunArgs) -> anyhow::Result<()> {
|
||||
let prompt_text = resolve_root_prompt(root_prompt);
|
||||
let mut items: Vec<UserInput> = imgs
|
||||
.into_iter()
|
||||
.map(|path| UserInput::LocalImage { path })
|
||||
.map(|path| UserInput::LocalImage { path, detail: None })
|
||||
.collect();
|
||||
items.push(UserInput::Text {
|
||||
text: prompt_text.clone(),
|
||||
@@ -743,7 +798,7 @@ async fn run_exec_session(args: ExecRunArgs) -> anyhow::Result<()> {
|
||||
event_processor.print_config_summary(&config, &prompt_summary, &session_configured);
|
||||
if !json_mode
|
||||
&& let Some(message) =
|
||||
codex_core::config::system_bwrap_warning(config.permissions.permission_profile.get())
|
||||
codex_core::config::system_bwrap_warning(config.permissions.permission_profile())
|
||||
{
|
||||
event_processor.process_warning(message);
|
||||
}
|
||||
@@ -769,10 +824,13 @@ async fn run_exec_session(args: ExecRunArgs) -> anyhow::Result<()> {
|
||||
request_id: request_ids.next(),
|
||||
params: TurnStartParams {
|
||||
thread_id: primary_thread_id_for_span.clone(),
|
||||
client_user_message_id: None,
|
||||
input: items.into_iter().map(Into::into).collect(),
|
||||
responsesapi_client_metadata: None,
|
||||
additional_context: None,
|
||||
environments: None,
|
||||
cwd: Some(default_cwd),
|
||||
runtime_workspace_roots: None,
|
||||
approval_policy: Some(default_approval_policy.into()),
|
||||
approvals_reviewer: None,
|
||||
sandbox_policy: None,
|
||||
@@ -936,7 +994,7 @@ fn thread_start_params_from_config(config: &Config) -> ThreadStartParams {
|
||||
let permissions = permissions_selection_from_config(config);
|
||||
let sandbox = permissions.is_none().then(|| {
|
||||
sandbox_mode_from_permission_profile(
|
||||
&config.permissions.permission_profile(),
|
||||
&config.permissions.effective_permission_profile(),
|
||||
config.cwd.as_path(),
|
||||
)
|
||||
});
|
||||
@@ -944,12 +1002,20 @@ fn thread_start_params_from_config(config: &Config) -> ThreadStartParams {
|
||||
model: config.model.clone(),
|
||||
model_provider: Some(config.model_provider_id.clone()),
|
||||
cwd: Some(config.cwd.to_string_lossy().to_string()),
|
||||
runtime_workspace_roots: Some(
|
||||
config
|
||||
.workspace_roots
|
||||
.iter()
|
||||
.map(AbsolutePathBuf::to_path_buf)
|
||||
.collect(),
|
||||
),
|
||||
approval_policy: Some(config.permissions.approval_policy.value().into()),
|
||||
approvals_reviewer: approvals_reviewer_override_from_config(config),
|
||||
sandbox: sandbox.flatten(),
|
||||
permissions,
|
||||
config: config_request_overrides_from_config(config),
|
||||
config: None,
|
||||
ephemeral: Some(config.ephemeral),
|
||||
thread_source: Some(ThreadSource::User),
|
||||
..ThreadStartParams::default()
|
||||
}
|
||||
}
|
||||
@@ -958,7 +1024,7 @@ fn thread_resume_params_from_config(config: &Config, thread_id: String) -> Threa
|
||||
let permissions = permissions_selection_from_config(config);
|
||||
let sandbox = permissions.is_none().then(|| {
|
||||
sandbox_mode_from_permission_profile(
|
||||
&config.permissions.permission_profile(),
|
||||
&config.permissions.effective_permission_profile(),
|
||||
config.cwd.as_path(),
|
||||
)
|
||||
});
|
||||
@@ -967,38 +1033,31 @@ fn thread_resume_params_from_config(config: &Config, thread_id: String) -> Threa
|
||||
model: config.model.clone(),
|
||||
model_provider: Some(config.model_provider_id.clone()),
|
||||
cwd: Some(config.cwd.to_string_lossy().to_string()),
|
||||
runtime_workspace_roots: Some(
|
||||
config
|
||||
.workspace_roots
|
||||
.iter()
|
||||
.map(AbsolutePathBuf::to_path_buf)
|
||||
.collect(),
|
||||
),
|
||||
approval_policy: Some(config.permissions.approval_policy.value().into()),
|
||||
approvals_reviewer: approvals_reviewer_override_from_config(config),
|
||||
sandbox: sandbox.flatten(),
|
||||
permissions,
|
||||
config: config_request_overrides_from_config(config),
|
||||
config: None,
|
||||
..ThreadResumeParams::default()
|
||||
}
|
||||
}
|
||||
|
||||
fn permissions_selection_from_config(config: &Config) -> Option<PermissionProfileSelectionParams> {
|
||||
fn permissions_selection_from_config(config: &Config) -> Option<String> {
|
||||
config
|
||||
.permissions
|
||||
.active_permission_profile()
|
||||
.map(permissions_selection_from_active_profile)
|
||||
.map(permission_profile_id_from_active_profile)
|
||||
}
|
||||
|
||||
fn permissions_selection_from_active_profile(
|
||||
active: ActivePermissionProfile,
|
||||
) -> PermissionProfileSelectionParams {
|
||||
let modifications = active
|
||||
.modifications
|
||||
.into_iter()
|
||||
.map(|modification| match modification {
|
||||
ActivePermissionProfileModification::AdditionalWritableRoot { path } => {
|
||||
PermissionProfileModificationParams::AdditionalWritableRoot { path }
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
PermissionProfileSelectionParams::Profile {
|
||||
id: active.id,
|
||||
modifications: (!modifications.is_empty()).then_some(modifications),
|
||||
}
|
||||
fn permission_profile_id_from_active_profile(active: ActivePermissionProfile) -> String {
|
||||
active.id
|
||||
}
|
||||
|
||||
fn sandbox_mode_from_permission_profile(
|
||||
@@ -1026,13 +1085,6 @@ fn sandbox_mode_from_permission_profile(
|
||||
}
|
||||
}
|
||||
|
||||
fn config_request_overrides_from_config(config: &Config) -> Option<HashMap<String, Value>> {
|
||||
config
|
||||
.active_profile
|
||||
.as_ref()
|
||||
.map(|profile| HashMap::from([("profile".to_string(), Value::String(profile.clone()))]))
|
||||
}
|
||||
|
||||
fn approvals_reviewer_override_from_config(
|
||||
config: &Config,
|
||||
) -> Option<codex_app_server_protocol::ApprovalsReviewer> {
|
||||
@@ -1063,6 +1115,8 @@ fn session_configured_from_thread_start_response(
|
||||
session_configured_from_thread_response(
|
||||
&response.thread.session_id,
|
||||
&response.thread.id,
|
||||
response.thread.parent_thread_id.as_deref(),
|
||||
response.thread.thread_source.map(Into::into),
|
||||
response.thread.name.clone(),
|
||||
response.thread.path.clone(),
|
||||
response.model.clone(),
|
||||
@@ -1070,11 +1124,7 @@ fn session_configured_from_thread_start_response(
|
||||
response.service_tier.clone(),
|
||||
response.approval_policy.to_core(),
|
||||
response.approvals_reviewer.to_core(),
|
||||
response
|
||||
.permission_profile
|
||||
.clone()
|
||||
.map(Into::into)
|
||||
.unwrap_or_else(|| config.permissions.permission_profile()),
|
||||
config.permissions.effective_permission_profile(),
|
||||
response.active_permission_profile.clone().map(Into::into),
|
||||
response.cwd.clone(),
|
||||
response.reasoning_effort,
|
||||
@@ -1088,6 +1138,8 @@ fn session_configured_from_thread_resume_response(
|
||||
session_configured_from_thread_response(
|
||||
&response.thread.session_id,
|
||||
&response.thread.id,
|
||||
response.thread.parent_thread_id.as_deref(),
|
||||
response.thread.thread_source.map(Into::into),
|
||||
response.thread.name.clone(),
|
||||
response.thread.path.clone(),
|
||||
response.model.clone(),
|
||||
@@ -1095,11 +1147,7 @@ fn session_configured_from_thread_resume_response(
|
||||
response.service_tier.clone(),
|
||||
response.approval_policy.to_core(),
|
||||
response.approvals_reviewer.to_core(),
|
||||
response
|
||||
.permission_profile
|
||||
.clone()
|
||||
.map(Into::into)
|
||||
.unwrap_or_else(|| config.permissions.permission_profile()),
|
||||
config.permissions.effective_permission_profile(),
|
||||
response.active_permission_profile.clone().map(Into::into),
|
||||
response.cwd.clone(),
|
||||
response.reasoning_effort,
|
||||
@@ -1122,6 +1170,8 @@ fn review_target_to_api(target: ReviewTarget) -> ApiReviewTarget {
|
||||
fn session_configured_from_thread_response(
|
||||
session_id: &str,
|
||||
thread_id: &str,
|
||||
parent_thread_id: Option<&str>,
|
||||
thread_source: Option<codex_protocol::protocol::ThreadSource>,
|
||||
thread_name: Option<String>,
|
||||
rollout_path: Option<PathBuf>,
|
||||
model: String,
|
||||
@@ -1138,12 +1188,17 @@ fn session_configured_from_thread_response(
|
||||
.map_err(|err| format!("session id `{session_id}` is invalid: {err}"))?;
|
||||
let thread_id = ThreadId::from_string(thread_id)
|
||||
.map_err(|err| format!("thread id `{thread_id}` is invalid: {err}"))?;
|
||||
let parent_thread_id = parent_thread_id
|
||||
.map(ThreadId::from_string)
|
||||
.transpose()
|
||||
.map_err(|err| format!("parent thread id is invalid: {err}"))?;
|
||||
|
||||
Ok(SessionConfiguredEvent {
|
||||
session_id,
|
||||
thread_id,
|
||||
forked_from_id: None,
|
||||
thread_source: None,
|
||||
parent_thread_id,
|
||||
thread_source,
|
||||
thread_name,
|
||||
model,
|
||||
model_provider_id,
|
||||
@@ -1604,6 +1659,15 @@ async fn handle_server_request(
|
||||
)
|
||||
.await
|
||||
}
|
||||
ServerRequest::AttestationGenerate { request_id, .. } => {
|
||||
reject_server_request(
|
||||
client,
|
||||
request_id,
|
||||
&method,
|
||||
"attestation generation is not supported in exec mode".to_string(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
ServerRequest::ApplyPatchApproval { request_id, params } => {
|
||||
reject_server_request(
|
||||
client,
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
use super::*;
|
||||
use codex_otel::set_parent_from_w3c_trace_context;
|
||||
use codex_protocol::config_types::ApprovalsReviewer;
|
||||
use codex_protocol::models::ActivePermissionProfile;
|
||||
use codex_protocol::models::BUILT_IN_PERMISSION_PROFILE_WORKSPACE;
|
||||
use codex_utils_absolute_path::test_support::PathBufExt;
|
||||
use codex_utils_absolute_path::test_support::test_path_buf;
|
||||
use opentelemetry::trace::TraceContextExt;
|
||||
@@ -305,6 +307,7 @@ fn turn_items_for_thread_returns_matching_turn_items() {
|
||||
id: "thread-1".to_string(),
|
||||
session_id: "thread-1".to_string(),
|
||||
forked_from_id: None,
|
||||
parent_thread_id: None,
|
||||
preview: String::new(),
|
||||
ephemeral: false,
|
||||
model_provider: "openai".to_string(),
|
||||
@@ -409,6 +412,7 @@ async fn thread_start_params_include_review_policy_when_review_policy_is_manual_
|
||||
let codex_home = tempdir().expect("create temp codex home");
|
||||
let cwd = tempdir().expect("create temp cwd");
|
||||
let config = ConfigBuilder::default()
|
||||
.loader_overrides(LoaderOverrides::without_managed_config_for_tests())
|
||||
.codex_home(codex_home.path().to_path_buf())
|
||||
.harness_overrides(ConfigOverrides {
|
||||
approvals_reviewer: Some(ApprovalsReviewer::User),
|
||||
@@ -455,6 +459,120 @@ async fn thread_start_params_include_review_policy_when_auto_review_is_enabled()
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn build_exec_config_retries_without_invalid_headless_policy_for_auto_review() {
|
||||
let codex_home = tempdir().expect("create temp codex home");
|
||||
let cwd = tempdir().expect("create temp cwd");
|
||||
std::fs::write(
|
||||
codex_home.path().join("config.toml"),
|
||||
r#"
|
||||
approval_policy = "on-request"
|
||||
approvals_reviewer = "auto_review"
|
||||
"#,
|
||||
)
|
||||
.expect("write config");
|
||||
let requirements_path = codex_home.path().join("requirements.toml");
|
||||
std::fs::write(
|
||||
&requirements_path,
|
||||
r#"
|
||||
allowed_approval_policies = ["never", "on-request"]
|
||||
allowed_sandbox_modes = ["read-only", "workspace-write"]
|
||||
"#,
|
||||
)
|
||||
.expect("write requirements");
|
||||
let mut loader_overrides = LoaderOverrides::without_managed_config_for_tests();
|
||||
loader_overrides.system_requirements_path = Some(requirements_path);
|
||||
let overrides = ConfigOverrides {
|
||||
cwd: Some(cwd.path().to_path_buf()),
|
||||
approval_policy: Some(AskForApproval::Never),
|
||||
sandbox_mode: Some(SandboxMode::DangerFullAccess),
|
||||
..Default::default()
|
||||
};
|
||||
let build_config = |overrides| {
|
||||
ConfigBuilder::default()
|
||||
.codex_home(codex_home.path().to_path_buf())
|
||||
.loader_overrides(loader_overrides.clone())
|
||||
.harness_overrides(overrides)
|
||||
.build()
|
||||
};
|
||||
|
||||
let error = build_config(overrides.clone())
|
||||
.await
|
||||
.expect_err("synthetic headless approval policy should fail");
|
||||
assert!(
|
||||
error
|
||||
.to_string()
|
||||
.contains("`approval_policy = \"never\"` cannot be used")
|
||||
);
|
||||
|
||||
let config = build_exec_config(
|
||||
overrides,
|
||||
/*preserve_headless_approval_policy*/ false,
|
||||
build_config,
|
||||
)
|
||||
.await
|
||||
.expect("auto-review config should retry without the synthetic approval policy");
|
||||
|
||||
assert_eq!(
|
||||
config.permissions.approval_policy.value(),
|
||||
AskForApproval::OnRequest
|
||||
);
|
||||
assert_eq!(config.approvals_reviewer, ApprovalsReviewer::AutoReview);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn build_exec_config_preserves_headless_error_when_retry_fails() {
|
||||
let overrides = ConfigOverrides {
|
||||
approval_policy: Some(AskForApproval::Never),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let error = build_exec_config(
|
||||
overrides,
|
||||
/*preserve_headless_approval_policy*/ false,
|
||||
|overrides| async move {
|
||||
let message = if overrides.approval_policy == Some(AskForApproval::Never) {
|
||||
"headless error"
|
||||
} else {
|
||||
"retry error"
|
||||
};
|
||||
Err(std::io::Error::other(message))
|
||||
},
|
||||
)
|
||||
.await
|
||||
.expect_err("failed speculative retry should preserve the original error");
|
||||
|
||||
assert_eq!(error.to_string(), "headless error");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn thread_start_params_include_user_thread_source() {
|
||||
let codex_home = tempdir().expect("create temp codex home");
|
||||
let cwd = tempdir().expect("create temp cwd");
|
||||
let config = ConfigBuilder::default()
|
||||
.codex_home(codex_home.path().to_path_buf())
|
||||
.fallback_cwd(Some(cwd.path().to_path_buf()))
|
||||
.build()
|
||||
.await
|
||||
.expect("build config");
|
||||
|
||||
let params = thread_start_params_from_config(&config);
|
||||
|
||||
assert_eq!(
|
||||
params.thread_source,
|
||||
Some(codex_app_server_protocol::ThreadSource::User)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn active_profile_selection_uses_profile_id_only() {
|
||||
let selection = permission_profile_id_from_active_profile(ActivePermissionProfile::new(
|
||||
BUILT_IN_PERMISSION_PROFILE_WORKSPACE,
|
||||
));
|
||||
|
||||
assert_eq!(selection, BUILT_IN_PERMISSION_PROFILE_WORKSPACE.to_string());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn thread_lifecycle_params_include_legacy_sandbox_when_no_active_profile() {
|
||||
let codex_home = tempdir().expect("create temp codex home");
|
||||
@@ -513,7 +631,7 @@ async fn session_configured_from_thread_response_uses_review_policy_from_respons
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn session_configured_from_thread_response_uses_permission_profile_from_response() {
|
||||
async fn session_configured_from_thread_response_uses_permission_profile_from_config() {
|
||||
let codex_home = tempdir().expect("create temp codex home");
|
||||
let cwd = tempdir().expect("create temp cwd");
|
||||
let config = ConfigBuilder::default()
|
||||
@@ -522,13 +640,56 @@ async fn session_configured_from_thread_response_uses_permission_profile_from_re
|
||||
.build()
|
||||
.await
|
||||
.expect("build config");
|
||||
let mut response = sample_thread_start_response();
|
||||
response.permission_profile = Some(PermissionProfile::Disabled.into());
|
||||
let response = sample_thread_start_response();
|
||||
|
||||
let event = session_configured_from_thread_start_response(&response, &config)
|
||||
.expect("build bootstrap session configured event");
|
||||
|
||||
assert_eq!(event.permission_profile, PermissionProfile::Disabled);
|
||||
assert_eq!(
|
||||
event.permission_profile,
|
||||
config.permissions.effective_permission_profile()
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn session_configured_from_thread_response_preserves_thread_source() {
|
||||
let codex_home = tempdir().expect("create temp codex home");
|
||||
let cwd = tempdir().expect("create temp cwd");
|
||||
let config = ConfigBuilder::default()
|
||||
.codex_home(codex_home.path().to_path_buf())
|
||||
.fallback_cwd(Some(cwd.path().to_path_buf()))
|
||||
.build()
|
||||
.await
|
||||
.expect("build config");
|
||||
let response = sample_thread_start_response();
|
||||
|
||||
let event = session_configured_from_thread_start_response(&response, &config)
|
||||
.expect("build bootstrap session configured event");
|
||||
|
||||
assert_eq!(
|
||||
event.thread_source,
|
||||
Some(codex_protocol::protocol::ThreadSource::User)
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn session_configured_from_thread_response_preserves_parent_thread_id() {
|
||||
let codex_home = tempdir().expect("create temp codex home");
|
||||
let cwd = tempdir().expect("create temp cwd");
|
||||
let config = ConfigBuilder::default()
|
||||
.codex_home(codex_home.path().to_path_buf())
|
||||
.fallback_cwd(Some(cwd.path().to_path_buf()))
|
||||
.build()
|
||||
.await
|
||||
.expect("build config");
|
||||
let parent_thread_id = ThreadId::new();
|
||||
let mut response = sample_thread_start_response();
|
||||
response.thread.parent_thread_id = Some(parent_thread_id.to_string());
|
||||
|
||||
let event = session_configured_from_thread_start_response(&response, &config)
|
||||
.expect("build bootstrap session configured event");
|
||||
|
||||
assert_eq!(event.parent_thread_id, Some(parent_thread_id));
|
||||
}
|
||||
|
||||
fn sample_thread_start_response() -> ThreadStartResponse {
|
||||
@@ -537,6 +698,7 @@ fn sample_thread_start_response() -> ThreadStartResponse {
|
||||
id: "67e55044-10b1-426f-9247-bb680e5fe0c8".to_string(),
|
||||
session_id: "67e55044-10b1-426f-9247-bb680e5fe0c7".to_string(),
|
||||
forked_from_id: None,
|
||||
parent_thread_id: None,
|
||||
preview: String::new(),
|
||||
ephemeral: false,
|
||||
model_provider: "openai".to_string(),
|
||||
@@ -547,7 +709,7 @@ fn sample_thread_start_response() -> ThreadStartResponse {
|
||||
cwd: test_path_buf("/tmp").abs(),
|
||||
cli_version: "0.0.0".to_string(),
|
||||
source: codex_app_server_protocol::SessionSource::Cli,
|
||||
thread_source: None,
|
||||
thread_source: Some(codex_app_server_protocol::ThreadSource::User),
|
||||
agent_nickname: None,
|
||||
agent_role: None,
|
||||
git_info: None,
|
||||
@@ -558,6 +720,7 @@ fn sample_thread_start_response() -> ThreadStartResponse {
|
||||
model_provider: "openai".to_string(),
|
||||
service_tier: None,
|
||||
cwd: test_path_buf("/tmp").abs(),
|
||||
runtime_workspace_roots: Vec::new(),
|
||||
instruction_sources: Vec::new(),
|
||||
approval_policy: codex_app_server_protocol::AskForApproval::OnRequest,
|
||||
approvals_reviewer: codex_app_server_protocol::ApprovalsReviewer::AutoReview,
|
||||
@@ -567,7 +730,6 @@ fn sample_thread_start_response() -> ThreadStartResponse {
|
||||
exclude_tmpdir_env_var: false,
|
||||
exclude_slash_tmp: false,
|
||||
},
|
||||
permission_profile: None,
|
||||
active_permission_profile: None,
|
||||
reasoning_effort: None,
|
||||
}
|
||||
|
||||
@@ -32,8 +32,7 @@ fn main() -> anyhow::Result<()> {
|
||||
let mut inner = top_cli.inner;
|
||||
inner
|
||||
.config_overrides
|
||||
.raw_overrides
|
||||
.splice(0..0, top_cli.config_overrides.raw_overrides);
|
||||
.prepend_root_overrides(top_cli.config_overrides);
|
||||
|
||||
run_main(inner, arg0_paths).await?;
|
||||
Ok(())
|
||||
|
||||
@@ -7,6 +7,7 @@ fn top_cli_parses_resume_prompt_after_config_flag() {
|
||||
let cli = TopCli::parse_from([
|
||||
"codex-exec",
|
||||
"resume",
|
||||
"--strict-config",
|
||||
"--last",
|
||||
"--json",
|
||||
"--model",
|
||||
@@ -17,8 +18,12 @@ fn top_cli_parses_resume_prompt_after_config_flag() {
|
||||
"--skip-git-repo-check",
|
||||
PROMPT,
|
||||
]);
|
||||
let mut inner = cli.inner;
|
||||
inner
|
||||
.config_overrides
|
||||
.prepend_root_overrides(cli.config_overrides);
|
||||
|
||||
let Some(codex_exec::Command::Resume(args)) = cli.inner.command else {
|
||||
let Some(codex_exec::Command::Resume(args)) = inner.command.as_ref() else {
|
||||
panic!("expected resume command");
|
||||
};
|
||||
let effective_prompt = args.prompt.clone().or_else(|| {
|
||||
@@ -29,9 +34,10 @@ fn top_cli_parses_resume_prompt_after_config_flag() {
|
||||
}
|
||||
});
|
||||
assert_eq!(effective_prompt.as_deref(), Some(PROMPT));
|
||||
assert_eq!(cli.config_overrides.raw_overrides.len(), 1);
|
||||
assert_eq!(inner.config_overrides.raw_overrides.len(), 1);
|
||||
assert_eq!(
|
||||
cli.config_overrides.raw_overrides[0],
|
||||
inner.config_overrides.raw_overrides[0],
|
||||
"reasoning_level=xhigh"
|
||||
);
|
||||
assert!(inner.strict_config);
|
||||
}
|
||||
|
||||
@@ -111,6 +111,7 @@ fn session_configured_produces_thread_started_event() {
|
||||
session_id: SessionId::from(thread_id),
|
||||
thread_id,
|
||||
forked_from_id: None,
|
||||
parent_thread_id: None,
|
||||
thread_source: None,
|
||||
thread_name: None,
|
||||
model: "codex-mini-latest".to_string(),
|
||||
@@ -478,6 +479,7 @@ fn mcp_tool_call_begin_and_end_emit_item_events() {
|
||||
status: ApiMcpToolCallStatus::InProgress,
|
||||
arguments: json!({ "key": "value" }),
|
||||
mcp_app_resource_uri: None,
|
||||
plugin_id: None,
|
||||
result: None,
|
||||
error: None,
|
||||
duration_ms: None,
|
||||
@@ -495,6 +497,7 @@ fn mcp_tool_call_begin_and_end_emit_item_events() {
|
||||
status: ApiMcpToolCallStatus::Completed,
|
||||
arguments: json!({ "key": "value" }),
|
||||
mcp_app_resource_uri: None,
|
||||
plugin_id: None,
|
||||
result: Some(Box::new(McpToolCallResult {
|
||||
content: Vec::new(),
|
||||
structured_content: None,
|
||||
@@ -540,6 +543,7 @@ fn mcp_tool_call_begin_and_end_emit_item_events() {
|
||||
arguments: json!({ "key": "value" }),
|
||||
result: Some(McpToolCallItemResult {
|
||||
content: Vec::new(),
|
||||
meta: None,
|
||||
structured_content: None,
|
||||
}),
|
||||
error: None,
|
||||
@@ -565,6 +569,7 @@ fn mcp_tool_call_failure_sets_failed_status() {
|
||||
status: ApiMcpToolCallStatus::Failed,
|
||||
arguments: json!({ "param": 42 }),
|
||||
mcp_app_resource_uri: None,
|
||||
plugin_id: None,
|
||||
result: None,
|
||||
error: Some(McpToolCallError {
|
||||
message: "tool exploded".to_string(),
|
||||
@@ -613,6 +618,7 @@ fn mcp_tool_call_defaults_arguments_and_preserves_structured_content() {
|
||||
status: ApiMcpToolCallStatus::InProgress,
|
||||
arguments: serde_json::Value::Null,
|
||||
mcp_app_resource_uri: None,
|
||||
plugin_id: None,
|
||||
result: None,
|
||||
error: None,
|
||||
duration_ms: None,
|
||||
@@ -630,6 +636,7 @@ fn mcp_tool_call_defaults_arguments_and_preserves_structured_content() {
|
||||
status: ApiMcpToolCallStatus::Completed,
|
||||
arguments: serde_json::Value::Null,
|
||||
mcp_app_resource_uri: None,
|
||||
plugin_id: None,
|
||||
result: Some(Box::new(McpToolCallResult {
|
||||
content: vec![json!({
|
||||
"type": "text",
|
||||
@@ -681,6 +688,7 @@ fn mcp_tool_call_defaults_arguments_and_preserves_structured_content() {
|
||||
"type": "text",
|
||||
"text": "done",
|
||||
})],
|
||||
meta: None,
|
||||
structured_content: Some(json!({ "status": "ok" })),
|
||||
}),
|
||||
error: None,
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
event: response.created
|
||||
data: {"type":"response.created","response":{"id":"resp1"}}
|
||||
|
||||
event: response.output_item.done
|
||||
data: {"type":"response.output_item.done","item":{"type":"message","role":"assistant","content":[{"type":"output_text","text":"fixture hello"}]}}
|
||||
|
||||
event: response.completed
|
||||
data: {"type":"response.completed","response":{"id":"resp1","output":[]}}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ use anyhow::Context;
|
||||
use assert_cmd::prelude::*;
|
||||
use codex_apply_patch::CODEX_CORE_APPLY_PATCH_ARG1;
|
||||
use core_test_support::responses::ev_apply_patch_custom_tool_call;
|
||||
use core_test_support::responses::ev_apply_patch_function_call;
|
||||
use core_test_support::responses::ev_completed;
|
||||
use core_test_support::responses::mount_sse_sequence;
|
||||
use core_test_support::responses::sse;
|
||||
@@ -71,7 +70,7 @@ async fn test_apply_patch_tool() -> anyhow::Result<()> {
|
||||
ev_completed("request_0"),
|
||||
]),
|
||||
sse(vec![
|
||||
ev_apply_patch_function_call("request_1", update_patch),
|
||||
ev_apply_patch_custom_tool_call("request_1", update_patch),
|
||||
ev_completed("request_1"),
|
||||
]),
|
||||
sse(vec![ev_completed("request_2")]),
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
#![cfg(not(target_os = "windows"))]
|
||||
#![allow(clippy::expect_used, clippy::unwrap_used)]
|
||||
|
||||
use core_test_support::responses;
|
||||
use core_test_support::test_codex_exec::test_codex_exec;
|
||||
|
||||
async fn run_exec_with_auto_review_config(extra_args: &[&str]) -> anyhow::Result<String> {
|
||||
let test = test_codex_exec();
|
||||
std::fs::write(
|
||||
test.home_path().join("config.toml"),
|
||||
r#"
|
||||
approval_policy = "on-request"
|
||||
approvals_reviewer = "auto_review"
|
||||
"#,
|
||||
)?;
|
||||
|
||||
let server = responses::start_mock_server().await;
|
||||
let body = responses::sse(vec![
|
||||
responses::ev_response_created("response_1"),
|
||||
responses::ev_assistant_message("response_1", "done"),
|
||||
responses::ev_completed("response_1"),
|
||||
]);
|
||||
responses::mount_sse_once(&server, body).await;
|
||||
|
||||
let mut cmd = test.cmd_with_server(&server);
|
||||
let output = cmd
|
||||
.arg("--skip-git-repo-check")
|
||||
.args(extra_args)
|
||||
.arg("check approval mode")
|
||||
.output()?;
|
||||
|
||||
assert!(output.status.success(), "exec run failed: {output:?}");
|
||||
|
||||
Ok(String::from_utf8(output.stderr)?)
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn exec_preserves_on_request_for_auto_review_config() -> anyhow::Result<()> {
|
||||
let stderr = run_exec_with_auto_review_config(&[]).await?;
|
||||
assert!(
|
||||
stderr.contains("approval: on-request"),
|
||||
"stderr missing preserved auto-review approval mode: {stderr}"
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn exec_bypass_preserves_never_for_auto_review_config() -> anyhow::Result<()> {
|
||||
let stderr =
|
||||
run_exec_with_auto_review_config(&["--dangerously-bypass-approvals-and-sandbox"]).await?;
|
||||
assert!(
|
||||
stderr.contains("approval: never"),
|
||||
"stderr missing bypass approval mode: {stderr}"
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn exec_full_auto_preserves_never_for_auto_review_config() -> anyhow::Result<()> {
|
||||
let stderr = run_exec_with_auto_review_config(&["--full-auto"]).await?;
|
||||
assert!(
|
||||
stderr.contains("approval: never"),
|
||||
"stderr missing full-auto approval mode: {stderr}"
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -1,9 +1,19 @@
|
||||
#![cfg(not(target_os = "windows"))]
|
||||
#![allow(clippy::expect_used, clippy::unwrap_used)]
|
||||
|
||||
use codex_utils_cargo_bin::find_resource;
|
||||
use core_test_support::responses;
|
||||
use core_test_support::skip_if_no_network;
|
||||
use core_test_support::test_codex_exec::test_codex_exec;
|
||||
use walkdir::WalkDir;
|
||||
use wiremock::MockServer;
|
||||
|
||||
fn exec_sse_response() -> String {
|
||||
responses::sse(vec![
|
||||
responses::ev_response_created("resp-ephemeral"),
|
||||
responses::ev_assistant_message("msg-ephemeral", "ephemeral response"),
|
||||
responses::ev_completed("resp-ephemeral"),
|
||||
])
|
||||
}
|
||||
|
||||
fn session_rollout_count(home_path: &std::path::Path) -> usize {
|
||||
let sessions_dir = home_path.join("sessions");
|
||||
@@ -19,13 +29,15 @@ fn session_rollout_count(home_path: &std::path::Path) -> usize {
|
||||
.count()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn persists_rollout_file_by_default() -> anyhow::Result<()> {
|
||||
let test = test_codex_exec();
|
||||
let fixture = find_resource!("tests/fixtures/cli_responses_fixture.sse")?;
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn persists_rollout_file_by_default() -> anyhow::Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
test.cmd()
|
||||
.env("CODEX_RS_SSE_FIXTURE", &fixture)
|
||||
let test = test_codex_exec();
|
||||
let server = MockServer::start().await;
|
||||
let _response_mock = responses::mount_sse_once(&server, exec_sse_response()).await;
|
||||
|
||||
test.cmd_with_server(&server)
|
||||
.arg("--skip-git-repo-check")
|
||||
.arg("default persistence behavior")
|
||||
.assert()
|
||||
@@ -35,13 +47,15 @@ fn persists_rollout_file_by_default() -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn does_not_persist_rollout_file_in_ephemeral_mode() -> anyhow::Result<()> {
|
||||
let test = test_codex_exec();
|
||||
let fixture = find_resource!("tests/fixtures/cli_responses_fixture.sse")?;
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn does_not_persist_rollout_file_in_ephemeral_mode() -> anyhow::Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
test.cmd()
|
||||
.env("CODEX_RS_SSE_FIXTURE", &fixture)
|
||||
let test = test_codex_exec();
|
||||
let server = MockServer::start().await;
|
||||
let _response_mock = responses::mount_sse_once(&server, exec_sse_response()).await;
|
||||
|
||||
test.cmd_with_server(&server)
|
||||
.arg("--skip-git-repo-check")
|
||||
.arg("--ephemeral")
|
||||
.arg("ephemeral behavior")
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Aggregates all former standalone integration tests as modules.
|
||||
mod add_dir;
|
||||
mod apply_patch;
|
||||
mod approval_policy;
|
||||
mod auth_env;
|
||||
mod ephemeral;
|
||||
mod mcp_required_exit;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#![allow(clippy::unwrap_used, clippy::expect_used)]
|
||||
use anyhow::Context;
|
||||
use codex_utils_cargo_bin::find_resource;
|
||||
use core_test_support::responses;
|
||||
use core_test_support::skip_if_no_network;
|
||||
use core_test_support::test_codex_exec::test_codex_exec;
|
||||
use pretty_assertions::assert_eq;
|
||||
use serde_json::Value;
|
||||
@@ -8,6 +9,7 @@ use std::string::ToString;
|
||||
use tempfile::TempDir;
|
||||
use uuid::Uuid;
|
||||
use walkdir::WalkDir;
|
||||
use wiremock::MockServer;
|
||||
|
||||
/// Utility: scan the sessions dir for a rollout file that contains `marker`
|
||||
/// in any response_item.message.content entry. Returns the absolute path.
|
||||
@@ -104,26 +106,41 @@ fn last_user_image_count(path: &std::path::Path) -> usize {
|
||||
last_count
|
||||
}
|
||||
|
||||
fn exec_fixture() -> anyhow::Result<std::path::PathBuf> {
|
||||
Ok(find_resource!("tests/fixtures/cli_responses_fixture.sse")?)
|
||||
}
|
||||
|
||||
fn exec_repo_root() -> anyhow::Result<std::path::PathBuf> {
|
||||
Ok(codex_utils_cargo_bin::repo_root()?)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exec_resume_last_appends_to_existing_file() -> anyhow::Result<()> {
|
||||
fn exec_sse_response(index: usize) -> String {
|
||||
let response_id = format!("resp-exec-{index}");
|
||||
let message_id = format!("msg-exec-{index}");
|
||||
responses::sse(vec![
|
||||
responses::ev_response_created(&response_id),
|
||||
responses::ev_assistant_message(&message_id, "exec response"),
|
||||
responses::ev_completed(&response_id),
|
||||
])
|
||||
}
|
||||
|
||||
async fn mount_exec_responses(
|
||||
server: &MockServer,
|
||||
count: usize,
|
||||
) -> core_test_support::responses::ResponseMock {
|
||||
responses::mount_sse_sequence(server, (0..count).map(exec_sse_response).collect()).await
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn exec_resume_last_appends_to_existing_file() -> anyhow::Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
let test = test_codex_exec();
|
||||
let fixture = exec_fixture()?;
|
||||
let server = MockServer::start().await;
|
||||
let _response_mock = mount_exec_responses(&server, /*count*/ 2).await;
|
||||
let repo_root = exec_repo_root()?;
|
||||
|
||||
// 1) First run: create a session with a unique marker in the content.
|
||||
let marker = format!("resume-last-{}", Uuid::new_v4());
|
||||
let prompt = format!("echo {marker}");
|
||||
|
||||
test.cmd()
|
||||
.env("CODEX_RS_SSE_FIXTURE", &fixture)
|
||||
test.cmd_with_server(&server)
|
||||
.arg("--skip-git-repo-check")
|
||||
.arg("-C")
|
||||
.arg(&repo_root)
|
||||
@@ -140,8 +157,7 @@ fn exec_resume_last_appends_to_existing_file() -> anyhow::Result<()> {
|
||||
let marker2 = format!("resume-last-2-{}", Uuid::new_v4());
|
||||
let prompt2 = format!("echo {marker2}");
|
||||
|
||||
test.cmd()
|
||||
.env("CODEX_RS_SSE_FIXTURE", &fixture)
|
||||
test.cmd_with_server(&server)
|
||||
.arg("--skip-git-repo-check")
|
||||
.arg("-C")
|
||||
.arg(&repo_root)
|
||||
@@ -164,18 +180,20 @@ fn exec_resume_last_appends_to_existing_file() -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exec_resume_last_accepts_prompt_after_flag_in_json_mode() -> anyhow::Result<()> {
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn exec_resume_last_accepts_prompt_after_flag_in_json_mode() -> anyhow::Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
let test = test_codex_exec();
|
||||
let fixture = exec_fixture()?;
|
||||
let server = MockServer::start().await;
|
||||
let _response_mock = mount_exec_responses(&server, /*count*/ 2).await;
|
||||
let repo_root = exec_repo_root()?;
|
||||
|
||||
// 1) First run: create a session with a unique marker in the content.
|
||||
let marker = format!("resume-last-json-{}", Uuid::new_v4());
|
||||
let prompt = format!("echo {marker}");
|
||||
|
||||
test.cmd()
|
||||
.env("CODEX_RS_SSE_FIXTURE", &fixture)
|
||||
test.cmd_with_server(&server)
|
||||
.arg("--skip-git-repo-check")
|
||||
.arg("-C")
|
||||
.arg(&repo_root)
|
||||
@@ -192,8 +210,7 @@ fn exec_resume_last_accepts_prompt_after_flag_in_json_mode() -> anyhow::Result<(
|
||||
let marker2 = format!("resume-last-json-2-{}", Uuid::new_v4());
|
||||
let prompt2 = format!("echo {marker2}");
|
||||
|
||||
test.cmd()
|
||||
.env("CODEX_RS_SSE_FIXTURE", &fixture)
|
||||
test.cmd_with_server(&server)
|
||||
.arg("--skip-git-repo-check")
|
||||
.arg("-C")
|
||||
.arg(&repo_root)
|
||||
@@ -216,18 +233,20 @@ fn exec_resume_last_accepts_prompt_after_flag_in_json_mode() -> anyhow::Result<(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exec_resume_last_respects_cwd_filter_and_all_flag() -> anyhow::Result<()> {
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn exec_resume_last_respects_cwd_filter_and_all_flag() -> anyhow::Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
let test = test_codex_exec();
|
||||
let fixture = exec_fixture()?;
|
||||
let server = MockServer::start().await;
|
||||
let _response_mock = mount_exec_responses(&server, /*count*/ 5).await;
|
||||
|
||||
let dir_a = TempDir::new()?;
|
||||
let dir_b = TempDir::new()?;
|
||||
|
||||
let marker_a = format!("resume-cwd-a-{}", Uuid::new_v4());
|
||||
let prompt_a = format!("echo {marker_a}");
|
||||
test.cmd()
|
||||
.env("CODEX_RS_SSE_FIXTURE", &fixture)
|
||||
test.cmd_with_server(&server)
|
||||
.arg("--skip-git-repo-check")
|
||||
.arg("-C")
|
||||
.arg(dir_a.path())
|
||||
@@ -237,8 +256,7 @@ fn exec_resume_last_respects_cwd_filter_and_all_flag() -> anyhow::Result<()> {
|
||||
|
||||
let marker_b = format!("resume-cwd-b-{}", Uuid::new_v4());
|
||||
let prompt_b = format!("echo {marker_b}");
|
||||
test.cmd()
|
||||
.env("CODEX_RS_SSE_FIXTURE", &fixture)
|
||||
test.cmd_with_server(&server)
|
||||
.arg("--skip-git-repo-check")
|
||||
.arg("-C")
|
||||
.arg(dir_b.path())
|
||||
@@ -260,8 +278,7 @@ fn exec_resume_last_respects_cwd_filter_and_all_flag() -> anyhow::Result<()> {
|
||||
let session_id_b = extract_conversation_id(&path_b);
|
||||
let marker_b_touch = format!("resume-cwd-b-touch-{}", Uuid::new_v4());
|
||||
let prompt_b_touch = format!("echo {marker_b_touch}");
|
||||
test.cmd()
|
||||
.env("CODEX_RS_SSE_FIXTURE", &fixture)
|
||||
test.cmd_with_server(&server)
|
||||
.arg("--skip-git-repo-check")
|
||||
.arg("-C")
|
||||
.arg(dir_b.path())
|
||||
@@ -278,8 +295,7 @@ fn exec_resume_last_respects_cwd_filter_and_all_flag() -> anyhow::Result<()> {
|
||||
|
||||
let marker_b2 = format!("resume-cwd-b-2-{}", Uuid::new_v4());
|
||||
let prompt_b2 = format!("echo {marker_b2}");
|
||||
test.cmd()
|
||||
.env("CODEX_RS_SSE_FIXTURE", &fixture)
|
||||
test.cmd_with_server(&server)
|
||||
.arg("--skip-git-repo-check")
|
||||
.arg("-C")
|
||||
.arg(dir_a.path())
|
||||
@@ -299,8 +315,7 @@ fn exec_resume_last_respects_cwd_filter_and_all_flag() -> anyhow::Result<()> {
|
||||
|
||||
let marker_a2 = format!("resume-cwd-a-2-{}", Uuid::new_v4());
|
||||
let prompt_a2 = format!("echo {marker_a2}");
|
||||
test.cmd()
|
||||
.env("CODEX_RS_SSE_FIXTURE", &fixture)
|
||||
test.cmd_with_server(&server)
|
||||
.arg("--skip-git-repo-check")
|
||||
.arg("-C")
|
||||
.arg(dir_a.path())
|
||||
@@ -323,24 +338,29 @@ fn exec_resume_last_respects_cwd_filter_and_all_flag() -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exec_resume_accepts_global_flags_after_subcommand() -> anyhow::Result<()> {
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn exec_resume_accepts_global_flags_after_subcommand() -> anyhow::Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
let test = test_codex_exec();
|
||||
let fixture = exec_fixture()?;
|
||||
let server = MockServer::start().await;
|
||||
let _response_mock = mount_exec_responses(&server, /*count*/ 2).await;
|
||||
|
||||
// Seed a session.
|
||||
test.cmd()
|
||||
.env("CODEX_RS_SSE_FIXTURE", &fixture)
|
||||
test.cmd_with_server(&server)
|
||||
.arg("--skip-git-repo-check")
|
||||
.arg("echo seed-resume-session")
|
||||
.assert()
|
||||
.success();
|
||||
|
||||
// Resume while passing global flags after the subcommand to ensure clap accepts them.
|
||||
let base = format!("{}/v1", server.uri());
|
||||
let base_config = format!("openai_base_url={}", serde_json::to_string(&base)?);
|
||||
test.cmd()
|
||||
.env("CODEX_RS_SSE_FIXTURE", &fixture)
|
||||
.arg("resume")
|
||||
.arg("--last")
|
||||
.arg("--config")
|
||||
.arg(base_config)
|
||||
.arg("--json")
|
||||
.arg("--model")
|
||||
.arg("gpt-5.2-codex")
|
||||
@@ -355,18 +375,76 @@ fn exec_resume_accepts_global_flags_after_subcommand() -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exec_resume_by_id_appends_to_existing_file() -> anyhow::Result<()> {
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn exec_resume_includes_output_schema_in_request() -> anyhow::Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
let test = test_codex_exec();
|
||||
let fixture = exec_fixture()?;
|
||||
let server = MockServer::start().await;
|
||||
let response_mock = mount_exec_responses(&server, /*count*/ 2).await;
|
||||
|
||||
let schema_contents = serde_json::json!({
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"answer": { "type": "string" }
|
||||
},
|
||||
"required": ["answer"],
|
||||
"additionalProperties": false
|
||||
});
|
||||
let schema_path = test.cwd_path().join("schema.json");
|
||||
std::fs::write(&schema_path, serde_json::to_vec_pretty(&schema_contents)?)?;
|
||||
|
||||
test.cmd_with_server(&server)
|
||||
.arg("--skip-git-repo-check")
|
||||
.arg("echo seed-resume-session")
|
||||
.assert()
|
||||
.success();
|
||||
|
||||
test.cmd_with_server(&server)
|
||||
.arg("--skip-git-repo-check")
|
||||
.arg("resume")
|
||||
.arg("--last")
|
||||
.arg("--json")
|
||||
.arg("--output-schema")
|
||||
.arg(&schema_path)
|
||||
.arg("echo resume-with-schema")
|
||||
.assert()
|
||||
.success();
|
||||
|
||||
let requests = response_mock.requests();
|
||||
assert_eq!(requests.len(), 2);
|
||||
let payload: Value = requests[1].body_json();
|
||||
let text = payload.get("text").expect("request missing text field");
|
||||
let format = text
|
||||
.get("format")
|
||||
.expect("request missing text.format field");
|
||||
assert_eq!(
|
||||
format,
|
||||
&serde_json::json!({
|
||||
"name": "codex_output_schema",
|
||||
"type": "json_schema",
|
||||
"strict": true,
|
||||
"schema": schema_contents,
|
||||
})
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn exec_resume_by_id_appends_to_existing_file() -> anyhow::Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
let test = test_codex_exec();
|
||||
let server = MockServer::start().await;
|
||||
let _response_mock = mount_exec_responses(&server, /*count*/ 2).await;
|
||||
let repo_root = exec_repo_root()?;
|
||||
|
||||
// 1) First run: create a session
|
||||
let marker = format!("resume-by-id-{}", Uuid::new_v4());
|
||||
let prompt = format!("echo {marker}");
|
||||
|
||||
test.cmd()
|
||||
.env("CODEX_RS_SSE_FIXTURE", &fixture)
|
||||
test.cmd_with_server(&server)
|
||||
.arg("--skip-git-repo-check")
|
||||
.arg("-C")
|
||||
.arg(&repo_root)
|
||||
@@ -387,8 +465,7 @@ fn exec_resume_by_id_appends_to_existing_file() -> anyhow::Result<()> {
|
||||
let marker2 = format!("resume-by-id-2-{}", Uuid::new_v4());
|
||||
let prompt2 = format!("echo {marker2}");
|
||||
|
||||
test.cmd()
|
||||
.env("CODEX_RS_SSE_FIXTURE", &fixture)
|
||||
test.cmd_with_server(&server)
|
||||
.arg("--skip-git-repo-check")
|
||||
.arg("-C")
|
||||
.arg(&repo_root)
|
||||
@@ -410,17 +487,19 @@ fn exec_resume_by_id_appends_to_existing_file() -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exec_resume_preserves_cli_configuration_overrides() -> anyhow::Result<()> {
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn exec_resume_preserves_cli_configuration_overrides() -> anyhow::Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
let test = test_codex_exec();
|
||||
let fixture = exec_fixture()?;
|
||||
let server = MockServer::start().await;
|
||||
let _response_mock = mount_exec_responses(&server, /*count*/ 2).await;
|
||||
let repo_root = exec_repo_root()?;
|
||||
|
||||
let marker = format!("resume-config-{}", Uuid::new_v4());
|
||||
let prompt = format!("echo {marker}");
|
||||
|
||||
test.cmd()
|
||||
.env("CODEX_RS_SSE_FIXTURE", &fixture)
|
||||
test.cmd_with_server(&server)
|
||||
.arg("--skip-git-repo-check")
|
||||
.arg("--sandbox")
|
||||
.arg("workspace-write")
|
||||
@@ -440,8 +519,7 @@ fn exec_resume_preserves_cli_configuration_overrides() -> anyhow::Result<()> {
|
||||
let prompt2 = format!("echo {marker2}");
|
||||
|
||||
let output = test
|
||||
.cmd()
|
||||
.env("CODEX_RS_SSE_FIXTURE", &fixture)
|
||||
.cmd_with_server(&server)
|
||||
.arg("--skip-git-repo-check")
|
||||
.arg("--sandbox")
|
||||
.arg("workspace-write")
|
||||
@@ -484,17 +562,19 @@ fn exec_resume_preserves_cli_configuration_overrides() -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exec_resume_accepts_images_after_subcommand() -> anyhow::Result<()> {
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn exec_resume_accepts_images_after_subcommand() -> anyhow::Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
let test = test_codex_exec();
|
||||
let fixture = exec_fixture()?;
|
||||
let server = MockServer::start().await;
|
||||
let _response_mock = mount_exec_responses(&server, /*count*/ 2).await;
|
||||
let repo_root = exec_repo_root()?;
|
||||
|
||||
let marker = format!("resume-image-{}", Uuid::new_v4());
|
||||
let prompt = format!("echo {marker}");
|
||||
|
||||
test.cmd()
|
||||
.env("CODEX_RS_SSE_FIXTURE", &fixture)
|
||||
test.cmd_with_server(&server)
|
||||
.arg("--skip-git-repo-check")
|
||||
.arg("-C")
|
||||
.arg(&repo_root)
|
||||
@@ -516,8 +596,7 @@ fn exec_resume_accepts_images_after_subcommand() -> anyhow::Result<()> {
|
||||
|
||||
let marker2 = format!("resume-image-2-{}", Uuid::new_v4());
|
||||
let prompt2 = format!("echo {marker2}");
|
||||
test.cmd()
|
||||
.env("CODEX_RS_SSE_FIXTURE", &fixture)
|
||||
test.cmd_with_server(&server)
|
||||
.arg("--skip-git-repo-check")
|
||||
.arg("-C")
|
||||
.arg(&repo_root)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#![cfg(unix)]
|
||||
use codex_core::spawn::StdioPolicy;
|
||||
use codex_protocol::protocol::SandboxPolicy;
|
||||
use codex_protocol::models::PermissionProfile;
|
||||
use codex_protocol::permissions::NetworkSandboxPolicy;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use codex_utils_absolute_path::test_support::PathBufExt;
|
||||
use std::collections::HashMap;
|
||||
@@ -14,7 +15,7 @@ use tokio::process::Child;
|
||||
async fn spawn_command_under_sandbox(
|
||||
command: Vec<String>,
|
||||
command_cwd: AbsolutePathBuf,
|
||||
sandbox_policy: &SandboxPolicy,
|
||||
permission_profile: &PermissionProfile,
|
||||
sandbox_cwd: &AbsolutePathBuf,
|
||||
stdio_policy: StdioPolicy,
|
||||
env: HashMap<String, String>,
|
||||
@@ -24,7 +25,6 @@ async fn spawn_command_under_sandbox(
|
||||
use codex_core::exec::build_exec_request;
|
||||
use codex_core::sandboxing::SandboxPermissions;
|
||||
use codex_protocol::config_types::WindowsSandboxLevel;
|
||||
use codex_protocol::models::PermissionProfile;
|
||||
use std::process::Stdio;
|
||||
|
||||
let codex_linux_sandbox_exe = None;
|
||||
@@ -42,8 +42,9 @@ async fn spawn_command_under_sandbox(
|
||||
justification: None,
|
||||
arg0: None,
|
||||
},
|
||||
&PermissionProfile::from_legacy_sandbox_policy(sandbox_policy),
|
||||
permission_profile,
|
||||
sandbox_cwd,
|
||||
std::slice::from_ref(sandbox_cwd),
|
||||
&codex_linux_sandbox_exe,
|
||||
/*use_legacy_landlock*/ false,
|
||||
)
|
||||
@@ -83,22 +84,20 @@ async fn spawn_command_under_sandbox(
|
||||
async fn spawn_command_under_sandbox(
|
||||
command: Vec<String>,
|
||||
command_cwd: AbsolutePathBuf,
|
||||
sandbox_policy: &SandboxPolicy,
|
||||
permission_profile: &PermissionProfile,
|
||||
sandbox_cwd: &AbsolutePathBuf,
|
||||
stdio_policy: StdioPolicy,
|
||||
env: HashMap<String, String>,
|
||||
) -> std::io::Result<Child> {
|
||||
use codex_core::spawn_command_under_linux_sandbox;
|
||||
use codex_protocol::models::PermissionProfile;
|
||||
|
||||
let codex_linux_sandbox_exe = core_test_support::find_codex_linux_sandbox_exe()
|
||||
.map_err(|err| io::Error::new(io::ErrorKind::NotFound, err))?;
|
||||
let permission_profile = PermissionProfile::from_legacy_sandbox_policy(sandbox_policy);
|
||||
spawn_command_under_linux_sandbox(
|
||||
codex_linux_sandbox_exe,
|
||||
command,
|
||||
command_cwd,
|
||||
&permission_profile,
|
||||
permission_profile,
|
||||
sandbox_cwd,
|
||||
/*use_legacy_landlock*/ false,
|
||||
stdio_policy,
|
||||
@@ -118,9 +117,16 @@ async fn spawn_command_under_sandbox(
|
||||
async fn linux_sandbox_test_env() -> Option<HashMap<String, String>> {
|
||||
let command_cwd = AbsolutePathBuf::current_dir().ok()?;
|
||||
let sandbox_cwd = command_cwd.clone();
|
||||
let policy = SandboxPolicy::new_read_only_policy();
|
||||
let permission_profile = PermissionProfile::read_only();
|
||||
|
||||
if can_apply_linux_sandbox_policy(&policy, &command_cwd, &sandbox_cwd, HashMap::new()).await {
|
||||
if can_apply_linux_sandbox_policy(
|
||||
&permission_profile,
|
||||
&command_cwd,
|
||||
&sandbox_cwd,
|
||||
HashMap::new(),
|
||||
)
|
||||
.await
|
||||
{
|
||||
return Some(HashMap::new());
|
||||
}
|
||||
|
||||
@@ -135,7 +141,7 @@ async fn linux_sandbox_test_env() -> Option<HashMap<String, String>> {
|
||||
/// This is used as a capability probe so sandbox behavior tests only run when
|
||||
/// Landlock enforcement is actually active.
|
||||
async fn can_apply_linux_sandbox_policy(
|
||||
policy: &SandboxPolicy,
|
||||
permission_profile: &PermissionProfile,
|
||||
command_cwd: &AbsolutePathBuf,
|
||||
sandbox_cwd: &AbsolutePathBuf,
|
||||
env: HashMap<String, String>,
|
||||
@@ -143,7 +149,7 @@ async fn can_apply_linux_sandbox_policy(
|
||||
let spawn_result = spawn_command_under_sandbox(
|
||||
vec!["/usr/bin/true".to_string()],
|
||||
command_cwd.clone(),
|
||||
policy,
|
||||
permission_profile,
|
||||
sandbox_cwd,
|
||||
StdioPolicy::RedirectForShellTool,
|
||||
env,
|
||||
@@ -180,12 +186,12 @@ async fn python_multiprocessing_lock_works_under_sandbox() {
|
||||
#[cfg(target_os = "linux")]
|
||||
let writable_roots: Vec<AbsolutePathBuf> = vec!["/dev/shm".try_into().unwrap()];
|
||||
|
||||
let policy = SandboxPolicy::WorkspaceWrite {
|
||||
writable_roots,
|
||||
network_access: false,
|
||||
exclude_tmpdir_env_var: false,
|
||||
exclude_slash_tmp: false,
|
||||
};
|
||||
let permission_profile = PermissionProfile::workspace_write_with(
|
||||
&writable_roots,
|
||||
NetworkSandboxPolicy::Restricted,
|
||||
/*exclude_tmpdir_env_var*/ true,
|
||||
/*exclude_slash_tmp*/ true,
|
||||
);
|
||||
|
||||
let python_code = r#"import multiprocessing
|
||||
from multiprocessing import Lock, Process
|
||||
@@ -210,7 +216,7 @@ if __name__ == '__main__':
|
||||
python_code.to_string(),
|
||||
],
|
||||
command_cwd,
|
||||
&policy,
|
||||
&permission_profile,
|
||||
&sandbox_cwd,
|
||||
StdioPolicy::Inherit,
|
||||
sandbox_env,
|
||||
@@ -242,7 +248,7 @@ async fn python_getpwuid_works_under_sandbox() {
|
||||
return;
|
||||
}
|
||||
|
||||
let policy = SandboxPolicy::new_read_only_policy();
|
||||
let permission_profile = PermissionProfile::read_only();
|
||||
let command_cwd = AbsolutePathBuf::current_dir().expect("should be able to get current dir");
|
||||
let sandbox_cwd = command_cwd.clone();
|
||||
|
||||
@@ -253,7 +259,7 @@ async fn python_getpwuid_works_under_sandbox() {
|
||||
"import pwd, os; print(pwd.getpwuid(os.getuid()))".to_string(),
|
||||
],
|
||||
command_cwd,
|
||||
&policy,
|
||||
&permission_profile,
|
||||
&sandbox_cwd,
|
||||
StdioPolicy::RedirectForShellTool,
|
||||
sandbox_env,
|
||||
@@ -294,12 +300,12 @@ async fn sandbox_distinguishes_command_and_policy_cwds() {
|
||||
// Note writable_roots is empty: verify that `canonical_allowed_path` is
|
||||
// writable only because it is under the sandbox policy cwd, not because it
|
||||
// is under a writable root.
|
||||
let policy = SandboxPolicy::WorkspaceWrite {
|
||||
writable_roots: vec![],
|
||||
network_access: false,
|
||||
exclude_tmpdir_env_var: true,
|
||||
exclude_slash_tmp: true,
|
||||
};
|
||||
let permission_profile = PermissionProfile::workspace_write_with(
|
||||
&[],
|
||||
NetworkSandboxPolicy::Restricted,
|
||||
/*exclude_tmpdir_env_var*/ true,
|
||||
/*exclude_slash_tmp*/ true,
|
||||
);
|
||||
|
||||
// Attempt to write inside the command cwd, which is outside of the sandbox policy cwd.
|
||||
let mut child = spawn_command_under_sandbox(
|
||||
@@ -309,7 +315,7 @@ async fn sandbox_distinguishes_command_and_policy_cwds() {
|
||||
"echo forbidden > forbidden.txt".to_string(),
|
||||
],
|
||||
command_root.clone(),
|
||||
&policy,
|
||||
&permission_profile,
|
||||
&canonical_sandbox_root,
|
||||
StdioPolicy::Inherit,
|
||||
sandbox_env.clone(),
|
||||
@@ -340,7 +346,7 @@ async fn sandbox_distinguishes_command_and_policy_cwds() {
|
||||
canonical_allowed_path.to_string_lossy().into_owned(),
|
||||
],
|
||||
command_root,
|
||||
&policy,
|
||||
&permission_profile,
|
||||
&canonical_sandbox_root,
|
||||
StdioPolicy::Inherit,
|
||||
sandbox_env,
|
||||
@@ -375,12 +381,12 @@ async fn sandbox_blocks_first_time_dot_codex_creation() {
|
||||
create_dir_all(&repo_root).await.expect("mkdir repo");
|
||||
let dot_codex = repo_root.join(".codex");
|
||||
let config_toml = dot_codex.join("config.toml");
|
||||
let policy = SandboxPolicy::WorkspaceWrite {
|
||||
writable_roots: vec![],
|
||||
network_access: false,
|
||||
exclude_tmpdir_env_var: true,
|
||||
exclude_slash_tmp: true,
|
||||
};
|
||||
let permission_profile = PermissionProfile::workspace_write_with(
|
||||
&[],
|
||||
NetworkSandboxPolicy::Restricted,
|
||||
/*exclude_tmpdir_env_var*/ true,
|
||||
/*exclude_slash_tmp*/ true,
|
||||
);
|
||||
|
||||
let mut child = spawn_command_under_sandbox(
|
||||
vec![
|
||||
@@ -390,7 +396,7 @@ async fn sandbox_blocks_first_time_dot_codex_creation() {
|
||||
.to_string(),
|
||||
],
|
||||
repo_root.clone(),
|
||||
&policy,
|
||||
&permission_profile,
|
||||
&repo_root,
|
||||
StdioPolicy::RedirectForShellTool,
|
||||
sandbox_env,
|
||||
@@ -507,7 +513,7 @@ fn unix_sock_body() {
|
||||
async fn allow_unix_socketpair_recvfrom() {
|
||||
run_code_under_sandbox(
|
||||
"allow_unix_socketpair_recvfrom",
|
||||
&SandboxPolicy::new_read_only_policy(),
|
||||
&PermissionProfile::read_only(),
|
||||
|| async { unix_sock_body() },
|
||||
)
|
||||
.await
|
||||
@@ -519,7 +525,7 @@ const IN_SANDBOX_ENV_VAR: &str = "IN_SANDBOX";
|
||||
#[expect(clippy::expect_used)]
|
||||
pub async fn run_code_under_sandbox<F, Fut>(
|
||||
test_selector: &str,
|
||||
policy: &SandboxPolicy,
|
||||
permission_profile: &PermissionProfile,
|
||||
child_body: F,
|
||||
) -> io::Result<Option<ExitStatus>>
|
||||
where
|
||||
@@ -544,7 +550,7 @@ where
|
||||
let mut child = spawn_command_under_sandbox(
|
||||
cmds,
|
||||
command_cwd,
|
||||
policy,
|
||||
permission_profile,
|
||||
&sandbox_cwd,
|
||||
stdio_policy,
|
||||
HashMap::from([("IN_SANDBOX".into(), "1".into())]),
|
||||
|
||||
Reference in New Issue
Block a user