mirror of
https://github.com/openai/codex.git
synced 2026-11-30 00:10:49 +00:00
core: inherit AGENTS override in linked worktrees
This commit is contained in:
@@ -25,6 +25,8 @@ use codex_exec_server::Environment;
|
||||
use codex_exec_server::ExecutorFileSystem;
|
||||
use codex_exec_server::LOCAL_FS;
|
||||
use codex_features::Feature;
|
||||
use codex_git_utils::get_git_repo_root_with_fs;
|
||||
use codex_git_utils::resolve_root_git_project_for_trust;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use dunce::canonicalize as normalize_path;
|
||||
use std::io;
|
||||
@@ -293,6 +295,15 @@ impl<'a> AgentsMdManager<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
let linked_checkout_roots = match (
|
||||
get_git_repo_root_with_fs(fs, &dir).await,
|
||||
resolve_root_git_project_for_trust(fs, &dir).await,
|
||||
) {
|
||||
(Some(checkout_root), Some(repo_root)) if checkout_root != repo_root => {
|
||||
Some((checkout_root, repo_root))
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
let search_dirs: Vec<AbsolutePathBuf> = if let Some(root) = project_root {
|
||||
let mut dirs = Vec::new();
|
||||
let mut cursor = dir.clone();
|
||||
@@ -315,8 +326,14 @@ impl<'a> AgentsMdManager<'a> {
|
||||
let mut found: Vec<AbsolutePathBuf> = Vec::new();
|
||||
let candidate_filenames = self.candidate_filenames();
|
||||
for d in search_dirs {
|
||||
for name in &candidate_filenames {
|
||||
let candidate = d.join(name);
|
||||
let mut candidates = vec![d.join(LOCAL_AGENTS_MD_FILENAME)];
|
||||
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));
|
||||
}
|
||||
candidates.extend(candidate_filenames.iter().skip(1).map(|name| d.join(name)));
|
||||
for candidate in candidates {
|
||||
match fs.get_metadata(&candidate, /*sandbox*/ None).await {
|
||||
Ok(md) if md.is_file => {
|
||||
found.push(candidate);
|
||||
|
||||
@@ -394,6 +394,31 @@ async fn agents_local_md_preferred() {
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn linked_worktrees_inherit_agents_local_md_from_primary_checkout() {
|
||||
let tmp = tempfile::tempdir().expect("tempdir");
|
||||
let repo = tmp.path().join("repo");
|
||||
let worktree = tmp.path().join("worktree");
|
||||
let worktree_git_dir = repo.join(".git/worktrees/feature");
|
||||
fs::create_dir_all(&worktree_git_dir).unwrap();
|
||||
fs::create_dir_all(&worktree).unwrap();
|
||||
fs::write(
|
||||
worktree.join(".git"),
|
||||
format!("gitdir: {}\n", worktree_git_dir.display()),
|
||||
)
|
||||
.unwrap();
|
||||
fs::write(repo.join(LOCAL_AGENTS_MD_FILENAME), "primary local").unwrap();
|
||||
fs::write(worktree.join(DEFAULT_AGENTS_MD_FILENAME), "versioned").unwrap();
|
||||
|
||||
let mut cfg = make_config(&tmp, /*limit*/ 4096, /*instructions*/ None).await;
|
||||
cfg.cwd = worktree.abs();
|
||||
|
||||
assert_eq!(
|
||||
get_user_instructions(&cfg).await.as_deref(),
|
||||
Some("primary local")
|
||||
);
|
||||
}
|
||||
|
||||
/// When AGENTS.md is absent but a configured fallback exists, the fallback is used.
|
||||
#[tokio::test]
|
||||
async fn uses_configured_fallback_when_agents_missing() {
|
||||
|
||||
Reference in New Issue
Block a user