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>
65 lines
2.3 KiB
Rust
65 lines
2.3 KiB
Rust
use dirigent_fermata::core::{Decision, Op, Policy};
|
|
use std::fs;
|
|
use tempfile::TempDir;
|
|
|
|
fn make_project(botignore: &str, botsecrets_policy: &str) -> TempDir {
|
|
let tmp = TempDir::new().unwrap();
|
|
fs::write(tmp.path().join(".botignore"), botignore).unwrap();
|
|
if !botsecrets_policy.is_empty() {
|
|
fs::write(tmp.path().join(".botsecrets"), botsecrets_policy).unwrap();
|
|
}
|
|
tmp
|
|
}
|
|
|
|
#[test]
|
|
fn botignore_blocks_read() {
|
|
let tmp = make_project(".env\n", "");
|
|
let policy = Policy::load(tmp.path()).unwrap();
|
|
let target = tmp.path().join(".env");
|
|
fs::write(&target, "").unwrap();
|
|
let d = policy.check(Op::Read, &target).unwrap();
|
|
assert!(matches!(d, Decision::Deny(_)));
|
|
}
|
|
|
|
#[test]
|
|
fn botignore_blocks_write_too() {
|
|
let tmp = make_project(".env\n", "");
|
|
let policy = Policy::load(tmp.path()).unwrap();
|
|
let target = tmp.path().join(".env");
|
|
let d = policy.check(Op::Write, &target).unwrap();
|
|
assert!(matches!(d, Decision::Deny(_)));
|
|
}
|
|
|
|
#[test]
|
|
fn unmatched_path_allowed() {
|
|
let tmp = make_project(".env\n", "");
|
|
let policy = Policy::load(tmp.path()).unwrap();
|
|
let target = tmp.path().join("src/main.rs");
|
|
fs::create_dir_all(target.parent().unwrap()).unwrap();
|
|
fs::write(&target, "").unwrap();
|
|
let d = policy.check(Op::Read, &target).unwrap();
|
|
assert_eq!(d, Decision::Allow);
|
|
}
|
|
|
|
#[test]
|
|
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();
|
|
fs::write(&target, "").unwrap();
|
|
assert!(matches!(policy.check(Op::Read, &target).unwrap(), Decision::Deny(_)));
|
|
assert_eq!(policy.check(Op::Write, &target).unwrap(), Decision::Allow);
|
|
}
|
|
|
|
#[test]
|
|
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();
|
|
fs::write(&target, "").unwrap();
|
|
assert_eq!(policy.check(Op::Read, &target).unwrap(), Decision::Allow);
|
|
assert!(matches!(policy.check(Op::Write, &target).unwrap(), Decision::Deny(_)));
|
|
}
|