Files
MichilisandClaude Opus 5.5 44d61df9c9 tests: golden output baseline and default rejection messages
Phase 0 of PLAN.md: pin today's write-policy behavior before the Azzamo
work starts, so every later phase can prove it changed nothing.

- tests/golden.rs runs the binary on test/golden.inputs with a frozen
  copy of the write-side config (test/golden.toml) and compares stdout
  line by line with test/golden.expected. The inputs extend test/inputs
  to cover kinds messages, content shadow rejects (incl. homoglyphs),
  rate limiting and the rate-limit ban.
- Exact-string tests for every default rejection message.
- Rename test_run_filters_shadow_reject to test_protected_events_reject
  (it asserts Reject).
- Add PLAN.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 06:54:30 +00:00

51 lines
2.1 KiB
Rust

//! Golden-output test: pipes `test/golden.inputs` through the real binary with
//! the frozen `test/golden.toml` and compares stdout line by line against
//! `test/golden.expected`. It pins today's observable behavior (every accept,
//! reject message and shadow reject) so later changes can prove they kept it.
//!
//! The inputs cover each write-side path: whitelist reject, protected event,
//! per-kind messages, content shadow reject (plain and homoglyph), rate limit,
//! and the rate-limit ban. They all arrive within one second, so the ratelimit
//! token refill (whole seconds) never kicks in and the output is deterministic.
//!
//! To regenerate after an intentional behavior change:
//! NOTEGUARD_CONFIG=test/golden.toml ./target/debug/noteguard \
//! < test/golden.inputs > test/golden.expected
use std::io::Write;
use std::process::{Command, Stdio};
#[test]
fn golden_output_matches() {
let root = env!("CARGO_MANIFEST_DIR");
let inputs = std::fs::read(format!("{root}/test/golden.inputs")).expect("read golden.inputs");
let expected =
std::fs::read_to_string(format!("{root}/test/golden.expected")).expect("read golden.expected");
let mut child = Command::new(env!("CARGO_BIN_EXE_noteguard"))
.env("NOTEGUARD_CONFIG", format!("{root}/test/golden.toml"))
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::null())
.spawn()
.expect("spawn noteguard");
// Drop stdin after writing so noteguard sees EOF and exits.
child
.stdin
.take()
.expect("stdin")
.write_all(&inputs)
.expect("write inputs");
let out = child.wait_with_output().expect("noteguard output");
assert!(out.status.success(), "noteguard exited with {}", out.status);
let actual = String::from_utf8(out.stdout).expect("utf8 stdout");
let actual: Vec<&str> = actual.lines().collect();
let expected: Vec<&str> = expected.lines().collect();
for (i, (a, e)) in actual.iter().zip(&expected).enumerate() {
assert_eq!(a, e, "golden mismatch at output line {}", i + 1);
}
assert_eq!(actual.len(), expected.len(), "golden output line count");
}