Skip to content

Commit 38de0a1

Browse files
authored
fix: declare test path relative to $CARGO_MANIFEST_DIR (#8498)
This is another fix to prepare for Buck2. See #8496 for related changes. --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/openai/codex/pull/8498). * __->__ #8498 * #8496
1 parent e61bae1 commit 38de0a1

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

codex-rs/apply-patch/tests/suite/scenarios.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ use tempfile::tempdir;
88

99
#[test]
1010
fn test_apply_patch_scenarios() -> anyhow::Result<()> {
11-
for scenario in fs::read_dir("tests/fixtures/scenarios")? {
11+
let scenarios_dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/scenarios");
12+
for scenario in fs::read_dir(scenarios_dir)? {
1213
let scenario = scenario?;
1314
let path = scenario.path();
1415
if path.is_dir() {
@@ -81,11 +82,15 @@ fn snapshot_dir_recursive(
8182
continue;
8283
};
8384
let rel = stripped.to_path_buf();
84-
let file_type = entry.file_type()?;
85-
if file_type.is_dir() {
85+
86+
// Under Buck2, files in `__srcs` are often materialized as symlinks.
87+
// Use `metadata()` (follows symlinks) so our fixture snapshots work
88+
// under both Cargo and Buck2.
89+
let metadata = fs::metadata(&path)?;
90+
if metadata.is_dir() {
8691
entries.insert(rel.clone(), Entry::Dir);
8792
snapshot_dir_recursive(base, &path, entries)?;
88-
} else if file_type.is_file() {
93+
} else if metadata.is_file() {
8994
let contents = fs::read(&path)?;
9095
entries.insert(rel, Entry::File(contents));
9196
}
@@ -97,12 +102,14 @@ fn copy_dir_recursive(src: &Path, dst: &Path) -> anyhow::Result<()> {
97102
for entry in fs::read_dir(src)? {
98103
let entry = entry?;
99104
let path = entry.path();
100-
let file_type = entry.file_type()?;
101105
let dest_path = dst.join(entry.file_name());
102-
if file_type.is_dir() {
106+
107+
// See note in `snapshot_dir_recursive` about Buck2 symlink trees.
108+
let metadata = fs::metadata(&path)?;
109+
if metadata.is_dir() {
103110
fs::create_dir_all(&dest_path)?;
104111
copy_dir_recursive(&path, &dest_path)?;
105-
} else if file_type.is_file() {
112+
} else if metadata.is_file() {
106113
if let Some(parent) = dest_path.parent() {
107114
fs::create_dir_all(parent)?;
108115
}

0 commit comments

Comments
 (0)