use super::{evaluate_bash_command, unclassifiable_command};
use crate::commands::pm_guard_secret_read::evaluate_secret_file_read_command;
mod secret_file_glob_matches_an_unrelated_token {
use super::*;
#[test]
fn a_one_character_glob_fragment_does_not_name_a_secret_family() {
for command in [
r#"gh issue list --search "\s* guard" --state all"#,
r"grep -cvE '^\s*(//|\*|/\*|\*/|$)' crates/trusty-mpm/src/lib.rs",
"gh issue list --search 's* guard' --state all",
] {
assert_eq!(
evaluate_secret_file_read_command(command),
None,
"a regex fragment must not read as a secret glob: {command}"
);
}
}
#[test]
fn a_real_secret_glob_and_a_real_secret_path_still_deny() {
for command in [
"cat *.env",
"cat .e*",
"cat *.pem",
"cat ./secrets*",
"cat .env",
"cat secrets.pem",
"cat id_rsa",
] {
assert!(
evaluate_secret_file_read_command(command).is_some(),
"a real secret target must still deny: {command}"
);
}
}
}
mod dotenv_placeholder_files {
use super::*;
#[test]
fn placeholder_suffixes_are_readable() {
for command in [
"cat apps/advisor/.env.example",
"printf 'KEY=\\n' >> apps/advisor/.env.example",
"cat .env.example",
"cat .env.sample",
"cat .env.template",
"cat config/.env.example",
] {
assert_eq!(
evaluate_secret_file_read_command(command),
None,
"a placeholder env file must be readable: {command}"
);
}
}
#[test]
fn real_dotenv_files_still_deny() {
for command in [
"cat .env",
"cat .env.local",
"cat .env.production",
"cat apps/advisor/.env.local",
"cat terraform.tfvars",
"cat id_rsa",
] {
assert!(
evaluate_secret_file_read_command(command).is_some(),
"a real secret env file must still deny: {command}"
);
}
}
#[test]
fn the_placeholder_exemption_covers_only_the_dotenv_family() {
assert_eq!(evaluate_secret_file_read_command("cat .env.example"), None);
for command in ["cat id_rsa.sample", "cat secrets.example"] {
assert!(
evaluate_secret_file_read_command(command).is_some(),
"only the dotenv family is exempt: {command}"
);
}
}
#[test]
fn a_placeholder_suffix_is_honoured_only_as_the_final_extension() {
for command in ["cat .env.example.bak", "cat .env.sample.local"] {
assert!(
evaluate_secret_file_read_command(command).is_some(),
"a placeholder suffix behind another extension must deny: {command}"
);
}
}
}
mod go_template_braces {
use super::*;
#[test]
fn a_go_template_format_argument_is_allowed() {
for command in [
"docker images --format '{{.Repository}}:{{.Tag}}'",
"docker ps --format '{{.ID}}'",
"docker inspect --format '{{.Created}}' abc123",
"docker ps --format \"{{.Names}}\\t{{.Status}}\"",
] {
assert_eq!(
evaluate_secret_file_read_command(command),
None,
"a Go-template format argument must allow: {command}"
);
}
}
#[test]
fn a_sequence_group_that_expands_onto_a_secret_name_denies() {
for command in [
"cat .en{v..v}",
"cat .en{u..v}",
"cat id_rs{a..a}",
"cat id_rs{a..c}",
"cat secret{s..s}.txt",
"cp .en{v..v} /tmp/x/",
] {
assert!(
evaluate_secret_file_read_command(command).is_some(),
"a sequence group reaching a secret name must deny: {command}"
);
}
}
#[test]
fn an_ordinary_sequence_group_is_allowed() {
for command in [
"for i in {1..5}; do echo $i; done",
"echo {a..e}",
"mkdir -p build/{1..3}",
"echo {1..5000}",
] {
assert_eq!(
evaluate_secret_file_read_command(command),
None,
"an ordinary sequence group must allow: {command}"
);
}
}
#[test]
fn a_real_brace_alternation_still_denies() {
for command in [
"cat {.env,.env.prod}",
"cp secret.{tfvars,bak} /tmp/",
"cat .{e,env}",
] {
assert!(
evaluate_secret_file_read_command(command).is_some(),
"a real brace alternation naming a secret must still deny: {command}"
);
}
}
}
mod harness_refusals_are_not_this_guard {
use super::*;
const REPORTED_REFUSALS: &[&str] = &[
"ls apps",
"ls -la",
"grep -rl healthz services",
"grep -n healthz docs/specs/domain-service-shell.md",
r#"grep -E "^test result" /private/tmp/claude-502/proj/sess/scratchpad/gate-7359-test.txt"#,
"grep -n scratchpad crates/trusty-mpm/src/bin/tm/commands/pm_guard.rs \
crates/trusty-mpm/src/bin/tm/commands/pm_guard_bash/mod.rs",
"grep -n fn -B 4 -A 12 crates/trusty-mpm/src/bin/tm/commands/pm_guard_bash/mod.rs",
"ls",
"ls -1 crates/trusty-mpm/src/bin/tm/commands/pm_guard_bash",
"cat -n crates/trusty-mpm/src/bin/tm/commands/pm_guard_bash/mod.rs",
"cat /private/tmp/claude-502/proj/sess/scratchpad/gate-7477.txt",
"grep -rln healthz services",
"find crates/trusty-mpm/src/bin/tm/commands/pm_guard_bash -maxdepth 1 -type f",
"find docs/adr -name '0057-*.md'",
"cargo --version",
"git log --oneline -5",
];
const WRITE_SHAPED_REFUSALS: &[&str] = &[
"echo 'fn main() {}' > crates/trusty-mpm/src/lib.rs",
"ls -la > listing.txt",
"grep -rn healthz services >> notes.md",
"cat crates/a/src/lib.rs > crates/b/src/lib.rs",
];
#[test]
fn every_reported_shape_is_classifiable_and_allowed_here() {
for command in REPORTED_REFUSALS {
assert_eq!(
unclassifiable_command(command),
None,
"the harness refused this as unverifiable; this guard must still \
establish what it runs: {command}"
);
assert_eq!(
evaluate_bash_command(command),
None,
"a read-only command must allow: {command}"
);
}
}
#[test]
fn the_verdict_for_one_command_never_varies_within_one_process() {
for command in REPORTED_REFUSALS {
let first = (
unclassifiable_command(command),
evaluate_bash_command(command),
);
for round in 1..50 {
assert_eq!(
(
unclassifiable_command(command),
evaluate_bash_command(command)
),
first,
"verdict changed on round {round} for: {command}"
);
}
}
}
#[test]
fn every_reported_shape_is_admitted_on_all_fifty_rounds() {
for command in REPORTED_REFUSALS {
for round in 0..50 {
assert_eq!(
unclassifiable_command(command),
None,
"round {round}: this guard must still establish what it runs: {command}"
);
assert_eq!(
evaluate_bash_command(command),
None,
"round {round}: a read-only command must allow: {command}"
);
}
}
}
#[test]
fn a_write_shaped_command_is_refused_on_all_fifty_rounds() {
for command in WRITE_SHAPED_REFUSALS {
for round in 0..50 {
assert!(
evaluate_bash_command(command).is_some(),
"round {round}: a write must still be refused: {command}"
);
}
}
}
}