Render turn diffs for foreign environment paths (#34654)

## Why

Turn diffs need to render paths from remote environments whose path convention may differ from the Codex host.

## What changed

- Preserve `PathUri` values through applied patch deltas, display-root discovery, and turn-diff tracking.
- Add host-independent relative-path rendering and normalize Windows drive-letter case in `PathUri`.
- Render paths relative to each environment's repository root while keeping Git diff headers slash-separated.

## Testing

- Cover POSIX, Windows, UNC, encoded-separator, and opaque URI relative paths.
- Verify an applied patch in a remote Windows working directory emits a portable unified diff.

GitOrigin-RevId: 526f70ae36a40627de5496d375310d12295b69bb
This commit is contained in:
Adam Perry @ OpenAI authored and copyberry committed 2026-07-22 02:19:45 +00:00
1 parent 9fce9e13fd
commit 1823c13771
11 files changed
+303 -95

No files matched your search

+83
View File
@@ -66,6 +66,20 @@ fn file_uri_parses_a_windows_path_on_any_host() {
);
}
#[test]
fn file_uri_normalizes_windows_drive_letter_case() {
let lowercase = PathUri::parse("file:///c:/Users/Alice%20Smith/src/main.rs")
.expect("Windows file URI should parse");
let uppercase = PathUri::parse("file:///C:/Users/Alice%20Smith/src/main.rs")
.expect("Windows file URI should parse");
assert_eq!(lowercase, uppercase);
assert_eq!(
lowercase.to_string(),
"file:///C:/Users/Alice%20Smith/src/main.rs"
);
}
#[test]
fn infers_path_conventions_from_uri_shape() {
for (uri, expected) in [
@@ -158,6 +172,75 @@ fn inferred_native_path_string_uses_the_inferred_convention() {
}
}
#[test]
fn relative_path_from_is_host_independent() {
// `file://abc/...` has an authority and is inferred as Windows UNC, while
// `file:///abc/...` is hostless and inferred as POSIX.
for (path, base, expected) in [
(
"file:///home/alice/project/src/a%20file.rs",
"file:///home/alice/project",
Some("src/a file.rs"),
),
(
"file:///c:/Users/Alice/project/src/main.rs",
"file:///C:/Users/Alice/project",
Some(r"src\main.rs"),
),
(
"file://server/share/project/src/main.rs",
"file://server/share/project",
Some(r"src\main.rs"),
),
(
"file:///home/alice/project",
"file:///home/alice/project/",
Some(""),
),
(
"file:///home/alice/project-two/main.rs",
"file:///home/alice/project",
None,
),
(
"file://other/share/project/main.rs",
"file://server/share/project",
None,
),
(
"file:///home/alice/project/src%2Fmain.rs",
"file:///home/alice/project",
None,
),
(
"file:///C:/project/src%5Cmain.rs",
"file:///C:/project",
None,
),
("file:///C:/project/main.rs", "file:///", None),
] {
let path = PathUri::parse(path).expect("valid path URI");
let base = PathUri::parse(base).expect("valid base URI");
assert_eq!(
path.relative_path_from(&base).as_deref(),
expected,
"finding {path} relative to {base}"
);
}
}
#[test]
fn relative_path_from_treats_fallback_uris_as_opaque() {
let path = PathUri::parse("file:///%00/bad/path/YQ").expect("valid fallback URI");
let other = PathUri::parse("file:///%00/bad/path/Yg").expect("valid fallback URI");
let root = PathUri::parse("file:///").expect("valid root URI");
assert_eq!(path.relative_path_from(&path), Some(String::new()));
assert_eq!(path.relative_path_from(&other), None);
assert_eq!(path.relative_path_from(&root), None);
}
#[cfg(windows)]
#[test]
fn file_uri_falls_back_for_windows_prefixes_without_a_uri_representation() {