From bc5b050c6b7980ce475cb9c6a63f564ec71f31d2 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 17 Aug 2026 00:42:58 +0000 Subject: [PATCH 1/6] test: closure classifier contract and acceptance suite (RED) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Contract, input model and tests for the pure classifier. The classification logic is deliberately absent — `classify` returns a placeholder so the suite fails, and the GREEN commit has something to turn green. RED and GREEN are kept as separate commits so the chronology stays legible. Input boundary, decided before implementation. The Step 0B envelope (pull_request/reviews/review_comments/issue_comments/check_runs) is a TEST container, not the production schema — a file has to carry several surfaces at once. The production model is instead: Subject repository, pull_request, expected_sha, head_before, head_after Policy id, required_observations (authoritative order), completeness_claimed observations id -> Acquisition falsifications established facts with provenance known_debts Acquisition status is stated by the caller, never inferred from an absent key, an empty array, a null or a parse error: Available(T) NotProduced RateLimited Failed{reason} which is what keeps OWED (nobody produced it) apart from CANNOT_CHECK (an attempt failed). A failed query that yielded no values is not an empty result. No prose oracle. Nothing reads English. A defect claim arrives as an already established FalsificationFact with provenance; extracting such facts from vendor responses belongs to the acquisition layer. The fixture loader in tests/frozen_fixtures.rs unwraps the envelope into typed inputs and may not inject outcomes: no fixture name maps to an expected state. It supplies observable facts only — which commit a review binds to, whether a review comment references it by pull_request_review_id, which checks exist at which SHA. Each fixture test asserts its hostile precondition from the JSON before asserting any classifier behaviour. Two harness mappings are labelled as such rather than buried: vendor check name -> policy observation id, and reviewer login -> policy observation id. #147 enumerates the ids but does not state either mapping; resolving them is the acquisition layer's job. Cases with no historical fixture witness (OWED, CANNOT_CHECK) are marked logic-level unit witnesses on the tests themselves. The frozen corpus is not claimed to cover them. Refs #147 Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_013K3sUCBMGGjf5v4AqsW7Qk --- Cargo.lock | 8 + Cargo.toml | 1 + crates/o7-closure-classifier/Cargo.toml | 29 ++ crates/o7-closure-classifier/src/lib.rs | 279 ++++++++++++ .../o7-closure-classifier/tests/acceptance.rs | 396 ++++++++++++++++++ .../tests/frozen_fixtures.rs | 336 +++++++++++++++ 6 files changed, 1049 insertions(+) create mode 100644 crates/o7-closure-classifier/Cargo.toml create mode 100644 crates/o7-closure-classifier/src/lib.rs create mode 100644 crates/o7-closure-classifier/tests/acceptance.rs create mode 100644 crates/o7-closure-classifier/tests/frozen_fixtures.rs diff --git a/Cargo.lock b/Cargo.lock index 44f6caff..be287d87 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1050,6 +1050,14 @@ dependencies = [ "thiserror", ] +[[package]] +name = "o7-closure-classifier" +version = "0.1.0" +dependencies = [ + "serde", + "serde_json", +] + [[package]] name = "o7-harness-policy" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 9a079fd1..086f13f4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ members = [ "crates/o7-worker", "crates/o7-worktree", "crates/o7-verifier", + "crates/o7-closure-classifier", "crates/o7-run", "crates/o7-sandbox-protocol", "crates/o7-harness-policy", diff --git a/crates/o7-closure-classifier/Cargo.toml b/crates/o7-closure-classifier/Cargo.toml new file mode 100644 index 00000000..65c3c6c4 --- /dev/null +++ b/crates/o7-closure-classifier/Cargo.toml @@ -0,0 +1,29 @@ +[package] +name = "o7-closure-classifier" +version = "0.1.0" +edition = "2021" +description = "Pure closure classifier: explicit observations in, deterministic closure predicate out. No network, no GitHub API, no local Git authority, no attestation — those layers live outside and above this crate." +publish = false + +[lib] +name = "o7_closure_classifier" +path = "src/lib.rs" + +[dependencies] +serde = { version = "1", features = ["derive"] } +serde_json = "1" + +# Mirror the workspace discipline: no unsafe, no panics-by-default. +[lints.rust] +unsafe_code = "forbid" +unreachable_pub = "deny" +rust_2018_idioms = { level = "deny", priority = -1 } + +[lints.clippy] +unwrap_used = "deny" +expect_used = "deny" +panic = "deny" +dbg_macro = "deny" +todo = "deny" +unimplemented = "deny" +indexing_slicing = "deny" diff --git a/crates/o7-closure-classifier/src/lib.rs b/crates/o7-closure-classifier/src/lib.rs new file mode 100644 index 00000000..06668336 --- /dev/null +++ b/crates/o7-closure-classifier/src/lib.rs @@ -0,0 +1,279 @@ +//! Pure closure classifier (issue #147, the step after the frozen Step 0B +//! fixtures and their integrity validator). +//! +//! ```text +//! explicit observations -> classifier -> closure predicate +//! ``` +//! +//! WHAT THIS CRATE IS NOT. It performs no acquisition. It opens no socket, calls +//! no GitHub API, runs no `git`, reads no `.git/`, consults no branch or working +//! tree, and produces no attestation. A later acquisition adapter turns API +//! responses into a [`ClassifierInput`]; a later envelope step wraps the output. +//! Both are outside this crate by design — the classifier must be callable +//! entirely in memory. +//! +//! WHAT THE PREDICATE CLAIMS. Only this: every observation the policy explicitly +//! required has the recorded state, for this immutable subject, under the +//! declared assumptions. `PASS` does NOT mean the observation set is complete, +//! the pull request is correct, review was exhaustive, no unknown defect exists, +//! or that anything may be merged. The policy carries +//! `completeness_claimed = false` and the required set is enumerated in the +//! output so a later reader can see exactly what was asked. +//! +//! ACQUISITION STATUS IS AN INPUT, NOT AN INFERENCE. This crate never decides +//! that an observation is missing by finding an absent key, an empty array, a +//! null or a parse error. The caller states what happened via [`Acquisition`], +//! which is what keeps the two failure modes apart: +//! +//! ```text +//! OWED nobody produced the required evidence +//! CANNOT_CHECK an attempt to obtain it did not yield a trustworthy answer +//! ``` +//! +//! NO PROSE ORACLE. Nothing here reads English. A defect claim reaches the +//! classifier as an already-established [`FalsificationFact`] carrying +//! provenance; extracting such facts from vendor responses is the acquisition +//! layer's job. This crate decides only what an established fact does to the +//! state vector. + +// Mirror the workspace discipline. +#![forbid(unsafe_code)] + +use serde::Serialize; +use std::collections::BTreeMap; + +/// The five states of #147, kept distinct. Neighbours are never merged. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)] +#[serde(rename_all = "SCREAMING_SNAKE_CASE")] +pub enum State { + /// Admissible positive evidence exists for the frozen subject. + Pass, + /// An admissible established defect exists for the frozen subject. + Finding, + /// Required evidence does not yet exist; nobody has produced it. + Owed, + /// An attempt to obtain a required observation did not yield a trustworthy + /// answer. This is NOT `Owed`: somebody tried and the attempt failed. + CannotCheck, + /// The pull request head differs from the expected subject, before or after + /// evaluation. + Stale, +} + +impl State { + /// Headline precedence, presentation only: + /// `STALE > FINDING > CANNOT_CHECK > OWED > PASS`. + fn rank(self) -> u8 { + match self { + State::Pass => 0, + State::Owed => 1, + State::CannotCheck => 2, + State::Finding => 3, + State::Stale => 4, + } + } +} + +/// What happened when the caller tried to obtain one observation. The classifier +/// never infers any of these from the shape of missing data. +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum Acquisition { + /// The observation was obtained. + Available(T), + /// The acquisition succeeded and established that nobody has produced the + /// required evidence — an authoritative absence, not a failure. + NotProduced, + /// The producer was rate-limited, so no verdict is available yet. Still + /// nobody's verdict; never a pass and never a failure. + RateLimited, + /// The attempt itself failed: transport, tool, permission, malformed + /// response. A failed query that yielded no values is not an empty result. + Failed { reason: String }, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum CheckConclusion { + Success, + Failure, +} + +/// A CI check as observed, with the commit it is bound to. +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct CheckEvidence { + pub stable_id: String, + pub head_sha: String, + pub conclusion: CheckConclusion, +} + +/// A submitted review object as observed. `commit_id` is its immutable binding; +/// `carries_finding` is supplied by the acquisition layer, never inferred here +/// from body text. +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct ReviewEvidence { + pub stable_id: String, + pub commit_id: String, + pub author: String, + pub carries_finding: bool, +} + +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum ObservationInput { + Check(Acquisition), + Review(Acquisition), +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)] +#[serde(rename_all = "kebab-case")] +pub enum SourceKind { + GithubActionsCheck, + SubmittedReview, + ReviewComment, + IssueComment, +} + +/// How well established a falsification is, recorded as provenance. It does NOT +/// gate whether the fact counts: by the time a fact reaches this crate it is an +/// already-established falsification, and #147 makes falsification the WIDE +/// surface — "a concrete defect claim from any surface must be checked if it is +/// verifiable, even when that surface is inadmissible as a closure verdict." +/// Inventing a verification threshold here would narrow that deliberately wide +/// surface on this crate's own authority. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)] +#[serde(rename_all = "SCREAMING_SNAKE_CASE")] +pub enum Verification { + Reproduced, + Claimed, +} + +/// An established defect claim, with enough provenance to re-fetch it. Carries +/// no prose: the classifier decides what an established fact does, not whether +/// some text amounts to one. +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct FalsificationFact { + pub source_kind: SourceKind, + pub stable_id: String, + /// Present only where the surface has an immutable commit binding. Absent + /// binding does NOT disqualify a falsification — see [`Verification`]. + pub subject_sha: Option, + pub author: String, + pub verification: Verification, +} + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct Subject { + pub repository: String, + pub pull_request: u64, + /// The frozen subject every admissible positive observation must bind to. + pub expected_sha: String, + pub head_before: String, + pub head_after: String, +} + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct Policy { + pub id: String, + /// Authoritative enumeration. Output observation order follows it. + pub required_observations: Vec, + /// Always false in V0: enumerating a required set is not claiming the set is + /// complete. + pub completeness_claimed: bool, +} + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct ClassifierInput { + pub subject: Subject, + pub policy: Policy, + pub observations: BTreeMap, + pub falsifications: Vec, + /// Debt tracked independently of reviewer cleanliness. A clean reviewer does + /// not discharge it. + pub known_debts: Vec, +} + +#[derive(Debug, Clone, PartialEq, Eq, Serialize)] +pub struct SourceOut { + pub kind: SourceKind, + pub stable_id: String, +} + +#[derive(Debug, Clone, PartialEq, Eq, Serialize)] +pub struct ObservationOut { + pub id: String, + pub state: State, + #[serde(skip_serializing_if = "Option::is_none")] + pub source: Option, +} + +#[derive(Debug, Clone, PartialEq, Eq, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct PolicyOut { + pub id: String, + pub required_observations: Vec, + pub completeness_claimed: bool, +} + +#[derive(Debug, Clone, PartialEq, Eq, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct FalsificationOut { + pub source: SourceOut, + #[serde(skip_serializing_if = "Option::is_none")] + pub subject_sha: Option, + pub author: String, + pub verification: Verification, +} + +/// The deterministic closure predicate. No timestamp, no generated id, no +/// iteration-order nondeterminism: the same semantic input serializes to the +/// same bytes. +#[derive(Debug, Clone, PartialEq, Eq, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct Predicate { + pub schema_version: u32, + pub repository: String, + pub pull_request: u64, + pub git_commit: String, + pub policy: PolicyOut, + pub observations: Vec, + /// Established falsifications, kept as their own record. A headline of + /// `FINDING` driven by one of these would otherwise be unexplainable from + /// the predicate alone. + pub falsifications: Vec, + /// True when the head moved before or after evaluation. Kept beside the + /// per-observation vector rather than overwriting it, so a stale snapshot + /// still shows what each observation said about the frozen subject. + pub subject_stale: bool, + pub headline: State, + pub known_debts: Vec, +} + +impl Predicate { + /// Deterministic serialization. Provided as a convenience; the classifier + /// core is fully testable without touching a filesystem. + pub fn to_json(&self) -> Result { + serde_json::to_string_pretty(self) + } +} + +/// Classify one snapshot. Every invocation is independent: no memory of a +/// previous headline, so a finding that disappears does not linger. +pub fn classify(_input: &ClassifierInput) -> Predicate { + // RED: the contract, the input model and the acceptance tests exist; the + // classification logic does not yet. This placeholder deliberately fails the + // suite so the GREEN commit has something to turn green. + Predicate { + schema_version: 1, + repository: String::new(), + pull_request: 0, + git_commit: String::new(), + policy: PolicyOut { + id: String::new(), + required_observations: Vec::new(), + completeness_claimed: false, + }, + observations: Vec::new(), + falsifications: Vec::new(), + subject_stale: false, + headline: State::Pass, + known_debts: Vec::new(), + } +} diff --git a/crates/o7-closure-classifier/tests/acceptance.rs b/crates/o7-closure-classifier/tests/acceptance.rs new file mode 100644 index 00000000..53c09027 --- /dev/null +++ b/crates/o7-closure-classifier/tests/acceptance.rs @@ -0,0 +1,396 @@ +//! Acceptance cases from issue #147 that apply to the pure classifier. +//! +//! These use CONSTRUCTED typed inputs, not the frozen Step 0B fixtures. Where a +//! case has no historical fixture witness — `OWED`, `CANNOT_CHECK` — that is +//! stated on the test itself: a logic-level unit witness is not a claim that the +//! frozen corpus covers the path. + +// Justification for the restriction-lint allowance, per the precedent in +// `tests/a0_candidate_state_e2e.rs`: every panic path below is this test's own +// assertion over inputs it constructed itself. +#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)] + +use o7_closure_classifier::{ + classify, Acquisition, CheckConclusion, CheckEvidence, ClassifierInput, FalsificationFact, + ObservationInput, Policy, ReviewEvidence, SourceKind, State, Subject, Verification, +}; +use std::collections::BTreeMap; + +const HEAD: &str = "ed7969c4636362bcfc248bcb9957e140ca899f8c"; +const OTHER: &str = "c08abce9dd0356facae400db1950cd9644976114"; + +const CI_IDS: &[&str] = &[ + "ci/worker-gate", + "ci/dependency-policy", + "ci/dependency-advisories", + "ci/worktree-verifier", +]; + +fn policy() -> Policy { + let mut required: Vec = CI_IDS.iter().map(|s| (*s).to_owned()).collect(); + required.push("review/codex".to_owned()); + required.push("review/coderabbit".to_owned()); + Policy { + id: "007/closure/v1".to_owned(), + required_observations: required, + completeness_claimed: false, + } +} + +fn subject(expected: &str, before: &str, after: &str) -> Subject { + Subject { + repository: "PhysShell/007".to_owned(), + pull_request: 145, + expected_sha: expected.to_owned(), + head_before: before.to_owned(), + head_after: after.to_owned(), + } +} + +fn passing_check(sha: &str, name: &str) -> ObservationInput { + ObservationInput::Check(Acquisition::Available(CheckEvidence { + stable_id: format!("check:{name}"), + head_sha: sha.to_owned(), + conclusion: CheckConclusion::Success, + })) +} + +fn clean_review(sha: &str, author: &str) -> ObservationInput { + ObservationInput::Review(Acquisition::Available(ReviewEvidence { + stable_id: format!("review:{author}"), + commit_id: sha.to_owned(), + author: author.to_owned(), + carries_finding: false, + })) +} + +/// Every CI check passing at `sha`, both reviewers clean at `sha`. +fn all_green(sha: &str) -> BTreeMap { + let mut m = BTreeMap::new(); + for name in CI_IDS { + m.insert((*name).to_owned(), passing_check(sha, name)); + } + m.insert("review/codex".to_owned(), clean_review(sha, "codex")); + m.insert( + "review/coderabbit".to_owned(), + clean_review(sha, "coderabbit"), + ); + m +} + +fn input(subject: Subject, observations: BTreeMap) -> ClassifierInput { + ClassifierInput { + subject, + policy: policy(), + observations, + falsifications: Vec::new(), + known_debts: Vec::new(), + } +} + +fn state_of(p: &o7_closure_classifier::Predicate, id: &str) -> State { + p.observations + .iter() + .find(|o| o.id == id) + .map(|o| o.state) + .unwrap_or_else(|| panic!("observation {id} missing from the predicate")) +} + +// ------------------------------------------------------------------ 1, 2, 6 -- + +#[test] +fn case_01_initial_head_differs_from_expected_is_stale() { + let p = classify(&input(subject(HEAD, OTHER, HEAD), all_green(HEAD))); + assert_eq!(p.headline, State::Stale); + assert!(p.subject_stale); +} + +#[test] +fn case_02_final_head_differs_from_expected_is_stale() { + let p = classify(&input(subject(HEAD, HEAD, OTHER), all_green(HEAD))); + assert_eq!(p.headline, State::Stale); + assert!(p.subject_stale); +} + +#[test] +fn case_02b_stale_snapshot_still_preserves_the_observation_vector() { + // The head moving must not erase what each observation said about the frozen + // subject; the headline is derived presentation, not a replacement. + let p = classify(&input(subject(HEAD, HEAD, OTHER), all_green(HEAD))); + assert_eq!(p.headline, State::Stale); + assert_eq!(state_of(&p, "ci/worker-gate"), State::Pass); + assert_eq!(state_of(&p, "review/codex"), State::Pass); +} + +// --------------------------------------------------------------------- 3, 11 -- + +#[test] +fn case_03_clean_review_on_the_wrong_sha_is_not_positive_evidence() { + let mut obs = all_green(HEAD); + obs.insert("review/codex".to_owned(), clean_review(OTHER, "codex")); + let p = classify(&input(subject(HEAD, HEAD, HEAD), obs)); + assert_eq!( + state_of(&p, "review/codex"), + State::Owed, + "a review bound to another commit produces no verdict for this subject" + ); + assert_ne!(p.headline, State::Pass); +} + +#[test] +fn case_11_ci_and_reviews_from_different_shas_cannot_combine() { + // CI genuinely at the subject, reviews genuinely elsewhere. Neither rescues + // the other into a positive snapshot. + let mut obs = all_green(HEAD); + obs.insert("review/codex".to_owned(), clean_review(OTHER, "codex")); + obs.insert( + "review/coderabbit".to_owned(), + clean_review(OTHER, "coderabbit"), + ); + let p = classify(&input(subject(HEAD, HEAD, HEAD), obs)); + for id in ["review/codex", "review/coderabbit"] { + assert_eq!(state_of(&p, id), State::Owed); + } + for id in CI_IDS { + assert_eq!(state_of(&p, id), State::Pass); + } + assert_eq!(p.headline, State::Owed); +} + +#[test] +fn case_11b_a_check_bound_to_another_sha_is_not_evidence_here() { + let mut obs = all_green(HEAD); + obs.insert( + "ci/worker-gate".to_owned(), + passing_check(OTHER, "worker-gate"), + ); + let p = classify(&input(subject(HEAD, HEAD, HEAD), obs)); + assert_eq!(state_of(&p, "ci/worker-gate"), State::Owed); +} + +// ------------------------------------------------------------------------ 4 -- + +#[test] +fn case_04_a_mutable_comment_cannot_be_positive_verdict_evidence() { + // BY CONSTRUCTION, and this test records that rather than pretending to + // discover it: the ONLY channel into a `review/*` observation is + // `ReviewEvidence`, which carries an immutable `commit_id`. There is no + // variant through which an issue comment, reaction, walkthrough or command + // reply could arrive as positive evidence. A reviewer that posted only a + // clean-sounding comment therefore leaves its required observation OWED. + let mut obs = all_green(HEAD); + obs.insert( + "review/coderabbit".to_owned(), + ObservationInput::Review(Acquisition::NotProduced), + ); + let p = classify(&input(subject(HEAD, HEAD, HEAD), obs)); + assert_eq!(state_of(&p, "review/coderabbit"), State::Owed); + assert_eq!(p.headline, State::Owed); +} + +// --------------------------------------------------------------------- 5, 12 -- + +#[test] +fn case_05_structured_falsification_from_a_non_verdict_surface_is_preserved() { + // Everything a policy asks for is green; a falsification arrives from a + // surface that could never carry a verdict. It must still be able to produce + // a finding — the asymmetry #147 requires. + let mut inp = input(subject(HEAD, HEAD, HEAD), all_green(HEAD)); + inp.falsifications.push(FalsificationFact { + source_kind: SourceKind::IssueComment, + stable_id: "issuecomment-5305700001".to_owned(), + subject_sha: None, + author: "coderabbitai[bot]".to_owned(), + verification: Verification::Reproduced, + }); + let p = classify(&inp); + assert_eq!(p.headline, State::Finding); + assert_eq!(p.falsifications.len(), 1); + // The positive observations are NOT rewritten by it: both facts survive. + assert_eq!(state_of(&p, "review/codex"), State::Pass); +} + +#[test] +fn case_05b_falsification_without_a_commit_binding_still_counts() { + // Positive evidence is strict about SHA binding; falsification is not. An + // issue comment has no commit binding at all, and gating on one would + // silently narrow the wide surface. + let mut inp = input(subject(HEAD, HEAD, HEAD), all_green(HEAD)); + inp.falsifications.push(FalsificationFact { + source_kind: SourceKind::IssueComment, + stable_id: "issuecomment-1".to_owned(), + subject_sha: None, + author: "someone[bot]".to_owned(), + verification: Verification::Claimed, + }); + assert_eq!(classify(&inp).headline, State::Finding); +} + +#[test] +fn case_12_same_vendor_same_sha_conflicting_surfaces_are_not_collapsed() { + // The submitted commit-bound review controls verdict accounting; a claim on + // another surface from the same author is preserved rather than deleted. + let mut obs = all_green(HEAD); + obs.insert( + "review/codex".to_owned(), + ObservationInput::Review(Acquisition::Available(ReviewEvidence { + stable_id: "review:codex".to_owned(), + commit_id: HEAD.to_owned(), + author: "codex[bot]".to_owned(), + carries_finding: true, + })), + ); + let mut inp = input(subject(HEAD, HEAD, HEAD), obs); + inp.falsifications.push(FalsificationFact { + source_kind: SourceKind::ReviewComment, + stable_id: "discussion_r3791453710".to_owned(), + subject_sha: Some(HEAD.to_owned()), + author: "codex[bot]".to_owned(), + verification: Verification::Reproduced, + }); + let p = classify(&inp); + assert_eq!(state_of(&p, "review/codex"), State::Finding); + assert_eq!(p.falsifications.len(), 1); + assert_eq!(p.headline, State::Finding); +} + +// --------------------------------------------------------------------- 6, 7 -- + +#[test] +fn case_06_no_verdict_produced_is_owed_not_pass() { + // LOGIC-LEVEL UNIT WITNESS. The frozen Step 0B corpus has no rate-limit or + // absent-verdict specimen, and this test does not claim otherwise. + for acq in [Acquisition::NotProduced, Acquisition::RateLimited] { + let mut obs = all_green(HEAD); + obs.insert("review/codex".to_owned(), ObservationInput::Review(acq)); + let p = classify(&input(subject(HEAD, HEAD, HEAD), obs)); + assert_eq!(state_of(&p, "review/codex"), State::Owed); + } +} + +#[test] +fn case_07_acquisition_failure_is_cannot_check_not_owed_and_not_empty_success() { + // LOGIC-LEVEL UNIT WITNESS — no Step 0B specimen exists for an API error. + let mut obs = all_green(HEAD); + obs.insert( + "ci/worker-gate".to_owned(), + ObservationInput::Check(Acquisition::Failed { + reason: "503 from the checks endpoint".to_owned(), + }), + ); + let p = classify(&input(subject(HEAD, HEAD, HEAD), obs)); + assert_eq!(state_of(&p, "ci/worker-gate"), State::CannotCheck); + assert_ne!(state_of(&p, "ci/worker-gate"), State::Owed); + assert_ne!(p.headline, State::Pass); +} + +#[test] +fn case_07b_a_missing_required_observation_is_owed() { + let mut obs = all_green(HEAD); + obs.remove("review/coderabbit"); + let p = classify(&input(subject(HEAD, HEAD, HEAD), obs)); + assert_eq!(state_of(&p, "review/coderabbit"), State::Owed); +} + +// --------------------------------------------------------------------- 8, 9 -- + +#[test] +fn case_08_finding_and_cannot_check_both_survive_headline_is_finding() { + let mut obs = all_green(HEAD); + obs.insert( + "review/codex".to_owned(), + ObservationInput::Review(Acquisition::Available(ReviewEvidence { + stable_id: "review:codex".to_owned(), + commit_id: HEAD.to_owned(), + author: "codex[bot]".to_owned(), + carries_finding: true, + })), + ); + obs.insert( + "ci/worktree-verifier".to_owned(), + ObservationInput::Check(Acquisition::Failed { + reason: "runner vanished".to_owned(), + }), + ); + let p = classify(&input(subject(HEAD, HEAD, HEAD), obs)); + assert_eq!(state_of(&p, "review/codex"), State::Finding); + assert_eq!(state_of(&p, "ci/worktree-verifier"), State::CannotCheck); + assert_eq!(p.headline, State::Finding); +} + +#[test] +fn case_09_a_later_snapshot_without_the_finding_is_cannot_check_not_pass() { + // Each invocation is a fresh snapshot: no memory of a previous headline, and + // equally no inheritance of one. + let mut obs = all_green(HEAD); + obs.insert( + "ci/worktree-verifier".to_owned(), + ObservationInput::Check(Acquisition::Failed { + reason: "runner vanished".to_owned(), + }), + ); + let p = classify(&input(subject(HEAD, HEAD, HEAD), obs)); + assert_eq!(state_of(&p, "ci/worktree-verifier"), State::CannotCheck); + assert_eq!(p.headline, State::CannotCheck); + assert_ne!(p.headline, State::Pass); +} + +// ------------------------------------------------------------- 10, 14, 15 -- + +#[test] +fn case_10_pass_enumerates_the_required_set_and_disclaims_completeness() { + let p = classify(&input(subject(HEAD, HEAD, HEAD), all_green(HEAD))); + assert_eq!(p.headline, State::Pass); + assert_eq!( + p.policy.required_observations, + policy().required_observations + ); + assert!(!p.policy.completeness_claimed); + assert_eq!(p.observations.len(), policy().required_observations.len()); +} + +#[test] +fn case_14_known_debt_survives_clean_reviewer_evidence() { + let mut inp = input(subject(HEAD, HEAD, HEAD), all_green(HEAD)); + inp.known_debts = vec!["W8".to_owned(), "W9 both arms".to_owned()]; + let p = classify(&inp); + assert_eq!(p.headline, State::Pass); + assert_eq!( + p.known_debts, + vec!["W8".to_owned(), "W9 both arms".to_owned()] + ); +} + +#[test] +fn case_15_predicate_makes_no_merge_authorization_claim() { + let p = classify(&input(subject(HEAD, HEAD, HEAD), all_green(HEAD))); + let json = p.to_json().expect("serializing the predicate"); + for forbidden in ["merge", "approve", "authoriz", "mergeable", "ready_to"] { + assert!( + !json.to_lowercase().contains(forbidden), + "predicate must not speak about {forbidden}: {json}" + ); + } +} + +// --------------------------------------------------------------- 13, output -- + +#[test] +fn case_13_classification_is_a_pure_function_of_its_input() { + // Independence from local Git state is STRUCTURAL: this crate links no git + // API, spawns no process and reads no path, which the PR's scope scan + // checks. What a test can show is the observable half — the same input + // always yields byte-identical output, so nothing ambient leaks in. + let inp = input(subject(HEAD, HEAD, HEAD), all_green(HEAD)); + let a = classify(&inp).to_json().expect("serializing"); + let b = classify(&inp).to_json().expect("serializing"); + assert_eq!(a, b); + assert!(!a.contains("timestamp")); +} + +#[test] +fn observation_order_follows_the_authoritative_policy_order() { + let p = classify(&input(subject(HEAD, HEAD, HEAD), all_green(HEAD))); + let ids: Vec<&str> = p.observations.iter().map(|o| o.id.as_str()).collect(); + assert_eq!(ids, policy().required_observations); +} diff --git a/crates/o7-closure-classifier/tests/frozen_fixtures.rs b/crates/o7-closure-classifier/tests/frozen_fixtures.rs new file mode 100644 index 00000000..77b4d88f --- /dev/null +++ b/crates/o7-closure-classifier/tests/frozen_fixtures.rs @@ -0,0 +1,336 @@ +//! The three frozen Step 0B fixtures, driven through the classifier. +//! +//! The fixtures are read from `tests/fixtures/github/` at the workspace root and +//! are NEVER written to. Each test asserts the fixture's hostile precondition +//! FIRST, straight from the JSON, before asserting anything about classifier +//! behaviour — a test that passes because the adversarial condition was never +//! constructed is the failure mode this corpus exists to prevent. +//! +//! THE ENVELOPE IS NOT THE PRODUCTION INPUT SCHEMA. The fixture files carry +//! several API surfaces in one document because a file must. The loader below +//! unwraps those surfaces and builds typed [`ClassifierInput`]s; it is test +//! infrastructure, and the production input model deliberately looks nothing +//! like the envelope. +//! +//! THE LOADER MAY NOT INJECT OUTCOMES. Nowhere below does a fixture name map to +//! an expected state. The loader supplies observable facts — which commit a +//! review is bound to, whether a review comment references it, which checks +//! exist at which SHA — and the classifier decides the states. + +// Justification for the restriction-lint allowance, per the precedent in +// `tests/a0_candidate_state_e2e.rs`: every panic path below is this test's own +// assertion or its own reading of a file it ships with. +#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)] + +use o7_closure_classifier::{ + classify, Acquisition, CheckConclusion, CheckEvidence, ClassifierInput, FalsificationFact, + ObservationInput, Policy, Predicate, ReviewEvidence, SourceKind, State, Subject, Verification, +}; +use serde_json::Value; +use std::collections::BTreeMap; +use std::path::PathBuf; + +/// HARNESS MAPPING, not a fixture fact: #147's policy enumerates observation ids +/// but does not state which vendor check name produces each. Resolving that is +/// the acquisition layer's job; the table is spelled out here so the choice is +/// visible rather than buried in a match arm. +const CHECK_NAME_TO_ID: &[(&str, &str)] = &[ + ("worker gate", "ci/worker-gate"), + ("dependency policy", "ci/dependency-policy"), + ("dependency advisories", "ci/dependency-advisories"), + ("worktree+verifier tests", "ci/worktree-verifier"), +]; + +/// HARNESS MAPPING, same status as above: which policy observation a given bot's +/// submitted review satisfies. +fn reviewer_id_for(login: &str) -> Option<&'static str> { + if login.starts_with("chatgpt-codex-connector") { + Some("review/codex") + } else if login.starts_with("coderabbitai") { + Some("review/coderabbit") + } else { + None + } +} + +fn policy() -> Policy { + Policy { + id: "007/closure/v1".to_owned(), + required_observations: vec![ + "ci/worker-gate".to_owned(), + "ci/dependency-policy".to_owned(), + "ci/dependency-advisories".to_owned(), + "ci/worktree-verifier".to_owned(), + "review/codex".to_owned(), + "review/coderabbit".to_owned(), + ], + completeness_claimed: false, + } +} + +fn fixture(name: &str) -> Value { + let path: PathBuf = PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join("../../tests/fixtures/github") + .join(name); + let text = std::fs::read_to_string(&path) + .unwrap_or_else(|e| panic!("reading frozen fixture {}: {e}", path.display())); + serde_json::from_str(&text).unwrap_or_else(|e| panic!("parsing frozen fixture {name}: {e}")) +} + +fn ptr<'a>(doc: &'a Value, p: &str) -> &'a Value { + doc.pointer(p) + .unwrap_or_else(|| panic!("frozen fixture pointer {p} does not resolve")) +} + +fn text<'a>(doc: &'a Value, p: &str) -> &'a str { + ptr(doc, p) + .as_str() + .unwrap_or_else(|| panic!("frozen fixture pointer {p} is not a string")) +} + +/// Unwrap the envelope into typed observations. Purely structural: a review +/// carries a finding iff some review comment references it by +/// `pull_request_review_id`. No body text is read. +fn observations_from(doc: &Value) -> BTreeMap { + let mut out = BTreeMap::new(); + + if let Some(runs) = doc + .pointer("/check_runs/check_runs") + .and_then(Value::as_array) + { + for run in runs { + let name = run.get("name").and_then(Value::as_str).unwrap_or_default(); + let Some((_, id)) = CHECK_NAME_TO_ID.iter().find(|(n, _)| *n == name) else { + continue; + }; + let head_sha = run + .get("head_sha") + .and_then(Value::as_str) + .unwrap_or_default(); + let success = run.get("conclusion").and_then(Value::as_str) == Some("success"); + out.insert( + (*id).to_owned(), + ObservationInput::Check(Acquisition::Available(CheckEvidence { + stable_id: run + .get("id") + .map(std::string::ToString::to_string) + .unwrap_or_default(), + head_sha: head_sha.to_owned(), + conclusion: if success { + CheckConclusion::Success + } else { + CheckConclusion::Failure + }, + })), + ); + } + } + + let empty = Vec::new(); + let review_comments = doc + .pointer("/review_comments") + .and_then(Value::as_array) + .unwrap_or(&empty); + + if let Some(reviews) = doc.pointer("/reviews").and_then(Value::as_array) { + for review in reviews { + let login = review + .pointer("/user/login") + .and_then(Value::as_str) + .unwrap_or_default(); + let Some(id) = reviewer_id_for(login) else { + continue; + }; + let review_id = review.get("id").cloned().unwrap_or(Value::Null); + let carries_finding = review_comments + .iter() + .any(|c| c.get("pull_request_review_id") == Some(&review_id)); + out.insert( + id.to_owned(), + ObservationInput::Review(Acquisition::Available(ReviewEvidence { + stable_id: review_id.to_string(), + commit_id: review + .get("commit_id") + .and_then(Value::as_str) + .unwrap_or_default() + .to_owned(), + author: login.to_owned(), + carries_finding, + })), + ); + } + } + + // Any required reviewer with no submitted review object produced no verdict. + // Stated explicitly rather than left to be inferred from a missing key. + for id in policy().required_observations { + if id.starts_with("review/") { + out.entry(id) + .or_insert(ObservationInput::Review(Acquisition::NotProduced)); + } + } + + out +} + +fn classify_fixture(doc: &Value, falsifications: Vec) -> Predicate { + let head = text(doc, "/pull_request/head/sha").to_owned(); + classify(&ClassifierInput { + subject: Subject { + repository: text(doc, "/pull_request/head/repo/full_name").to_owned(), + pull_request: ptr(doc, "/pull_request/number") + .as_u64() + .unwrap_or_default(), + expected_sha: head.clone(), + head_before: head.clone(), + head_after: head, + }, + policy: policy(), + observations: observations_from(doc), + falsifications, + known_debts: Vec::new(), + }) +} + +fn state_of(p: &Predicate, id: &str) -> State { + p.observations + .iter() + .find(|o| o.id == id) + .map(|o| o.state) + .unwrap_or_else(|| panic!("observation {id} missing")) +} + +// --------------------------------------------------- stale-review-wrong-sha -- + +#[test] +fn stale_review_wrong_sha() { + let doc = fixture("stale-review-wrong-sha.json"); + + // HOSTILE PRECONDITION, asserted before any classifier expectation. + let head = text(&doc, "/pull_request/head/sha"); + let review_sha = text(&doc, "/reviews/0/commit_id"); + assert_ne!( + review_sha, head, + "fixture must present a review bound to a commit other than the head" + ); + assert_eq!( + text(&doc, "/check_runs/check_runs/0/head_sha"), + head, + "fixture must present checks bound to the head" + ); + + let p = classify_fixture(&doc, Vec::new()); + + // The review does not bind to the subject, so it yields no verdict for it — + // neither a pass nor a finding. + assert_eq!(state_of(&p, "review/codex"), State::Owed); + // The checks that DO bind to the head must not rescue the wrong-SHA review. + for id in [ + "ci/worker-gate", + "ci/dependency-policy", + "ci/dependency-advisories", + "ci/worktree-verifier", + ] { + assert_eq!(state_of(&p, id), State::Pass); + } + assert_eq!(state_of(&p, "review/coderabbit"), State::Owed); + assert_eq!(p.headline, State::Owed); + assert_ne!(p.headline, State::Pass); + // The SUBJECT is not stale here — the head never moved. It is the REVIEW + // artifact that is bound to a superseded commit, which is a different thing + // and must not be conflated with a stale snapshot. + assert!(!p.subject_stale); +} + +// ------------------------------------------------- falsification-in-comment -- + +#[test] +fn falsification_in_comment() { + let doc = fixture("falsification-in-comment.json"); + + // HOSTILE PRECONDITION first. + let head = text(&doc, "/pull_request/head/sha"); + assert_eq!(text(&doc, "/reviews/0/commit_id"), head); + assert!( + ptr(&doc, "/review_comments") + .as_array() + .is_some_and(Vec::is_empty), + "fixture must present an empty review-comment surface" + ); + let comment_author = text(&doc, "/issue_comments/0/user/login"); + assert!( + !text(&doc, "/issue_comments/0/body").is_empty(), + "fixture must present a defect claim on the issue-comment surface" + ); + + // The frozen README documents `/issue_comments/0` as carrying a concrete, + // reproducible defect claim. The harness supplies that as an already + // established fact WITH ITS PROVENANCE — it does not infer a prose grammar, + // and nothing here reads the body to decide whether it is "real". + let falsification = FalsificationFact { + source_kind: SourceKind::IssueComment, + stable_id: ptr(&doc, "/issue_comments/0/id").to_string(), + subject_sha: None, + author: comment_author.to_owned(), + verification: Verification::Reproduced, + }; + + let p = classify_fixture(&doc, vec![falsification]); + + // The review surface at the head records no finding, so it passes as a + // verdict... + assert_eq!(state_of(&p, "review/codex"), State::Pass); + // ...the other required reviewer produced no verdict object at all... + assert_eq!(state_of(&p, "review/coderabbit"), State::Owed); + // ...and the claim on the verdict-less surface still falsifies. + assert_eq!(p.falsifications.len(), 1); + assert_eq!(p.headline, State::Finding); +} + +// ---------------------------------------------- conflicting-review-surfaces -- + +#[test] +fn conflicting_review_surfaces() { + let doc = fixture("conflicting-review-surfaces.json"); + + // HOSTILE PRECONDITION first: one vendor, one head, two surfaces. + let head = text(&doc, "/pull_request/head/sha"); + assert_eq!(text(&doc, "/reviews/0/commit_id"), head); + assert_eq!(text(&doc, "/review_comments/0/commit_id"), head); + assert_eq!( + text(&doc, "/reviews/0/user/login"), + text(&doc, "/issue_comments/0/user/login"), + "fixture must present the same author on both surfaces" + ); + assert_eq!( + ptr(&doc, "/review_comments/0/pull_request_review_id"), + ptr(&doc, "/reviews/0/id"), + "the review comment must belong to that submitted review" + ); + + let p = classify_fixture(&doc, Vec::new()); + + // The submitted, commit-bound review controls verdict accounting, and it + // carries a finding. The issue comment claiming the same commit is clean has + // NO channel into positive evidence, so it cannot overturn this — and it is + // not deleted either: it remains in the fixture, unread by the classifier. + assert_eq!(state_of(&p, "review/codex"), State::Finding); + assert_eq!(state_of(&p, "review/coderabbit"), State::Owed); + assert_eq!(p.headline, State::Finding); + assert_ne!(p.headline, State::Pass); +} + +#[test] +fn frozen_fixtures_are_never_written_to() { + // Reading is the only access this file makes; recorded as an assertion so a + // future edit that starts writing has to delete a line that says not to. + for name in [ + "stale-review-wrong-sha.json", + "falsification-in-comment.json", + "conflicting-review-surfaces.json", + ] { + let before = fixture(name); + let _ = classify_fixture(&before, Vec::new()); + assert_eq!(before, fixture(name)); + } +} From cfd1d3b4114f5c5e7547c40c1dfa8ff351402647 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 17 Aug 2026 00:44:53 +0000 Subject: [PATCH 2/6] feat: pure closure classifier implementation (GREEN) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Minimal logic to satisfy the RED suite. No acquisition, no network, no GitHub API, no local Git authority, no attestation. State derivation, per required observation in authoritative policy order: check bound to expected_sha + success -> PASS bound to expected_sha + failure -> FINDING bound elsewhere -> OWED (not evidence about this subject; never combined across commits) review bound to expected_sha, no finding -> PASS bound to expected_sha, finding -> FINDING bound elsewhere -> OWED (no verdict here at all) either NotProduced | RateLimited -> OWED Failed{..} -> CANNOT_CHECK absent from the input -> OWED Positive reviewer evidence is strict about commit binding. Falsification is deliberately wide: an established fact counts even with no commit binding at all, because #147 makes falsification the wider surface and gating it on a binding an issue comment cannot have would silently narrow it. Headline is derived presentation over everything recorded — the observation vector, plus falsification (which owns no required slot), plus subject staleness — and never rewrites the vector. A head that moved sets subject_stale and the STALE headline while each observation still reports what it said about the frozen subject. Each call is an independent snapshot: no memory of a previous headline, so a finding that disappears leaves CANNOT_CHECK as the headline rather than being inherited or decaying to PASS. Output is deterministic: no timestamp, no generated id, observations in policy order, same semantic input -> byte-identical JSON. The predicate records the required set and completenessClaimed=false, so PASS reads as "everything asked for passed", never as "the set is complete" or "this may be merged". 24 tests pass: 20 acceptance, 4 against the frozen Step 0B fixtures. The frozen fixtures, their README and the integrity validator are unchanged. Refs #147 Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_013K3sUCBMGGjf5v4AqsW7Qk --- crates/o7-closure-classifier/src/lib.rs | 138 +++++++++++++++++++++--- 1 file changed, 123 insertions(+), 15 deletions(-) diff --git a/crates/o7-closure-classifier/src/lib.rs b/crates/o7-closure-classifier/src/lib.rs index 06668336..240c96ae 100644 --- a/crates/o7-closure-classifier/src/lib.rs +++ b/crates/o7-closure-classifier/src/lib.rs @@ -254,26 +254,134 @@ impl Predicate { } } +/// A check is positive evidence only when it is bound to the frozen subject. +/// A check bound elsewhere is not evidence about this subject at all, so it +/// leaves the observation owed rather than combining across commits. +fn classify_check( + acq: &Acquisition, + expected_sha: &str, +) -> (State, Option) { + match acq { + Acquisition::Available(check) => { + let source = Some(SourceOut { + kind: SourceKind::GithubActionsCheck, + stable_id: check.stable_id.clone(), + }); + if check.head_sha != expected_sha { + (State::Owed, source) + } else { + match check.conclusion { + CheckConclusion::Success => (State::Pass, source), + CheckConclusion::Failure => (State::Finding, source), + } + } + } + Acquisition::NotProduced | Acquisition::RateLimited => (State::Owed, None), + Acquisition::Failed { .. } => (State::CannotCheck, None), + } +} + +/// Positive reviewer evidence is strict: the submitted review's immutable +/// commit binding must equal the frozen subject. A wrong-SHA review yields no +/// verdict here — neither a pass nor a finding. +fn classify_review( + acq: &Acquisition, + expected_sha: &str, +) -> (State, Option) { + match acq { + Acquisition::Available(review) => { + let source = Some(SourceOut { + kind: SourceKind::SubmittedReview, + stable_id: review.stable_id.clone(), + }); + if review.commit_id != expected_sha { + (State::Owed, source) + } else if review.carries_finding { + (State::Finding, source) + } else { + (State::Pass, source) + } + } + Acquisition::NotProduced | Acquisition::RateLimited => (State::Owed, None), + Acquisition::Failed { .. } => (State::CannotCheck, None), + } +} + /// Classify one snapshot. Every invocation is independent: no memory of a /// previous headline, so a finding that disappears does not linger. -pub fn classify(_input: &ClassifierInput) -> Predicate { - // RED: the contract, the input model and the acceptance tests exist; the - // classification logic does not yet. This placeholder deliberately fails the - // suite so the GREEN commit has something to turn green. +pub fn classify(input: &ClassifierInput) -> Predicate { + let expected = input.subject.expected_sha.as_str(); + + // The head moving invalidates the SNAPSHOT, not the individual observations, + // which remain statements about the frozen subject. Recorded alongside the + // vector so nothing is overwritten. + let subject_stale = + input.subject.head_before != expected || input.subject.head_after != expected; + + let observations: Vec = input + .policy + .required_observations + .iter() + .map(|id| { + // A required observation nobody supplied is owed. Absence of an + // entry is the caller's explicit omission, not an acquisition + // failure, and the two are not merged. + let (state, source) = match input.observations.get(id) { + None => (State::Owed, None), + Some(ObservationInput::Check(acq)) => classify_check(acq, expected), + Some(ObservationInput::Review(acq)) => classify_review(acq, expected), + }; + ObservationOut { + id: id.clone(), + state, + source, + } + }) + .collect(); + + let falsifications: Vec = input + .falsifications + .iter() + .map(|f| FalsificationOut { + source: SourceOut { + kind: f.source_kind, + stable_id: f.stable_id.clone(), + }, + subject_sha: f.subject_sha.clone(), + author: f.author.clone(), + verification: f.verification, + }) + .collect(); + + // Headline is derived presentation over everything recorded: the observation + // vector, plus falsification (which has no required-observation slot of its + // own), plus subject staleness. The vector itself is never rewritten. + let mut headline = observations + .iter() + .map(|o| o.state) + .max_by_key(|s| s.rank()) + .unwrap_or(State::Pass); + if !falsifications.is_empty() && State::Finding.rank() > headline.rank() { + headline = State::Finding; + } + if subject_stale { + headline = State::Stale; + } + Predicate { schema_version: 1, - repository: String::new(), - pull_request: 0, - git_commit: String::new(), + repository: input.subject.repository.clone(), + pull_request: input.subject.pull_request, + git_commit: input.subject.expected_sha.clone(), policy: PolicyOut { - id: String::new(), - required_observations: Vec::new(), - completeness_claimed: false, + id: input.policy.id.clone(), + required_observations: input.policy.required_observations.clone(), + completeness_claimed: input.policy.completeness_claimed, }, - observations: Vec::new(), - falsifications: Vec::new(), - subject_stale: false, - headline: State::Pass, - known_debts: Vec::new(), + observations, + falsifications, + subject_stale, + headline, + known_debts: input.known_debts.clone(), } } From 7c28468e6b352eb95bd143b7a8bbb0304986da8f Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 17 Aug 2026 01:12:06 +0000 Subject: [PATCH 3/6] test: correct falsification, input-validity and completeness semantics (RED-2) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Review findings against the classifier. The GREEN suite was green while holding three wrong semantics and one avoidable hole; these tests state the corrected rules and fail against the current logic. Contract/type changes are here so the tests compile; the behaviour is not yet implemented. 1. A CLAIMED falsification was treated as a FINDING. #147 defines FINDING as an admissible VERIFIED defect, and the wide falsification surface means a counterexample may arrive from a surface that cannot carry a verdict — not that an unverified claim is a defect. V0 semantics: REPRODUCED -> FINDING CLAIMED -> OWED (verification still owed) VERIFICATION_FAILED -> CANNOT_CHECK (attempted, no trustworthy answer) FalsificationOut therefore gains its own `state`, so a headline of FINDING, OWED or CANNOT_CHECK driven by this channel is explainable from the predicate rather than only from this crate's source. 2. A falsification explicitly bound to ANOTHER commit still raised this subject's snapshot. A wide surface means more KINDS of surface, not defects of any commit in the universe, and #147 forbids combining evidence across SHAs. Now ClassifierError::FalsificationSubjectMismatch. `None` stays admissible: an issue comment has no binding to give. 3. A required observation missing from the input map became OWED. That contradicts the rule this design exists for — acquisition state is carried by the caller, never inferred. An absent entry could be not-produced, a broken adapter, or a lost element; naming that unknown OWED converts a construction failure into a domain fact. Now ClassifierError::MissingRequiredObservation, and classify returns Result: malformed input gets no well-formed predicate. 4. Policy.completeness_claimed was a caller-settable bool documented as "always false in V0" — a false claim the library would have serialized faithfully. The field is removed from the input entirely and the output materializes completenessClaimed: false unconditionally, so the forbidden state cannot be constructed. Also: `falsifications[]` is no longer described as established defects. It is a falsification channel whose records carry their own state, since a CLAIMED record is precisely not an established defect. RED-2 state: 4 failing (the four corrected rules), 20 passing, 4 fixture tests passing. Frozen Step 0B fixtures, README and validator untouched. Refs #147 Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_013K3sUCBMGGjf5v4AqsW7Qk --- crates/o7-closure-classifier/src/lib.rs | 107 ++++++++++--- .../o7-closure-classifier/tests/acceptance.rs | 140 ++++++++++++++---- .../tests/frozen_fixtures.rs | 2 +- 3 files changed, 196 insertions(+), 53 deletions(-) diff --git a/crates/o7-closure-classifier/src/lib.rs b/crates/o7-closure-classifier/src/lib.rs index 240c96ae..1f4630a7 100644 --- a/crates/o7-closure-classifier/src/lib.rs +++ b/crates/o7-closure-classifier/src/lib.rs @@ -131,34 +131,84 @@ pub enum SourceKind { IssueComment, } -/// How well established a falsification is, recorded as provenance. It does NOT -/// gate whether the fact counts: by the time a fact reaches this crate it is an -/// already-established falsification, and #147 makes falsification the WIDE -/// surface — "a concrete defect claim from any surface must be checked if it is -/// verifiable, even when that surface is inadmissible as a closure verdict." -/// Inventing a verification threshold here would narrow that deliberately wide -/// surface on this crate's own authority. +/// How far a falsification-channel record has actually got. #147 defines +/// `FINDING` as an admissible VERIFIED defect, and the wide falsification +/// surface only means "a checkable counterexample may arrive from a surface that +/// could never carry a verdict" — it does not mean an unverified claim is a +/// defect. So this gates, and each value maps to exactly one state. #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)] #[serde(rename_all = "SCREAMING_SNAKE_CASE")] pub enum Verification { + /// Verified: the defect was reproduced. -> `FINDING` Reproduced, + /// A concrete claim exists and its verification is still owed. -> `OWED` Claimed, + /// Verification was attempted and did not yield a trustworthy answer. + /// -> `CANNOT_CHECK` + VerificationFailed, } -/// An established defect claim, with enough provenance to re-fetch it. Carries -/// no prose: the classifier decides what an established fact does, not whether -/// some text amounts to one. +/// One record on the falsification channel — NOT necessarily an established +/// defect: see [`Verification`], which decides what this record contributes. +/// Carries no prose. The classifier never reads text to decide whether some +/// wording amounts to a defect claim. #[derive(Debug, Clone, PartialEq, Eq)] pub struct FalsificationFact { pub source_kind: SourceKind, pub stable_id: String, - /// Present only where the surface has an immutable commit binding. Absent - /// binding does NOT disqualify a falsification — see [`Verification`]. + /// Present only where the surface has an immutable commit binding. `None` is + /// admissible — an issue comment has no commit binding, and requiring one + /// would silently close the wide surface. But a record explicitly bound to + /// ANOTHER commit is rejected as invalid input rather than allowed to + /// contaminate this subject: a wide surface means more KINDS of surface, not + /// defects of any commit in the universe. pub subject_sha: Option, pub author: String, pub verification: Verification, } +/// Refusals to classify. A malformed input never receives a well-formed closure +/// predicate — that is precisely how an inference would sneak in disguised as a +/// domain fact. +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum ClassifierError { + /// A policy-required observation had no entry at all. We cannot know whether + /// it was not produced, or lost by a broken adapter, or never fetched. + /// Naming that unknown `OWED` would convert a construction failure into a + /// domain fact, which is the whole thing this design refuses to do. + MissingRequiredObservation { id: String }, + /// A falsification record explicitly bound to a different commit. Evidence + /// is never combined across SHAs. + FalsificationSubjectMismatch { + stable_id: String, + subject_sha: String, + expected_sha: String, + }, +} + +impl std::fmt::Display for ClassifierError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + ClassifierError::MissingRequiredObservation { id } => write!( + f, + "required observation `{id}` has no entry: acquisition state is carried by the \ + caller, never inferred from absence" + ), + ClassifierError::FalsificationSubjectMismatch { + stable_id, + subject_sha, + expected_sha, + } => write!( + f, + "falsification `{stable_id}` is bound to {subject_sha}, not to the subject \ + {expected_sha}" + ), + } + } +} + +impl std::error::Error for ClassifierError {} + #[derive(Debug, Clone, PartialEq, Eq)] pub struct Subject { pub repository: String, @@ -174,9 +224,11 @@ pub struct Policy { pub id: String, /// Authoritative enumeration. Output observation order follows it. pub required_observations: Vec, - /// Always false in V0: enumerating a required set is not claiming the set is - /// complete. - pub completeness_claimed: bool, + // NOTE: there is deliberately no `completeness_claimed` field. V0 must + // always disclaim completeness, and a caller-settable bool documented as + // "always false" is a false claim waiting to be serialized. The output + // materializes `completenessClaimed: false` unconditionally, so the + // forbidden state cannot be constructed at all. } #[derive(Debug, Clone, PartialEq, Eq)] @@ -220,6 +272,10 @@ pub struct FalsificationOut { pub subject_sha: Option, pub author: String, pub verification: Verification, + /// What this record contributes, so a headline of `FINDING`, `OWED` or + /// `CANNOT_CHECK` driven by the falsification channel is explainable from + /// the predicate itself rather than only from this crate's source. + pub state: State, } /// The deterministic closure predicate. No timestamp, no generated id, no @@ -234,9 +290,11 @@ pub struct Predicate { pub git_commit: String, pub policy: PolicyOut, pub observations: Vec, - /// Established falsifications, kept as their own record. A headline of - /// `FINDING` driven by one of these would otherwise be unexplainable from - /// the predicate alone. + /// Falsification-channel records, each with its own state. NOT a list of + /// established defects: a `CLAIMED` record is an unverified counterexample + /// and contributes `OWED`. Kept as their own list because such a record + /// belongs to no required observation, and attaching it to one would + /// misreport which observation produced the state. pub falsifications: Vec, /// True when the head moved before or after evaluation. Kept beside the /// per-observation vector rather than overwriting it, so a stale snapshot @@ -309,7 +367,7 @@ fn classify_review( /// Classify one snapshot. Every invocation is independent: no memory of a /// previous headline, so a finding that disappears does not linger. -pub fn classify(input: &ClassifierInput) -> Predicate { +pub fn classify(input: &ClassifierInput) -> Result { let expected = input.subject.expected_sha.as_str(); // The head moving invalidates the SNAPSHOT, not the individual observations, @@ -350,6 +408,9 @@ pub fn classify(input: &ClassifierInput) -> Predicate { subject_sha: f.subject_sha.clone(), author: f.author.clone(), verification: f.verification, + // RED-2: every record still reports FINDING regardless of how far + // its verification actually got. GREEN-2 maps each variant. + state: State::Finding, }) .collect(); @@ -368,7 +429,7 @@ pub fn classify(input: &ClassifierInput) -> Predicate { headline = State::Stale; } - Predicate { + Ok(Predicate { schema_version: 1, repository: input.subject.repository.clone(), pull_request: input.subject.pull_request, @@ -376,12 +437,14 @@ pub fn classify(input: &ClassifierInput) -> Predicate { policy: PolicyOut { id: input.policy.id.clone(), required_observations: input.policy.required_observations.clone(), - completeness_claimed: input.policy.completeness_claimed, + // Unconditional: V0 never claims completeness, and the input has no + // field through which a caller could claim it. + completeness_claimed: false, }, observations, falsifications, subject_stale, headline, known_debts: input.known_debts.clone(), - } + }) } diff --git a/crates/o7-closure-classifier/tests/acceptance.rs b/crates/o7-closure-classifier/tests/acceptance.rs index 53c09027..f9dcc8c4 100644 --- a/crates/o7-closure-classifier/tests/acceptance.rs +++ b/crates/o7-closure-classifier/tests/acceptance.rs @@ -11,8 +11,9 @@ #![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)] use o7_closure_classifier::{ - classify, Acquisition, CheckConclusion, CheckEvidence, ClassifierInput, FalsificationFact, - ObservationInput, Policy, ReviewEvidence, SourceKind, State, Subject, Verification, + classify, Acquisition, CheckConclusion, CheckEvidence, ClassifierError, ClassifierInput, + FalsificationFact, ObservationInput, Policy, ReviewEvidence, SourceKind, State, Subject, + Verification, }; use std::collections::BTreeMap; @@ -33,7 +34,6 @@ fn policy() -> Policy { Policy { id: "007/closure/v1".to_owned(), required_observations: required, - completeness_claimed: false, } } @@ -88,6 +88,11 @@ fn input(subject: Subject, observations: BTreeMap) -> } } +/// `classify` now refuses malformed input, so every well-formed case unwraps. +fn ok(inp: &ClassifierInput) -> o7_closure_classifier::Predicate { + classify(inp).expect("this input is well formed") +} + fn state_of(p: &o7_closure_classifier::Predicate, id: &str) -> State { p.observations .iter() @@ -100,14 +105,14 @@ fn state_of(p: &o7_closure_classifier::Predicate, id: &str) -> State { #[test] fn case_01_initial_head_differs_from_expected_is_stale() { - let p = classify(&input(subject(HEAD, OTHER, HEAD), all_green(HEAD))); + let p = ok(&input(subject(HEAD, OTHER, HEAD), all_green(HEAD))); assert_eq!(p.headline, State::Stale); assert!(p.subject_stale); } #[test] fn case_02_final_head_differs_from_expected_is_stale() { - let p = classify(&input(subject(HEAD, HEAD, OTHER), all_green(HEAD))); + let p = ok(&input(subject(HEAD, HEAD, OTHER), all_green(HEAD))); assert_eq!(p.headline, State::Stale); assert!(p.subject_stale); } @@ -116,7 +121,7 @@ fn case_02_final_head_differs_from_expected_is_stale() { fn case_02b_stale_snapshot_still_preserves_the_observation_vector() { // The head moving must not erase what each observation said about the frozen // subject; the headline is derived presentation, not a replacement. - let p = classify(&input(subject(HEAD, HEAD, OTHER), all_green(HEAD))); + let p = ok(&input(subject(HEAD, HEAD, OTHER), all_green(HEAD))); assert_eq!(p.headline, State::Stale); assert_eq!(state_of(&p, "ci/worker-gate"), State::Pass); assert_eq!(state_of(&p, "review/codex"), State::Pass); @@ -128,7 +133,7 @@ fn case_02b_stale_snapshot_still_preserves_the_observation_vector() { fn case_03_clean_review_on_the_wrong_sha_is_not_positive_evidence() { let mut obs = all_green(HEAD); obs.insert("review/codex".to_owned(), clean_review(OTHER, "codex")); - let p = classify(&input(subject(HEAD, HEAD, HEAD), obs)); + let p = ok(&input(subject(HEAD, HEAD, HEAD), obs)); assert_eq!( state_of(&p, "review/codex"), State::Owed, @@ -147,7 +152,7 @@ fn case_11_ci_and_reviews_from_different_shas_cannot_combine() { "review/coderabbit".to_owned(), clean_review(OTHER, "coderabbit"), ); - let p = classify(&input(subject(HEAD, HEAD, HEAD), obs)); + let p = ok(&input(subject(HEAD, HEAD, HEAD), obs)); for id in ["review/codex", "review/coderabbit"] { assert_eq!(state_of(&p, id), State::Owed); } @@ -164,7 +169,7 @@ fn case_11b_a_check_bound_to_another_sha_is_not_evidence_here() { "ci/worker-gate".to_owned(), passing_check(OTHER, "worker-gate"), ); - let p = classify(&input(subject(HEAD, HEAD, HEAD), obs)); + let p = ok(&input(subject(HEAD, HEAD, HEAD), obs)); assert_eq!(state_of(&p, "ci/worker-gate"), State::Owed); } @@ -183,7 +188,7 @@ fn case_04_a_mutable_comment_cannot_be_positive_verdict_evidence() { "review/coderabbit".to_owned(), ObservationInput::Review(Acquisition::NotProduced), ); - let p = classify(&input(subject(HEAD, HEAD, HEAD), obs)); + let p = ok(&input(subject(HEAD, HEAD, HEAD), obs)); assert_eq!(state_of(&p, "review/coderabbit"), State::Owed); assert_eq!(p.headline, State::Owed); } @@ -203,7 +208,7 @@ fn case_05_structured_falsification_from_a_non_verdict_surface_is_preserved() { author: "coderabbitai[bot]".to_owned(), verification: Verification::Reproduced, }); - let p = classify(&inp); + let p = ok(&inp); assert_eq!(p.headline, State::Finding); assert_eq!(p.falsifications.len(), 1); // The positive observations are NOT rewritten by it: both facts survive. @@ -211,19 +216,76 @@ fn case_05_structured_falsification_from_a_non_verdict_surface_is_preserved() { } #[test] -fn case_05b_falsification_without_a_commit_binding_still_counts() { - // Positive evidence is strict about SHA binding; falsification is not. An - // issue comment has no commit binding at all, and gating on one would - // silently narrow the wide surface. +fn case_05b_falsification_without_a_commit_binding_is_still_admissible() { + // Positive evidence is strict about SHA binding; the falsification channel + // is not. An issue comment has no commit binding at all, and requiring one + // would silently close the wide surface. let mut inp = input(subject(HEAD, HEAD, HEAD), all_green(HEAD)); inp.falsifications.push(FalsificationFact { source_kind: SourceKind::IssueComment, stable_id: "issuecomment-1".to_owned(), subject_sha: None, author: "someone[bot]".to_owned(), + verification: Verification::Reproduced, + }); + assert_eq!(ok(&inp).headline, State::Finding); +} + +#[test] +fn case_05c_a_claimed_falsification_is_owed_not_finding() { + // #147 defines FINDING as an admissible VERIFIED defect. A concrete claim + // whose verification is still owed is exactly that: owed. Treating it as a + // finding would assert a defect nobody has established. + let mut inp = input(subject(HEAD, HEAD, HEAD), all_green(HEAD)); + inp.falsifications.push(FalsificationFact { + source_kind: SourceKind::IssueComment, + stable_id: "issuecomment-2".to_owned(), + subject_sha: None, + author: "someone[bot]".to_owned(), verification: Verification::Claimed, }); - assert_eq!(classify(&inp).headline, State::Finding); + let p = ok(&inp); + assert_eq!(p.falsifications[0].state, State::Owed); + assert_eq!(p.headline, State::Owed); + assert_ne!(p.headline, State::Finding); +} + +#[test] +fn case_05d_failed_verification_of_a_falsification_is_cannot_check() { + // Somebody tried to verify the counterexample and got no trustworthy + // answer. That is not "no defect" and not "defect" — it is the third thing. + let mut inp = input(subject(HEAD, HEAD, HEAD), all_green(HEAD)); + inp.falsifications.push(FalsificationFact { + source_kind: SourceKind::ReviewComment, + stable_id: "discussion-3".to_owned(), + subject_sha: Some(HEAD.to_owned()), + author: "someone[bot]".to_owned(), + verification: Verification::VerificationFailed, + }); + let p = ok(&inp); + assert_eq!(p.falsifications[0].state, State::CannotCheck); + assert_eq!(p.headline, State::CannotCheck); +} + +#[test] +fn case_05e_a_falsification_bound_to_another_sha_is_invalid_input() { + // A wide surface means more KINDS of surface, not defects of any commit in + // the universe. Evidence is never combined across SHAs, so this is refused + // rather than quietly contaminating the snapshot. + let mut inp = input(subject(HEAD, HEAD, HEAD), all_green(HEAD)); + inp.falsifications.push(FalsificationFact { + source_kind: SourceKind::ReviewComment, + stable_id: "discussion-4".to_owned(), + subject_sha: Some(OTHER.to_owned()), + author: "someone[bot]".to_owned(), + verification: Verification::Reproduced, + }); + match classify(&inp) { + Err(ClassifierError::FalsificationSubjectMismatch { stable_id, .. }) => { + assert_eq!(stable_id, "discussion-4"); + } + other => panic!("expected a subject-mismatch refusal, got {other:?}"), + } } #[test] @@ -248,7 +310,7 @@ fn case_12_same_vendor_same_sha_conflicting_surfaces_are_not_collapsed() { author: "codex[bot]".to_owned(), verification: Verification::Reproduced, }); - let p = classify(&inp); + let p = ok(&inp); assert_eq!(state_of(&p, "review/codex"), State::Finding); assert_eq!(p.falsifications.len(), 1); assert_eq!(p.headline, State::Finding); @@ -263,7 +325,7 @@ fn case_06_no_verdict_produced_is_owed_not_pass() { for acq in [Acquisition::NotProduced, Acquisition::RateLimited] { let mut obs = all_green(HEAD); obs.insert("review/codex".to_owned(), ObservationInput::Review(acq)); - let p = classify(&input(subject(HEAD, HEAD, HEAD), obs)); + let p = ok(&input(subject(HEAD, HEAD, HEAD), obs)); assert_eq!(state_of(&p, "review/codex"), State::Owed); } } @@ -278,18 +340,25 @@ fn case_07_acquisition_failure_is_cannot_check_not_owed_and_not_empty_success() reason: "503 from the checks endpoint".to_owned(), }), ); - let p = classify(&input(subject(HEAD, HEAD, HEAD), obs)); + let p = ok(&input(subject(HEAD, HEAD, HEAD), obs)); assert_eq!(state_of(&p, "ci/worker-gate"), State::CannotCheck); assert_ne!(state_of(&p, "ci/worker-gate"), State::Owed); assert_ne!(p.headline, State::Pass); } #[test] -fn case_07b_a_missing_required_observation_is_owed() { +fn case_07b_a_missing_required_observation_is_invalid_input_not_owed() { + // We cannot know whether it was never produced, lost by a broken adapter, + // or never fetched. Calling that unknown OWED would turn a construction + // failure into a domain fact — the exact move this design exists to refuse. let mut obs = all_green(HEAD); obs.remove("review/coderabbit"); - let p = classify(&input(subject(HEAD, HEAD, HEAD), obs)); - assert_eq!(state_of(&p, "review/coderabbit"), State::Owed); + match classify(&input(subject(HEAD, HEAD, HEAD), obs)) { + Err(ClassifierError::MissingRequiredObservation { id }) => { + assert_eq!(id, "review/coderabbit"); + } + other => panic!("expected a missing-observation refusal, got {other:?}"), + } } // --------------------------------------------------------------------- 8, 9 -- @@ -312,7 +381,7 @@ fn case_08_finding_and_cannot_check_both_survive_headline_is_finding() { reason: "runner vanished".to_owned(), }), ); - let p = classify(&input(subject(HEAD, HEAD, HEAD), obs)); + let p = ok(&input(subject(HEAD, HEAD, HEAD), obs)); assert_eq!(state_of(&p, "review/codex"), State::Finding); assert_eq!(state_of(&p, "ci/worktree-verifier"), State::CannotCheck); assert_eq!(p.headline, State::Finding); @@ -329,7 +398,7 @@ fn case_09_a_later_snapshot_without_the_finding_is_cannot_check_not_pass() { reason: "runner vanished".to_owned(), }), ); - let p = classify(&input(subject(HEAD, HEAD, HEAD), obs)); + let p = ok(&input(subject(HEAD, HEAD, HEAD), obs)); assert_eq!(state_of(&p, "ci/worktree-verifier"), State::CannotCheck); assert_eq!(p.headline, State::CannotCheck); assert_ne!(p.headline, State::Pass); @@ -339,7 +408,7 @@ fn case_09_a_later_snapshot_without_the_finding_is_cannot_check_not_pass() { #[test] fn case_10_pass_enumerates_the_required_set_and_disclaims_completeness() { - let p = classify(&input(subject(HEAD, HEAD, HEAD), all_green(HEAD))); + let p = ok(&input(subject(HEAD, HEAD, HEAD), all_green(HEAD))); assert_eq!(p.headline, State::Pass); assert_eq!( p.policy.required_observations, @@ -349,11 +418,22 @@ fn case_10_pass_enumerates_the_required_set_and_disclaims_completeness() { assert_eq!(p.observations.len(), policy().required_observations.len()); } +#[test] +fn case_10b_v0_cannot_emit_a_completeness_claim() { + // Not "we remember to set it false" — there is no input field through which + // `true` could be constructed, so the forbidden state is unreachable. + let p = ok(&input(subject(HEAD, HEAD, HEAD), all_green(HEAD))); + assert!(!p.policy.completeness_claimed); + let json = p.to_json().expect("serializing"); + assert!(json.contains("\"completenessClaimed\": false")); + assert!(!json.contains("\"completenessClaimed\": true")); +} + #[test] fn case_14_known_debt_survives_clean_reviewer_evidence() { let mut inp = input(subject(HEAD, HEAD, HEAD), all_green(HEAD)); inp.known_debts = vec!["W8".to_owned(), "W9 both arms".to_owned()]; - let p = classify(&inp); + let p = ok(&inp); assert_eq!(p.headline, State::Pass); assert_eq!( p.known_debts, @@ -363,7 +443,7 @@ fn case_14_known_debt_survives_clean_reviewer_evidence() { #[test] fn case_15_predicate_makes_no_merge_authorization_claim() { - let p = classify(&input(subject(HEAD, HEAD, HEAD), all_green(HEAD))); + let p = ok(&input(subject(HEAD, HEAD, HEAD), all_green(HEAD))); let json = p.to_json().expect("serializing the predicate"); for forbidden in ["merge", "approve", "authoriz", "mergeable", "ready_to"] { assert!( @@ -382,15 +462,15 @@ fn case_13_classification_is_a_pure_function_of_its_input() { // checks. What a test can show is the observable half — the same input // always yields byte-identical output, so nothing ambient leaks in. let inp = input(subject(HEAD, HEAD, HEAD), all_green(HEAD)); - let a = classify(&inp).to_json().expect("serializing"); - let b = classify(&inp).to_json().expect("serializing"); + let a = ok(&inp).to_json().expect("serializing"); + let b = ok(&inp).to_json().expect("serializing"); assert_eq!(a, b); assert!(!a.contains("timestamp")); } #[test] fn observation_order_follows_the_authoritative_policy_order() { - let p = classify(&input(subject(HEAD, HEAD, HEAD), all_green(HEAD))); + let p = ok(&input(subject(HEAD, HEAD, HEAD), all_green(HEAD))); let ids: Vec<&str> = p.observations.iter().map(|o| o.id.as_str()).collect(); assert_eq!(ids, policy().required_observations); } diff --git a/crates/o7-closure-classifier/tests/frozen_fixtures.rs b/crates/o7-closure-classifier/tests/frozen_fixtures.rs index 77b4d88f..c32d67a5 100644 --- a/crates/o7-closure-classifier/tests/frozen_fixtures.rs +++ b/crates/o7-closure-classifier/tests/frozen_fixtures.rs @@ -64,7 +64,6 @@ fn policy() -> Policy { "review/codex".to_owned(), "review/coderabbit".to_owned(), ], - completeness_claimed: false, } } @@ -190,6 +189,7 @@ fn classify_fixture(doc: &Value, falsifications: Vec) -> Pred falsifications, known_debts: Vec::new(), }) + .expect("the fixture adapter supplies every required observation explicitly") } fn state_of(p: &Predicate, id: &str) -> State { From 039316ce071f6559dbd1092ee56c156fb73d1241 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 17 Aug 2026 01:22:45 +0000 Subject: [PATCH 4/6] feat: implement corrected falsification and input-validity semantics (GREEN-2) Turns RED-2 green. Four rules, no more. Falsification records now carry their own state, derived from how far verification actually got: REPRODUCED -> FINDING CLAIMED -> OWED VERIFICATION_FAILED -> CANNOT_CHECK and the headline is the maximum over the observation vector CHAINED with the falsification states, rather than a special case that could only ever raise FINDING. A claimed counterexample therefore leaves an otherwise-green snapshot at OWED, which is what it is: a defect nobody has established yet. Input validity is checked before anything is derived, because a predicate built from an input we misread looks exactly like one we did not: required id absent from the map -> MissingRequiredObservation falsification bound to another commit -> FalsificationSubjectMismatch The unreachable `None` arm left after the presence check maps to CANNOT_CHECK rather than OWED, so even the impossible path refuses to invent an authoritative absence. completenessClaimed is materialized as false unconditionally; the input has no field through which true could be constructed. 24 acceptance + 4 fixture tests pass. Workspace fmt, clippy -D warnings, and the worker-gate-equivalent test run are clean. Frozen Step 0B fixtures, README and validator untouched. Refs #147 Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_013K3sUCBMGGjf5v4AqsW7Qk --- crates/o7-closure-classifier/src/lib.rs | 39 ++++++++++++++----- .../o7-closure-classifier/tests/acceptance.rs | 6 ++- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/crates/o7-closure-classifier/src/lib.rs b/crates/o7-closure-classifier/src/lib.rs index 1f4630a7..d0687c39 100644 --- a/crates/o7-closure-classifier/src/lib.rs +++ b/crates/o7-closure-classifier/src/lib.rs @@ -370,6 +370,26 @@ fn classify_review( pub fn classify(input: &ClassifierInput) -> Result { let expected = input.subject.expected_sha.as_str(); + // Refuse malformed input before deriving anything. A predicate produced from + // an input we could not read correctly is worse than no predicate: it looks + // exactly like one we could. + for id in &input.policy.required_observations { + if !input.observations.contains_key(id) { + return Err(ClassifierError::MissingRequiredObservation { id: id.clone() }); + } + } + for f in &input.falsifications { + if let Some(sha) = &f.subject_sha { + if sha != expected { + return Err(ClassifierError::FalsificationSubjectMismatch { + stable_id: f.stable_id.clone(), + subject_sha: sha.clone(), + expected_sha: expected.to_owned(), + }); + } + } + } + // The head moving invalidates the SNAPSHOT, not the individual observations, // which remain statements about the frozen subject. Recorded alongside the // vector so nothing is overwritten. @@ -381,11 +401,10 @@ pub fn classify(input: &ClassifierInput) -> Result { .required_observations .iter() .map(|id| { - // A required observation nobody supplied is owed. Absence of an - // entry is the caller's explicit omission, not an acquisition - // failure, and the two are not merged. + // Presence was established above, so `None` here is unreachable — + // and is still not silently turned into a state. let (state, source) = match input.observations.get(id) { - None => (State::Owed, None), + None => (State::CannotCheck, None), Some(ObservationInput::Check(acq)) => classify_check(acq, expected), Some(ObservationInput::Review(acq)) => classify_review(acq, expected), }; @@ -408,9 +427,11 @@ pub fn classify(input: &ClassifierInput) -> Result { subject_sha: f.subject_sha.clone(), author: f.author.clone(), verification: f.verification, - // RED-2: every record still reports FINDING regardless of how far - // its verification actually got. GREEN-2 maps each variant. - state: State::Finding, + state: match f.verification { + Verification::Reproduced => State::Finding, + Verification::Claimed => State::Owed, + Verification::VerificationFailed => State::CannotCheck, + }, }) .collect(); @@ -420,11 +441,9 @@ pub fn classify(input: &ClassifierInput) -> Result { let mut headline = observations .iter() .map(|o| o.state) + .chain(falsifications.iter().map(|f| f.state)) .max_by_key(|s| s.rank()) .unwrap_or(State::Pass); - if !falsifications.is_empty() && State::Finding.rank() > headline.rank() { - headline = State::Finding; - } if subject_stale { headline = State::Stale; } diff --git a/crates/o7-closure-classifier/tests/acceptance.rs b/crates/o7-closure-classifier/tests/acceptance.rs index f9dcc8c4..751e906d 100644 --- a/crates/o7-closure-classifier/tests/acceptance.rs +++ b/crates/o7-closure-classifier/tests/acceptance.rs @@ -245,7 +245,8 @@ fn case_05c_a_claimed_falsification_is_owed_not_finding() { verification: Verification::Claimed, }); let p = ok(&inp); - assert_eq!(p.falsifications[0].state, State::Owed); + let record = p.falsifications.first().expect("one record"); + assert_eq!(record.state, State::Owed); assert_eq!(p.headline, State::Owed); assert_ne!(p.headline, State::Finding); } @@ -263,7 +264,8 @@ fn case_05d_failed_verification_of_a_falsification_is_cannot_check() { verification: Verification::VerificationFailed, }); let p = ok(&inp); - assert_eq!(p.falsifications[0].state, State::CannotCheck); + let record = p.falsifications.first().expect("one record"); + assert_eq!(record.state, State::CannotCheck); assert_eq!(p.headline, State::CannotCheck); } From b85d6427587f215e33173c01000bde4aa79910a6 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 17 Aug 2026 08:55:34 +0000 Subject: [PATCH 5/6] test: predicate must preserve acquisition provenance (RED-3) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Third review finding, and one floor below the previous two. #147 requires the predicate to "preserve provenance for each observation sufficiently to re-fetch/re-evaluate it later". The classifier was discarding provenance it had already been handed: NotProduced -> OWED, source None RateLimited -> OWED, source None Failed{reason} -> CANNOT_CHECK, reason LOST After serialization nobody can tell "nobody produced it" from "the reviewer was rate-limited", though those are two different observed facts. And "it failed" without a reason cannot be re-evaluated at all — which is the one thing the predicate is supposed to make possible. This is the same destructive collapse the headline rule forbids, one level down: several outcomes mapped onto one state, with the outcome thrown away. The falsification channel inherited the defect the moment it was added in RED-2: VERIFICATION_FAILED recorded that verification failed but never why. Contract change, behaviour not yet implemented: ObservationOut.acquisition = { status, reason? } status: AVAILABLE | NOT_PRODUCED | RATE_LIMITED | FAILED reason: required for FAILED Verification::VerificationFailed -> Verification::Failed { reason } FalsificationOut.verification = { status, reason? } State and acquisition outcome are deliberately separate fields: NOT_PRODUCED and RATE_LIMITED both yield OWED, and the predicate now records which path got there. RED-3 state: 3 failing (the three provenance witnesses), 25 passing, 4 fixture tests passing. Frozen Step 0B fixtures, README and validator untouched. Refs #147 Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_013K3sUCBMGGjf5v4AqsW7Qk --- crates/o7-closure-classifier/src/lib.rs | 72 ++++++++++-- .../o7-closure-classifier/tests/acceptance.rs | 109 +++++++++++++++++- 2 files changed, 170 insertions(+), 11 deletions(-) diff --git a/crates/o7-closure-classifier/src/lib.rs b/crates/o7-closure-classifier/src/lib.rs index d0687c39..0363f56a 100644 --- a/crates/o7-closure-classifier/src/lib.rs +++ b/crates/o7-closure-classifier/src/lib.rs @@ -136,16 +136,16 @@ pub enum SourceKind { /// surface only means "a checkable counterexample may arrive from a surface that /// could never carry a verdict" — it does not mean an unverified claim is a /// defect. So this gates, and each value maps to exactly one state. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)] -#[serde(rename_all = "SCREAMING_SNAKE_CASE")] +#[derive(Debug, Clone, PartialEq, Eq)] pub enum Verification { /// Verified: the defect was reproduced. -> `FINDING` Reproduced, /// A concrete claim exists and its verification is still owed. -> `OWED` Claimed, /// Verification was attempted and did not yield a trustworthy answer. - /// -> `CANNOT_CHECK` - VerificationFailed, + /// -> `CANNOT_CHECK`. The reason is carried so the predicate can say WHY, + /// not merely that something went wrong. + Failed { reason: String }, } /// One record on the falsification channel — NOT necessarily an established @@ -248,10 +248,53 @@ pub struct SourceOut { pub stable_id: String, } +/// How the observation was obtained, kept separate from the state it produced. +/// `NOT_PRODUCED` and `RATE_LIMITED` both yield `OWED`, and collapsing them into +/// the state alone would destroy two distinct observed facts — the same +/// destructive collapse the headline rule forbids, one level down. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)] +#[serde(rename_all = "SCREAMING_SNAKE_CASE")] +pub enum AcquisitionStatus { + Available, + NotProduced, + RateLimited, + Failed, +} + +#[derive(Debug, Clone, PartialEq, Eq, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct AcquisitionOut { + pub status: AcquisitionStatus, + /// Always present for `FAILED`: #147 requires the predicate to preserve + /// enough provenance to re-evaluate later, and "it failed" alone cannot be + /// re-evaluated. + #[serde(skip_serializing_if = "Option::is_none")] + pub reason: Option, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)] +#[serde(rename_all = "SCREAMING_SNAKE_CASE")] +pub enum VerificationStatus { + Reproduced, + Claimed, + Failed, +} + +#[derive(Debug, Clone, PartialEq, Eq, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct VerificationOut { + pub status: VerificationStatus, + #[serde(skip_serializing_if = "Option::is_none")] + pub reason: Option, +} + #[derive(Debug, Clone, PartialEq, Eq, Serialize)] pub struct ObservationOut { pub id: String, pub state: State, + /// The acquisition outcome that produced `state`. Distinct from it on + /// purpose: several outcomes map to one state. + pub acquisition: AcquisitionOut, #[serde(skip_serializing_if = "Option::is_none")] pub source: Option, } @@ -271,7 +314,7 @@ pub struct FalsificationOut { #[serde(skip_serializing_if = "Option::is_none")] pub subject_sha: Option, pub author: String, - pub verification: Verification, + pub verification: VerificationOut, /// What this record contributes, so a headline of `FINDING`, `OWED` or /// `CANNOT_CHECK` driven by the falsification channel is explainable from /// the predicate itself rather than only from this crate's source. @@ -411,6 +454,13 @@ pub fn classify(input: &ClassifierInput) -> Result { ObservationOut { id: id.clone(), state, + // RED-3: every observation reports AVAILABLE with no reason, so + // NOT_PRODUCED / RATE_LIMITED / FAILED are indistinguishable in + // the predicate. GREEN-3 carries the real outcome through. + acquisition: AcquisitionOut { + status: AcquisitionStatus::Available, + reason: None, + }, source, } }) @@ -426,11 +476,19 @@ pub fn classify(input: &ClassifierInput) -> Result { }, subject_sha: f.subject_sha.clone(), author: f.author.clone(), - verification: f.verification, + // RED-3: the failure reason is dropped here. GREEN-3 keeps it. + verification: VerificationOut { + status: match f.verification { + Verification::Reproduced => VerificationStatus::Reproduced, + Verification::Claimed => VerificationStatus::Claimed, + Verification::Failed { .. } => VerificationStatus::Failed, + }, + reason: None, + }, state: match f.verification { Verification::Reproduced => State::Finding, Verification::Claimed => State::Owed, - Verification::VerificationFailed => State::CannotCheck, + Verification::Failed { .. } => State::CannotCheck, }, }) .collect(); diff --git a/crates/o7-closure-classifier/tests/acceptance.rs b/crates/o7-closure-classifier/tests/acceptance.rs index 751e906d..4c6080eb 100644 --- a/crates/o7-closure-classifier/tests/acceptance.rs +++ b/crates/o7-closure-classifier/tests/acceptance.rs @@ -11,9 +11,9 @@ #![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)] use o7_closure_classifier::{ - classify, Acquisition, CheckConclusion, CheckEvidence, ClassifierError, ClassifierInput, - FalsificationFact, ObservationInput, Policy, ReviewEvidence, SourceKind, State, Subject, - Verification, + classify, Acquisition, AcquisitionStatus, CheckConclusion, CheckEvidence, ClassifierError, + ClassifierInput, FalsificationFact, ObservationInput, Policy, ReviewEvidence, SourceKind, + State, Subject, Verification, VerificationStatus, }; use std::collections::BTreeMap; @@ -93,6 +93,16 @@ fn ok(inp: &ClassifierInput) -> o7_closure_classifier::Predicate { classify(inp).expect("this input is well formed") } +fn obs_of<'a>( + p: &'a o7_closure_classifier::Predicate, + id: &str, +) -> &'a o7_closure_classifier::ObservationOut { + p.observations + .iter() + .find(|o| o.id == id) + .unwrap_or_else(|| panic!("observation {id} missing from the predicate")) +} + fn state_of(p: &o7_closure_classifier::Predicate, id: &str) -> State { p.observations .iter() @@ -261,7 +271,9 @@ fn case_05d_failed_verification_of_a_falsification_is_cannot_check() { stable_id: "discussion-3".to_owned(), subject_sha: Some(HEAD.to_owned()), author: "someone[bot]".to_owned(), - verification: Verification::VerificationFailed, + verification: Verification::Failed { + reason: "reproducer unavailable".to_owned(), + }, }); let p = ok(&inp); let record = p.falsifications.first().expect("one record"); @@ -476,3 +488,92 @@ fn observation_order_follows_the_authoritative_policy_order() { let ids: Vec<&str> = p.observations.iter().map(|o| o.id.as_str()).collect(); assert_eq!(ids, policy().required_observations); } + +// ------------------------------------------------------- provenance (RED-3) -- + +#[test] +fn case_16_not_produced_and_rate_limited_are_both_owed_yet_distinguishable() { + // Two different observed facts that share one state. If the predicate keeps + // only the state, it has destroyed the distinction — the same destructive + // collapse the headline rule forbids, one level down. + let mut obs = all_green(HEAD); + obs.insert( + "review/codex".to_owned(), + ObservationInput::Review(Acquisition::NotProduced), + ); + obs.insert( + "review/coderabbit".to_owned(), + ObservationInput::Review(Acquisition::RateLimited), + ); + let p = ok(&input(subject(HEAD, HEAD, HEAD), obs)); + + let codex = obs_of(&p, "review/codex"); + let rabbit = obs_of(&p, "review/coderabbit"); + assert_eq!(codex.state, State::Owed); + assert_eq!(rabbit.state, State::Owed); + assert_eq!(codex.acquisition.status, AcquisitionStatus::NotProduced); + assert_eq!(rabbit.acquisition.status, AcquisitionStatus::RateLimited); + assert_ne!(codex.acquisition.status, rabbit.acquisition.status); +} + +#[test] +fn case_17_a_failed_acquisition_keeps_its_reason_in_the_predicate() { + // "It failed" cannot be re-evaluated later; #147 requires enough provenance + // to re-fetch or re-evaluate, so the reason has to survive serialization. + let mut obs = all_green(HEAD); + obs.insert( + "ci/worker-gate".to_owned(), + ObservationInput::Check(Acquisition::Failed { + reason: "503 from the checks endpoint".to_owned(), + }), + ); + let p = ok(&input(subject(HEAD, HEAD, HEAD), obs)); + + let gate = obs_of(&p, "ci/worker-gate"); + assert_eq!(gate.state, State::CannotCheck); + assert_eq!(gate.acquisition.status, AcquisitionStatus::Failed); + assert_eq!( + gate.acquisition.reason.as_deref(), + Some("503 from the checks endpoint") + ); + let json = p.to_json().expect("serializing"); + assert!(json.contains("503 from the checks endpoint")); +} + +#[test] +fn case_18_a_failed_falsification_verification_keeps_its_reason() { + let mut inp = input(subject(HEAD, HEAD, HEAD), all_green(HEAD)); + inp.falsifications.push(FalsificationFact { + source_kind: SourceKind::ReviewComment, + stable_id: "discussion-9".to_owned(), + subject_sha: Some(HEAD.to_owned()), + author: "someone[bot]".to_owned(), + verification: Verification::Failed { + reason: "reproducer unavailable".to_owned(), + }, + }); + let p = ok(&inp); + + let record = p.falsifications.first().expect("one record"); + assert_eq!(record.state, State::CannotCheck); + assert_eq!(record.verification.status, VerificationStatus::Failed); + assert_eq!( + record.verification.reason.as_deref(), + Some("reproducer unavailable") + ); + assert!(p + .to_json() + .expect("serializing") + .contains("reproducer unavailable")); +} + +#[test] +fn case_19_available_observations_record_that_status_too() { + let p = ok(&input(subject(HEAD, HEAD, HEAD), all_green(HEAD))); + for id in policy().required_observations { + assert_eq!( + obs_of(&p, &id).acquisition.status, + AcquisitionStatus::Available + ); + } +} From 4f4546e16ab1f664885e11b787b0fa69db536c67 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 17 Aug 2026 09:02:32 +0000 Subject: [PATCH 6/6] feat: preserve acquisition provenance in the predicate (GREEN-3) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Turns RED-3 green. The classifier no longer discards provenance it was handed. Each observation now reports its acquisition outcome alongside its state, because several outcomes map to one state and only the state was surviving: AVAILABLE -> PASS | FINDING | OWED (wrong SHA) NOT_PRODUCED -> OWED RATE_LIMITED -> OWED FAILED { reason } -> CANNOT_CHECK, reason carried so "nobody produced it" and "the reviewer was rate-limited" are once again two readable facts rather than one indistinguishable OWED, and a failed acquisition says why — without which #147's re-fetch/re-evaluate requirement cannot be met. The falsification channel gets the same treatment: Verification::Failed carries a reason and FalsificationOut serializes status plus reason. The unreachable `None` arm now reports FAILED with an explicit reason rather than a bare CANNOT_CHECK, so even the impossible path explains itself. Also corrects a doc comment that RED-2 made stale: FalsificationFact was still described as "already-established", which stopped being true the moment `Claimed` was introduced — a claimed record is exactly a counterexample whose verification is still owed. 28 acceptance + 4 fixture tests pass. Workspace fmt, clippy -D warnings and the worker-gate-equivalent run are clean. Frozen Step 0B fixtures, README and validator untouched. Refs #147 Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_013K3sUCBMGGjf5v4AqsW7Qk --- crates/o7-closure-classifier/src/lib.rs | 102 +++++++++++++++--------- 1 file changed, 66 insertions(+), 36 deletions(-) diff --git a/crates/o7-closure-classifier/src/lib.rs b/crates/o7-closure-classifier/src/lib.rs index 0363f56a..09a7119b 100644 --- a/crates/o7-closure-classifier/src/lib.rs +++ b/crates/o7-closure-classifier/src/lib.rs @@ -31,10 +31,12 @@ //! ``` //! //! NO PROSE ORACLE. Nothing here reads English. A defect claim reaches the -//! classifier as an already-established [`FalsificationFact`] carrying -//! provenance; extracting such facts from vendor responses is the acquisition -//! layer's job. This crate decides only what an established fact does to the -//! state vector. +//! classifier as a structured [`FalsificationFact`] carrying provenance and a +//! [`Verification`] status; extracting such facts from vendor responses is the +//! acquisition layer's job. Note that such a record is NOT necessarily an +//! established defect — a `Claimed` one is precisely a counterexample whose +//! verification is still owed — so this crate decides what each record +//! contributes, never whether some wording amounts to one. // Mirror the workspace discipline. #![forbid(unsafe_code)] @@ -361,24 +363,47 @@ impl Predicate { fn classify_check( acq: &Acquisition, expected_sha: &str, -) -> (State, Option) { +) -> (State, AcquisitionOut, Option) { match acq { Acquisition::Available(check) => { let source = Some(SourceOut { kind: SourceKind::GithubActionsCheck, stable_id: check.stable_id.clone(), }); - if check.head_sha != expected_sha { - (State::Owed, source) + let state = if check.head_sha != expected_sha { + State::Owed } else { match check.conclusion { - CheckConclusion::Success => (State::Pass, source), - CheckConclusion::Failure => (State::Finding, source), + CheckConclusion::Success => State::Pass, + CheckConclusion::Failure => State::Finding, } - } + }; + (state, available(), source) } - Acquisition::NotProduced | Acquisition::RateLimited => (State::Owed, None), - Acquisition::Failed { .. } => (State::CannotCheck, None), + Acquisition::NotProduced => (State::Owed, status(AcquisitionStatus::NotProduced), None), + Acquisition::RateLimited => (State::Owed, status(AcquisitionStatus::RateLimited), None), + Acquisition::Failed { reason } => (State::CannotCheck, failed(reason), None), + } +} + +fn available() -> AcquisitionOut { + AcquisitionOut { + status: AcquisitionStatus::Available, + reason: None, + } +} + +fn status(status: AcquisitionStatus) -> AcquisitionOut { + AcquisitionOut { + status, + reason: None, + } +} + +fn failed(reason: &str) -> AcquisitionOut { + AcquisitionOut { + status: AcquisitionStatus::Failed, + reason: Some(reason.to_owned()), } } @@ -388,23 +413,25 @@ fn classify_check( fn classify_review( acq: &Acquisition, expected_sha: &str, -) -> (State, Option) { +) -> (State, AcquisitionOut, Option) { match acq { Acquisition::Available(review) => { let source = Some(SourceOut { kind: SourceKind::SubmittedReview, stable_id: review.stable_id.clone(), }); - if review.commit_id != expected_sha { - (State::Owed, source) + let state = if review.commit_id != expected_sha { + State::Owed } else if review.carries_finding { - (State::Finding, source) + State::Finding } else { - (State::Pass, source) - } + State::Pass + }; + (state, available(), source) } - Acquisition::NotProduced | Acquisition::RateLimited => (State::Owed, None), - Acquisition::Failed { .. } => (State::CannotCheck, None), + Acquisition::NotProduced => (State::Owed, status(AcquisitionStatus::NotProduced), None), + Acquisition::RateLimited => (State::Owed, status(AcquisitionStatus::RateLimited), None), + Acquisition::Failed { reason } => (State::CannotCheck, failed(reason), None), } } @@ -446,21 +473,19 @@ pub fn classify(input: &ClassifierInput) -> Result { .map(|id| { // Presence was established above, so `None` here is unreachable — // and is still not silently turned into a state. - let (state, source) = match input.observations.get(id) { - None => (State::CannotCheck, None), + let (state, acquisition, source) = match input.observations.get(id) { + None => ( + State::CannotCheck, + failed("required observation absent from the input map"), + None, + ), Some(ObservationInput::Check(acq)) => classify_check(acq, expected), Some(ObservationInput::Review(acq)) => classify_review(acq, expected), }; ObservationOut { id: id.clone(), state, - // RED-3: every observation reports AVAILABLE with no reason, so - // NOT_PRODUCED / RATE_LIMITED / FAILED are indistinguishable in - // the predicate. GREEN-3 carries the real outcome through. - acquisition: AcquisitionOut { - status: AcquisitionStatus::Available, - reason: None, - }, + acquisition, source, } }) @@ -476,14 +501,19 @@ pub fn classify(input: &ClassifierInput) -> Result { }, subject_sha: f.subject_sha.clone(), author: f.author.clone(), - // RED-3: the failure reason is dropped here. GREEN-3 keeps it. - verification: VerificationOut { - status: match f.verification { - Verification::Reproduced => VerificationStatus::Reproduced, - Verification::Claimed => VerificationStatus::Claimed, - Verification::Failed { .. } => VerificationStatus::Failed, + verification: match &f.verification { + Verification::Reproduced => VerificationOut { + status: VerificationStatus::Reproduced, + reason: None, + }, + Verification::Claimed => VerificationOut { + status: VerificationStatus::Claimed, + reason: None, + }, + Verification::Failed { reason } => VerificationOut { + status: VerificationStatus::Failed, + reason: Some(reason.clone()), }, - reason: None, }, state: match f.verification { Verification::Reproduced => State::Finding,