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:
pakrym-oai
2026-03-25 16:02:22 +00:00
committed by GitHub
parent 178c3b15b4
commit 504aeb0e09
65 changed files with 717 additions and 422 deletions
+26 -10
View File
@@ -207,6 +207,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;
@@ -1778,7 +1779,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
@@ -4026,13 +4032,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(),
});
}
@@ -4274,7 +4280,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(),
@@ -4693,7 +4699,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."
@@ -5415,7 +5429,7 @@ impl ChatWidget {
let service_tier = self.config.service_tier.map(Some);
let op = AppCommand::user_turn(
items,
self.config.cwd.clone(),
self.config.cwd.to_path_buf(),
self.config.permissions.approval_policy.value(),
self.config.permissions.sandbox_policy.get().clone(),
effective_mode.model().to_string(),
@@ -7022,7 +7036,9 @@ impl ChatWidget {
}
fn status_line_cwd(&self) -> &Path {
self.current_cwd.as_ref().unwrap_or(&self.config.cwd)
self.current_cwd
.as_deref()
.unwrap_or(self.config.cwd.as_path())
}
fn status_line_project_root(&self) -> Option<PathBuf> {
@@ -9617,7 +9633,7 @@ impl ChatWidget {
placeholder_style,
/*reasoning_effort*/ None,
/*show_fast_status*/ false,
config.cwd.clone(),
config.cwd.to_path_buf(),
CODEX_CLI_VERSION,
))
}
@@ -10331,7 +10347,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()));
}
@@ -10356,7 +10372,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()));
}