mirror of
https://github.com/openai/codex.git
synced 2026-04-30 01:16:54 +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:
@@ -63,6 +63,12 @@ impl AbsolutePathBuf {
|
||||
Self::from_absolute_path(current_dir)
|
||||
}
|
||||
|
||||
/// Construct an absolute path from `path`, resolving relative paths against
|
||||
/// the process current working directory.
|
||||
pub fn relative_to_current_dir<P: AsRef<Path>>(path: P) -> std::io::Result<Self> {
|
||||
Self::resolve_path_against_base(path, std::env::current_dir()?)
|
||||
}
|
||||
|
||||
pub fn join<P: AsRef<Path>>(&self, path: P) -> std::io::Result<Self> {
|
||||
Self::resolve_path_against_base(path, &self.0)
|
||||
}
|
||||
@@ -104,6 +110,14 @@ impl AsRef<Path> for AbsolutePathBuf {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Deref for AbsolutePathBuf {
|
||||
type Target = Path;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl From<AbsolutePathBuf> for PathBuf {
|
||||
fn from(path: AbsolutePathBuf) -> Self {
|
||||
path.into_path_buf()
|
||||
@@ -216,6 +230,17 @@ mod tests {
|
||||
assert_eq!(abs_path_buf.as_path(), base_dir.join("file.txt").as_path());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn relative_to_current_dir_resolves_relative_path() -> std::io::Result<()> {
|
||||
let current_dir = std::env::current_dir()?;
|
||||
let abs_path_buf = AbsolutePathBuf::relative_to_current_dir("file.txt")?;
|
||||
assert_eq!(
|
||||
abs_path_buf.as_path(),
|
||||
current_dir.join("file.txt").as_path()
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn guard_used_in_deserialization() {
|
||||
let temp_dir = tempdir().expect("base dir");
|
||||
|
||||
Reference in New Issue
Block a user