mirror of
https://github.com/openai/codex.git
synced 2026-12-02 00:31:03 +00:00
Merge remote-tracking branch 'origin/main' into dev/stevenlee/plugin-service-preview-routing
# Conflicts: # codex-rs/app-server/src/request_processors/plugins.rs # codex-rs/core-plugins/src/remote.rs
This commit is contained in:
@@ -252,13 +252,6 @@
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"description": "DEPRECATED: *All* commands are auto‑approved, but they are expected to run inside a sandbox where network access is disabled and writes are confined to a specific set of paths. If the command fails, it will be escalated to the user to approve execution without a sandbox. Prefer `OnRequest` for interactive runs or `Never` for non-interactive runs.",
|
||||
"enum": [
|
||||
"on-failure"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"description": "The model decides when to ask the user for approval.",
|
||||
"enum": [
|
||||
|
||||
@@ -171,7 +171,7 @@ For all of testing, running, building, and formatting, do not attempt to fix unr
|
||||
|
||||
Be mindful of whether to run validation commands proactively. In the absence of behavioral guidance:
|
||||
|
||||
- When running in non-interactive approval modes like **never** or **on-failure**, you can proactively run tests, lint and do whatever you need to ensure you've completed the task. If you are unable to run tests, you must still do your utmost best to complete the task.
|
||||
- When running in the non-interactive approval mode **never**, you can proactively run tests, lint and do whatever you need to ensure you've completed the task. If you are unable to run tests, you must still do your utmost best to complete the task.
|
||||
- When working in interactive approval modes like **untrusted**, or **on-request**, hold off on running tests or lint commands until the user is ready for you to finalize your output, because these commands take time to run and slow down iteration. Instead suggest what you want to do next, and let the user confirm first.
|
||||
- When working on test-related tasks, such as adding tests, fixing tests, or reproducing a bug to verify behavior, you may proactively run tests regardless of approval mode. Use your judgement to decide whether this is a test-related task.
|
||||
|
||||
|
||||
@@ -145,7 +145,7 @@ For all of testing, running, building, and formatting, do not attempt to fix unr
|
||||
|
||||
Be mindful of whether to run validation commands proactively. In the absence of behavioral guidance:
|
||||
|
||||
- When running in non-interactive approval modes like **never** or **on-failure**, you can proactively run tests, lint and do whatever you need to ensure you've completed the task. If you are unable to run tests, you must still do your utmost best to complete the task.
|
||||
- When running in the non-interactive approval mode **never**, you can proactively run tests, lint and do whatever you need to ensure you've completed the task. If you are unable to run tests, you must still do your utmost best to complete the task.
|
||||
- When working in interactive approval modes like **untrusted**, or **on-request**, hold off on running tests or lint commands until the user is ready for you to finalize your output, because these commands take time to run and slow down iteration. Instead suggest what you want to do next, and let the user confirm first.
|
||||
- When working on test-related tasks, such as adding tests, fixing tests, or reproducing a bug to verify behavior, you may proactively run tests regardless of approval mode. Use your judgement to decide whether this is a test-related task.
|
||||
|
||||
|
||||
@@ -158,7 +158,7 @@ For all of testing, running, building, and formatting, do not attempt to fix unr
|
||||
|
||||
Be mindful of whether to run validation commands proactively. In the absence of behavioral guidance:
|
||||
|
||||
- When running in non-interactive approval modes like **never** or **on-failure**, proactively run tests, lint and do whatever you need to ensure you've completed the task.
|
||||
- When running in the non-interactive approval mode **never**, proactively run tests, lint and do whatever you need to ensure you've completed the task.
|
||||
- When working in interactive approval modes like **untrusted**, or **on-request**, hold off on running tests or lint commands until the user is ready for you to finalize your output, because these commands take time to run and slow down iteration. Instead suggest what you want to do next, and let the user confirm first.
|
||||
- When working on test-related tasks, such as adding tests, fixing tests, or reproducing a bug to verify behavior, you may proactively run tests regardless of approval mode. Use your judgement to decide whether this is a test-related task.
|
||||
|
||||
|
||||
@@ -640,7 +640,7 @@ async fn selected_user_config_file_layers_over_base_user_config() {
|
||||
tmp.path().join(CONFIG_TOML_FILE),
|
||||
r#"
|
||||
model = "gpt-main"
|
||||
approval_policy = "on-failure"
|
||||
approval_policy = "on-request"
|
||||
"#,
|
||||
)
|
||||
.expect("write default user config");
|
||||
@@ -697,7 +697,7 @@ approval_policy = "on-failure"
|
||||
.effective_config()
|
||||
.get("approval_policy")
|
||||
.and_then(TomlValue::as_str),
|
||||
Some("on-failure")
|
||||
Some("on-request")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1033,12 +1033,6 @@ personality = true
|
||||
config_requirements
|
||||
.approval_policy
|
||||
.can_set(&AskForApproval::Never)?;
|
||||
assert!(
|
||||
config_requirements
|
||||
.approval_policy
|
||||
.can_set(&AskForApproval::OnFailure)
|
||||
.is_err()
|
||||
);
|
||||
assert_eq!(
|
||||
config_requirements.web_search_mode.value(),
|
||||
WebSearchMode::Cached
|
||||
|
||||
@@ -8320,7 +8320,7 @@ model_provider = "openai-custom"
|
||||
[profiles.zdr]
|
||||
model = "o3"
|
||||
model_provider = "openai"
|
||||
approval_policy = "on-failure"
|
||||
approval_policy = "on-request"
|
||||
|
||||
[profiles.zdr.analytics]
|
||||
enabled = false
|
||||
@@ -8328,7 +8328,7 @@ enabled = false
|
||||
[profiles.gpt5]
|
||||
model = "gpt-5.4"
|
||||
model_provider = "openai"
|
||||
approval_policy = "on-failure"
|
||||
approval_policy = "on-request"
|
||||
model_reasoning_effort = "high"
|
||||
model_reasoning_summary = "detailed"
|
||||
model_verbosity = "high"
|
||||
|
||||
@@ -377,6 +377,7 @@ pub fn build_exec_request(
|
||||
args: args.to_vec(),
|
||||
cwd,
|
||||
env,
|
||||
managed_network: None,
|
||||
additional_permissions: None,
|
||||
};
|
||||
let options = ExecOptions {
|
||||
@@ -459,6 +460,7 @@ pub(crate) async fn execute_exec_request(
|
||||
arg0,
|
||||
exec_server_sandbox: _,
|
||||
exec_server_enforce_managed_network: _,
|
||||
exec_server_managed_network: _,
|
||||
} = exec_request;
|
||||
|
||||
// TODO(anp): Keep PathUri through the local process launch boundary.
|
||||
|
||||
@@ -177,7 +177,6 @@ pub(crate) fn prompt_is_rejected_by_policy(
|
||||
) -> Option<&'static str> {
|
||||
match approval_policy {
|
||||
AskForApproval::Never => Some(PROMPT_CONFLICT_REASON),
|
||||
AskForApproval::OnFailure => None,
|
||||
AskForApproval::OnRequest => None,
|
||||
AskForApproval::UnlessTrusted => None,
|
||||
AskForApproval::Granular(granular_config) => {
|
||||
@@ -689,15 +688,14 @@ pub(crate) fn render_decision_for_unmatched_command(
|
||||
Decision::Forbidden
|
||||
}
|
||||
}
|
||||
AskForApproval::OnFailure
|
||||
| AskForApproval::OnRequest
|
||||
AskForApproval::OnRequest
|
||||
| AskForApproval::UnlessTrusted
|
||||
| AskForApproval::Granular(_) => Decision::Prompt,
|
||||
};
|
||||
}
|
||||
|
||||
match approval_policy {
|
||||
AskForApproval::Never | AskForApproval::OnFailure => {
|
||||
AskForApproval::Never => {
|
||||
// We allow the command to run, relying on the sandbox for
|
||||
// protection.
|
||||
Decision::Allow
|
||||
|
||||
@@ -738,10 +738,9 @@ fn hook_run_metric_tags(run: &HookRunSummary) -> [(&'static str, &'static str);
|
||||
fn hook_permission_mode(turn_context: &TurnContext) -> String {
|
||||
match turn_context.approval_policy.value() {
|
||||
AskForApproval::Never => "bypassPermissions",
|
||||
AskForApproval::UnlessTrusted
|
||||
| AskForApproval::OnFailure
|
||||
| AskForApproval::OnRequest
|
||||
| AskForApproval::Granular(_) => "default",
|
||||
AskForApproval::UnlessTrusted | AskForApproval::OnRequest | AskForApproval::Granular(_) => {
|
||||
"default"
|
||||
}
|
||||
}
|
||||
.to_string()
|
||||
}
|
||||
|
||||
@@ -653,10 +653,8 @@ async fn maybe_request_codex_apps_auth_elicitation(
|
||||
AskForApproval::Granular(granular_config) if !granular_config.allows_mcp_elicitations() => {
|
||||
return result;
|
||||
}
|
||||
AskForApproval::OnFailure
|
||||
| AskForApproval::OnRequest
|
||||
| AskForApproval::UnlessTrusted
|
||||
| AskForApproval::Granular(_) => {}
|
||||
AskForApproval::OnRequest | AskForApproval::UnlessTrusted | AskForApproval::Granular(_) => {
|
||||
}
|
||||
}
|
||||
|
||||
let connector_id = metadata.and_then(|metadata| metadata.connector_id.as_deref());
|
||||
|
||||
@@ -2922,7 +2922,6 @@ async fn approve_mode_skips_guardian_in_every_permission_mode() {
|
||||
|
||||
for approval_policy in [
|
||||
AskForApproval::UnlessTrusted,
|
||||
AskForApproval::OnFailure,
|
||||
AskForApproval::OnRequest,
|
||||
AskForApproval::Granular(GranularApprovalConfig {
|
||||
sandbox_approval: true,
|
||||
|
||||
@@ -44,10 +44,7 @@ pub fn assess_patch_safety(
|
||||
}
|
||||
|
||||
match policy {
|
||||
AskForApproval::OnFailure
|
||||
| AskForApproval::Never
|
||||
| AskForApproval::OnRequest
|
||||
| AskForApproval::Granular(_) => {
|
||||
AskForApproval::Never | AskForApproval::OnRequest | AskForApproval::Granular(_) => {
|
||||
// Continue to see if this can be auto-approved.
|
||||
}
|
||||
// TODO(ragona): I'm not sure this is actually correct? I believe in this case
|
||||
@@ -66,9 +63,7 @@ pub fn assess_patch_safety(
|
||||
// Even though the patch appears to be constrained to writable paths, it is
|
||||
// possible that paths in the patch are hard links to files outside the
|
||||
// writable roots, so we should still run `apply_patch` in a sandbox in that case.
|
||||
if is_write_patch_constrained_to_writable_paths(action, file_system_sandbox_policy, cwd)
|
||||
|| matches!(policy, AskForApproval::OnFailure)
|
||||
{
|
||||
if is_write_patch_constrained_to_writable_paths(action, file_system_sandbox_policy, cwd) {
|
||||
if matches!(
|
||||
permission_profile,
|
||||
PermissionProfile::Disabled | PermissionProfile::External { .. }
|
||||
|
||||
@@ -15,6 +15,7 @@ use crate::exec::execute_exec_request;
|
||||
use crate::spawn::CODEX_SANDBOX_ENV_VAR;
|
||||
use crate::spawn::CODEX_SANDBOX_NETWORK_DISABLED_ENV_VAR;
|
||||
use codex_file_system::FileSystemSandboxContext;
|
||||
use codex_network_proxy::ManagedNetworkSandboxContext;
|
||||
use codex_network_proxy::NetworkProxy;
|
||||
use codex_protocol::config_types::WindowsSandboxLevel;
|
||||
use codex_protocol::exec_output::ExecToolCallOutput;
|
||||
@@ -63,6 +64,7 @@ pub struct ExecRequest {
|
||||
pub arg0: Option<String>,
|
||||
pub(crate) exec_server_sandbox: Option<FileSystemSandboxContext>,
|
||||
pub(crate) exec_server_enforce_managed_network: bool,
|
||||
pub(crate) exec_server_managed_network: Option<ManagedNetworkSandboxContext>,
|
||||
}
|
||||
|
||||
impl ExecRequest {
|
||||
@@ -107,6 +109,7 @@ impl ExecRequest {
|
||||
arg0,
|
||||
exec_server_sandbox: None,
|
||||
exec_server_enforce_managed_network: false,
|
||||
exec_server_managed_network: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,6 +168,7 @@ impl ExecRequest {
|
||||
arg0,
|
||||
exec_server_sandbox: None,
|
||||
exec_server_enforce_managed_network: false,
|
||||
exec_server_managed_network: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -724,7 +724,7 @@ impl Codex {
|
||||
op: Op,
|
||||
trace: Option<W3cTraceContext>,
|
||||
) -> CodexResult<String> {
|
||||
let id = Uuid::now_v7().to_string();
|
||||
let id = new_submission_id();
|
||||
let sub = Submission {
|
||||
id: id.clone(),
|
||||
op,
|
||||
@@ -742,7 +742,7 @@ impl Codex {
|
||||
client_user_message_id: Option<String>,
|
||||
) -> CodexResult<String> {
|
||||
debug_assert!(matches!(op, Op::UserInput { .. }));
|
||||
let id = Uuid::now_v7().to_string();
|
||||
let id = new_submission_id();
|
||||
let sub = Submission {
|
||||
id: id.clone(),
|
||||
op,
|
||||
@@ -869,6 +869,15 @@ impl Codex {
|
||||
}
|
||||
}
|
||||
|
||||
/// Generate a core submission ID. App-server exposes submission IDs that
|
||||
/// create turns as a public-facing turn ID.
|
||||
///
|
||||
/// Some use cases take advantage of the fact that these are UUID7 which
|
||||
/// encodes a timestamp, so think carefully before changing this.
|
||||
fn new_submission_id() -> String {
|
||||
Uuid::now_v7().to_string()
|
||||
}
|
||||
|
||||
fn get_service_tier(
|
||||
configured_service_tier: Option<String>,
|
||||
fast_mode_enabled: bool,
|
||||
@@ -2237,8 +2246,7 @@ impl Session {
|
||||
strict_auto_review: false,
|
||||
});
|
||||
}
|
||||
AskForApproval::OnFailure
|
||||
| AskForApproval::OnRequest
|
||||
AskForApproval::OnRequest
|
||||
| AskForApproval::UnlessTrusted
|
||||
| AskForApproval::Granular(_) => {}
|
||||
}
|
||||
|
||||
@@ -748,15 +748,6 @@ impl Session {
|
||||
) {
|
||||
post_session_configured_events.push(event);
|
||||
}
|
||||
if config.permissions.approval_policy.value() == AskForApproval::OnFailure {
|
||||
post_session_configured_events.push(Event {
|
||||
id: "".to_owned(),
|
||||
msg: EventMsg::Warning(WarningEvent {
|
||||
message: "`on-failure` approval policy is deprecated and will be removed in a future release. Use `on-request` for interactive approvals or `never` for non-interactive runs.".to_string(),
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
let auth = auth.as_ref();
|
||||
let auth_mode = auth.map(CodexAuth::auth_mode).map(TelemetryAuthMode::from);
|
||||
let account_id = auth.and_then(CodexAuth::get_account_id);
|
||||
|
||||
@@ -1288,7 +1288,7 @@ async fn reload_user_config_layer_updates_base_and_selected_profile_layers() {
|
||||
let profile_config_path = codex_home.join("work.config.toml");
|
||||
std::fs::write(
|
||||
&base_config_path,
|
||||
"model = \"base\"\napproval_policy = \"on-failure\"\n",
|
||||
"model = \"base\"\napproval_policy = \"on-request\"\n",
|
||||
)
|
||||
.expect("write base user config");
|
||||
std::fs::write(&profile_config_path, "model = \"profile-old\"\n")
|
||||
@@ -10147,7 +10147,7 @@ async fn rejects_escalated_permissions_when_policy_not_on_request() {
|
||||
// Ensure policy is NOT OnRequest so the early rejection path triggers
|
||||
turn_context_raw
|
||||
.approval_policy
|
||||
.set(AskForApproval::OnFailure)
|
||||
.set(AskForApproval::Never)
|
||||
.expect("test setup should allow updating approval policy");
|
||||
let session = Arc::new(session);
|
||||
let mut turn_context = Arc::new(turn_context_raw);
|
||||
@@ -10310,7 +10310,7 @@ async fn unified_exec_rejects_escalated_permissions_when_policy_not_on_request()
|
||||
let (session, mut turn_context_raw) = make_session_and_context().await;
|
||||
turn_context_raw
|
||||
.approval_policy
|
||||
.set(AskForApproval::OnFailure)
|
||||
.set(AskForApproval::Never)
|
||||
.expect("test setup should allow updating approval policy");
|
||||
let session = Arc::new(session);
|
||||
let turn_context = Arc::new(turn_context_raw);
|
||||
|
||||
@@ -407,7 +407,7 @@ async fn strict_auto_review_turn_grant_forces_guardian_for_shell_command_policy_
|
||||
|
||||
turn_context_raw
|
||||
.approval_policy
|
||||
.set(AskForApproval::OnFailure)
|
||||
.set(AskForApproval::Never)
|
||||
.expect("test setup should allow updating approval policy");
|
||||
turn_context_raw.permission_profile = codex_protocol::models::PermissionProfile::Disabled;
|
||||
let mut config = (*turn_context_raw.config).clone();
|
||||
|
||||
@@ -226,6 +226,7 @@ pub(crate) async fn execute_user_shell_command(
|
||||
arg0: None,
|
||||
exec_server_sandbox: None,
|
||||
exec_server_enforce_managed_network: false,
|
||||
exec_server_managed_network: None,
|
||||
};
|
||||
|
||||
let stdout_stream = Some(StdoutStream {
|
||||
|
||||
@@ -24,7 +24,6 @@ use crate::tools::registry::CoreToolRuntime;
|
||||
use crate::tools::registry::ToolExecutor;
|
||||
use codex_tools::ToolName;
|
||||
use codex_tools::ToolSpec;
|
||||
use codex_utils_path_uri::PathUri;
|
||||
|
||||
pub struct ViewImageHandler {
|
||||
options: ViewImageToolOptions,
|
||||
@@ -140,36 +139,31 @@ impl ViewImageHandler {
|
||||
"view_image is unavailable in this session".to_string(),
|
||||
));
|
||||
};
|
||||
// TODO(anp): Resolve tool paths using the selected environment's native path convention
|
||||
// so view_image can support relative paths in foreign environments.
|
||||
let cwd = turn_environment.cwd().to_abs_path().map_err(|err| {
|
||||
let path_uri = turn_environment.cwd().join(&path).map_err(|err| {
|
||||
FunctionCallError::RespondToModel(format!(
|
||||
"environment cwd `{}` is not native to the Codex host: {err}",
|
||||
turn_environment.cwd()
|
||||
"unable to resolve image path `{path}` against environment cwd `{}`: {err}",
|
||||
turn_environment.cwd(),
|
||||
))
|
||||
})?;
|
||||
let abs_path = cwd.join(path);
|
||||
let model_visible_path = path_uri.inferred_native_path_string();
|
||||
let sandbox = turn.file_system_sandbox_context(
|
||||
/*additional_permissions*/ None,
|
||||
turn_environment.cwd(),
|
||||
);
|
||||
let fs = turn_environment.environment.get_filesystem();
|
||||
let path_uri = PathUri::from_abs_path(&abs_path);
|
||||
|
||||
let metadata = fs
|
||||
.get_metadata(&path_uri, Some(&sandbox))
|
||||
.await
|
||||
.map_err(|error| {
|
||||
FunctionCallError::RespondToModel(format!(
|
||||
"unable to locate image at `{}`: {error}",
|
||||
abs_path.display()
|
||||
"unable to locate image at `{model_visible_path}`: {error}"
|
||||
))
|
||||
})?;
|
||||
|
||||
if !metadata.is_file {
|
||||
return Err(FunctionCallError::RespondToModel(format!(
|
||||
"image path `{}` is not a file",
|
||||
abs_path.display()
|
||||
"image path `{model_visible_path}` is not a file"
|
||||
)));
|
||||
}
|
||||
let file_bytes = fs
|
||||
@@ -177,11 +171,9 @@ impl ViewImageHandler {
|
||||
.await
|
||||
.map_err(|error| {
|
||||
FunctionCallError::RespondToModel(format!(
|
||||
"unable to read image at `{}`: {error}",
|
||||
abs_path.display()
|
||||
"unable to read image at `{model_visible_path}`: {error}"
|
||||
))
|
||||
})?;
|
||||
let event_path = abs_path.clone();
|
||||
|
||||
let can_request_original_detail = can_request_original_image_detail(&turn.model_info);
|
||||
let use_original_detail =
|
||||
@@ -197,7 +189,7 @@ impl ViewImageHandler {
|
||||
|
||||
let item = TurnItem::ImageView(ImageViewItem {
|
||||
id: call_id,
|
||||
path: event_path,
|
||||
path: path_uri,
|
||||
});
|
||||
session.emit_turn_item_started(turn.as_ref(), &item).await;
|
||||
session.emit_turn_item_completed(turn.as_ref(), item).await;
|
||||
|
||||
@@ -250,7 +250,6 @@ fn allow_once_and_allow_for_session_both_allow_network() {
|
||||
fn only_never_policy_disables_network_approval_flow() {
|
||||
assert!(!allows_network_approval_flow(AskForApproval::Never));
|
||||
assert!(allows_network_approval_flow(AskForApproval::OnRequest));
|
||||
assert!(allows_network_approval_flow(AskForApproval::OnFailure));
|
||||
assert!(allows_network_approval_flow(AskForApproval::UnlessTrusted));
|
||||
}
|
||||
|
||||
|
||||
@@ -205,7 +205,6 @@ impl Approvable<ApplyPatchRequest> for ApplyPatchRuntime {
|
||||
match policy {
|
||||
AskForApproval::Never => false,
|
||||
AskForApproval::Granular(granular_config) => granular_config.allows_sandbox_approval(),
|
||||
AskForApproval::OnFailure => true,
|
||||
AskForApproval::OnRequest => true,
|
||||
AskForApproval::UnlessTrusted => true,
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ pub(crate) fn build_sandbox_command(
|
||||
args: args.to_vec(),
|
||||
cwd,
|
||||
env: env.clone(),
|
||||
managed_network: None,
|
||||
additional_permissions,
|
||||
})
|
||||
}
|
||||
@@ -67,26 +68,26 @@ pub(crate) fn exec_env_for_sandbox_permissions(
|
||||
env
|
||||
}
|
||||
|
||||
pub(crate) fn strip_managed_proxy_env(env: &mut HashMap<String, String>) {
|
||||
for key in PROXY_ENV_KEYS {
|
||||
env.remove(*key);
|
||||
pub(crate) fn is_managed_proxy_env_var(key: &str, value: &str) -> bool {
|
||||
if PROXY_ENV_KEYS.contains(&key) {
|
||||
return true;
|
||||
}
|
||||
for key in CUSTOM_CA_ENV_KEYS {
|
||||
if env
|
||||
.get(key)
|
||||
.is_some_and(|value| is_managed_mitm_ca_trust_bundle_path(value))
|
||||
{
|
||||
env.remove(key);
|
||||
}
|
||||
if CUSTOM_CA_ENV_KEYS.contains(&key) {
|
||||
return is_managed_mitm_ca_trust_bundle_path(value);
|
||||
}
|
||||
// Only macOS injects a Codex-owned SSH wrapper for the managed SOCKS proxy.
|
||||
#[cfg(target_os = "macos")]
|
||||
if env
|
||||
.get(PROXY_GIT_SSH_COMMAND_ENV_KEY)
|
||||
.is_some_and(|command| command.starts_with(CODEX_PROXY_GIT_SSH_COMMAND_MARKER))
|
||||
{
|
||||
env.remove(PROXY_GIT_SSH_COMMAND_ENV_KEY);
|
||||
key == PROXY_GIT_SSH_COMMAND_ENV_KEY
|
||||
&& value.starts_with(CODEX_PROXY_GIT_SSH_COMMAND_MARKER)
|
||||
}
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
{
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn strip_managed_proxy_env(env: &mut HashMap<String, String>) {
|
||||
env.retain(|key, value| !is_managed_proxy_env_var(key, value));
|
||||
}
|
||||
|
||||
/// Prepends `path_entry` to `PATH`, removing duplicate and empty existing
|
||||
|
||||
@@ -168,6 +168,7 @@ pub(super) async fn try_run_zsh_fork(
|
||||
arg0,
|
||||
exec_server_sandbox: _,
|
||||
exec_server_enforce_managed_network: _,
|
||||
exec_server_managed_network: _,
|
||||
} = sandbox_exec_request;
|
||||
let ParsedShellCommand { script, login, .. } = extract_shell_script(&command)?;
|
||||
let effective_timeout = Duration::from_millis(
|
||||
@@ -902,6 +903,7 @@ impl CoreShellCommandExecutor {
|
||||
arg0: self.arg0.clone(),
|
||||
exec_server_sandbox: None,
|
||||
exec_server_enforce_managed_network: false,
|
||||
exec_server_managed_network: None,
|
||||
},
|
||||
/*stdout_stream*/ None,
|
||||
after_spawn,
|
||||
@@ -1010,6 +1012,7 @@ impl CoreShellCommandExecutor {
|
||||
args: args.to_vec(),
|
||||
cwd,
|
||||
env,
|
||||
managed_network: None,
|
||||
additional_permissions,
|
||||
};
|
||||
let options = ExecOptions {
|
||||
|
||||
@@ -41,6 +41,7 @@ use crate::unified_exec::NoopSpawnLifecycle;
|
||||
use crate::unified_exec::UnifiedExecError;
|
||||
use crate::unified_exec::UnifiedExecProcess;
|
||||
use crate::unified_exec::UnifiedExecProcessManager;
|
||||
use codex_network_proxy::ManagedNetworkSandboxContext;
|
||||
use codex_network_proxy::NetworkProxy;
|
||||
use codex_protocol::error::CodexErr;
|
||||
use codex_protocol::error::SandboxErr;
|
||||
@@ -117,6 +118,7 @@ fn build_unified_exec_sandbox_command(
|
||||
command: &[String],
|
||||
cwd: &PathUri,
|
||||
env: &HashMap<String, String>,
|
||||
managed_network: Option<ManagedNetworkSandboxContext>,
|
||||
additional_permissions: Option<AdditionalPermissionProfile>,
|
||||
) -> Result<SandboxCommand, ToolError> {
|
||||
let (program, args) = command
|
||||
@@ -127,6 +129,7 @@ fn build_unified_exec_sandbox_command(
|
||||
args: args.to_vec(),
|
||||
cwd: cwd.clone(),
|
||||
env: env.clone(),
|
||||
managed_network,
|
||||
additional_permissions,
|
||||
})
|
||||
}
|
||||
@@ -321,22 +324,28 @@ impl<'a> ToolRuntime<UnifiedExecRequest, UnifiedExecProcess> for UnifiedExecRunt
|
||||
req.network.as_ref(),
|
||||
launch_sandbox_permissions,
|
||||
);
|
||||
let mut env = exec_env_for_sandbox_permissions(&req.env, launch_sandbox_permissions);
|
||||
if let Some(network) = managed_network {
|
||||
network
|
||||
.apply_to_env_for_optional_environment(
|
||||
&mut env,
|
||||
Some(&req.turn_environment.environment_id),
|
||||
)
|
||||
.map_err(|err| {
|
||||
ToolError::Codex(CodexErr::Io(io::Error::other(format!(
|
||||
"failed to prepare network proxy for environment `{}`: {err}",
|
||||
req.turn_environment.environment_id
|
||||
))))
|
||||
})?;
|
||||
}
|
||||
let env = exec_env_for_sandbox_permissions(&req.env, launch_sandbox_permissions);
|
||||
let (env, managed_network_context) = match managed_network {
|
||||
Some(network) => {
|
||||
let prepared = network
|
||||
.prepare_for_optional_environment(
|
||||
env,
|
||||
Some(&req.turn_environment.environment_id),
|
||||
)
|
||||
.map_err(|err| {
|
||||
ToolError::Codex(CodexErr::Io(io::Error::other(format!(
|
||||
"failed to prepare network proxy for environment `{}`: {err}",
|
||||
req.turn_environment.environment_id
|
||||
))))
|
||||
})?;
|
||||
(prepared.env, Some(prepared.sandbox_context))
|
||||
}
|
||||
None => (env, None),
|
||||
};
|
||||
let explicit_env_overrides = req.explicit_env_overrides.clone();
|
||||
#[cfg(unix)]
|
||||
let mut env = env;
|
||||
#[cfg(unix)]
|
||||
let runtime_path_prepends = {
|
||||
let mut runtime_path_prepends = RuntimePathPrepends::default();
|
||||
if !environment_is_remote {
|
||||
@@ -385,6 +394,7 @@ impl<'a> ToolRuntime<UnifiedExecRequest, UnifiedExecProcess> for UnifiedExecRunt
|
||||
&command,
|
||||
&req.cwd,
|
||||
&env,
|
||||
managed_network_context.clone(),
|
||||
req.additional_permissions.clone(),
|
||||
)
|
||||
.map_err(|error| match error {
|
||||
@@ -450,6 +460,7 @@ impl<'a> ToolRuntime<UnifiedExecRequest, UnifiedExecProcess> for UnifiedExecRunt
|
||||
&command,
|
||||
&req.cwd,
|
||||
&env,
|
||||
managed_network_context,
|
||||
req.additional_permissions.clone(),
|
||||
)
|
||||
.map_err(|error| match error {
|
||||
|
||||
@@ -196,7 +196,7 @@ impl ExecApprovalRequirement {
|
||||
}
|
||||
}
|
||||
|
||||
/// - Never, OnFailure: do not ask
|
||||
/// - Never: do not ask
|
||||
/// - OnRequest: ask unless filesystem access is unrestricted
|
||||
/// - Granular: ask unless filesystem access is unrestricted, but auto-reject
|
||||
/// when granular sandbox approval is disabled.
|
||||
@@ -206,7 +206,7 @@ pub(crate) fn default_exec_approval_requirement(
|
||||
file_system_sandbox_policy: &FileSystemSandboxPolicy,
|
||||
) -> ExecApprovalRequirement {
|
||||
let needs_approval = match policy {
|
||||
AskForApproval::Never | AskForApproval::OnFailure => false,
|
||||
AskForApproval::Never => false,
|
||||
AskForApproval::OnRequest | AskForApproval::Granular(_) => {
|
||||
matches!(
|
||||
file_system_sandbox_policy.kind,
|
||||
@@ -356,7 +356,6 @@ pub(crate) trait Approvable<Req> {
|
||||
/// Decide we can request an approval for no-sandbox execution.
|
||||
fn wants_no_sandbox_approval(&self, policy: AskForApproval) -> bool {
|
||||
match policy {
|
||||
AskForApproval::OnFailure => true,
|
||||
AskForApproval::UnlessTrusted => true,
|
||||
AskForApproval::Never => false,
|
||||
AskForApproval::OnRequest => false,
|
||||
@@ -466,6 +465,7 @@ impl<'a> SandboxAttempt<'a> {
|
||||
network: Option<&NetworkProxy>,
|
||||
environment_id: Option<&str>,
|
||||
) -> Result<crate::sandboxing::ExecRequest, CodexErr> {
|
||||
let managed_network = command.managed_network.clone();
|
||||
let exec_server_permissions = effective_permission_profile(
|
||||
self.exec_server_permissions,
|
||||
command.additional_permissions.as_ref(),
|
||||
@@ -492,6 +492,7 @@ impl<'a> SandboxAttempt<'a> {
|
||||
options,
|
||||
self.workspace_roots.to_vec(),
|
||||
);
|
||||
exec_request.exec_server_managed_network = managed_network;
|
||||
if self.sandbox_requested {
|
||||
exec_request.exec_server_sandbox = Some(FileSystemSandboxContext {
|
||||
permissions: exec_server_permissions.into(),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use super::*;
|
||||
use crate::sandboxing::SandboxPermissions;
|
||||
use crate::tools::hook_names::HookToolName;
|
||||
use codex_network_proxy::ManagedNetworkSandboxContext;
|
||||
use codex_protocol::permissions::FileSystemAccessMode;
|
||||
use codex_protocol::permissions::FileSystemPath;
|
||||
use codex_protocol::permissions::FileSystemSandboxEntry;
|
||||
@@ -212,7 +213,7 @@ fn exec_server_env_keeps_command_native_and_carries_sandbox_context() {
|
||||
.clone()
|
||||
.materialize_project_roots_with_workspace_roots(std::slice::from_ref(&cwd));
|
||||
let manager = SandboxManager::new();
|
||||
let attempt = SandboxAttempt {
|
||||
let mut attempt = SandboxAttempt {
|
||||
sandbox: SandboxType::None,
|
||||
sandbox_requested: true,
|
||||
permissions: &permissions,
|
||||
@@ -227,20 +228,24 @@ fn exec_server_env_keeps_command_native_and_carries_sandbox_context() {
|
||||
windows_sandbox_private_desktop: false,
|
||||
network_denial_cancellation_token: None,
|
||||
};
|
||||
let command = SandboxCommand {
|
||||
let managed_network = ManagedNetworkSandboxContext {
|
||||
loopback_ports: vec![43123],
|
||||
allow_local_binding: false,
|
||||
};
|
||||
let command = || SandboxCommand {
|
||||
program: "/bin/bash".into(),
|
||||
args: vec!["-lc".to_string(), "pwd".to_string()],
|
||||
cwd: cwd_uri.clone(),
|
||||
env: HashMap::new(),
|
||||
managed_network: Some(managed_network.clone()),
|
||||
additional_permissions: None,
|
||||
};
|
||||
let options = crate::sandboxing::ExecOptions {
|
||||
let options = || crate::sandboxing::ExecOptions {
|
||||
expiration: crate::exec::ExecExpiration::DefaultTimeout,
|
||||
capture_policy: crate::exec::ExecCapturePolicy::ShellTool,
|
||||
};
|
||||
|
||||
let request = attempt
|
||||
.env_for_exec_server(command, options, /*network*/ None, Some("remote"))
|
||||
.env_for_exec_server(command(), options(), /*network*/ None, Some("remote"))
|
||||
.expect("prepare remote exec request");
|
||||
|
||||
assert_eq!(
|
||||
@@ -256,8 +261,8 @@ fn exec_server_env_keeps_command_native_and_carries_sandbox_context() {
|
||||
assert_eq!(
|
||||
request.exec_server_sandbox,
|
||||
Some(codex_exec_server::FileSystemSandboxContext {
|
||||
permissions: exec_server_permissions.into(),
|
||||
cwd: Some(cwd_uri),
|
||||
permissions: exec_server_permissions.clone().into(),
|
||||
cwd: Some(cwd_uri.clone()),
|
||||
workspace_roots: Vec::new(),
|
||||
windows_sandbox_level: codex_protocol::config_types::WindowsSandboxLevel::Disabled,
|
||||
windows_sandbox_private_desktop: false,
|
||||
@@ -265,4 +270,17 @@ fn exec_server_env_keeps_command_native_and_carries_sandbox_context() {
|
||||
})
|
||||
);
|
||||
assert!(request.exec_server_enforce_managed_network);
|
||||
assert_eq!(
|
||||
request.exec_server_managed_network,
|
||||
Some(managed_network.clone())
|
||||
);
|
||||
|
||||
attempt.sandbox_requested = false;
|
||||
let request = attempt
|
||||
.env_for_exec_server(command(), options(), /*network*/ None, Some("remote"))
|
||||
.expect("prepare unsandboxed remote exec request");
|
||||
|
||||
assert_eq!(request.exec_server_sandbox, None);
|
||||
assert!(!request.exec_server_enforce_managed_network);
|
||||
assert_eq!(request.exec_server_managed_network, Some(managed_network));
|
||||
}
|
||||
|
||||
@@ -96,6 +96,7 @@ use tracing::warn;
|
||||
const MULTI_AGENT_V2_NAMESPACE_DESCRIPTION: &str = "Tools for spawning and managing sub-agents.";
|
||||
const IMAGE_GEN_NAMESPACE: &str = "image_gen";
|
||||
const IMAGEGEN_TOOL_NAME: &str = "imagegen";
|
||||
const ACTOR_AUTHORIZATION_HEADER: &str = "x-openai-actor-authorization";
|
||||
|
||||
type PlannedRuntime = Arc<dyn CoreToolRuntime>;
|
||||
|
||||
@@ -383,10 +384,12 @@ fn image_generation_tool_enabled(turn_context: &TurnContext) -> bool {
|
||||
}
|
||||
|
||||
fn image_generation_runtime_enabled(turn_context: &TurnContext) -> bool {
|
||||
turn_context
|
||||
.auth_manager
|
||||
.as_deref()
|
||||
.is_some_and(AuthManager::current_auth_uses_codex_backend)
|
||||
(provider_uses_actor_authorization(turn_context)
|
||||
|| (turn_context.provider.info().requires_openai_auth
|
||||
&& turn_context
|
||||
.auth_manager
|
||||
.as_deref()
|
||||
.is_some_and(AuthManager::current_auth_uses_codex_backend)))
|
||||
&& turn_context.provider.capabilities().image_generation
|
||||
&& turn_context
|
||||
.model_info
|
||||
@@ -394,6 +397,16 @@ fn image_generation_runtime_enabled(turn_context: &TurnContext) -> bool {
|
||||
.contains(&InputModality::Image)
|
||||
}
|
||||
|
||||
fn provider_uses_actor_authorization(turn_context: &TurnContext) -> bool {
|
||||
let provider_info = turn_context.provider.info();
|
||||
!provider_info.requires_openai_auth
|
||||
&& provider_info.http_headers.as_ref().is_some_and(|headers| {
|
||||
headers.iter().any(|(name, value)| {
|
||||
name.eq_ignore_ascii_case(ACTOR_AUTHORIZATION_HEADER) && !value.trim().is_empty()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
fn standalone_image_generation_model_visible(turn_context: &TurnContext) -> bool {
|
||||
if !image_generation_runtime_enabled(turn_context) || !namespace_tools_enabled(turn_context) {
|
||||
return false;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use std::collections::BTreeMap;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
use codex_features::Feature;
|
||||
@@ -270,6 +271,29 @@ fn use_bedrock_provider(turn: &mut TurnContext) {
|
||||
turn.provider = create_model_provider(provider_info, turn.auth_manager.clone());
|
||||
}
|
||||
|
||||
fn use_provider_auth(
|
||||
turn: &mut TurnContext,
|
||||
requires_openai_auth: bool,
|
||||
actor_header: Option<(&str, &str)>,
|
||||
) {
|
||||
let mut provider_info = turn.config.model_provider.clone();
|
||||
provider_info.requires_openai_auth = requires_openai_auth;
|
||||
provider_info.http_headers = actor_header.map(|(name, value)| {
|
||||
HashMap::from([
|
||||
(name.to_string(), value.to_string()),
|
||||
(
|
||||
"ChatGPT-Account-ID".to_string(),
|
||||
"test-account-id".to_string(),
|
||||
),
|
||||
])
|
||||
});
|
||||
turn.auth_manager = None;
|
||||
update_config(turn, |config| {
|
||||
config.model_provider = provider_info.clone();
|
||||
});
|
||||
turn.provider = create_model_provider(provider_info, /*auth_manager*/ None);
|
||||
}
|
||||
|
||||
struct WebRunExtensionTool;
|
||||
|
||||
impl ToolExecutor<ExtensionToolCall> for WebRunExtensionTool {
|
||||
@@ -1455,6 +1479,110 @@ async fn hosted_tools_follow_provider_auth_model_and_config_gates() {
|
||||
.await;
|
||||
api_key_auth.assert_visible_lacks(&["image_generation"]);
|
||||
|
||||
let unrelated_chatgpt_auth = probe(|turn| {
|
||||
use_chatgpt_auth(turn);
|
||||
set_feature(turn, Feature::ImageGeneration, /*enabled*/ true);
|
||||
let mut provider_info = turn.provider.info().clone();
|
||||
provider_info.requires_openai_auth = false;
|
||||
provider_info.http_headers = None;
|
||||
update_config(turn, |config| {
|
||||
config.model_provider = provider_info.clone();
|
||||
});
|
||||
turn.provider = create_model_provider(provider_info, turn.auth_manager.clone());
|
||||
turn.model_info.input_modalities = vec![InputModality::Image];
|
||||
})
|
||||
.await;
|
||||
unrelated_chatgpt_auth.assert_visible_lacks(&["image_generation"]);
|
||||
|
||||
let provider_without_actor_auth = probe(|turn| {
|
||||
set_feature(turn, Feature::ImageGeneration, /*enabled*/ true);
|
||||
use_provider_auth(
|
||||
turn, /*requires_openai_auth*/ false, /*actor_header*/ None,
|
||||
);
|
||||
turn.model_info.input_modalities = vec![InputModality::Image];
|
||||
})
|
||||
.await;
|
||||
provider_without_actor_auth.assert_visible_lacks(&["image_generation"]);
|
||||
|
||||
let provider_authenticated = probe(|turn| {
|
||||
set_feature(turn, Feature::ImageGeneration, /*enabled*/ true);
|
||||
use_provider_auth(
|
||||
turn,
|
||||
/*requires_openai_auth*/ false,
|
||||
Some(("X-OpenAI-Actor-Authorization", "test-actor-authorization")),
|
||||
);
|
||||
turn.model_info.input_modalities = vec![InputModality::Image];
|
||||
})
|
||||
.await;
|
||||
provider_authenticated.assert_visible_contains(&["image_generation"]);
|
||||
|
||||
let empty_actor_auth = probe(|turn| {
|
||||
set_feature(turn, Feature::ImageGeneration, /*enabled*/ true);
|
||||
use_provider_auth(
|
||||
turn,
|
||||
/*requires_openai_auth*/ false,
|
||||
Some(("x-openai-actor-authorization", " ")),
|
||||
);
|
||||
turn.model_info.input_modalities = vec![InputModality::Image];
|
||||
})
|
||||
.await;
|
||||
empty_actor_auth.assert_visible_lacks(&["image_generation"]);
|
||||
|
||||
let feature_disabled = probe(|turn| {
|
||||
set_feature(turn, Feature::ImageGeneration, /*enabled*/ false);
|
||||
use_provider_auth(
|
||||
turn,
|
||||
/*requires_openai_auth*/ false,
|
||||
Some(("x-openai-actor-authorization", "test-actor-authorization")),
|
||||
);
|
||||
turn.model_info.input_modalities = vec![InputModality::Image];
|
||||
})
|
||||
.await;
|
||||
feature_disabled.assert_visible_lacks(&["image_generation"]);
|
||||
|
||||
let text_only_model = probe(|turn| {
|
||||
set_feature(turn, Feature::ImageGeneration, /*enabled*/ true);
|
||||
use_provider_auth(
|
||||
turn,
|
||||
/*requires_openai_auth*/ false,
|
||||
Some(("x-openai-actor-authorization", "test-actor-authorization")),
|
||||
);
|
||||
turn.model_info.input_modalities = vec![];
|
||||
})
|
||||
.await;
|
||||
text_only_model.assert_visible_lacks(&["image_generation"]);
|
||||
|
||||
let unsupported_image_generation_provider = probe(|turn| {
|
||||
set_feature(turn, Feature::ImageGeneration, /*enabled*/ true);
|
||||
use_bedrock_provider(turn);
|
||||
let mut provider_info = turn.provider.info().clone();
|
||||
provider_info.requires_openai_auth = false;
|
||||
provider_info.http_headers = Some(HashMap::from([(
|
||||
"x-openai-actor-authorization".to_string(),
|
||||
"test-actor-authorization".to_string(),
|
||||
)]));
|
||||
turn.auth_manager = None;
|
||||
update_config(turn, |config| {
|
||||
config.model_provider = provider_info.clone();
|
||||
});
|
||||
turn.provider = create_model_provider(provider_info, /*auth_manager*/ None);
|
||||
turn.model_info.input_modalities = vec![InputModality::Image];
|
||||
})
|
||||
.await;
|
||||
unsupported_image_generation_provider.assert_visible_lacks(&["image_generation"]);
|
||||
|
||||
let codex_managed_auth_provider = probe(|turn| {
|
||||
set_feature(turn, Feature::ImageGeneration, /*enabled*/ true);
|
||||
use_provider_auth(
|
||||
turn,
|
||||
/*requires_openai_auth*/ true,
|
||||
Some(("x-openai-actor-authorization", "test-actor-authorization")),
|
||||
);
|
||||
turn.model_info.input_modalities = vec![InputModality::Image];
|
||||
})
|
||||
.await;
|
||||
codex_managed_auth_provider.assert_visible_lacks(&["image_generation"]);
|
||||
|
||||
let image_generation = probe(|turn| {
|
||||
use_chatgpt_auth(turn);
|
||||
set_feature(turn, Feature::ImageGeneration, /*enabled*/ true);
|
||||
|
||||
@@ -26,6 +26,7 @@ use crate::tools::events::ToolEventStage;
|
||||
use crate::tools::network_approval::DeferredNetworkApproval;
|
||||
use crate::tools::network_approval::finish_deferred_network_approval;
|
||||
use crate::tools::orchestrator::ToolOrchestrator;
|
||||
use crate::tools::runtimes::is_managed_proxy_env_var;
|
||||
use crate::tools::runtimes::unified_exec::UnifiedExecRequest as UnifiedExecToolRequest;
|
||||
use crate::tools::runtimes::unified_exec::UnifiedExecRuntime;
|
||||
use crate::tools::sandboxing::SandboxAttempt;
|
||||
@@ -143,10 +144,16 @@ fn exec_server_env_for_request(
|
||||
HashMap<String, String>,
|
||||
) {
|
||||
if let Some(exec_server_env_config) = &request.exec_server_env_config {
|
||||
(
|
||||
Some(exec_server_env_config.policy.clone()),
|
||||
env_overlay_for_exec_server(&request.env, &exec_server_env_config.local_policy_env),
|
||||
)
|
||||
let mut env =
|
||||
env_overlay_for_exec_server(&request.env, &exec_server_env_config.local_policy_env);
|
||||
if request.exec_server_managed_network.is_some() {
|
||||
for (key, value) in &request.env {
|
||||
if is_managed_proxy_env_var(key, value) {
|
||||
env.insert(key.clone(), value.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
(Some(exec_server_env_config.policy.clone()), env)
|
||||
} else {
|
||||
(None, request.env.clone())
|
||||
}
|
||||
@@ -175,6 +182,7 @@ fn exec_server_params_for_request(
|
||||
arg0: request.arg0.clone(),
|
||||
sandbox: request.exec_server_sandbox.clone(),
|
||||
enforce_managed_network: request.exec_server_enforce_managed_network,
|
||||
managed_network: request.exec_server_managed_network.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use super::*;
|
||||
use crate::unified_exec::clamp_yield_time;
|
||||
use codex_network_proxy::ManagedNetworkSandboxContext;
|
||||
use pretty_assertions::assert_eq;
|
||||
use tokio::time::Duration;
|
||||
use tokio::time::Instant;
|
||||
@@ -76,6 +77,10 @@ fn exec_server_params_use_path_uri_and_env_policy_overlay_contract() {
|
||||
codex_protocol::permissions::FileSystemSandboxPolicy::unrestricted();
|
||||
let network_sandbox_policy = codex_protocol::permissions::NetworkSandboxPolicy::Restricted;
|
||||
let permission_profile = codex_protocol::models::PermissionProfile::Disabled;
|
||||
let managed_network = ManagedNetworkSandboxContext {
|
||||
loopback_ports: vec![43123],
|
||||
allow_local_binding: false,
|
||||
};
|
||||
let mut request = ExecRequest {
|
||||
command: vec!["bash".to_string(), "-lc".to_string(), "true".to_string()],
|
||||
cwd: cwd.clone().into(),
|
||||
@@ -83,6 +88,15 @@ fn exec_server_params_use_path_uri_and_env_policy_overlay_contract() {
|
||||
("HOME".to_string(), "/client-home".to_string()),
|
||||
("PATH".to_string(), "/sandbox-path".to_string()),
|
||||
("CODEX_THREAD_ID".to_string(), "thread-1".to_string()),
|
||||
(
|
||||
"HTTP_PROXY".to_string(),
|
||||
"http://127.0.0.1:43123".to_string(),
|
||||
),
|
||||
("CODEX_NETWORK_PROXY_ACTIVE".to_string(), "1".to_string()),
|
||||
(
|
||||
"SSL_CERT_FILE".to_string(),
|
||||
"/client/custom-ca.pem".to_string(),
|
||||
),
|
||||
]),
|
||||
exec_server_env_config: Some(ExecServerEnvConfig {
|
||||
policy: codex_exec_server::ExecEnvPolicy {
|
||||
@@ -95,6 +109,15 @@ fn exec_server_params_use_path_uri_and_env_policy_overlay_contract() {
|
||||
local_policy_env: HashMap::from([
|
||||
("HOME".to_string(), "/client-home".to_string()),
|
||||
("PATH".to_string(), "/client-path".to_string()),
|
||||
(
|
||||
"HTTP_PROXY".to_string(),
|
||||
"http://127.0.0.1:43123".to_string(),
|
||||
),
|
||||
("CODEX_NETWORK_PROXY_ACTIVE".to_string(), "1".to_string()),
|
||||
(
|
||||
"SSL_CERT_FILE".to_string(),
|
||||
"/client/custom-ca.pem".to_string(),
|
||||
),
|
||||
]),
|
||||
}),
|
||||
network: None,
|
||||
@@ -112,7 +135,8 @@ fn exec_server_params_use_path_uri_and_env_policy_overlay_contract() {
|
||||
windows_sandbox_filesystem_overrides: None,
|
||||
arg0: None,
|
||||
exec_server_sandbox: None,
|
||||
exec_server_enforce_managed_network: false,
|
||||
exec_server_enforce_managed_network: true,
|
||||
exec_server_managed_network: Some(managed_network.clone()),
|
||||
};
|
||||
|
||||
let params =
|
||||
@@ -120,12 +144,19 @@ fn exec_server_params_use_path_uri_and_env_policy_overlay_contract() {
|
||||
|
||||
assert_eq!(params.process_id.as_str(), "123");
|
||||
assert_eq!(params.cwd, request.cwd);
|
||||
assert!(params.enforce_managed_network);
|
||||
assert_eq!(params.managed_network, Some(managed_network));
|
||||
assert!(params.env_policy.is_some());
|
||||
assert_eq!(
|
||||
params.env,
|
||||
HashMap::from([
|
||||
("PATH".to_string(), "/sandbox-path".to_string()),
|
||||
("CODEX_THREAD_ID".to_string(), "thread-1".to_string()),
|
||||
(
|
||||
"HTTP_PROXY".to_string(),
|
||||
"http://127.0.0.1:43123".to_string(),
|
||||
),
|
||||
("CODEX_NETWORK_PROXY_ACTIVE".to_string(), "1".to_string(),),
|
||||
])
|
||||
);
|
||||
request.exec_server_sandbox = Some(
|
||||
|
||||
@@ -1085,40 +1085,6 @@ fn scenarios() -> Vec<ScenarioSpec> {
|
||||
output_contains: "rejected by user",
|
||||
},
|
||||
},
|
||||
ScenarioSpec {
|
||||
name: "danger_full_access_on_failure_allows_outside_write",
|
||||
approval_policy: OnFailure,
|
||||
sandbox_policy: SandboxPolicy::DangerFullAccess,
|
||||
action: ActionKind::WriteFile {
|
||||
target: TargetPath::OutsideWorkspace("dfa_on_failure.txt"),
|
||||
content: "danger-on-failure",
|
||||
},
|
||||
sandbox_permissions: SandboxPermissions::UseDefault,
|
||||
features: vec![],
|
||||
model_override: Some("gpt-5.2"),
|
||||
outcome: Outcome::Auto,
|
||||
expectation: Expectation::FileCreated {
|
||||
target: TargetPath::OutsideWorkspace("dfa_on_failure.txt"),
|
||||
content: "danger-on-failure",
|
||||
},
|
||||
},
|
||||
ScenarioSpec {
|
||||
name: "danger_full_access_on_failure_allows_outside_write_gpt_5_1_no_exit",
|
||||
approval_policy: OnFailure,
|
||||
sandbox_policy: SandboxPolicy::DangerFullAccess,
|
||||
action: ActionKind::WriteFile {
|
||||
target: TargetPath::OutsideWorkspace("dfa_on_failure_5_1.txt"),
|
||||
content: "danger-on-failure",
|
||||
},
|
||||
sandbox_permissions: SandboxPermissions::UseDefault,
|
||||
features: vec![],
|
||||
model_override: Some("gpt-5.4"),
|
||||
outcome: Outcome::Auto,
|
||||
expectation: Expectation::FileCreatedNoExitCode {
|
||||
target: TargetPath::OutsideWorkspace("dfa_on_failure_5_1.txt"),
|
||||
content: "danger-on-failure",
|
||||
},
|
||||
},
|
||||
ScenarioSpec {
|
||||
name: "danger_full_access_unless_trusted_requests_approval",
|
||||
approval_policy: UnlessTrusted,
|
||||
@@ -1297,48 +1263,6 @@ fn scenarios() -> Vec<ScenarioSpec> {
|
||||
message_contains: &["exec command rejected by user"],
|
||||
},
|
||||
},
|
||||
#[cfg(not(target_os = "linux"))] // TODO (pakrym): figure out why linux behaves differently
|
||||
ScenarioSpec {
|
||||
name: "read_only_on_failure_escalates_after_sandbox_error",
|
||||
approval_policy: OnFailure,
|
||||
sandbox_policy: SandboxPolicy::new_read_only_policy(),
|
||||
action: ActionKind::WriteFile {
|
||||
target: TargetPath::Workspace("ro_on_failure.txt"),
|
||||
content: "read-only-on-failure",
|
||||
},
|
||||
sandbox_permissions: SandboxPermissions::UseDefault,
|
||||
features: vec![],
|
||||
model_override: Some("gpt-5.2"),
|
||||
outcome: Outcome::ExecApproval {
|
||||
decision: ReviewDecision::Approved,
|
||||
expected_reason: Some("command failed; retry without sandbox?"),
|
||||
},
|
||||
expectation: Expectation::FileCreated {
|
||||
target: TargetPath::Workspace("ro_on_failure.txt"),
|
||||
content: "read-only-on-failure",
|
||||
},
|
||||
},
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
ScenarioSpec {
|
||||
name: "read_only_on_failure_escalates_after_sandbox_error_gpt_5_1_no_exit",
|
||||
approval_policy: OnFailure,
|
||||
sandbox_policy: SandboxPolicy::new_read_only_policy(),
|
||||
action: ActionKind::WriteFile {
|
||||
target: TargetPath::Workspace("ro_on_failure_5_1.txt"),
|
||||
content: "read-only-on-failure",
|
||||
},
|
||||
sandbox_permissions: SandboxPermissions::UseDefault,
|
||||
features: vec![],
|
||||
model_override: Some("gpt-5.4"),
|
||||
outcome: Outcome::ExecApproval {
|
||||
decision: ReviewDecision::Approved,
|
||||
expected_reason: Some("command failed; retry without sandbox?"),
|
||||
},
|
||||
expectation: Expectation::FileCreatedNoExitCode {
|
||||
target: TargetPath::Workspace("ro_on_failure_5_1.txt"),
|
||||
content: "read-only-on-failure",
|
||||
},
|
||||
},
|
||||
ScenarioSpec {
|
||||
name: "read_only_on_request_network_escalates_when_approved",
|
||||
approval_policy: OnRequest,
|
||||
@@ -1676,27 +1600,6 @@ fn scenarios() -> Vec<ScenarioSpec> {
|
||||
body_contains: "workspace-network-ok",
|
||||
},
|
||||
},
|
||||
#[cfg(not(target_os = "linux"))] // TODO (pakrym): figure out why linux behaves differently
|
||||
ScenarioSpec {
|
||||
name: "workspace_write_on_failure_escalates_outside_workspace",
|
||||
approval_policy: OnFailure,
|
||||
sandbox_policy: workspace_write(false),
|
||||
action: ActionKind::WriteFile {
|
||||
target: TargetPath::OutsideWorkspace("ww_on_failure.txt"),
|
||||
content: "workspace-on-failure",
|
||||
},
|
||||
sandbox_permissions: SandboxPermissions::UseDefault,
|
||||
features: vec![],
|
||||
model_override: Some("gpt-5.2"),
|
||||
outcome: Outcome::ExecApproval {
|
||||
decision: ReviewDecision::Approved,
|
||||
expected_reason: Some("command failed; retry without sandbox?"),
|
||||
},
|
||||
expectation: Expectation::FileCreated {
|
||||
target: TargetPath::OutsideWorkspace("ww_on_failure.txt"),
|
||||
content: "workspace-on-failure",
|
||||
},
|
||||
},
|
||||
ScenarioSpec {
|
||||
name: "workspace_write_unless_trusted_requires_approval_outside_workspace",
|
||||
approval_policy: UnlessTrusted,
|
||||
@@ -2982,7 +2885,7 @@ mode = "limited"
|
||||
allow_local_binding = true
|
||||
"#,
|
||||
)?;
|
||||
let approval_policy = AskForApproval::OnFailure;
|
||||
let approval_policy = AskForApproval::OnRequest;
|
||||
let sandbox_policy = SandboxPolicy::WorkspaceWrite {
|
||||
writable_roots: vec![],
|
||||
network_access: true,
|
||||
@@ -3467,7 +3370,7 @@ mode = "limited"
|
||||
allow_local_binding = true
|
||||
"#,
|
||||
)?;
|
||||
let approval_policy = AskForApproval::OnFailure;
|
||||
let approval_policy = AskForApproval::OnRequest;
|
||||
let turn_sandbox_policy = SandboxPolicy::WorkspaceWrite {
|
||||
writable_roots: vec![],
|
||||
network_access: true,
|
||||
|
||||
@@ -2200,7 +2200,7 @@ allow_local_binding = true
|
||||
)
|
||||
.await;
|
||||
|
||||
let approval_policy = AskForApproval::OnFailure;
|
||||
let approval_policy = AskForApproval::OnRequest;
|
||||
let permission_profile = network_workspace_write_profile();
|
||||
let permission_profile_for_config = permission_profile.clone();
|
||||
let test = test_codex()
|
||||
@@ -2283,71 +2283,6 @@ allow_local_binding = true
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
#[tokio::test]
|
||||
async fn permission_request_hook_sees_retry_context_after_sandbox_denial() -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
let server = start_mock_server().await;
|
||||
let call_id = "permissionrequest-retry-shell-command";
|
||||
let marker = "permissionrequest_retry_marker.txt";
|
||||
let command = format!("printf retry > {marker}");
|
||||
let args = serde_json::json!({ "command": command });
|
||||
let responses = mount_sse_sequence(
|
||||
&server,
|
||||
vec![
|
||||
sse(vec![
|
||||
ev_response_created("resp-1"),
|
||||
core_test_support::responses::ev_function_call(
|
||||
call_id,
|
||||
"shell_command",
|
||||
&serde_json::to_string(&args)?,
|
||||
),
|
||||
ev_completed("resp-1"),
|
||||
]),
|
||||
sse(vec![
|
||||
ev_response_created("resp-2"),
|
||||
ev_assistant_message("msg-1", "permission request hook allowed retry"),
|
||||
ev_completed("resp-2"),
|
||||
]),
|
||||
],
|
||||
)
|
||||
.await;
|
||||
|
||||
let mut builder = test_codex()
|
||||
.with_pre_build_hook(|home| {
|
||||
install_allow_permission_request_hook(home)
|
||||
.expect("failed to write permission request hook test fixture");
|
||||
})
|
||||
.with_config(trust_discovered_hooks);
|
||||
let test = builder.build(&server).await?;
|
||||
let marker_path = test.workspace_path(marker);
|
||||
let _ = fs::remove_file(&marker_path);
|
||||
|
||||
test.submit_turn_with_approval_and_permission_profile(
|
||||
"retry the shell command after sandbox denial",
|
||||
AskForApproval::OnFailure,
|
||||
PermissionProfile::read_only(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
let requests = responses.requests();
|
||||
assert_eq!(requests.len(), 2);
|
||||
requests[1].function_call_output(call_id);
|
||||
assert_eq!(
|
||||
fs::read_to_string(&marker_path).context("read retry marker")?,
|
||||
"retry"
|
||||
);
|
||||
|
||||
assert_single_permission_request_hook_input(
|
||||
test.codex_home_path(),
|
||||
&command,
|
||||
/*description*/ None,
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn pre_tool_use_blocks_shell_command_before_execution() -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
@@ -165,7 +165,7 @@ mode = "limited"
|
||||
allow_local_binding = true
|
||||
"#,
|
||||
)?;
|
||||
let approval_policy = AskForApproval::OnFailure;
|
||||
let approval_policy = AskForApproval::OnRequest;
|
||||
let permission_profile = PermissionProfile::workspace_write_with(
|
||||
&[],
|
||||
NetworkSandboxPolicy::Enabled,
|
||||
@@ -263,7 +263,7 @@ async fn submit_managed_network_turn(
|
||||
additional_context: Default::default(),
|
||||
thread_settings: codex_protocol::protocol::ThreadSettingsOverrides {
|
||||
environments: Some(turn_environment_selections),
|
||||
approval_policy: Some(AskForApproval::OnFailure),
|
||||
approval_policy: Some(AskForApproval::OnRequest),
|
||||
approvals_reviewer: Some(ApprovalsReviewer::User),
|
||||
sandbox_policy: Some(sandbox_policy),
|
||||
permission_profile,
|
||||
|
||||
@@ -315,151 +315,6 @@ async fn explicit_remote_shell_runs_in_remote_cwd() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn remote_sandbox_denial_requests_approval_and_retries() -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
skip_if_wine_exec!(Ok(()), "requires the Docker-backed POSIX executor");
|
||||
let Some(_remote_env) = get_remote_test_env() else {
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
const CALL_ID: &str = "remote-sandbox-denial";
|
||||
const CONTENTS: &str = "remote sandbox retry succeeded";
|
||||
|
||||
let server = start_mock_server().await;
|
||||
let test = unified_exec_test(&server).await?;
|
||||
let nonce = SystemTime::now().duration_since(UNIX_EPOCH)?.as_millis();
|
||||
let remote_cwd = PathBuf::from(format!("/tmp/codex-remote-denial-cwd-{nonce}")).abs();
|
||||
let target_path = PathBuf::from(format!("/tmp/codex-remote-denial-target-{nonce}")).abs();
|
||||
let remote_cwd_uri = PathUri::from_host_native_path(&remote_cwd)?;
|
||||
let target_uri = PathUri::from_host_native_path(&target_path)?;
|
||||
test.fs()
|
||||
.create_directory(
|
||||
&remote_cwd_uri,
|
||||
CreateDirectoryOptions { recursive: true },
|
||||
/*sandbox*/ None,
|
||||
)
|
||||
.await?;
|
||||
test.fs()
|
||||
.remove(
|
||||
&target_uri,
|
||||
RemoveOptions {
|
||||
recursive: false,
|
||||
force: true,
|
||||
},
|
||||
/*sandbox*/ None,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let command = format!("printf {CONTENTS:?} > {target_path:?} && cat {target_path:?}");
|
||||
let response_mock = mount_sse_sequence(
|
||||
&server,
|
||||
vec![
|
||||
sse(vec![
|
||||
ev_response_created("resp-remote-denial-1"),
|
||||
ev_function_call(
|
||||
CALL_ID,
|
||||
"exec_command",
|
||||
&json!({
|
||||
"shell": "/bin/sh",
|
||||
"cmd": command,
|
||||
"login": false,
|
||||
"yield_time_ms": 5_000,
|
||||
"environment_id": REMOTE_ENVIRONMENT_ID,
|
||||
})
|
||||
.to_string(),
|
||||
),
|
||||
ev_completed("resp-remote-denial-1"),
|
||||
]),
|
||||
sse(vec![
|
||||
ev_response_created("resp-remote-denial-2"),
|
||||
ev_assistant_message("msg-remote-denial", "done"),
|
||||
ev_completed("resp-remote-denial-2"),
|
||||
]),
|
||||
],
|
||||
)
|
||||
.await;
|
||||
|
||||
submit_turn_with_approval_and_environments(
|
||||
&test,
|
||||
"retry a sandbox-denied command in the remote environment",
|
||||
vec![TurnEnvironmentSelection {
|
||||
environment_id: REMOTE_ENVIRONMENT_ID.to_string(),
|
||||
cwd: PathUri::from_abs_path(&remote_cwd),
|
||||
}],
|
||||
AskForApproval::OnFailure,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let event = wait_for_event(&test.codex, |event| {
|
||||
matches!(
|
||||
event,
|
||||
EventMsg::ExecApprovalRequest(_) | EventMsg::TurnComplete(_)
|
||||
)
|
||||
})
|
||||
.await;
|
||||
let EventMsg::ExecApprovalRequest(approval) = event else {
|
||||
panic!("expected remote sandbox approval before completion: {event:?}");
|
||||
};
|
||||
assert_eq!(approval.call_id, CALL_ID);
|
||||
assert_eq!(
|
||||
approval.environment_id.as_deref(),
|
||||
Some(REMOTE_ENVIRONMENT_ID)
|
||||
);
|
||||
assert_eq!(
|
||||
approval.reason.as_deref(),
|
||||
Some("command failed; retry without sandbox?")
|
||||
);
|
||||
|
||||
test.codex
|
||||
.submit(Op::ExecApproval {
|
||||
id: approval.effective_approval_id(),
|
||||
turn_id: None,
|
||||
decision: ReviewDecision::Approved,
|
||||
})
|
||||
.await?;
|
||||
wait_for_event(&test.codex, |event| {
|
||||
matches!(event, EventMsg::TurnComplete(_))
|
||||
})
|
||||
.await;
|
||||
|
||||
assert!(
|
||||
response_mock
|
||||
.function_call_output_text(CALL_ID)
|
||||
.is_some_and(|output| output.contains(CONTENTS)),
|
||||
"approved retry should return the remote command output"
|
||||
);
|
||||
assert_eq!(
|
||||
test.fs()
|
||||
.read_file_text(&target_uri, /*sandbox*/ None)
|
||||
.await?,
|
||||
CONTENTS
|
||||
);
|
||||
|
||||
test.fs()
|
||||
.remove(
|
||||
&target_uri,
|
||||
RemoveOptions {
|
||||
recursive: false,
|
||||
force: true,
|
||||
},
|
||||
/*sandbox*/ None,
|
||||
)
|
||||
.await?;
|
||||
test.fs()
|
||||
.remove(
|
||||
&remote_cwd_uri,
|
||||
RemoveOptions {
|
||||
recursive: true,
|
||||
force: true,
|
||||
},
|
||||
/*sandbox*/ None,
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn deferred_executor_does_not_duplicate_initial_environment_context() -> Result<()> {
|
||||
let server = start_mock_server().await;
|
||||
|
||||
@@ -29,7 +29,6 @@ use codex_protocol::protocol::Op;
|
||||
use codex_protocol::protocol::TurnEnvironmentSelection;
|
||||
use codex_protocol::user_input::UserInput;
|
||||
use codex_utils_path_uri::PathUri;
|
||||
use core_test_support::PathBufExt;
|
||||
use core_test_support::PathExt;
|
||||
use core_test_support::get_remote_test_env;
|
||||
use core_test_support::responses;
|
||||
@@ -42,7 +41,6 @@ use core_test_support::responses::mount_sse_sequence;
|
||||
use core_test_support::responses::sse;
|
||||
use core_test_support::responses::start_mock_server;
|
||||
use core_test_support::skip_if_no_network;
|
||||
use core_test_support::skip_if_wine_exec;
|
||||
use core_test_support::test_codex::TestCodex;
|
||||
use core_test_support::test_codex::local;
|
||||
use core_test_support::test_codex::test_codex;
|
||||
@@ -59,8 +57,6 @@ use serde_json::json;
|
||||
use std::fs;
|
||||
use std::io::Cursor;
|
||||
use std::path::PathBuf;
|
||||
use std::time::SystemTime;
|
||||
use std::time::UNIX_EPOCH;
|
||||
use tempfile::TempDir;
|
||||
use tokio::time::Duration;
|
||||
use wiremock::BodyPrintLimit;
|
||||
@@ -295,6 +291,7 @@ async fn view_image_tool_attaches_local_image() -> anyhow::Result<()> {
|
||||
|
||||
let rel_path = "assets/example.png";
|
||||
let abs_path = cwd.join(rel_path);
|
||||
let path_uri = PathUri::from_abs_path(&abs_path);
|
||||
let original_width = 2304;
|
||||
let original_height = 864;
|
||||
write_workspace_png(
|
||||
@@ -369,20 +366,20 @@ async fn view_image_tool_attaches_local_image() -> anyhow::Result<()> {
|
||||
match item_started.expect("view image item started event emitted") {
|
||||
codex_protocol::items::TurnItem::ImageView(item) => {
|
||||
assert_eq!(item.id, call_id);
|
||||
assert_eq!(item.path, abs_path);
|
||||
assert_eq!(item.path, path_uri);
|
||||
}
|
||||
other => panic!("expected ImageView item, got {other:?}"),
|
||||
}
|
||||
match item_completed.expect("view image item completed event emitted") {
|
||||
codex_protocol::items::TurnItem::ImageView(item) => {
|
||||
assert_eq!(item.id, call_id);
|
||||
assert_eq!(item.path, abs_path);
|
||||
assert_eq!(item.path, path_uri);
|
||||
}
|
||||
other => panic!("expected ImageView item, got {other:?}"),
|
||||
}
|
||||
let legacy_event = legacy_event.expect("legacy view image event emitted");
|
||||
assert_eq!(legacy_event.call_id, call_id);
|
||||
assert_eq!(legacy_event.path, abs_path);
|
||||
assert_eq!(legacy_event.path, path_uri);
|
||||
|
||||
let req = mock.single_request();
|
||||
let body = req.body_json();
|
||||
@@ -557,8 +554,10 @@ async fn view_image_tool_applies_local_sandbox_read_denies() -> anyhow::Result<(
|
||||
.function_call_output_content_and_success(call_id)
|
||||
.and_then(|(content, _)| content)
|
||||
.context("sandboxed view_image error text present")?;
|
||||
let expected_locate_prefix = format!("unable to locate image at `{}`:", denied_path.display());
|
||||
let expected_read_prefix = format!("unable to read image at `{}`:", denied_path.display());
|
||||
let denied_path_display =
|
||||
PathUri::from_host_native_path(&denied_path)?.inferred_native_path_string();
|
||||
let expected_locate_prefix = format!("unable to locate image at `{denied_path_display}`:");
|
||||
let expected_read_prefix = format!("unable to read image at `{denied_path_display}`:");
|
||||
assert!(
|
||||
output_text.starts_with(&expected_locate_prefix)
|
||||
|| output_text.starts_with(&expected_read_prefix),
|
||||
@@ -570,8 +569,6 @@ async fn view_image_tool_applies_local_sandbox_read_denies() -> anyhow::Result<(
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn view_image_routes_to_selected_remote_environment() -> anyhow::Result<()> {
|
||||
// TODO(anp): Remove after remote-cwd fixtures use target-native paths.
|
||||
skip_if_wine_exec!(Ok(()), "hardcodes a POSIX remote cwd");
|
||||
skip_if_no_network!(Ok(()));
|
||||
let Some(_remote_env) = get_remote_test_env() else {
|
||||
return Ok(());
|
||||
@@ -583,37 +580,26 @@ async fn view_image_routes_to_selected_remote_environment() -> anyhow::Result<()
|
||||
let local_cwd = TempDir::new()?;
|
||||
fs::write(local_cwd.path().join("remote.png"), b"not a remote image")?;
|
||||
let local_selection = local(local_cwd.path().abs());
|
||||
let remote_cwd = PathBuf::from(format!(
|
||||
"/tmp/codex-view-image-routing-{}",
|
||||
SystemTime::now().duration_since(UNIX_EPOCH)?.as_millis()
|
||||
))
|
||||
.abs();
|
||||
let image_path = remote_cwd.join("remote.png");
|
||||
let remote_cwd_uri = PathUri::from_host_native_path(&remote_cwd)?;
|
||||
test.fs()
|
||||
.create_directory(
|
||||
&remote_cwd_uri,
|
||||
CreateDirectoryOptions { recursive: true },
|
||||
/*sandbox*/ None,
|
||||
)
|
||||
.await?;
|
||||
let remote_cwd_uri = PathUri::from_abs_path(test.executor_environment().cwd());
|
||||
let image_path_uri = remote_cwd_uri.join("remote.png")?;
|
||||
let png = png_bytes(/*width*/ 1, /*height*/ 1, [0, 255, 0, 255])?;
|
||||
let image_path_uri = PathUri::from_host_native_path(&image_path)?;
|
||||
test.fs()
|
||||
.write_file(&image_path_uri, png, /*sandbox*/ None)
|
||||
.await?;
|
||||
let absolute_image_path = image_path_uri.inferred_native_path_string();
|
||||
let remote_selection = TurnEnvironmentSelection {
|
||||
environment_id: REMOTE_ENVIRONMENT_ID.to_string(),
|
||||
cwd: PathUri::from_abs_path(&remote_cwd),
|
||||
cwd: remote_cwd_uri,
|
||||
};
|
||||
let call_id = "call-view-image-multi-env";
|
||||
let relative_call_id = "call-view-image-relative-multi-env";
|
||||
let absolute_call_id = "call-view-image-absolute-multi-env";
|
||||
let response_mock = mount_sse_sequence(
|
||||
&server,
|
||||
vec![
|
||||
sse(vec![
|
||||
ev_response_created("resp-1"),
|
||||
ev_function_call(
|
||||
call_id,
|
||||
relative_call_id,
|
||||
"view_image",
|
||||
&json!({
|
||||
"path": "remote.png",
|
||||
@@ -625,9 +611,22 @@ async fn view_image_routes_to_selected_remote_environment() -> anyhow::Result<()
|
||||
]),
|
||||
sse(vec![
|
||||
ev_response_created("resp-2"),
|
||||
ev_assistant_message("msg-1", "done"),
|
||||
ev_function_call(
|
||||
absolute_call_id,
|
||||
"view_image",
|
||||
&json!({
|
||||
"path": absolute_image_path,
|
||||
"environment_id": REMOTE_ENVIRONMENT_ID,
|
||||
})
|
||||
.to_string(),
|
||||
),
|
||||
ev_completed("resp-2"),
|
||||
]),
|
||||
sse(vec![
|
||||
ev_response_created("resp-3"),
|
||||
ev_assistant_message("msg-1", "done"),
|
||||
ev_completed("resp-3"),
|
||||
]),
|
||||
],
|
||||
)
|
||||
.await;
|
||||
@@ -638,30 +637,32 @@ async fn view_image_routes_to_selected_remote_environment() -> anyhow::Result<()
|
||||
)
|
||||
.await?;
|
||||
|
||||
let output = response_mock
|
||||
let request = response_mock
|
||||
.last_request()
|
||||
.context("missing request containing view_image output")?
|
||||
.function_call_output(call_id)
|
||||
.clone();
|
||||
let output_items = output
|
||||
.get("output")
|
||||
.and_then(Value::as_array)
|
||||
.context("view_image output should be content items")?;
|
||||
assert_eq!(output_items.len(), 1);
|
||||
let image_url = output_items[0]
|
||||
.get("image_url")
|
||||
.and_then(Value::as_str)
|
||||
.context("view_image output should include image_url")?;
|
||||
assert!(
|
||||
image_url.starts_with("data:image/png;base64,"),
|
||||
"unexpected image_url: {image_url}",
|
||||
);
|
||||
for call_id in [relative_call_id, absolute_call_id] {
|
||||
let output = request.function_call_output(call_id);
|
||||
let output_items = output
|
||||
.get("output")
|
||||
.and_then(Value::as_array)
|
||||
.context("view_image output should be content items")?;
|
||||
assert_eq!(output_items.len(), 1);
|
||||
let image_url = output_items[0]
|
||||
.get("image_url")
|
||||
.and_then(Value::as_str)
|
||||
.context("view_image output should include image_url")?;
|
||||
assert!(
|
||||
image_url.starts_with("data:image/png;base64,"),
|
||||
"unexpected image_url: {image_url}",
|
||||
);
|
||||
}
|
||||
|
||||
test.fs()
|
||||
.remove(
|
||||
&remote_cwd_uri,
|
||||
&image_path_uri,
|
||||
RemoveOptions {
|
||||
recursive: true,
|
||||
recursive: false,
|
||||
force: true,
|
||||
},
|
||||
/*sandbox*/ None,
|
||||
@@ -1174,7 +1175,8 @@ async fn view_image_tool_errors_when_path_is_directory() -> anyhow::Result<()> {
|
||||
.function_call_output_content_and_success(call_id)
|
||||
.and_then(|(content, _)| content)
|
||||
.expect("output text present");
|
||||
let expected_message = format!("image path `{}` is not a file", abs_path.display());
|
||||
let expected_path = PathUri::from_host_native_path(&abs_path)?.inferred_native_path_string();
|
||||
let expected_message = format!("image path `{expected_path}` is not a file");
|
||||
assert_eq!(output_text, expected_message);
|
||||
|
||||
assert!(
|
||||
@@ -1253,19 +1255,26 @@ async fn view_image_tool_turns_invalid_image_into_placeholder() -> anyhow::Resul
|
||||
async fn view_image_tool_errors_when_file_missing() -> anyhow::Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
let remote_test_env = get_remote_test_env();
|
||||
println!("view_image missing-file test exec-server environment: {remote_test_env:?}");
|
||||
|
||||
let server = start_mock_server().await;
|
||||
|
||||
let mut builder = test_codex();
|
||||
let test = builder.build_with_remote_env(&server).await?;
|
||||
let TestCodex {
|
||||
codex,
|
||||
config,
|
||||
session_configured,
|
||||
..
|
||||
} = &test;
|
||||
|
||||
let rel_path = "missing/example.png";
|
||||
let abs_path = config.cwd.join(rel_path);
|
||||
// Under wine-exec, the executor cwd is stored as a host-compatible `/C:/...`
|
||||
// projection. Reconstruct its `PathUri` so the expected error uses the selected
|
||||
// environment's native Windows spelling, matching the handler.
|
||||
let expected_path = PathUri::from_abs_path(test.executor_environment().cwd())
|
||||
.join(rel_path)?
|
||||
.inferred_native_path_string();
|
||||
|
||||
let call_id = "view-image-missing";
|
||||
let arguments = serde_json::json!({ "path": rel_path }).to_string();
|
||||
@@ -1309,7 +1318,7 @@ async fn view_image_tool_errors_when_file_missing() -> anyhow::Result<()> {
|
||||
.function_call_output_content_and_success(call_id)
|
||||
.and_then(|(content, _)| content)
|
||||
.expect("output text present");
|
||||
let expected_prefix = format!("unable to locate image at `{}`:", abs_path.display());
|
||||
let expected_prefix = format!("unable to locate image at `{expected_path}`:");
|
||||
assert!(
|
||||
output_text.starts_with(&expected_prefix),
|
||||
"expected error to start with `{expected_prefix}` but got `{output_text}`"
|
||||
|
||||
Reference in New Issue
Block a user