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>
71 lines
1.9 KiB
Rust
71 lines
1.9 KiB
Rust
use dirigent_fermata::core::secrets::config::SecretsConfig;
|
|
|
|
#[test]
|
|
fn parses_policy_sections() {
|
|
let src = r#"
|
|
[policy.read]
|
|
patterns = [".env*", "secrets/**"]
|
|
|
|
[policy.write]
|
|
patterns = ["vendor/**", "*.lock"]
|
|
|
|
[policy.bash]
|
|
deny = ["rm -rf /", "git push --force*"]
|
|
ask = ["rm:*"]
|
|
allow_prefixes = ["make test", "git checkout:*"]
|
|
"#;
|
|
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_has_no_policy() {
|
|
let cfg = SecretsConfig::from_toml("").unwrap();
|
|
assert!(cfg.policy.is_none());
|
|
}
|
|
|
|
#[test]
|
|
fn loads_policy_from_disk() {
|
|
let tmp = tempfile::tempdir().unwrap();
|
|
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 no_botsecrets_means_no_policy() {
|
|
let tmp = tempfile::tempdir().unwrap();
|
|
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 /"]);
|
|
}
|