sync from monorepo @ 5408ddc3

This commit is contained in:
2026-05-09 00:05:40 +02:00
parent b03dc15371
commit 16a42d54f8
5 changed files with 191 additions and 39 deletions
+55 -4
View File
@@ -8,7 +8,7 @@ fn finds_botignore_toml_first() {
let root = tmp.path();
fs::create_dir_all(root.join("sub/deep")).unwrap();
fs::write(root.join("botignore.toml"), "").unwrap();
fs::write(root.join(".botignore"), "").unwrap();
fs::write(root.join(".botignore.toml"), "").unwrap();
fs::create_dir_all(root.join(".git")).unwrap();
let target = root.join("sub/deep/file.rs");
@@ -19,11 +19,11 @@ fn finds_botignore_toml_first() {
}
#[test]
fn falls_back_to_botignore() {
fn finds_dot_botignore_toml() {
let tmp = TempDir::new().unwrap();
let root = tmp.path();
fs::create_dir_all(root.join("sub")).unwrap();
fs::write(root.join(".botignore"), "").unwrap();
fs::write(root.join(".botignore.toml"), "").unwrap();
let target = root.join("sub/file.rs");
fs::write(&target, "").unwrap();
@@ -32,6 +32,57 @@ fn falls_back_to_botignore() {
assert_eq!(found, root);
}
#[test]
fn botignore_alone_does_not_stop_walk() {
// A bare .botignore is a policy file, not a project boundary.
// The walk should continue past it to find a real root marker.
let tmp = TempDir::new().unwrap();
let root = tmp.path();
fs::create_dir_all(root.join("a/b")).unwrap();
fs::create_dir_all(root.join(".git")).unwrap();
fs::write(root.join("a/.botignore"), "*.secret").unwrap();
let target = root.join("a/b/file.rs");
fs::write(&target, "").unwrap();
// Should find root (with .git), NOT root/a (with .botignore)
let found = find_project_root(&target).unwrap();
assert_eq!(found, root);
}
#[test]
fn botignore_used_as_fallback() {
// If only .botignore exists (no strong marker), it serves as a fallback
// root so that policy is still enforced.
let tmp = TempDir::new().unwrap();
let root = tmp.path();
fs::create_dir_all(root.join("sub")).unwrap();
fs::write(root.join(".botignore"), "*.secret").unwrap();
let target = root.join("sub/file.rs");
fs::write(&target, "").unwrap();
let found = find_project_root(&target).unwrap();
assert_eq!(found, root);
}
#[test]
fn strong_marker_preferred_over_botignore_fallback() {
// .botignore at a/b/, .git at root — walk past .botignore, use root.
let tmp = TempDir::new().unwrap();
let root = tmp.path();
fs::create_dir_all(root.join("a/b/c")).unwrap();
fs::create_dir_all(root.join(".git")).unwrap();
fs::write(root.join("a/b/.botignore"), "*.key").unwrap();
let target = root.join("a/b/c/file.rs");
fs::write(&target, "").unwrap();
// Should find root (with .git), not a/b (with .botignore)
let found = find_project_root(&target).unwrap();
assert_eq!(found, root);
}
#[test]
fn falls_back_to_git() {
let tmp = TempDir::new().unwrap();
@@ -59,7 +110,7 @@ fn walks_up_from_file_path_not_cwd() {
let tmp = TempDir::new().unwrap();
let root = tmp.path();
fs::create_dir_all(root.join("a/b/c")).unwrap();
fs::write(root.join("a/.botignore"), "").unwrap();
fs::write(root.join("a/botignore.toml"), "").unwrap();
let target = root.join("a/b/c/file.rs");
fs::write(&target, "").unwrap();