use std::fs;
use std::path::Path;
use std::process::Command;
const MSG: &str = "chore(deps): bump openssl for CVE-2026-1234";
fn rules(dir: &Path) -> std::path::PathBuf {
let path = dir.join("rules.yaml");
fs::write(
&path,
"extend_defaults: false\nrules:\n - id: never\n category: chore\n \
keywords: [\"zzz-never-matches-zzz\"]\n",
)
.expect("rules");
path
}
fn rules_test(dir: &Path, rules: &Path, extra: &str) -> String {
let cfg = dir.join("config.yaml");
fs::write(
&cfg,
format!(
"classification:\n rules_files: [\"{}\"]\n{extra}",
rules.display()
),
)
.expect("config");
let out = Command::new(env!("CARGO_BIN_EXE_tga"))
.current_dir(dir)
.args([
"--config",
cfg.to_str().expect("utf-8"),
"rules",
"test",
MSG,
])
.output()
.expect("run tga");
let stderr = String::from_utf8_lossy(&out.stderr);
assert!(out.status.success(), "tga failed: {stderr}");
String::from_utf8_lossy(&out.stdout).into_owned()
}
#[test]
fn rules_test_honours_weighted_sum_enabled_false() {
let dir = tempfile::tempdir().expect("tempdir");
let rules = rules(dir.path());
let on = rules_test(dir.path(), &rules, "");
assert!(on.contains("method : weighted_sum"), "control: {on}");
assert!(on.contains("category : chore"), "control: {on}");
let off = rules_test(dir.path(), &rules, " weighted_sum:\n enabled: false\n");
assert!(!off.contains("weighted_sum"), "tier is off: {off}");
assert!(off.contains("No tier matched"), "tier is off: {off}");
}