diff --git a/src/crates/adapters/opencode-adapter/src/instruction_source.rs b/src/crates/adapters/opencode-adapter/src/instruction_source.rs index 816962db89..5f18d1c656 100644 --- a/src/crates/adapters/opencode-adapter/src/instruction_source.rs +++ b/src/crates/adapters/opencode-adapter/src/instruction_source.rs @@ -448,6 +448,7 @@ mod tests { let config_dir = temp.path().join("config"); let workspace = temp.path().join("workspace"); std::fs::create_dir_all(&config_dir).expect("config directory"); + std::fs::create_dir_all(workspace.join(".git")).expect("workspace git boundary"); std::fs::create_dir_all(&workspace).expect("workspace directory"); std::fs::write(workspace.join("file.md"), "file\n").expect("file instruction"); std::fs::write(workspace.join("inline.md"), "inline\n").expect("inline instruction"); @@ -477,6 +478,7 @@ mod tests { let config_dir = temp.path().join("config"); let workspace = temp.path().join("workspace"); std::fs::create_dir_all(&config_dir).expect("config directory"); + std::fs::create_dir_all(workspace.join(".git")).expect("workspace git boundary"); std::fs::create_dir_all(&workspace).expect("workspace directory"); for name in ["legacy.md", "global.md", "shared.md", "project.md"] { std::fs::write(workspace.join(name), format!("{name}\n")).expect("instruction"); @@ -573,6 +575,7 @@ mod tests { let outside = temp.path().join("explicit.md"); std::fs::create_dir_all(&config_dir).expect("config directory"); std::fs::create_dir_all(&home_dir).expect("home directory"); + std::fs::create_dir_all(workspace.join(".git")).expect("workspace git boundary"); std::fs::create_dir_all(workspace.join("rules/nested")).expect("rules directory"); std::fs::write(workspace.join("rules/b.md"), "b\n").expect("b rule"); std::fs::write(workspace.join("rules/a.md"), "a\n").expect("a rule"); @@ -732,6 +735,7 @@ mod tests { let config_dir = temp.path().join("config"); let workspace = temp.path().join("workspace"); std::fs::create_dir_all(&config_dir).expect("config directory"); + std::fs::create_dir_all(workspace.join(".git")).expect("workspace git boundary"); std::fs::create_dir_all(&workspace).expect("workspace directory"); std::fs::write(workspace.join("root.md"), "root\n").expect("root rule"); let mut unrelated = workspace.join("unrelated"); @@ -758,6 +762,7 @@ mod tests { let config_dir = temp.path().join("config"); let workspace = temp.path().join("workspace"); std::fs::create_dir_all(&config_dir).expect("config directory"); + std::fs::create_dir_all(workspace.join(".git")).expect("workspace git boundary"); std::fs::create_dir_all(workspace.join("team-alpha")).expect("matching directory"); std::fs::write(workspace.join("team-alpha/rule.md"), "matching\n").expect("matching rule"); let unrelated = workspace.join("vendor"); @@ -785,6 +790,7 @@ mod tests { let config_dir = temp.path().join("config"); let workspace = temp.path().join("workspace"); std::fs::create_dir_all(&config_dir).expect("config directory"); + std::fs::create_dir_all(workspace.join(".git")).expect("workspace git boundary"); std::fs::write(config_dir.join("AGENTS.md"), "global\n").expect("global rule"); let mut too_deep = workspace.join("docs"); for index in 0..33 { @@ -810,6 +816,7 @@ mod tests { let config_dir = temp.path().join("config"); let workspace = temp.path().join("workspace"); std::fs::create_dir_all(&config_dir).expect("config directory"); + std::fs::create_dir_all(workspace.join(".git")).expect("workspace git boundary"); std::fs::create_dir_all(&workspace).expect("workspace directory"); for index in 0..257 { let name = format!("rules/{index:03}.md"); diff --git a/src/crates/adapters/opencode-adapter/tests/tool_source_contracts.rs b/src/crates/adapters/opencode-adapter/tests/tool_source_contracts.rs index d4b601e277..46523e2cb1 100644 --- a/src/crates/adapters/opencode-adapter/tests/tool_source_contracts.rs +++ b/src/crates/adapters/opencode-adapter/tests/tool_source_contracts.rs @@ -198,6 +198,12 @@ fn explicit_config_directory_is_appended_to_the_default_global_directory() { project_config_enabled: false, }); + // Anchor the project boundary at the workspace so the host environment's + // own git repository (e.g. a user home directory that is a git checkout) + // cannot leak into find_project_root and reclassify the explicit global + // directory as workspace-local. + fs::create_dir_all(temp.path().join("workspace/.git")).unwrap(); + let snapshot = provider .discover(&context(temp.path().join("workspace"))) .unwrap();