From c62318304a08ce563e4228931627cc9fbcd2cb1f Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Tue, 29 Sep 2026 15:28:32 +0200 Subject: [PATCH] test: distinguish clean and unsupported inputs --- docs/heuristics.md | 6 ++++-- src/detector.rs | 12 ++++++++++++ src/input/tests.rs | 17 +++++++++++++++++ tasks.md | 2 +- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/docs/heuristics.md b/docs/heuristics.md index e0dae7d..7cc0bc5 100644 --- a/docs/heuristics.md +++ b/docs/heuristics.md @@ -24,8 +24,10 @@ cluster of closely related phrases from being treated as independent proof. If the resulting evidence sum is `E`, the displayed score is `round(100 × E / (E + 50))`, bounded to `0..=100`. The configured `low`, `medium`, and `high` thresholds name the resulting band. Evidence below `low` -is explicitly reported as below threshold. No findings produce score zero and -no confidence verdict. +is explicitly reported as below threshold. Empty input and text with no +findings produce score zero and no confidence verdict. Binary, invalid UTF-8, +oversized, and unsupported inputs remain typed input errors; they are never +reported as clean analyses. Weights and thresholds are review policy, not calibrated probabilities. A score of 75 does not mean a 75% chance that AI wrote the input. diff --git a/src/detector.rs b/src/detector.rs index 112a837..e5b38b3 100644 --- a/src/detector.rs +++ b/src/detector.rs @@ -751,4 +751,16 @@ mod tests { assert_eq!(analysis.findings.len(), 3); assert_ne!(analysis.confidence_band, Some(ConfidenceBand::High)); } + + #[test] + fn empty_and_clean_text_have_zero_confidence_and_no_verdict() { + let detector = Detector::new(&Config::embedded()).unwrap(); + + for source in ["", "A specific, carefully sourced statement."] { + let analysis = detector.analyze(source); + assert!(analysis.findings.is_empty()); + assert_eq!(analysis.confidence.score(), 0); + assert_eq!(analysis.confidence_band, None); + } + } } diff --git a/src/input/tests.rs b/src/input/tests.rs index 7ca7f21..b639161 100644 --- a/src/input/tests.rs +++ b/src/input/tests.rs @@ -94,6 +94,23 @@ fn invalid_utf8_is_a_per_document_error() { assert!(documents.next().is_none()); } +#[test] +fn binary_content_is_an_input_error_not_a_clean_document() { + let directory = tempdir().expect("temp dir"); + let path = directory.path().join("binary.txt"); + fs::write(&path, b"clean prefix\0binary suffix").expect("write fixture"); + + let mut documents = read(&path, &limits()).expect("open input"); + let error = documents.next().expect("one result").unwrap_err(); + + assert!(matches!( + error, + InputError::BinaryContent { + source_id: SourceId::File(error_path) + } if error_path == path + )); +} + #[test] fn missing_path_is_rejected() { let directory = tempdir().expect("temp dir"); diff --git a/tasks.md b/tasks.md index eaab5fb..13ff687 100644 --- a/tasks.md +++ b/tasks.md @@ -120,7 +120,7 @@ configuration is explainable, and all precedence/validation tests pass. - [x] Design the confidence formula: bounded weighted evidence, per-rule caps, correlated-family damping, normalization to `0..=100`, and configurable low/medium/high thresholds. -- [ ] Return zero confidence and no verdict for empty/no-evidence input. Keep +- [x] Return zero confidence and no verdict for empty/no-evidence input. Keep unsupported/binary input distinct from a clean analysis. - [ ] Sort findings deterministically and deduplicate identical rule/span pairs. - [ ] Add table-driven unit tests for every shipped rule with positive examples