From 38de0a1de4ffec3310aec2d5dae3f44b58978bad Mon Sep 17 00:00:00 2001 From: Michael Bolin Date: Tue, 23 Dec 2025 19:29:48 -0800 Subject: [PATCH] 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 --- codex-rs/apply-patch/tests/suite/scenarios.rs | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/codex-rs/apply-patch/tests/suite/scenarios.rs b/codex-rs/apply-patch/tests/suite/scenarios.rs index b35ed8590d..0e21a7bc0a 100644 --- a/codex-rs/apply-patch/tests/suite/scenarios.rs +++ b/codex-rs/apply-patch/tests/suite/scenarios.rs @@ -8,7 +8,8 @@ use tempfile::tempdir; #[test] fn test_apply_patch_scenarios() -> anyhow::Result<()> { - for scenario in fs::read_dir("tests/fixtures/scenarios")? { + let scenarios_dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/scenarios"); + for scenario in fs::read_dir(scenarios_dir)? { let scenario = scenario?; let path = scenario.path(); if path.is_dir() { @@ -81,11 +82,15 @@ fn snapshot_dir_recursive( continue; }; let rel = stripped.to_path_buf(); - let file_type = entry.file_type()?; - if file_type.is_dir() { + + // Under Buck2, files in `__srcs` are often materialized as symlinks. + // Use `metadata()` (follows symlinks) so our fixture snapshots work + // under both Cargo and Buck2. + let metadata = fs::metadata(&path)?; + if metadata.is_dir() { entries.insert(rel.clone(), Entry::Dir); snapshot_dir_recursive(base, &path, entries)?; - } else if file_type.is_file() { + } else if metadata.is_file() { let contents = fs::read(&path)?; entries.insert(rel, Entry::File(contents)); } @@ -97,12 +102,14 @@ fn copy_dir_recursive(src: &Path, dst: &Path) -> anyhow::Result<()> { for entry in fs::read_dir(src)? { let entry = entry?; let path = entry.path(); - let file_type = entry.file_type()?; let dest_path = dst.join(entry.file_name()); - if file_type.is_dir() { + + // See note in `snapshot_dir_recursive` about Buck2 symlink trees. + let metadata = fs::metadata(&path)?; + if metadata.is_dir() { fs::create_dir_all(&dest_path)?; copy_dir_recursive(&path, &dest_path)?; - } else if file_type.is_file() { + } else if metadata.is_file() { if let Some(parent) = dest_path.parent() { fs::create_dir_all(parent)?; }