mirror of
https://github.com/openai/codex.git
synced 2026-11-16 22:00:36 +00:00
codex: fix cwd AbsolutePathBuf callers
This commit is contained in:
Generated
+2
@@ -1652,6 +1652,7 @@ dependencies = [
|
||||
"codex-stdio-to-uds",
|
||||
"codex-terminal-detection",
|
||||
"codex-tui",
|
||||
"codex-utils-absolute-path",
|
||||
"codex-utils-cargo-bin",
|
||||
"codex-utils-cli",
|
||||
"codex-utils-path",
|
||||
@@ -2336,6 +2337,7 @@ dependencies = [
|
||||
"codex-models-manager",
|
||||
"codex-protocol",
|
||||
"codex-shell-command",
|
||||
"codex-utils-absolute-path",
|
||||
"codex-utils-cli",
|
||||
"codex-utils-json-to-toml",
|
||||
"core_test_support",
|
||||
|
||||
@@ -42,6 +42,7 @@ codex-state = { workspace = true }
|
||||
codex-stdio-to-uds = { workspace = true }
|
||||
codex-terminal-detection = { workspace = true }
|
||||
codex-tui = { workspace = true }
|
||||
codex-utils-absolute-path = { workspace = true }
|
||||
codex-utils-path = { workspace = true }
|
||||
libc = { workspace = true }
|
||||
owo-colors = { workspace = true }
|
||||
|
||||
@@ -19,6 +19,7 @@ use codex_protocol::permissions::NetworkSandboxPolicy;
|
||||
use codex_sandboxing::landlock::create_linux_sandbox_command_args_for_policies;
|
||||
#[cfg(target_os = "macos")]
|
||||
use codex_sandboxing::seatbelt::create_seatbelt_command_args_for_policies;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use codex_utils_cli::CliConfigOverrides;
|
||||
use tokio::process::Child;
|
||||
use tokio::process::Command as TokioCommand;
|
||||
@@ -434,9 +435,10 @@ async fn build_debug_sandbox_config(
|
||||
.cli_overrides(cli_overrides)
|
||||
.harness_overrides(harness_overrides);
|
||||
if let Some(codex_home) = codex_home {
|
||||
let fallback_cwd = AbsolutePathBuf::relative_to_current_dir(&codex_home)?;
|
||||
builder = builder
|
||||
.codex_home(codex_home.clone())
|
||||
.fallback_cwd(Some(codex_home));
|
||||
.codex_home(codex_home)
|
||||
.fallback_cwd(Some(fallback_cwd));
|
||||
}
|
||||
builder.build().await
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ use codex_tui::AppExitInfo;
|
||||
use codex_tui::Cli as TuiCli;
|
||||
use codex_tui::ExitReason;
|
||||
use codex_tui::update_action::UpdateAction;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use codex_utils_cli::CliConfigOverrides;
|
||||
use owo_colors::OwoColorize;
|
||||
use std::io::IsTerminal;
|
||||
@@ -1143,12 +1144,17 @@ async fn run_debug_prompt_input_command(
|
||||
} else {
|
||||
interactive.sandbox_mode.map(Into::into)
|
||||
};
|
||||
let cwd = interactive
|
||||
.cwd
|
||||
.as_deref()
|
||||
.map(AbsolutePathBuf::relative_to_current_dir)
|
||||
.transpose()?;
|
||||
let overrides = ConfigOverrides {
|
||||
model: interactive.model,
|
||||
config_profile: interactive.config_profile,
|
||||
approval_policy,
|
||||
sandbox_mode,
|
||||
cwd: interactive.cwd,
|
||||
cwd,
|
||||
codex_self_exe: arg0_paths.codex_self_exe,
|
||||
codex_linux_sandbox_exe: arg0_paths.codex_linux_sandbox_exe,
|
||||
main_execve_wrapper_exe: arg0_paths.main_execve_wrapper_exe,
|
||||
|
||||
@@ -240,9 +240,12 @@ pub async fn run_main(cli: Cli, arg0_paths: Arg0DispatchPaths) -> anyhow::Result
|
||||
}
|
||||
};
|
||||
|
||||
let resolved_cwd = cwd.clone();
|
||||
let config_cwd = match resolved_cwd.as_deref() {
|
||||
Some(path) => AbsolutePathBuf::from_absolute_path(path.canonicalize()?)?,
|
||||
let resolved_cwd = cwd
|
||||
.as_deref()
|
||||
.map(|path| AbsolutePathBuf::from_absolute_path(path.canonicalize()?))
|
||||
.transpose()?;
|
||||
let config_cwd = match resolved_cwd.as_ref() {
|
||||
Some(path) => path.clone(),
|
||||
None => AbsolutePathBuf::current_dir()?,
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use super::*;
|
||||
use codex_otel::set_parent_from_w3c_trace_context;
|
||||
use codex_protocol::config_types::ApprovalsReviewer;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use opentelemetry::trace::TraceContextExt;
|
||||
use opentelemetry::trace::TraceId;
|
||||
use opentelemetry::trace::TracerProvider as _;
|
||||
@@ -210,7 +211,9 @@ async fn resume_lookup_model_providers_filters_only_last_lookup() {
|
||||
let cwd = tempdir().expect("create temp cwd");
|
||||
let mut config = ConfigBuilder::default()
|
||||
.codex_home(codex_home.path().to_path_buf())
|
||||
.fallback_cwd(Some(cwd.path().to_path_buf()))
|
||||
.fallback_cwd(Some(
|
||||
AbsolutePathBuf::try_from(cwd.path()).expect("temp cwd should be absolute"),
|
||||
))
|
||||
.build()
|
||||
.await
|
||||
.expect("build default config");
|
||||
@@ -348,7 +351,9 @@ async fn thread_start_params_include_review_policy_when_review_policy_is_manual_
|
||||
approvals_reviewer: Some(ApprovalsReviewer::User),
|
||||
..Default::default()
|
||||
})
|
||||
.fallback_cwd(Some(cwd.path().to_path_buf()))
|
||||
.fallback_cwd(Some(
|
||||
AbsolutePathBuf::try_from(cwd.path()).expect("temp cwd should be absolute"),
|
||||
))
|
||||
.build()
|
||||
.await
|
||||
.expect("build config with manual-only review policy");
|
||||
@@ -371,7 +376,9 @@ async fn thread_start_params_include_review_policy_when_auto_review_is_enabled()
|
||||
approvals_reviewer: Some(ApprovalsReviewer::GuardianSubagent),
|
||||
..Default::default()
|
||||
})
|
||||
.fallback_cwd(Some(cwd.path().to_path_buf()))
|
||||
.fallback_cwd(Some(
|
||||
AbsolutePathBuf::try_from(cwd.path()).expect("temp cwd should be absolute"),
|
||||
))
|
||||
.build()
|
||||
.await
|
||||
.expect("build config with guardian review policy");
|
||||
|
||||
@@ -21,6 +21,8 @@ async fn spawn_command_under_sandbox(
|
||||
env: HashMap<String, String>,
|
||||
) -> std::io::Result<Child> {
|
||||
use codex_core::seatbelt::spawn_command_under_seatbelt;
|
||||
let command_cwd = AbsolutePathBuf::try_from(command_cwd)
|
||||
.map_err(|err| io::Error::new(io::ErrorKind::InvalidInput, err))?;
|
||||
spawn_command_under_seatbelt(
|
||||
command,
|
||||
command_cwd,
|
||||
@@ -45,6 +47,8 @@ async fn spawn_command_under_sandbox(
|
||||
use codex_core::landlock::spawn_command_under_linux_sandbox;
|
||||
let codex_linux_sandbox_exe = core_test_support::find_codex_linux_sandbox_exe()
|
||||
.map_err(|err| io::Error::new(io::ErrorKind::NotFound, err))?;
|
||||
let command_cwd = AbsolutePathBuf::try_from(command_cwd)
|
||||
.map_err(|err| io::Error::new(io::ErrorKind::InvalidInput, err))?;
|
||||
spawn_command_under_linux_sandbox(
|
||||
codex_linux_sandbox_exe,
|
||||
command,
|
||||
|
||||
@@ -25,6 +25,7 @@ codex-features = { workspace = true }
|
||||
codex-login = { workspace = true }
|
||||
codex-models-manager = { workspace = true }
|
||||
codex-protocol = { workspace = true }
|
||||
codex-utils-absolute-path = { workspace = true }
|
||||
codex-utils-cli = { workspace = true }
|
||||
codex-utils-json-to-toml = { workspace = true }
|
||||
rmcp = { workspace = true }
|
||||
|
||||
@@ -6,6 +6,7 @@ use codex_core::config::ConfigOverrides;
|
||||
use codex_protocol::ThreadId;
|
||||
use codex_protocol::config_types::SandboxMode;
|
||||
use codex_protocol::protocol::AskForApproval;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use codex_utils_json_to_toml::json_to_toml;
|
||||
use rmcp::model::JsonObject;
|
||||
use rmcp::model::Tool;
|
||||
@@ -14,7 +15,6 @@ use schemars::r#gen::SchemaSettings;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use std::collections::HashMap;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
|
||||
/// Client-supplied configuration for a `codex` tool-call.
|
||||
@@ -173,7 +173,9 @@ impl CodexToolCallParam {
|
||||
let overrides = ConfigOverrides {
|
||||
model,
|
||||
config_profile: profile,
|
||||
cwd: cwd.map(PathBuf::from),
|
||||
cwd: cwd
|
||||
.map(AbsolutePathBuf::relative_to_current_dir)
|
||||
.transpose()?,
|
||||
approval_policy: approval_policy.map(Into::into),
|
||||
sandbox_mode: sandbox.map(Into::into),
|
||||
codex_self_exe: arg0_paths.codex_self_exe.clone(),
|
||||
|
||||
@@ -1101,8 +1101,9 @@ impl App {
|
||||
|
||||
async fn rebuild_config_for_cwd(&self, cwd: PathBuf) -> Result<Config> {
|
||||
let mut overrides = self.harness_overrides.clone();
|
||||
overrides.cwd = Some(cwd.clone());
|
||||
let cwd_display = cwd.display().to_string();
|
||||
let cwd = AbsolutePathBuf::relative_to_current_dir(&cwd)?;
|
||||
overrides.cwd = Some(cwd);
|
||||
ConfigBuilder::default()
|
||||
.codex_home(self.config.codex_home.clone())
|
||||
.cli_overrides(self.cli_kv_overrides.clone())
|
||||
|
||||
+16
-3
@@ -776,7 +776,7 @@ pub async fn run_main(
|
||||
cwd: if matches!(app_server_target, AppServerTarget::Remote { .. }) {
|
||||
None
|
||||
} else {
|
||||
cwd
|
||||
Some(config_cwd.clone())
|
||||
},
|
||||
model_provider: model_provider_override.clone(),
|
||||
config_profile: cli.config_profile.clone(),
|
||||
@@ -1646,6 +1646,19 @@ async fn load_config_or_exit_with_fallback_cwd(
|
||||
cloud_requirements: CloudRequirementsLoader,
|
||||
fallback_cwd: Option<PathBuf>,
|
||||
) -> Config {
|
||||
let fallback_cwd = match fallback_cwd
|
||||
.map(AbsolutePathBuf::relative_to_current_dir)
|
||||
.transpose()
|
||||
{
|
||||
Ok(cwd) => cwd,
|
||||
Err(err) => {
|
||||
#[allow(clippy::print_stderr)]
|
||||
{
|
||||
eprintln!("Error resolving fallback cwd: {err}");
|
||||
}
|
||||
std::process::exit(1);
|
||||
}
|
||||
};
|
||||
#[allow(clippy::print_stderr)]
|
||||
match ConfigBuilder::default()
|
||||
.cli_overrides(cli_kv_overrides)
|
||||
@@ -2211,7 +2224,7 @@ trust_level = "untrusted"
|
||||
std::fs::write(temp_dir.path().join("config.toml"), config_toml)?;
|
||||
|
||||
let trusted_overrides = ConfigOverrides {
|
||||
cwd: Some(trusted.clone()),
|
||||
cwd: Some(AbsolutePathBuf::relative_to_current_dir(&trusted)?),
|
||||
..Default::default()
|
||||
};
|
||||
let trusted_config = ConfigBuilder::default()
|
||||
@@ -2225,7 +2238,7 @@ trust_level = "untrusted"
|
||||
);
|
||||
|
||||
let untrusted_overrides = ConfigOverrides {
|
||||
cwd: Some(untrusted),
|
||||
cwd: Some(AbsolutePathBuf::relative_to_current_dir(&untrusted)?),
|
||||
..trusted_overrides
|
||||
};
|
||||
let untrusted_config = ConfigBuilder::default()
|
||||
|
||||
Reference in New Issue
Block a user