mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Use AbsolutePathBuf for cwd state (#15710)
Migrate `cwd` and related session/config state to `AbsolutePathBuf` so downstream consumers consistently see absolute working directories. Add test-only `.abs()` helpers for `Path`, `PathBuf`, and `TempDir`, and update branch-local tests to use them instead of `AbsolutePathBuf::try_from(...)`. For the remaining TUI/app-server snapshot coverage that renders absolute cwd values, keep the snapshots unchanged and skip the Windows-only cases where the platform-specific absolute path layout differs.
This commit is contained in:
1 parent
178c3b15b4
commit
504aeb0e09
65 files changed
+717
-422
No files matched your search
@@ -163,6 +163,7 @@ use codex_terminal_detection::Multiplexer;
|
||||
use codex_terminal_detection::TerminalInfo;
|
||||
use codex_terminal_detection::TerminalName;
|
||||
use codex_terminal_detection::terminal_info;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use codex_utils_sleep_inhibitor::SleepInhibitor;
|
||||
use crossterm::event::KeyCode;
|
||||
use crossterm::event::KeyEvent;
|
||||
@@ -1416,7 +1417,12 @@ impl ChatWidget {
|
||||
self.forked_from = event.forked_from_id;
|
||||
self.current_rollout_path = event.rollout_path.clone();
|
||||
self.current_cwd = Some(event.cwd.clone());
|
||||
self.config.cwd = event.cwd.clone();
|
||||
match AbsolutePathBuf::try_from(event.cwd.clone()) {
|
||||
Ok(cwd) => self.config.cwd = cwd,
|
||||
Err(err) => {
|
||||
tracing::warn!(path = %event.cwd.display(), %err, "session cwd should be absolute");
|
||||
}
|
||||
}
|
||||
if let Err(err) = self
|
||||
.config
|
||||
.permissions
|
||||
@@ -3475,13 +3481,13 @@ impl ChatWidget {
|
||||
id: ev.call_id,
|
||||
reason: ev.reason,
|
||||
changes: ev.changes.clone(),
|
||||
cwd: self.config.cwd.clone(),
|
||||
cwd: self.config.cwd.to_path_buf(),
|
||||
};
|
||||
self.bottom_pane
|
||||
.push_approval_request(request, &self.config.features);
|
||||
self.request_redraw();
|
||||
self.notify(Notification::EditApprovalRequested {
|
||||
cwd: self.config.cwd.clone(),
|
||||
cwd: self.config.cwd.to_path_buf(),
|
||||
changes: ev.changes.keys().cloned().collect(),
|
||||
});
|
||||
}
|
||||
@@ -3711,7 +3717,7 @@ impl ChatWidget {
|
||||
|
||||
let active_cell = Some(Self::placeholder_session_header_cell(&config));
|
||||
|
||||
let current_cwd = Some(config.cwd.clone());
|
||||
let current_cwd = Some(config.cwd.to_path_buf());
|
||||
let queued_message_edit_binding = queued_message_edit_binding_for_terminal(terminal_info());
|
||||
let mut widget = Self {
|
||||
app_event_tx: app_event_tx.clone(),
|
||||
@@ -3914,7 +3920,7 @@ impl ChatWidget {
|
||||
};
|
||||
|
||||
let active_cell = Some(Self::placeholder_session_header_cell(&config));
|
||||
let current_cwd = Some(config.cwd.clone());
|
||||
let current_cwd = Some(config.cwd.to_path_buf());
|
||||
|
||||
let queued_message_edit_binding = queued_message_edit_binding_for_terminal(terminal_info());
|
||||
let mut widget = Self {
|
||||
@@ -4537,7 +4543,15 @@ impl ChatWidget {
|
||||
self.app_event_tx.send(AppEvent::ForkCurrentSession);
|
||||
}
|
||||
SlashCommand::Init => {
|
||||
let init_target = self.config.cwd.join(DEFAULT_PROJECT_DOC_FILENAME);
|
||||
let init_target = match self.config.cwd.join(DEFAULT_PROJECT_DOC_FILENAME) {
|
||||
Ok(path) => path,
|
||||
Err(err) => {
|
||||
self.add_error_message(format!(
|
||||
"Failed to prepare {DEFAULT_PROJECT_DOC_FILENAME}: {err}",
|
||||
));
|
||||
return;
|
||||
}
|
||||
};
|
||||
if init_target.exists() {
|
||||
let message = format!(
|
||||
"{DEFAULT_PROJECT_DOC_FILENAME} already exists here. Skipping /init to avoid overwriting it."
|
||||
@@ -5268,7 +5282,7 @@ impl ChatWidget {
|
||||
let service_tier = self.config.service_tier.map(Some);
|
||||
let op = Op::UserTurn {
|
||||
items,
|
||||
cwd: self.config.cwd.clone(),
|
||||
cwd: self.config.cwd.to_path_buf(),
|
||||
approval_policy: self.config.permissions.approval_policy.value(),
|
||||
approvals_reviewer: None,
|
||||
sandbox_policy: self.config.permissions.sandbox_policy.get().clone(),
|
||||
@@ -8409,7 +8423,7 @@ impl ChatWidget {
|
||||
placeholder_style,
|
||||
/*reasoning_effort*/ None,
|
||||
/*show_fast_status*/ false,
|
||||
config.cwd.clone(),
|
||||
config.cwd.to_path_buf(),
|
||||
CODEX_CLI_VERSION,
|
||||
))
|
||||
}
|
||||
@@ -9158,7 +9172,7 @@ impl ChatWidget {
|
||||
name: "Review against a base branch".to_string(),
|
||||
description: Some("(PR Style)".into()),
|
||||
actions: vec![Box::new({
|
||||
let cwd = self.config.cwd.clone();
|
||||
let cwd = self.config.cwd.to_path_buf();
|
||||
move |tx| {
|
||||
tx.send(AppEvent::OpenReviewBranchPicker(cwd.clone()));
|
||||
}
|
||||
@@ -9185,7 +9199,7 @@ impl ChatWidget {
|
||||
items.push(SelectionItem {
|
||||
name: "Review a commit".to_string(),
|
||||
actions: vec![Box::new({
|
||||
let cwd = self.config.cwd.clone();
|
||||
let cwd = self.config.cwd.to_path_buf();
|
||||
move |tx| {
|
||||
tx.send(AppEvent::OpenReviewCommitPicker(cwd.clone()));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user