From 0ea86a2d76236c2bfc5a12a63af2a6b092c9b6b1 Mon Sep 17 00:00:00 2001 From: Brent Traut Date: Mon, 25 May 2026 23:48:17 -0700 Subject: [PATCH] codex: address PR review feedback (#24540) --- codex-rs/core/src/agents_md.rs | 15 +++++++++++---- codex-rs/core/src/agents_md_tests.rs | 11 +++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/codex-rs/core/src/agents_md.rs b/codex-rs/core/src/agents_md.rs index 103f21505d..79874a80ec 100644 --- a/codex-rs/core/src/agents_md.rs +++ b/codex-rs/core/src/agents_md.rs @@ -326,14 +326,20 @@ impl<'a> AgentsMdManager<'a> { let mut found: Vec = Vec::new(); let candidate_filenames = self.candidate_filenames(); for d in search_dirs { - let mut candidates = vec![d.join(LOCAL_AGENTS_MD_FILENAME)]; + let mut candidates = vec![(d.join(LOCAL_AGENTS_MD_FILENAME), false)]; if let Some((checkout_root, repo_root)) = linked_checkout_roots.as_ref() && let Ok(relative) = d.as_path().strip_prefix(checkout_root.as_path()) { - candidates.push(repo_root.join(relative).join(LOCAL_AGENTS_MD_FILENAME)); + let inherited = repo_root.join(relative).join(LOCAL_AGENTS_MD_FILENAME); + candidates.push((inherited, true)); } - candidates.extend(candidate_filenames.iter().skip(1).map(|name| d.join(name))); - for candidate in candidates { + candidates.extend( + candidate_filenames + .iter() + .skip(1) + .map(|name| (d.join(name), false)), + ); + for (candidate, is_inherited) in candidates { match fs.get_metadata(&candidate, /*sandbox*/ None).await { Ok(md) if md.is_file => { found.push(candidate); @@ -341,6 +347,7 @@ impl<'a> AgentsMdManager<'a> { } Ok(_) => {} Err(err) if err.kind() == io::ErrorKind::NotFound => continue, + Err(_) if is_inherited => continue, Err(err) => return Err(err), } } diff --git a/codex-rs/core/src/agents_md_tests.rs b/codex-rs/core/src/agents_md_tests.rs index 65219c6da2..5e302c39aa 100644 --- a/codex-rs/core/src/agents_md_tests.rs +++ b/codex-rs/core/src/agents_md_tests.rs @@ -7,6 +7,8 @@ use core_test_support::PathBufExt; use core_test_support::TempDirExt; use pretty_assertions::assert_eq; use std::fs; +#[cfg(unix)] +use std::os::unix::fs::PermissionsExt; use std::path::Path; use std::path::PathBuf; use tempfile::TempDir; @@ -417,6 +419,15 @@ async fn linked_worktrees_inherit_agents_local_md_from_primary_checkout() { get_user_instructions(&cfg).await.as_deref(), Some("primary local") ); + + #[cfg(unix)] + { + fs::set_permissions(&repo, fs::Permissions::from_mode(0o000)).unwrap(); + let instructions = get_user_instructions(&cfg).await; + fs::set_permissions(&repo, fs::Permissions::from_mode(0o755)).unwrap(); + + assert_eq!(instructions.as_deref(), Some("versioned")); + } } /// When AGENTS.md is absent but a configured fallback exists, the fallback is used.