♻️ fermata: unify botignore.toml into .botsecrets [policy] sections

Delete botignore.toml as a config file entirely. Per-operation policy
rules (read/write/bash) now live in .botsecrets under [policy.read],
[policy.write], and [policy.bash]. This reduces fermata's config story
to two files: .botignore (gitignore syntax) and .botsecrets (TOML).

Changes:
- Add PolicyConfig, OpRules, BashRules to secrets/config.rs with
  layer merge support
- Rewrite policy.rs to load from SecretsConfig instead of BotignoreToml
- Remove toml_config.rs module entirely
- Remove botignore.toml from project root strong markers
- Update all tests to use .botsecrets [policy.*] sections
- Update error messages to reference .botsecrets

All 194 tests pass.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Gabor Körber
2026-05-26 12:54:23 +02:00
co-authored by Claude Opus 4.6
parent 77520819f6
commit ac11512f62
10 changed files with 137 additions and 136 deletions
+7 -7
View File
@@ -2,36 +2,36 @@ use dirigent_fermata::core::{Decision, Policy};
use std::fs;
use tempfile::TempDir;
fn project_with(toml: &str) -> TempDir {
fn project_with(botsecrets: &str) -> TempDir {
let tmp = TempDir::new().unwrap();
fs::write(tmp.path().join("botignore.toml"), toml).unwrap();
fs::write(tmp.path().join(".botsecrets"), botsecrets).unwrap();
tmp
}
#[test]
fn deny_substring_blocks() {
let tmp = project_with("[bash]\ndeny = [\"rm -rf /\"]\n");
let tmp = project_with("[policy.bash]\ndeny = [\"rm -rf /\"]\n");
let p = Policy::load(tmp.path()).unwrap();
assert!(matches!(p.check_command("sudo rm -rf / now").unwrap(), Decision::Deny(_)));
}
#[test]
fn deny_glob_blocks() {
let tmp = project_with("[bash]\ndeny = [\"git push --force*\"]\n");
let tmp = project_with("[policy.bash]\ndeny = [\"git push --force*\"]\n");
let p = Policy::load(tmp.path()).unwrap();
assert!(matches!(p.check_command("git push --force-with-lease").unwrap(), Decision::Deny(_)));
}
#[test]
fn ask_returns_ask() {
let tmp = project_with("[bash]\nask = [\"rm *\"]\n");
let tmp = project_with("[policy.bash]\nask = [\"rm *\"]\n");
let p = Policy::load(tmp.path()).unwrap();
assert!(matches!(p.check_command("rm somefile").unwrap(), Decision::Ask(_)));
}
#[test]
fn allow_prefixes_allows() {
let tmp = project_with("[bash]\nallow_prefixes = [\"make test\"]\n");
let tmp = project_with("[policy.bash]\nallow_prefixes = [\"make test\"]\n");
let p = Policy::load(tmp.path()).unwrap();
assert_eq!(p.check_command("make test").unwrap(), Decision::Allow);
assert_eq!(p.check_command("make test-unit").unwrap(), Decision::Allow);
@@ -46,7 +46,7 @@ fn no_rules_means_allow() {
#[test]
fn deny_takes_precedence_over_allow_prefix() {
let tmp = project_with("[bash]\ndeny = [\"rm -rf /\"]\nallow_prefixes = [\"rm\"]\n");
let tmp = project_with("[policy.bash]\ndeny = [\"rm -rf /\"]\nallow_prefixes = [\"rm\"]\n");
let p = Policy::load(tmp.path()).unwrap();
assert!(matches!(p.check_command("rm -rf /").unwrap(), Decision::Deny(_)));
}
+7 -7
View File
@@ -2,11 +2,11 @@ use dirigent_fermata::core::{Decision, Op, Policy};
use std::fs;
use tempfile::TempDir;
fn make_project(botignore: &str, toml_text: &str) -> TempDir {
fn make_project(botignore: &str, botsecrets_policy: &str) -> TempDir {
let tmp = TempDir::new().unwrap();
fs::write(tmp.path().join(".botignore"), botignore).unwrap();
if !toml_text.is_empty() {
fs::write(tmp.path().join("botignore.toml"), toml_text).unwrap();
if !botsecrets_policy.is_empty() {
fs::write(tmp.path().join(".botsecrets"), botsecrets_policy).unwrap();
}
tmp
}
@@ -42,8 +42,8 @@ fn unmatched_path_allowed() {
}
#[test]
fn toml_read_block_applies_only_to_read() {
let tmp = make_project("", "[read]\npatterns = [\"secrets/**\"]\n");
fn policy_read_block_applies_only_to_read() {
let tmp = make_project("", "[policy.read]\npatterns = [\"secrets/**\"]\n");
let policy = Policy::load(tmp.path()).unwrap();
let target = tmp.path().join("secrets/key.pem");
fs::create_dir_all(target.parent().unwrap()).unwrap();
@@ -53,8 +53,8 @@ fn toml_read_block_applies_only_to_read() {
}
#[test]
fn toml_write_block_applies_only_to_write() {
let tmp = make_project("", "[write]\npatterns = [\"vendor/**\"]\n");
fn policy_write_block_applies_only_to_write() {
let tmp = make_project("", "[policy.write]\npatterns = [\"vendor/**\"]\n");
let policy = Policy::load(tmp.path()).unwrap();
let target = tmp.path().join("vendor/lib.rs");
fs::create_dir_all(target.parent().unwrap()).unwrap();
+3 -26
View File
@@ -3,13 +3,11 @@ use std::fs;
use tempfile::TempDir;
#[test]
fn finds_botignore_toml_first() {
fn finds_botsecrets_as_strong_marker() {
let tmp = TempDir::new().unwrap();
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.toml"), "").unwrap();
fs::create_dir_all(root.join(".git")).unwrap();
fs::write(root.join(".botsecrets"), "").unwrap();
let target = root.join("sub/deep/file.rs");
fs::write(&target, "").unwrap();
@@ -18,24 +16,8 @@ fn finds_botignore_toml_first() {
assert_eq!(found, root);
}
#[test]
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.toml"), "").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 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();
@@ -45,15 +27,12 @@ fn botignore_alone_does_not_stop_walk() {
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();
@@ -68,7 +47,6 @@ fn botignore_used_as_fallback() {
#[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();
@@ -78,7 +56,6 @@ fn strong_marker_preferred_over_botignore_fallback() {
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);
}
@@ -110,7 +87,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.toml"), "").unwrap();
fs::write(root.join("a/.botsecrets"), "").unwrap();
let target = root.join("a/b/c/file.rs");
fs::write(&target, "").unwrap();
+44 -21
View File
@@ -1,47 +1,70 @@
use dirigent_fermata::core::toml_config::{BotignoreToml, OpRules, BashRules};
use dirigent_fermata::core::secrets::config::SecretsConfig;
#[test]
fn parses_full_config() {
fn parses_policy_sections() {
let src = r#"
[read]
[policy.read]
patterns = [".env*", "secrets/**"]
[write]
[policy.write]
patterns = ["vendor/**", "*.lock"]
[bash]
[policy.bash]
deny = ["rm -rf /", "git push --force*"]
ask = ["rm:*"]
allow_prefixes = ["make test", "git checkout:*"]
"#;
let cfg: BotignoreToml = toml::from_str(src).unwrap();
assert_eq!(cfg.read.unwrap().patterns, vec![".env*", "secrets/**"]);
assert_eq!(cfg.write.unwrap().patterns, vec!["vendor/**", "*.lock"]);
let bash = cfg.bash.unwrap();
let cfg = SecretsConfig::from_toml(src).unwrap();
let policy = cfg.policy.unwrap();
assert_eq!(policy.read.unwrap().patterns, vec![".env*", "secrets/**"]);
assert_eq!(policy.write.unwrap().patterns, vec!["vendor/**", "*.lock"]);
let bash = policy.bash.unwrap();
assert_eq!(bash.deny, vec!["rm -rf /", "git push --force*"]);
assert_eq!(bash.ask, vec!["rm:*"]);
assert_eq!(bash.allow_prefixes, vec!["make test", "git checkout:*"]);
}
#[test]
fn empty_config_is_valid() {
let cfg: BotignoreToml = toml::from_str("").unwrap();
assert!(cfg.read.is_none());
assert!(cfg.write.is_none());
assert!(cfg.bash.is_none());
fn empty_config_has_no_policy() {
let cfg = SecretsConfig::from_toml("").unwrap();
assert!(cfg.policy.is_none());
}
#[test]
fn loads_from_disk_when_present() {
fn loads_policy_from_disk() {
let tmp = tempfile::tempdir().unwrap();
std::fs::write(tmp.path().join("botignore.toml"), "[read]\npatterns = [\".env\"]\n").unwrap();
let cfg = BotignoreToml::load(tmp.path()).unwrap();
assert_eq!(cfg.read.unwrap().patterns, vec![".env"]);
std::fs::write(
tmp.path().join(".botsecrets"),
"[policy.read]\npatterns = [\".env\"]\n",
)
.unwrap();
let cfg = SecretsConfig::load(tmp.path()).unwrap();
let policy = cfg.policy.unwrap();
assert_eq!(policy.read.unwrap().patterns, vec![".env"]);
}
#[test]
fn loads_empty_when_missing() {
fn no_botsecrets_means_no_policy() {
let tmp = tempfile::tempdir().unwrap();
let cfg = BotignoreToml::load(tmp.path()).unwrap();
assert!(cfg.read.is_none());
let cfg = SecretsConfig::load(tmp.path()).unwrap();
assert!(cfg.policy.is_none());
}
#[test]
fn policy_coexists_with_secrets_config() {
let src = r#"
[files]
patterns = [".env"]
[policy.read]
patterns = ["secrets/**"]
[policy.bash]
deny = ["rm -rf /"]
"#;
let cfg = SecretsConfig::from_toml(src).unwrap();
assert_eq!(cfg.files.patterns, vec![".env"]);
let policy = cfg.policy.unwrap();
assert_eq!(policy.read.unwrap().patterns, vec!["secrets/**"]);
assert_eq!(policy.bash.unwrap().deny, vec!["rm -rf /"]);
}
+4 -4
View File
@@ -9,9 +9,9 @@ fn fixture() -> TempDir {
let root = tmp.path();
fs::write(root.join(".botignore"), ".env\n.env.*\nconf/cert/**\nconf/mitmproxy/**\n").unwrap();
fs::write(
root.join("botignore.toml"),
root.join(".botsecrets"),
r#"
[read]
[policy.read]
patterns = [
"conf/localtestsettings.yaml",
"conf/localsettings.yaml",
@@ -19,14 +19,14 @@ patterns = [
".claude/self-reflections/**",
]
[write]
[policy.write]
patterns = [
"conf/localtestsettings.yaml",
"conf/localsettings.yaml",
"conf/default-secrets.yaml",
]
[bash]
[policy.bash]
deny = ["localtestsettings.yaml", "localsettings.yaml", "default-secrets.yaml", ".env"]
ask = ["rm *", "mv *"]
allow_prefixes = ["make test"]