From 81a09af61e99ff1840fe16428587a7e9d03adfb8 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Tue, 29 Sep 2026 17:47:13 +0200 Subject: [PATCH] test: enforce heuristic false-positive sign-off --- Cargo.lock | 71 +++++++++++++++++++ Cargo.toml | 1 + docs/dependencies.md | 2 +- docs/evaluation.md | 17 ++++- tasks.md | 2 +- tests/evaluation.rs | 44 +++++++++++- tests/fixtures/evaluation/README.md | 6 ++ tests/fixtures/evaluation/manifest.toml | 36 +++++++++- .../fixtures/evaluation/negative-assistant.md | 3 + tests/fixtures/evaluation/negative-prompt.md | 2 + tests/fixtures/evaluation/negative-source.rs | 5 ++ tests/fixtures/evaluation/negative-style.md | 2 + tests/fixtures/evaluation/signoff.toml | 7 ++ 13 files changed, 192 insertions(+), 6 deletions(-) create mode 100644 tests/fixtures/evaluation/negative-assistant.md create mode 100644 tests/fixtures/evaluation/negative-prompt.md create mode 100644 tests/fixtures/evaluation/negative-source.rs create mode 100644 tests/fixtures/evaluation/negative-style.md create mode 100644 tests/fixtures/evaluation/signoff.toml diff --git a/Cargo.lock b/Cargo.lock index a63de29..1e43ff1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -92,6 +92,15 @@ version = "2.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06" +[[package]] +name = "block-buffer" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2f6c7dbe95a6ed67ad9f18e57daf93a2f034c524b99fd2b76d18fdfeb6660aa" +dependencies = [ + "hybrid-array", +] + [[package]] name = "borrow-or-share" version = "0.2.4" @@ -208,6 +217,21 @@ version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c133bc6a41be0d194c306b5506d15e6feeea7b1d6604bd3f8310dfb2ca96486" +[[package]] +name = "const-oid" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6ef517f0926dd24a1582492c791b6a4818a4d94e789a334894aa15b0d12f55c" + +[[package]] +name = "cpufeatures" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca28b0ae3115b884660db4118d803791fd6756b6e88f39c0f3f7859060d7566" +dependencies = [ + "libc", +] + [[package]] name = "crc32fast" version = "1.5.2" @@ -262,6 +286,15 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5" +[[package]] +name = "crypto-common" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce6e4c961d6cd6c9a86db418387425e8bdeaf05b3c8bc1411e6dca4c252f1453" +dependencies = [ + "hybrid-array", +] + [[package]] name = "dashmap" version = "6.2.1" @@ -276,6 +309,17 @@ dependencies = [ "parking_lot_core", ] +[[package]] +name = "digest" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2" +dependencies = [ + "block-buffer", + "const-oid", + "crypto-common", +] + [[package]] name = "directories" version = "6.0.0" @@ -515,6 +559,15 @@ version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" +[[package]] +name = "hybrid-array" +version = "0.4.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27f864f10dfb56725ce5ce5472bc52252c8f93a4ab86327122cebf62c5f59a17" +dependencies = [ + "typenum", +] + [[package]] name = "icu_collections" version = "2.3.0" @@ -659,6 +712,7 @@ dependencies = [ "regex", "serde", "serde_json", + "sha2", "similar", "tempfile", "thiserror", @@ -1039,6 +1093,17 @@ dependencies = [ "serde_core", ] +[[package]] +name = "sha2" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "446ba717509524cb3f22f17ecc096f10f4822d76ab5c0b9822c5f9c284e825f4" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + [[package]] name = "shlex" version = "2.0.1" @@ -1407,6 +1472,12 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e28f89b80c87b8fb0cf04ab448d5dd0dd0ade2f8891bae878de66a75a28600e" +[[package]] +name = "typenum" +version = "1.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" + [[package]] name = "uncased" version = "0.9.10" diff --git a/Cargo.toml b/Cargo.toml index b2149df..18e8f5e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,6 +45,7 @@ zip = { version = "8.6.0", default-features = false, features = ["deflate-flate2 criterion = { version = "0.8.2", default-features = false } futures = { version = "0.3.34", default-features = false, features = ["std"] } insta = { version = "1.48.0", default-features = false } +sha2 = "0.11.0" tower = { version = "0.5.3", default-features = false, features = ["util"] } [[bench]] diff --git a/docs/dependencies.md b/docs/dependencies.md index b4edc5e..72359fe 100644 --- a/docs/dependencies.md +++ b/docs/dependencies.md @@ -22,7 +22,7 @@ behind `fancy-diagnostics`. ## Security, licenses, and unsafe code -`cargo audit --deny warnings` scanned 179 locked packages against 1,277 RustSec +`cargo audit --deny warnings` scanned 187 locked packages against 1,277 RustSec advisories without a finding. `cargo deny --locked check` passed advisories, licenses, and sources; it reports seven transitive duplicate-version families as warnings for ongoing review. [`deny.toml`](../deny.toml) contains the reviewed diff --git a/docs/evaluation.md b/docs/evaluation.md index f15eb64..d13a756 100644 --- a/docs/evaluation.md +++ b/docs/evaluation.md @@ -22,10 +22,25 @@ With the embedded schema-version 1 catalog, the corpus currently reports: | typography-non-ascii-hyphen | 1 | 0 | 0 | 100% | 100% | Aggregate labeled-rule counts are 11 true positives, 0 false positives, and 0 -false negatives. The clean-document false-positive rate is 0/1 (0%). The test +false negatives. The clean-document false-positive rate is 0/5 (0%). The test suite recomputes these values from the manifest and fails on drift. These perfect values describe a tiny purpose-built regression set, not expected performance on real documents. They must not be used as an accuracy or authorship claim. Broader, independently sourced data and domain-specific review are required before tuning default weights or thresholds. + +## Default-policy sign-off + +Each shipped rule has at least one explicitly labeled realistic near miss. The +0.1.0 review keeps all schema-version 1 rules, weights, and thresholds unchanged +and accepts them only as a conservative release baseline. The checked-in +`signoff.toml` records that decision, acknowledges the corpus limitations, and +contains the SHA-256 digest of `assets/heuristics.toml`. + +Any default rule, matcher, pattern, weight, occurrence cap, scope, or threshold +change invalidates the sign-off test. Renewal requires reviewing positive and +near-miss cases, reporting changed per-rule/aggregate metrics, explaining the +false-positive tradeoff, updating the digest and decision text, and obtaining +explicit maintainer approval in the change review. A green test alone is not +approval to tune defaults. diff --git a/tasks.md b/tasks.md index 828cf5b..69a16b0 100644 --- a/tasks.md +++ b/tasks.md @@ -229,7 +229,7 @@ same config. binary size. Generate an SBOM/checksums if releases distribute binaries. - [x] Add changelog, contribution guide, code of conduct, security reporting instructions, release profile, and reproducible release procedure. -- [ ] Run a false-positive review against the evaluation corpus and require an +- [x] Run a false-positive review against the evaluation corpus and require an explicit sign-off before changing default rule weights or thresholds. Acceptance: a new user can install and operate all three binaries from the README; diff --git a/tests/evaluation.rs b/tests/evaluation.rs index 268546f..826def7 100644 --- a/tests/evaluation.rs +++ b/tests/evaluation.rs @@ -2,6 +2,7 @@ use std::{collections::BTreeSet, fs, path::Path}; use john_slop::{AnalysisContext, Config, Detector}; use serde::Deserialize; +use sha2::{Digest, Sha256}; #[derive(Deserialize)] struct Manifest { @@ -15,6 +16,19 @@ struct Case { path: String, kind: String, expected: BTreeSet, + #[serde(default)] + near_miss_for: BTreeSet, +} + +#[derive(Deserialize)] +struct Signoff { + schema_version: u32, + release: String, + reviewed_on: String, + status: String, + catalog_sha256: String, + limitations_acknowledged: bool, + decision: String, } #[test] @@ -22,11 +36,12 @@ fn reviewed_corpus_reports_per_rule_metrics_and_false_positive_rate() { let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/evaluation"); let manifest_text = fs::read_to_string(root.join("manifest.toml")).unwrap(); let manifest: Manifest = toml::from_str(&manifest_text).unwrap(); - assert_eq!(manifest.schema_version, 1); + assert_eq!(manifest.schema_version, 2); assert_eq!(manifest.license, "MIT"); let detector = Detector::new(&Config::embedded()).unwrap(); let mut observations = Vec::new(); + let mut reviewed_near_misses = BTreeSet::new(); for case in manifest.cases { let text = fs::read_to_string(root.join(&case.path)).unwrap(); let context = match case.kind.as_str() { @@ -39,6 +54,7 @@ fn reviewed_corpus_reports_per_rule_metrics_and_false_positive_rate() { .into_iter() .map(|finding| finding.rule_id.to_string()) .collect::>(); + reviewed_near_misses.extend(case.near_miss_for); observations.push((case.path, case.expected, actual)); } @@ -84,5 +100,29 @@ fn reviewed_corpus_reports_per_rule_metrics_and_false_positive_rate() { ); assert_eq!((total_tp, total_fp, total_fn), (11, 0, 0)); - assert_eq!((false_positive_cases, negative_cases), (0, 1)); + assert_eq!((false_positive_cases, negative_cases), (0, 5)); + assert_eq!( + reviewed_near_misses, + detector + .rules() + .iter() + .map(|rule| rule.id().to_owned()) + .collect() + ); + + let signoff: Signoff = toml::from_str( + &fs::read_to_string(root.join("signoff.toml")).expect("read evaluation sign-off"), + ) + .expect("parse evaluation sign-off"); + let catalog_hash = Sha256::digest(include_bytes!("../assets/heuristics.toml")) + .iter() + .map(|byte| format!("{byte:02x}")) + .collect::(); + assert_eq!(signoff.schema_version, 1); + assert_eq!(signoff.release, env!("CARGO_PKG_VERSION")); + assert_eq!(signoff.status, "accepted-for-release-baseline"); + assert_eq!(signoff.catalog_sha256, catalog_hash); + assert!(signoff.limitations_acknowledged); + assert_eq!(signoff.reviewed_on, "2026-09-29"); + assert!(signoff.decision.contains("unchanged")); } diff --git a/tests/fixtures/evaluation/README.md b/tests/fixtures/evaluation/README.md index 58cb248..4e050de 100644 --- a/tests/fixtures/evaluation/README.md +++ b/tests/fixtures/evaluation/README.md @@ -7,3 +7,9 @@ signals only; no label claims that a human or an AI system authored the text. This is a characterization corpus for regression testing, not a representative benchmark. Additions require review for provenance, licensing, expected rule IDs, and realistic negative examples. + +Manifest schema 2 records which rule each clean case was reviewed as a realistic +near miss for. Together the negative cases must cover every enabled shipped +rule. `signoff.toml` binds the release decision to the SHA-256 digest of the +exact heuristic catalog; changing defaults invalidates the automated gate until +a reviewer reruns the corpus, assesses limitations, and explicitly renews it. diff --git a/tests/fixtures/evaluation/manifest.toml b/tests/fixtures/evaluation/manifest.toml index 05389df..64a412c 100644 --- a/tests/fixtures/evaluation/manifest.toml +++ b/tests/fixtures/evaluation/manifest.toml @@ -1,4 +1,4 @@ -schema_version = 1 +schema_version = 2 license = "MIT" [[cases]] @@ -35,3 +35,37 @@ expected = ["typography-non-ascii-hyphen"] path = "negative.md" kind = "prose" expected = [] +near_miss_for = ["typography-non-ascii-hyphen"] + +[[cases]] +path = "negative-assistant.md" +kind = "prose" +expected = [] +near_miss_for = [ + "assistant-answer-preface", + "assistant-capability-disclaimer", + "assistant-self-identification", + "knowledge-cutoff-disclaimer", +] + +[[cases]] +path = "negative-prompt.md" +kind = "prose" +expected = [] +near_miss_for = ["prompt-response-scaffolding"] + +[[cases]] +path = "negative-style.md" +kind = "prose" +expected = [] +near_miss_for = [ + "repeated-transition", + "templated-conclusion", + "templated-filler", +] + +[[cases]] +path = "negative-source.rs" +kind = "source-code" +expected = [] +near_miss_for = ["source-placeholder-todo", "source-tutorial-narration"] diff --git a/tests/fixtures/evaluation/negative-assistant.md b/tests/fixtures/evaluation/negative-assistant.md new file mode 100644 index 0000000..458e0c8 --- /dev/null +++ b/tests/fixtures/evaluation/negative-assistant.md @@ -0,0 +1,3 @@ +The editor described a model disclosure in original language and verified the +browser limitation against the tool documentation. The dataset date was cited +directly rather than presented as a generic cutoff disclaimer. diff --git a/tests/fixtures/evaluation/negative-prompt.md b/tests/fixtures/evaluation/negative-prompt.md new file mode 100644 index 0000000..aef506c --- /dev/null +++ b/tests/fixtures/evaluation/negative-prompt.md @@ -0,0 +1,2 @@ +Speaker A asked for a summary. Speaker B recorded the selected deterministic +parser and linked the benchmark evidence. diff --git a/tests/fixtures/evaluation/negative-source.rs b/tests/fixtures/evaluation/negative-source.rs new file mode 100644 index 0000000..1aa5cf9 --- /dev/null +++ b/tests/fixtures/evaluation/negative-source.rs @@ -0,0 +1,5 @@ +// Parse first because validation needs the normalized identifier. +// TODO(issue #42): replace the compatibility shim after the next release. +fn parse_identifier(input: &str) -> &str { + input.trim() +} diff --git a/tests/fixtures/evaluation/negative-style.md b/tests/fixtures/evaluation/negative-style.md new file mode 100644 index 0000000..7ba9481 --- /dev/null +++ b/tests/fixtures/evaluation/negative-style.md @@ -0,0 +1,2 @@ +Moreover, the first measurement includes its sample size. The conclusion names +the retained limit and the observed latency instead of repeating a template. diff --git a/tests/fixtures/evaluation/signoff.toml b/tests/fixtures/evaluation/signoff.toml new file mode 100644 index 0000000..019a205 --- /dev/null +++ b/tests/fixtures/evaluation/signoff.toml @@ -0,0 +1,7 @@ +schema_version = 1 +release = "0.1.0" +reviewed_on = "2026-09-29" +status = "accepted-for-release-baseline" +catalog_sha256 = "8617e56c1f874307fd967ef688c37d42efa750bfb833eb364b797dc588ce1fb0" +limitations_acknowledged = true +decision = "Keep the schema-version 1 default rules, weights, and thresholds unchanged. The reviewed characterization corpus has no observed false-positive cases; its small, authored sample does not establish real-world accuracy."