test: enforce heuristic false-positive sign-off

This commit is contained in:
Dandaedre 2026-09-29 17:47:13 +02:00
parent c46563845c
commit 81a09af61e
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
13 changed files with 192 additions and 6 deletions

71
Cargo.lock generated
View File

@ -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"

View File

@ -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]]

View File

@ -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

View File

@ -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.

View File

@ -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;

View File

@ -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<String>,
#[serde(default)]
near_miss_for: BTreeSet<String>,
}
#[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::<BTreeSet<_>>();
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::<String>();
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"));
}

View File

@ -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.

View File

@ -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"]

View File

@ -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.

View File

@ -0,0 +1,2 @@
Speaker A asked for a summary. Speaker B recorded the selected deterministic
parser and linked the benchmark evidence.

View File

@ -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()
}

View File

@ -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.

View File

@ -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."