Skip to content

Plan, apply and roll back changes to a production ontology, with a blast radius report and a proof an auditor can re-check.

a certified verdict is unconstructible without the evidence

FABIOTESSc195e9c8302a
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4a0e39c9..edf77bb5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,47 @@ All notable changes to Open Ontologies are documented here.
## [Unreleased]
### Changed
+- **A certified verdict is now unconstructible without the evidence, so laundering one is a
+ compile error rather than a test failure.** The discipline that `model_checked` requires
+ `checker_exit == 0`, that `preserved_checked` requires an accepted `oo-cert` run, and that
+ `checked` requires a zero exit code off a Lean binary, used to be carried by comments saying
+ "the ONE place this word is produced" and by tests that walked a serialised report looking for
+ a checked word with nothing behind it. Those tests were right and they still run. They were
+ also incomplete by construction: a new module that formatted `"model_checked"` in a new place
+ passed every one of them until somebody noticed and pointed a guard at it. `src/verdict.rs`
+ now holds the whole certified vocabulary. `Certified` has a private field and no constructor,
+ `CheckerRun` has private fields and one constructor that SPAWNS the checker and reads its exit
+ status, and `CheckerRun::accepted` is the only function in the crate that returns a `Certified`
+ and returns `None` on any non-zero exit. Every certified variant carries one:
+ `FolVerdict::ModelChecked`, `GoalVerdict::PreservedChecked`,
+ `GoalVerdict::PreservedUnderSuppliedRulesChecked`, `ClosureVerdict::Checked`,
+ `Warrant::Checked`, `CheckerStatus::Accepted` and `OwlReading`. The theorem name travels
+ inside the token rather than beside it, so `OOCert.certificate_sound`,
+ `OOCert.horn_certificate_sound` and `Fol.satisfiable_of_check` are unspeakable on a path that
+ did not run a checker either. Six `compile_fail` doctests run under `cargo test` and fail if
+ any of that stops being true; the induced error is E0451, "field `theorem` of struct
+ `Certified` is private". None of these types implements `Deserialize`, because parsing
+ `"preserved_checked"` out of somebody else's JSON is not the same act as earning it and a
+ derive would be a public constructor for the certified state; reports are read back as
+ `serde_json::Value`, which is what every caller already did. The WIRE FORMAT is unchanged:
+ `Serialize` is hand-written to emit the same bare string the derive emitted, verified
+ byte-for-byte against a binary built from the previous commit over `preserve`, `fol-model`,
+ `closure-diff`, `reason`, `reason --rules`, `rules-import` and three MCP `tools/call`
+ responses.
+- **The MCP server no longer advertises eight tools it cannot serve.** `onto_plugin_list`,
+ `onto_plugin_call`, `onto_embed`, `onto_hnsw_build`, `onto_search`, `onto_similarity`,
+ `onto_import_schema` and `onto_sql_ingest` each have a body that is
+ `#[cfg(not(feature = ...))] { return "Compiled without X feature" }`, so on a default build
+ every call to one of them fails for every input. They were listed in `tools/list` anyway: a
+ client read a description about embeddings or a Postgres URL, called the tool, and got an
+ error that had nothing to do with what it asked. `toolfilter::remove_unavailable` now drops
+ their routes before the operator's own filter and independently of its mode, so a default
+ build advertises 106 of the 114 registered tools and says which eight are missing and which
+ Cargo feature brings each one back. The server's instructions string used to state two
+ hand-typed totals, 114 and 112, neither of which was the number the router advertised, and to
+ promise that the eight WERE advertised; it is formatted from `tool_router.list_all()` now, so
+ there is no literal left to go stale.
+
- **A binding is data, and a certificate that admits two readings is refused.** Running the
Lean checker in `lean/OOCert/Horn.lean` and the independent Isabelle/HOL one in `isabelle/`
over 1,718 certificates found 47 rows where the two disagreed, always in the same direction
diff --git a/README.md b/README.md
index 6445eae8..00d4765f 100644
--- a/README.md
+++ b/README.md
@@ -237,10 +237,12 @@ Restart, and the `onto_*` tools are available. Cursor, Windsurf, Zed and VS Code
## What is in the box
**114 tools** to build, validate, query, diff, lint, version, reason over, align, plan, certify
-and govern RDF and OWL, over an in-memory Oxigraph store. A default build advertises all 114 tools.
-Eight need an optional Cargo feature and return an error without it: four need `embeddings`, two
-need `plugins`, two need `postgres` or `duckdb`. The published binaries and the GHCR image are
-built with the default feature set, so they do not carry those eight.
+and govern RDF and OWL, over an in-memory Oxigraph store. A default build advertises 106 tools.
+Eight need an optional Cargo feature: four need `embeddings`, two need `plugins`, two need
+`postgres` or `duckdb`. A build without the feature does not advertise them at all, because a
+tool that appears in `tools/list` and is guaranteed to fail is a promise the binary cannot keep.
+The published binaries and the GHCR image are built with the default feature set, so they do not
+carry those eight. A build with `--features embeddings,plugins,sql` has the full 114.
The Python package `open-ontologies-lite` now reasons as well, in pure Python with no Rust
toolchain, and its certificates are checked by the same Lean binaries. It is a second engine, and
diff --git a/docs/decisions/0006-a-model-is-a-certificate-and-a-refutation-is-not.md b/docs/decisions/0006-a-model-is-a-certificate-and-a-refutation-is-not.md
index 70d7148e..951f6ed5 100644
--- a/docs/decisions/0006-a-model-is-a-certificate-and-a-refutation-is-not.md
+++ b/docs/decisions/0006-a-model-is-a-certificate-and-a-refutation-is-not.md
@@ -86,6 +86,16 @@ finite model finder, and prints exactly the kind of object this layer can certif
the checker itself reported `goal_negated_present` AND the verdict is `model_checked`, computed
from what the checker read back rather than from the Rust side's intention.
+ The first and third are no longer rules a reviewer has to enforce. `verdict` is a
+ `verdict::FolVerdict` and `owl_reading` is a `verdict::OwlReading`, and the certified variant
+ of each carries a `verdict::Certified` whose field is private to `src/verdict.rs`. The only
+ function that returns one is `CheckerRun::accepted`, the only constructor of a `CheckerRun`
+ spawns the checker, and `accepted` returns `None` on any non-zero exit. So a code path that
+ has not run `oo-folmodel` cannot write either word: it is E0451, a privacy error, and
+ `compile_fail` doctests in `src/verdict.rs` fail if that stops being true. The second rule is
+ still enforced by reading, because "which question was asked" is a property of the SMT-LIB
+ this side emitted and not of anything the checker hands back.
+
`no_model_up_to_size_k` exists because the obvious wiring is wrong and takes ten minutes. A
finite-domain encoding that returns `unsat` has established that no model of that size exists,
which is not unsatisfiability and is often not even evidence of it. The formula
diff --git a/docs/decisions/0007-a-slice-preserves-a-conclusion-or-it-does-not.md b/docs/decisions/0007-a-slice-preserves-a-conclusion-or-it-does-not.md
index 7275db72..25fa45f7 100644
--- a/docs/decisions/0007-a-slice-preserves-a-conclusion-or-it-does-not.md
+++ b/docs/decisions/0007-a-slice-preserves-a-conclusion-or-it-does-not.md
@@ -113,6 +113,18 @@ preserves every claim asked of it, each with a Lean-checked certificate. Both ar
where it leaks, and it carries no skip guard, so it is the one gate a machine without Lean still
enforces.
+ The enum is now where the discipline is enforced as well as easy. `GoalVerdict::
+ PreservedChecked` and `PreservedUnderSuppliedRulesChecked` each carry a `verdict::Certified`,
+ which has a private field, no constructor, and exactly one producer in the crate:
+ `CheckerRun::accepted`, which returns `None` unless a process this crate spawned exited zero.
+ `CheckerStatus::Accepted` carries one too, so the acceptance those verdicts are read off cannot
+ be fabricated either, and `warrant` is now read OUT of the token rather than written beside it,
+ which makes `OOCert.certificate_sound` as unspeakable on an unchecked path as the verdict is.
+ `GoalVerdict` deliberately does not implement `Deserialize`: parsing `"preserved_checked"` out
+ of a report is not the same act as earning it, and a derive would be a public constructor for
+ the certified state. The serialisation guard above stays, because the type says nothing about
+ what `Serialize` writes, and that is exactly the half it was written to cover.
+
8. **A negative carries no certificate in this layer, ever.** `q ∉ closure(P)` is the engine's
opinion bounded by a rule table implementing 29 of OWL 2 RL's 78 rules, so the word is
`lost_under_profile_unchecked`. Printing "the projection does not entail `q`" flat would do in the
diff --git a/src/closure_diff.rs b/src/closure_diff.rs
index 977c27b8..230aa9fa 100644
--- a/src/closure_diff.rs
+++ b/src/closure_diff.rs
@@ -42,6 +42,7 @@ use crate::projection_entailment::{
CertKind, CertificateIndex, CheckerStatus, CoverageProxy, Guards, Spelled, LAKE_INSTALL,
STOP_THE_LINE,
};
+use crate::verdict::{Certified, ClosureVerdict};
use serde::{Deserialize, Serialize};
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
use std::path::{Path, PathBuf};
@@ -56,8 +57,16 @@ pub type NtTriple = Spelled;
// ───────────────────────────────────────────────────────────────────────────
/// Why the source is entitled to a conclusion. NEVER COLLAPSED.
-#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
-#[serde(rename_all = "snake_case")]
+///
+/// `Checked` carries the evidence, so the row below cannot wear the word on a
+/// run where nothing was checked:
+///
+/// ```compile_fail
+/// use open_ontologies::closure_diff::Warrant;
+/// use open_ontologies::verdict::Certified;
+/// let w = Warrant::Checked(Certified { theorem: "OOCert.certificate_sound" });
+/// ```
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Warrant {
/// The triple IS in the asserted graph. No rule fired, nothing was proved,
/// and nothing needed to be: a lookup, not an entailment claim. Listed
@@ -68,7 +77,7 @@ pub enum Warrant {
/// A derivation step for it appears in a certificate `oo-cert` ACCEPTED.
/// `OOCert.certificate_sound` applies. The only word that may be spoken
/// when a machine-checked theorem stands behind the row.
- Checked,
+ Checked(Certified),
/// The engine says it derived this and no checker has looked: the checker
/// was not built, was not run, or REJECTED the certificate.
EngineOpinion,
@@ -78,17 +87,35 @@ impl Warrant {
pub fn name(self) -> &'static str {
match self {
Warrant::AssertedInSource => "asserted_in_source",
- Warrant::Checked => "checked",
+ Warrant::Checked(_) => "checked",
Warrant::EngineOpinion => "engine_opinion",
}
}
- /// The theorem, named only where one stands behind the word.
+ /// The theorem, named only where one stands behind the word. It comes out
+ /// of the evidence now, not out of a match arm, so an unchecked run has no
+ /// way to print it.
pub fn theorem(self) -> Option<&'static str> {
match self {
- Warrant::Checked => Some("OOCert.certificate_sound"),
+ Warrant::Checked(c) => Some(c.theorem()),
_ => None,
}
}
+ pub fn is_checked(self) -> bool {
+ matches!(self, Warrant::Checked(_))
+ }
+}
+
+impl Serialize for Warrant {
+ /// The snake_case word the derive used to write, unchanged on the wire.
+ fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
+ s.serialize_str(self.name())
+ }
+}
+
+impl PartialEq<&str> for Warrant {
+ fn eq(&self, other: &&str) -> bool {
+ self.name() == *other
+ }
}
/// Whether a term's spelling can be trusted to name the same thing on both
@@ -122,13 +149,15 @@ pub fn comparability_of(t: &NtTriple, skolem_map: &BTreeMap<String, String>) ->
// What checked the closure this diff is computed from
// ───────────────────────────────────────────────────────────────────────────
-#[derive(Clone, Debug, Serialize, Deserialize)]
+#[derive(Clone, Debug, Serialize)]
pub struct CertificateVerdict {
- /// `"checked"` | `"engine_opinion"` | `"rejected"`. Exactly one place in
- /// this file can produce `"checked"`, and it has just read a zero exit code
- /// off the Lean binary. No other path reaches it.
- pub verdict: &'static str,
- /// `Some("OOCert.certificate_sound")` on `"checked"`, `None` otherwise.
+ /// `"checked"` | `"engine_opinion"` | `"rejected"`. The checked variant
+ /// carries the evidence a zero exit code minted, so no other path in this
+ /// file or any other can reach the word — it is not a `&'static str` any
+ /// more and there is nothing to assign.
+ pub verdict: ClosureVerdict,
+ /// `Some("OOCert.certificate_sound")` on `"checked"`, `None` otherwise,
+ /// and taken from the evidence rather than written beside it.
pub theorem: Option<&'static str>,
pub asserted: usize,
pub derivations: usize,
@@ -156,11 +185,12 @@ impl CertificateVerdict {
iterations: usize,
) -> Self {
// The ONE place `"checked"` is produced. It requires an accepted run,
- // which required exit code 0.
- let (verdict, exit, skipped): (&'static str, Option<i32>, Option<String>) = match status {
- CheckerStatus::Accepted { .. } => ("checked", Some(0), None),
+ // which required exit code 0 — and now the type says so: the arm below
+ // is the only one that has a `Certified` to put in the variant.
+ let (verdict, exit, skipped): (ClosureVerdict, Option<i32>, Option<String>) = match status {
+ CheckerStatus::Accepted(a) => (ClosureVerdict::Checked(a.certified()), Some(0), None),
CheckerStatus::Rejected { stdout } => (
- "rejected",
+ ClosureVerdict::Rejected,
Some(1),
Some(format!(
"the verified checker REJECTED this certificate, so nothing in this report is \
@@ -173,12 +203,12 @@ impl CertificateVerdict {
// that distinction, and mapping 2 to "rejected" would turn a
// missing file into a soundness finding.
CheckerStatus::Unreadable { stdout } => (
- "engine_opinion",
+ ClosureVerdict::EngineOpinion,
Some(2),
Some(format!("the checker could not read the certificate: {}", stdout.trim())),
),
CheckerStatus::Absent { what, install } => (
- "engine_opinion",
+ ClosureVerdict::EngineOpinion,
None,
Some(format!("{what}. {install}")),
),
@@ -186,15 +216,15 @@ impl CertificateVerdict {
// this arm is unreachable here. It is still mapped to the weakest
// word rather than left to a wildcard, because a wildcard is how a
// new status silently becomes "checked" one refactor later.
- CheckerStatus::NotNeeded { what } => ("engine_opinion", None, Some(what.clone())),
+ CheckerStatus::NotNeeded { what } => (ClosureVerdict::EngineOpinion, None, Some(what.clone())),
};
CertificateVerdict {
verdict,
- theorem: if verdict == "checked" { Some("OOCert.certificate_sound") } else { None },
+ theorem: verdict.theorem(),
asserted,
derivations,
checker_report: match status {
- CheckerStatus::Accepted { stdout, .. } => Some(stdout.clone()),
+ CheckerStatus::Accepted(a) => Some(a.stdout().to_string()),
_ => None,
},
checker_exit: exit,
@@ -206,7 +236,10 @@ impl CertificateVerdict {
}
fn warrant_for_derived(&self) -> Warrant {
- if self.verdict == "checked" { Warrant::Checked } else { Warrant::EngineOpinion }
+ match self.verdict {
+ ClosureVerdict::Checked(c) => Warrant::Checked(c),
+ _ => Warrant::EngineOpinion,
+ }
}
}
@@ -215,7 +248,10 @@ impl CertificateVerdict {
// ───────────────────────────────────────────────────────────────────────────
/// A conclusion of the source that the projection does not reach.
-#[derive(Clone, Debug, Serialize, Deserialize)]
+/// Not `Deserialize`: it carries a [`Warrant`], whose checked variant is
+/// evidence and not a word, so parsing one back out of JSON would be a public
+/// constructor for the certified state. Read a report as `serde_json::Value`.
+#[derive(Clone, Debug, Serialize)]
pub struct LostEntailment {
pub triple: NtTriple,
pub warrant: Warrant,
@@ -292,7 +328,8 @@ pub const NOT_DERIVED_MEANS: &str =
// The report
// ───────────────────────────────────────────────────────────────────────────
-#[derive(Clone, Debug, Serialize, Deserialize)]
+/// Not `Deserialize`, for the reason on [`LostEntailment`].
+#[derive(Clone, Debug, Serialize)]
pub struct ClosureDiffReport {
pub format: &'static str,
/// One sentence the reader cannot miss, first after `format` in the JSON
@@ -860,13 +897,40 @@ mod tests {
assert_eq!(fnv1a64(b"foobar"), 0x8594_4171_f739_67e8);
}
+ /// The acceptance row used to be written by hand:
+ ///
+ /// ```text
+ /// CheckerStatus::Accepted { theorem: "OOCert.certificate_sound", stdout: "{}".into() }
+ /// ```
+ ///
+ /// That line no longer compiles, and that is the point of this change.
+ /// `CheckerStatus::Accepted` now carries a `projection_entailment::
+ /// Accepted`, whose only constructor takes a `verdict::Certified`, which
+ /// nothing outside `src/verdict.rs` can build. A test that wants an
+ /// acceptance has to EARN one, so this one runs a process that exits zero
+ /// — which is exactly the condition the test is named after.
#[test]
fn a_checked_word_needs_exit_zero() {
+ let dir = std::env::temp_dir().join("oo-closure-diff-exit-zero");
+ std::fs::create_dir_all(&dir).unwrap();
+ let a = dir.join("asserted.tsv");
+ let d = dir.join("derivations.tsv");
+ std::fs::write(&a, "").unwrap();
+ std::fs::write(&d, "").unwrap();
+ // A script rather than `/bin/true`, which is `/usr/bin/true` on macOS
+ // and absent from `/bin` entirely. The suite found that itself.
+ let ok = dir.join("exit0.sh");
+ std::fs::write(&ok, "#!/bin/sh\nexit 0\n").unwrap();
+ #[cfg(unix)]
+ {
+ use std::os::unix::fs::PermissionsExt as _;
+ std::fs::set_permissions(&ok, std::fs::Permissions::from_mode(0o755)).unwrap();
+ }
+ let accepted = pe::run_checker(CertKind::OoCert, Some(ok.as_path()), &a, &d, None);
+ assert!(matches!(accepted, CheckerStatus::Accepted(_)), "{accepted:?}");
+
for (status, want) in [
- (
- CheckerStatus::Accepted { theorem: "OOCert.certificate_sound", stdout: "{}".into() },
- "checked",
- ),
+ (accepted, "checked"),
(CheckerStatus::Rejected { stdout: "no".into() }, "rejected"),
(CheckerStatus::Unreadable { stdout: "boom".into() }, "engine_opinion"),
(
diff --git a/src/fol_solve.rs b/src/fol_solve.rs
index 378b8983..5adf11d5 100644
--- a/src/fol_solve.rs
+++ b/src/fol_solve.rs
@@ -19,11 +19,16 @@
//!
//! Decision 0006 item 4 fixes five fields and five verdict words, and this
//! module is where they are computed. The rules are mechanical, and
-//! `tests/fol_solver_verdict_test.rs` fails if any of them is ever relaxed:
+//! `tests/fol_solver_verdict_test.rs` fails if any of them is ever relaxed.
+//! Since the verdict-by-construction change they are also UNREPRESENTABLE
+//! otherwise: the verdict is a [`crate::verdict::FolVerdict`], its certified
+//! variant carries a [`crate::verdict::Certified`], and that type has no
+//! public constructor. The rules restated, with what now enforces each:
//!
-//! 1. `model_checked` requires `checker_exit == 0`. There is exactly one place
-//! in this file that writes that word and it is inside the branch that has
-//! just read a zero exit code off `oo-folmodel`. No other path can reach it.
+//! 1. `model_checked` requires `checker_exit == 0`. It is not a string in this
+//! file any more. `FolVerdict::ModelChecked` takes evidence that only
+//! `CheckerRun::accepted` returns, and only on a zero exit code from a
+//! process this crate spawned. A new code path cannot write that word.
//! 2. `unsatisfiable_oracle` requires a run whose emitted problem carried NO
//! cardinality constraint. It is written only in the arm that reads the
//! unbounded probe's answer. A bounded run's `unsat` is
@@ -71,6 +76,11 @@ use std::time::{Duration, Instant};
use crate::fol_model::{FiniteModel, IngestError, mace4, z3};
use crate::tptp::{FolProblem, ladr, smtlib::SmtEncoding};
+use crate::verdict::{CheckerBinary, CheckerRun, FolVerdict, OwlReading};
+
+/// The Lean statement `oo-folmodel`'s acceptance discharges. It travels inside
+/// the evidence token, so a report cannot name it without an accepted run.
+const FOL_THEOREM: &str = "Fol.satisfiable_of_check";
/// Which model finder to drive.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
@@ -217,10 +227,12 @@ pub struct Outcome {
/// `null` means the checker was never run.
pub checker_exit: Option<i32>,
/// The one word. See the module docstring for the three mechanical rules.
- pub verdict: &'static str,
+ /// A type, not a string: the certified variant carries the evidence.
+ pub verdict: FolVerdict,
/// Non-null only when the CHECKER reported a negated goal AND the verdict
- /// is `model_checked`.
- pub owl_reading: Option<&'static str>,
+ /// is `model_checked`. Both halves are in the type: minting one takes the
+ /// checker's own report and the verdict's own `Certified`.
+ pub owl_reading: Option<OwlReading>,
/// The theorem the certified verdict names, when there is one.
pub theorem: Option<String>,
@@ -255,7 +267,7 @@ impl Outcome {
solver_verdict: "unknown",
encoding: "none".into(),
checker_exit: None,
- verdict: "unknown_oracle",
+ verdict: FolVerdict::UnknownOracle,
owl_reading: None,
theorem: None,
cardinality_search: Vec::new(),
@@ -490,7 +502,7 @@ pub fn solve(problem: &FolProblem, opts: &SolveOptions, dir: &Path) -> anyhow::R
solver_verdict: "unknown",
encoding: "none".into(),
checker_exit: None,
- verdict: "unknown_oracle",
+ verdict: FolVerdict::UnknownOracle,
owl_reading: None,
theorem: None,
cardinality_search: Vec::new(),
@@ -529,7 +541,7 @@ pub fn solve(problem: &FolProblem, opts: &SolveOptions, dir: &Path) -> anyhow::R
Err(e) => {
// The solver said sat and we could not read what it
// built. Not a fact about the ontology, and not quiet.
- out.verdict = "satisfiable_oracle";
+ out.verdict = FolVerdict::SatisfiableOracle;
out.disagreement = Some(Disagreement {
severity: "STOP_THE_LINE",
what: "model_not_ingested",
@@ -547,7 +559,7 @@ pub fn solve(problem: &FolProblem, opts: &SolveOptions, dir: &Path) -> anyhow::R
};
out.dropped_symbols = model.dropped.clone();
if let Err(e) = model.covers(&problem.vocabulary(), opts.solver.name()) {
- out.verdict = "satisfiable_oracle";
+ out.verdict = FolVerdict::SatisfiableOracle;
out.disagreement = Some(Disagreement {
severity: "STOP_THE_LINE",
what: "model_incomplete",
@@ -565,25 +577,29 @@ pub fn solve(problem: &FolProblem, opts: &SolveOptions, dir: &Path) -> anyhow::R
std::fs::write(&model_path, &model_tsv)?;
// ── The only place the certified word can be reached ──
- let co = Command::new(&checker)
- .arg(dir.join("problem.tsv"))
- .arg(&model_path)
- .output()?;
- let report = String::from_utf8_lossy(&co.stdout).trim().to_string();
+ //
+ // It is no longer "the only place" by inspection. `CheckerRun`
+ // is the only constructor of the evidence `FolVerdict::
+ // ModelChecked` requires, so this is the only place it CAN be
+ // reached, and a second one would have to run a checker too.
+ let mut cmd = Command::new(&checker);
+ cmd.arg(dir.join("problem.tsv")).arg(&model_path);
+ let run = CheckerRun::spawn(&CheckerBinary::found_at(checker.clone()), cmd)?;
+ let report = run.stdout().trim().to_string();
std::fs::write(dir.join("checker.json"), &report)?;
- let exit = co.status.code().unwrap_or(-1);
+ let exit = run.exit();
out.checker_exit = Some(exit);
out.checker_report = Some(report.clone());
- if exit == 0 {
- out.verdict = "model_checked";
- out.theorem = Some("Fol.satisfiable_of_check".to_string());
+ if let Some(cert) = run.accepted(FOL_THEOREM) {
+ out.verdict = FolVerdict::ModelChecked(cert);
+ out.theorem = Some(cert.theorem().to_string());
// Read the goal flag back off the CHECKER's report, not
- // off this side's intention.
- if report.contains("\"goal_negated_present\":true") {
- out.owl_reading = Some("not_entailed_under_unproved_translation");
- }
+ // off this side's intention. The `cert` argument is the
+ // "and the verdict is model_checked" half of the rule,
+ // carried by the signature instead of by this comment.
+ out.owl_reading = run.owl_reading(cert);
} else {
- out.verdict = "satisfiable_oracle";
+ out.verdict = FolVerdict::SatisfiableOracle;
out.disagreement = Some(Disagreement {
severity: "STOP_THE_LINE",
what: "model_not_confirmed",
@@ -612,14 +628,14 @@ pub fn solve(problem: &FolProblem, opts: &SolveOptions, dir: &Path) -> anyhow::R
out.solver_verdict = "unknown";
out.encoding = SmtEncoding::Finite(*out.cardinality_search.last().unwrap_or(&hi)).name();
out.bounded_search = format!("stopped: {why}");
- out.verdict = "unknown_oracle";
+ out.verdict = FolVerdict::UnknownOracle;
}
None => {
out.solver_verdict = "unsat";
out.encoding = SmtEncoding::Finite(hi).name();
out.bounded_search = format!("exhausted: no model of size {lo}..{hi}");
// NOT unsatisfiability. Decision 0006 item 4.
- out.verdict = "no_model_up_to_size_k";
+ out.verdict = FolVerdict::NoModelUpToSizeK;
}
}
@@ -640,14 +656,14 @@ pub fn solve(problem: &FolProblem, opts: &SolveOptions, dir: &Path) -> anyhow::R
SolverSays::Unsat => {
out.solver_verdict = "unsat";
out.encoding = SmtEncoding::Unbounded.name();
- out.verdict = "unsatisfiable_oracle";
+ out.verdict = FolVerdict::UnsatisfiableOracle;
}
SolverSays::Sat => {
out.solver_verdict = "sat";
out.encoding = SmtEncoding::Unbounded.name();
// Satisfiable, and with no finite model small enough to
// certify. Exactly the SHIQ finite-model-property case.
- out.verdict = "satisfiable_oracle";
+ out.verdict = FolVerdict::SatisfiableOracle;
}
SolverSays::Unknown => {}
}
@@ -678,7 +694,7 @@ pub fn outcome_json(o: &Outcome) -> serde_json::Value {
"disagreement": o.disagreement,
"skipped": o.skipped,
"seconds": (o.seconds * 1000.0).round() / 1000.0,
- "verdict_means": verdict_means(o.verdict),
+ "verdict_means": verdict_means(o.verdict.word()),
})
}
@@ -733,7 +749,7 @@ pub fn solve_export(
// item 7 records happening in this repository already.
let mut not_asked: Vec<serde_json::Value> = Vec::new();
let mut counts: BTreeMap<&'static str, usize> = BTreeMap::new();
- *counts.entry(ontology.verdict).or_default() += 1;
+ *counts.entry(ontology.verdict.word()).or_default() += 1;
let mut stop_the_line = usize::from(ontology.disagreement.is_some());
if let Some(path) = goals {
@@ -770,7 +786,7 @@ pub fn solve_export(
};
let gp = FolProblem::build(&read.axioms, Some(&ax))?;
let g = solve(&gp, opts, &dir.join(format!("goal_{i:05}")))?;
- *counts.entry(g.verdict).or_default() += 1;
+ *counts.entry(g.verdict.word()).or_default() += 1;
if g.disagreement.is_some() {
stop_the_line += 1;
}
diff --git a/src/lib.rs b/src/lib.rs
index 40a6e944..553ed034 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -30,6 +30,9 @@ pub mod pack;
pub mod support;
pub mod temporal;
pub mod policy;
+/// Certified verdicts that cannot be spelled without the evidence. Every
+/// module that prints a verdict word takes its vocabulary from here.
+pub mod verdict;
pub mod closure_diff;
pub mod projection_check;
pub mod projection_entailment;
diff --git a/src/projection_entailment.rs b/src/projection_entailment.rs
index 9afede15..c369d756 100644
--- a/src/projection_entailment.rs
+++ b/src/projection_entailment.rs
@@ -62,6 +62,7 @@
use crate::graph::GraphStore;
use crate::projection_check::{check_projection_loss, ProjectionLossReport};
use crate::reason::{InferenceTarget, Reasoner};
+use crate::verdict::{CheckerBinary, CheckerRun, Certified};
use serde::{Deserialize, Serialize};
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
use std::path::{Path, PathBuf};
@@ -629,10 +630,54 @@ impl CertificateIndex {
// The checker
// ───────────────────────────────────────────────────────────────────────────
-#[derive(Clone, Debug, Serialize, Deserialize)]
+/// An acceptance. The fields are private and the only constructor is
+/// [`Accepted::from_run`], which takes a [`Certified`] — and that type has no
+/// public constructor at all, so this struct cannot be built by a caller that
+/// did not run a checker and read a zero exit code.
+///
+/// It serialises as the two fields it always had, flattened under the `status`
+/// tag by serde's internally-tagged newtype-variant handling, so the wire
+/// format is byte-for-byte what it was.
+#[derive(Clone, Debug)]
+pub struct Accepted {
+ certified: Certified,
+ stdout: String,
+}
+
+impl Accepted {
+ fn from_run(certified: Certified, stdout: String) -> Accepted {
+ Accepted { certified, stdout }
+ }
+ /// The evidence, so a downstream verdict carries the token this run
+ /// earned rather than re-asserting the acceptance on its own authority.
+ pub fn certified(&self) -> Certified {
+ self.certified
+ }
+ pub fn theorem(&self) -> &'static str {
+ self.certified.theorem()
+ }
+ pub fn stdout(&self) -> &str {
+ &self.stdout
+ }
+}
+
+impl Serialize for Accepted {
+ /// `{"theorem": ..., "stdout": ...}`, exactly the two fields the struct
+ /// variant carried, so the tagged enum above still writes
+ /// `{"status":"accepted","theorem":...,"stdout":...}`.
+ fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
+ use serde::ser::SerializeStruct as _;
+ let mut st = s.serialize_struct("Accepted", 2)?;
+ st.serialize_field("theorem", self.certified.theorem())?;
+ st.serialize_field("stdout", &self.stdout)?;
+ st.end()
+ }
+}
+
+#[derive(Clone, Debug, Serialize)]
#[serde(tag = "status", rename_all = "snake_case")]
pub enum CheckerStatus {
- Accepted { theorem: &'static str, stdout: String },
+ Accepted(Accepted),
/// Exit 1. This module built the slice, so a rejection is a defect HERE or
/// in the emitter. It is never a downgrade to an unchecked verdict.
Rejected { stdout: String },
@@ -656,7 +701,7 @@ impl CheckerStatus {
}
pub fn word(&self) -> &'static str {
match self {
- CheckerStatus::Accepted { .. } => "accepted",
+ CheckerStatus::Accepted(_) => "accepted",
CheckerStatus::Rejected { .. } => "rejected",
CheckerStatus::Unreadable { .. } => "unreadable",
CheckerStatus::Absent { .. } => "absent",
@@ -715,6 +760,11 @@ pub fn run_oo_cert(checker: Option<&Path>, asserted: &Path, derivations: &Path)
/// The ONE place a checked verdict is produced, and it has just read an exit
/// code off a Lean binary.
+///
+/// "The one place" is no longer a promise in a comment. The acceptance it
+/// returns carries a [`Certified`], and [`crate::verdict::CheckerRun::spawn`]
+/// is the only thing in the crate that can mint one, so a second place would
+/// have to run a checker too.
pub fn run_checker(
kind: CertKind,
checker: Option<&Path>,
@@ -744,8 +794,8 @@ pub fn run_checker(
cmd.arg("check").arg(r).arg(asserted).arg(derivations);
}
}
- let out = match cmd.output() {
- Ok(o) => o,
+ let run = match CheckerRun::spawn(&CheckerBinary::found_at(bin.clone()), cmd) {
+ Ok(r) => r,
Err(e) => {
return CheckerStatus::Absent {
what: format!("{} could not be run: {e}", bin.display()),
@@ -753,23 +803,25 @@ pub fn run_checker(
};
}
};
- let text = format!(
- "{}{}",
- String::from_utf8_lossy(&out.stdout),
- String::from_utf8_lossy(&out.stderr)
- );
- match out.status.code() {
- Some(0) => CheckerStatus::Accepted {
- theorem: match kind {
- CertKind::OoCert => "OOCert.certificate_sound",
- CertKind::OoHorn => "OOCert.horn_certificate_sound",
+ let text = run.output();
+ // The theorem name is handed to the evidence rather than to the report, so
+ // a status with no acceptance behind it has no way to name one.
+ let theorem = match kind {
+ CertKind::OoCert => "OOCert.certificate_sound",
+ CertKind::OoHorn => "OOCert.horn_certificate_sound",
+ };
+ match run.accepted(theorem) {
+ Some(cert) => CheckerStatus::Accepted(Accepted::from_run(cert, text)),
+ // `lean/Main.lean` reserves 1 for a rejection and 2 for a file it
+ // could not read. Anything else is not a verdict in either direction.
+ None => match run.exit() {
+ 1 => CheckerStatus::Rejected { stdout: text },
+ 2 => CheckerStatus::Unreadable { stdout: text },
+ // `{:?}` on the raw `Option`, byte for byte what this arm has
+ // always printed: `None` for a signal death, `Some(n)` otherwise.
+ _ => CheckerStatus::Unreadable {
+ stdout: format!("{} exited with {:?}\n{text}", bin.display(), run.code()),
},
- stdout: text,
- },
- Some(1) => CheckerStatus::Rejected { stdout: text },
- Some(2) => CheckerStatus::Unreadable { stdout: text },
- other => CheckerStatus::Unreadable {
- stdout: format!("{} exited with {:?}\n{text}", bin.display(), other),
},
}
}
@@ -778,14 +830,26 @@ pub fn run_checker(
// Verdicts
// ───────────────────────────────────────────────────────────────────────────
-#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
-#[serde(rename_all = "snake_case")]
+/// The per-goal verdict.
+///
+/// The two CHECKED variants carry a [`Certified`], which has no public
+/// constructor, so neither can be named on a path that did not run the Lean
+/// checker. `Deserialize` is deliberately not implemented: reading
+/// `"preserved_checked"` out of somebody else's JSON is not the same act as
+/// earning it, and a derive would be a public constructor for both.
+///
+/// ```compile_fail
+/// use open_ontologies::projection_entailment::GoalVerdict;
+/// use open_ontologies::verdict::Certified;
+/// let v = GoalVerdict::PreservedChecked(Certified { theorem: "OOCert.certificate_sound" });
+/// ```
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum GoalVerdict {
/// `P` entails `q`, machine-checked over `P`'s own asserted graph.
- PreservedChecked,
+ PreservedChecked(Certified),
/// The same, but the run evaluated a SUPPLIED Horn table. True in every
/// model of `P` that ALSO satisfies those rules. Never shortened.
- PreservedUnderSuppliedRulesChecked,
+ PreservedUnderSuppliedRulesChecked(Certified),
/// `q` is literally in the slice. Verified by set membership over the
/// canonical spelling. Not a theorem and it does not pretend to be.
PreservedAsserted,
@@ -810,15 +874,35 @@ pub enum GoalVerdict {
}
impl GoalVerdict {
+ /// The wire word. Byte-identical to what `#[serde(rename_all =
+ /// "snake_case")]` used to derive, and the single source of the string now
+ /// that the two checked variants carry a payload serde would otherwise
+ /// have wrapped in an object.
+ pub fn word(self) -> &'static str {
+ match self {
+ GoalVerdict::PreservedChecked(_) => "preserved_checked",
+ GoalVerdict::PreservedUnderSuppliedRulesChecked(_) => {
+ "preserved_under_supplied_rules_checked"
+ }
+ GoalVerdict::PreservedAsserted => "preserved_asserted",
+ GoalVerdict::PreservedUnchecked => "preserved_unchecked",
+ GoalVerdict::LostUnderProfileUnchecked => "lost_under_profile_unchecked",
+ GoalVerdict::UngroundedInSource => "ungrounded_in_source",
+ GoalVerdict::ProjectionOnly => "projection_only",
+ GoalVerdict::CertificateRejected => "certificate_rejected",
+ GoalVerdict::Refused => "refused",
+ }
+ }
/// The theorem a verdict names, or `"none"`. A verdict with no theorem must
/// never render a string containing "checked", and the suite asserts that
/// over the SERIALISED report rather than over this function, because the
/// enum is where the discipline is easy and the serialisation is where it
- /// leaks.
+ /// leaks. The name now comes OUT OF THE EVIDENCE rather than out of a
+ /// match arm, so a run that never ran the checker cannot name a theorem.
pub fn warrant(self) -> &'static str {
match self {
- GoalVerdict::PreservedChecked => "OOCert.certificate_sound",
- GoalVerdict::PreservedUnderSuppliedRulesChecked => "OOCert.horn_certificate_sound",
+ GoalVerdict::PreservedChecked(c)
+ | GoalVerdict::PreservedUnderSuppliedRulesChecked(c) => c.theorem(),
_ => "none",
}
}
@@ -828,19 +912,19 @@ impl GoalVerdict {
pub fn is_preserved(self) -> bool {
matches!(
self,
- GoalVerdict::PreservedChecked
- | GoalVerdict::PreservedUnderSuppliedRulesChecked
+ GoalVerdict::PreservedChecked(_)
+ | GoalVerdict::PreservedUnderSuppliedRulesChecked(_)
| GoalVerdict::PreservedAsserted
| GoalVerdict::PreservedUnchecked
)
}
pub fn means(self) -> &'static str {
match self {
- GoalVerdict::PreservedChecked =>
+ GoalVerdict::PreservedChecked(_) =>
"the projection entails this goal: true in every model of the projection under the \
semantics in lean/OOCert/Semantics.lean. Machine-checked by oo-cert over the \
projection's own asserted.tsv",
- GoalVerdict::PreservedUnderSuppliedRulesChecked =>
+ GoalVerdict::PreservedUnderSuppliedRulesChecked(_) =>
"true in every model of the projection THAT ALSO SATISFIES the supplied rule \
table. The rules are assumed and never checked; a rule reading 'every supplier \
is compliant' produces certificates that check green for ever. Never shorten \
@@ -873,6 +957,28 @@ impl GoalVerdict {
}
}
+impl Serialize for GoalVerdict {
+ /// A bare string, exactly as `#[serde(rename_all = "snake_case")]` wrote
+ /// it before the checked variants grew a payload.
+ fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
+ s.serialize_str(self.word())
+ }
+}
+
+/// So the suite can go on asserting against the wire word without being able
+/// to build a checked variant to compare with.
+impl PartialEq<&str> for GoalVerdict {
+ fn eq(&self, other: &&str) -> bool {
+ self.word() == *other
+ }
+}
+
+impl std::fmt::Display for GoalVerdict {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.write_str(self.word())
+ }
+}
+
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct GoalCertificate {
pub dir: String,
@@ -883,7 +989,12 @@ pub struct GoalCertificate {
pub check_with: String,
}
-#[derive(Clone, Debug, Serialize, Deserialize)]
+/// Not `Deserialize`: it carries a [`GoalVerdict`], whose checked variants
+/// are evidence and not words. Reading `"preserved_checked"` out of somebody
+/// else's JSON is not the same act as earning it, and a derive here would be a
+/// public constructor for the certified state. Reports are read back as
+/// `serde_json::Value`, which is what every caller in the tree already does.
+#[derive(Clone, Debug, Serialize)]
pub struct GoalReport {
pub id: String,
pub as_written: String,
@@ -1123,7 +1234,8 @@ impl Default for Opts {
}
}
-#[derive(Clone, Debug, Serialize, Deserialize)]
+/// Not `Deserialize`, for the reason on [`GoalReport`].
+#[derive(Clone, Debug, Serialize)]
pub struct PreservationReport {
pub format: &'static str,
/// One sentence a reader cannot miss, first in the JSON after the format.
@@ -1380,7 +1492,7 @@ pub fn check_entailment_preservation(
if prj_cert.kind() == CertKind::OoHorn { Some(&rules_path) } else { None },
);
let v = match &status {
- CheckerStatus::Accepted { .. } => {
+ CheckerStatus::Accepted(a) => {
certificate = Some(GoalCertificate {
dir: out.parent().unwrap_or(&out).display().to_string(),
format: if prj_cert.kind() == CertKind::OoHorn { "oo-horn/1" } else { "oo-cert/1" },
@@ -1388,10 +1500,13 @@ pub fn check_entailment_preservation(
asserted: prj_cert.asserted_count(),
check_with: check_command(&prj_cert, &out),
});
+ // The token this goal's own checker run produced. It
+ // carries the theorem, so the warrant printed beside
+ // the verdict cannot drift from the run that earned it.
if prj_cert.kind() == CertKind::OoHorn {
- GoalVerdict::PreservedUnderSuppliedRulesChecked
+ GoalVerdict::PreservedUnderSuppliedRulesChecked(a.certified())
} else {
- GoalVerdict::PreservedChecked
+ GoalVerdict::PreservedChecked(a.certified())
}
}
CheckerStatus::Rejected { stdout } => {
@@ -1466,7 +1581,10 @@ pub fn check_entailment_preservation(
// ── Counts and the verdict on the run ───────────────────────────────
let count = |f: fn(GoalVerdict) -> bool| per_goal.iter().filter(|g| f(g.verdict)).count();
let preserved_checked = count(|v| {
- matches!(v, GoalVerdict::PreservedChecked | GoalVerdict::PreservedUnderSuppliedRulesChecked)
+ matches!(
+ v,
+ GoalVerdict::PreservedChecked(_) | GoalVerdict::PreservedUnderSuppliedRulesChecked(_)
+ )
});
let preserved_asserted = count(|v| v == GoalVerdict::PreservedAsserted);
let preserved_unchecked = count(|v| v == GoalVerdict::PreservedUnchecked);
diff --git a/src/reason.rs b/src/reason.rs
index ecad9591..9c14f590 100644
--- a/src/reason.rs
+++ b/src/reason.rs
@@ -1627,7 +1627,14 @@ impl Reasoner {
// has accepted a refutation. Nothing here may say that, or an
// engine opinion and a machine-checked result share a string
// and a consumer cannot tell them apart.
- "verdict": "clash_found_by_this_engine",
+ //
+ // The word comes from `verdict::EngineRefutation`, whose
+ // vocabulary is asserted disjoint from
+ // `verdict::CHECKER_OWNED_WORDS`, and which has no certified
+ // variant to reach for: nothing in the Rust tree runs
+ // `oo-refute`, so there is no evidence any code here could
+ // mint.
+ "verdict": crate::verdict::EngineRefutation::ClashFoundByThisEngine,
"checked_by_lean": false,
"clash_count": clashes.len(),
"by_rule": by_rule,
@@ -1702,8 +1709,9 @@ impl Reasoner {
"prefix": ids.len(),
"premises": c.premises.iter().map(show).collect::<Vec<_>>(),
// Written, not checked. The word for a checked
- // one is `oo-refute`'s to say.
- "verdict": "refutation_written_not_yet_checked",
+ // one is `oo-refute`'s to say, and this crate
+ // has no vocabulary that can say it.
+ "verdict": crate::verdict::EngineRefutation::RefutationWrittenNotYetChecked,
"check_with": format!(
"cd lean && lake exe oo-refute check {a} {r}",
a = dir.join("asserted.tsv").display(),
diff --git a/src/rulesyntax.rs b/src/rulesyntax.rs
index d6e0b187..845421bb 100644
--- a/src/rulesyntax.rs
+++ b/src/rulesyntax.rs
@@ -246,7 +246,14 @@ impl Import {
// Provenance, not a verdict. Every rule here was written by a user
// and discharged by nobody, so the only warrant a certificate over
// this table can earn is the relativised one.
- "verdict_this_table_is_eligible_for": "entailed_under_supplied_rules",
+ //
+ // This is the ONE place in the crate that names a checker-owned
+ // word outside an echo of the checker's own bytes, and it is not a
+ // verdict: the key says "is eligible for", `pronounced_by` says
+ // lean/ pronounces, and the constant lives in `verdict.rs` beside
+ // the list of words that belong to a checker so a reader who greps
+ // for the string lands on the paragraph that explains it.
+ "verdict_this_table_is_eligible_for": crate::verdict::ELIGIBLE_UNDER_SUPPLIED_RULES,
"theorem": "OOCert.horn_certificate_sound",
"means":
"a checked certificate over this table says every conclusion is true in every \
diff --git a/src/server.rs b/src/server.rs
index 06005f73..5fafb703 100644
--- a/src/server.rs
+++ b/src/server.rs
@@ -130,8 +130,26 @@ impl OpenOntologiesServer {
}
};
- // Apply tool filter by removing routes from the router.
+ // A tool this build cannot serve is not advertised. This runs BEFORE
+ // the operator's filter and does not consult it: a description in
+ // `tools/list` is a promise, and eight of the registered tools are
+ // behind a Cargo feature whose absence turns every call into
+ // "Compiled without X feature". See `toolfilter::FEATURE_GATED_TOOLS`.
let mut tool_router = Self::tool_router();
+ let unavailable = crate::toolfilter::remove_unavailable(&mut tool_router);
+ if !unavailable.is_empty() {
+ tracing::info!(
+ "not advertising {} tools this build cannot serve: {}",
+ unavailable.len(),
+ unavailable
+ .iter()
+ .map(|(t, f)| format!("{t} (needs --features {f})"))
+ .collect::<Vec<_>>()
+ .join(", ")
+ );
+ }
+
+ // Apply tool filter by removing routes from the router.
let removed = tool_filter.apply(&mut tool_router);
if !removed.is_empty() {
tracing::info!("tool filter removed {} tools: {:?}", removed.len(), removed);
@@ -3003,8 +3021,38 @@ impl OpenOntologiesServer {
#[tool_handler(router = self.tool_router)]
#[prompt_handler(router = self.prompt_router)]
impl ServerHandler for OpenOntologiesServer {
+ /// The instructions string states the count it MEASURES.
+ ///
+ /// It used to state two, 114 and 112, neither of which was the number the
+ /// router advertised, and the second sentence promised that the eight
+ /// feature-gated tools were advertised and would "return an error without
+ /// it". They are not advertised any more, so the sentence is now about
+ /// what is missing and why, and both numbers are read off the router the
+ /// client is about to call.
fn get_info(&self) -> ServerInfo {
+ let advertised = self.tool_router.list_all().len();
+ let withheld = crate::toolfilter::unavailable_in_this_build();
+ let tail = if withheld.is_empty() {
+ String::new()
+ } else {
+ format!(
+ " {} further tools are compiled in but NOT advertised, because this build \
+ lacks the Cargo feature each one needs and a tool that is guaranteed to fail \
+ should not appear in tools/list: {}. Rebuild with the feature to get them.",
+ withheld.len(),
+ crate::toolfilter::FEATURE_GATED_TOOLS
+ .iter()
+ .filter(|(t, _)| withheld.contains(t))
+ .map(|(t, f)| format!("{t} (--features {f})"))
+ .collect::<Vec<_>>()
+ .join(", ")
+ )
+ };
ServerInfo::new(ServerCapabilities::builder().enable_tools().enable_prompts().build())
- .with_instructions("Open Ontologies: AI-native ontology engine, an RDF/OWL/SPARQL MCP server with 114 tools and 6 workflow prompts for ontology engineering, validation, comparison, alignment, data ingestion, and exploration. All 112 tools are advertised in a default build; 8 of them require an optional Cargo feature (embeddings, plugins, postgres or duckdb) and return an error without it.")
+ .with_instructions(format!(
+ "Open Ontologies: AI-native ontology engine, an RDF/OWL/SPARQL MCP server with \
+ {advertised} tools and 6 workflow prompts for ontology engineering, validation, \
+ comparison, alignment, data ingestion, and exploration.{tail}"
+ ))
}
}
diff --git a/src/toolfilter.rs b/src/toolfilter.rs
index 959c875c..f83bfff8 100644
--- a/src/toolfilter.rs
+++ b/src/toolfilter.rs
@@ -91,6 +91,10 @@ impl ToolFilter {
/// Apply the filter to a `ToolRouter` by removing disallowed routes.
/// Returns the list of removed tool names (for logging/inspection).
+ ///
+ /// This is the OPERATOR's filter. [`remove_unavailable`] runs first and is
+ /// not optional: a tool the build cannot serve is never advertised,
+ /// whatever the operator asked for.
pub fn apply<S>(&self, router: &mut ToolRouter<S>) -> Vec<String>
where
S: Send + Sync + 'static,
@@ -120,6 +124,73 @@ impl ToolFilter {
}
}
+// ───────────────────────────────────────────────────────────────────────────
+// Tools this build cannot serve
+// ───────────────────────────────────────────────────────────────────────────
+
+/// The tools whose implementation is behind a Cargo feature, with the feature
+/// each one needs.
+///
+/// Eight of the registered tools have a body that is `#[cfg(not(feature =
+/// ...))] { return "Compiled without X feature" }`. Advertising one of those
+/// over `tools/list` is a promise the build cannot keep: a client reads the
+/// description, calls the tool, and gets an error that has nothing to do with
+/// its input. That is the same defect as a verdict claimed but not earned, one
+/// layer up — the advertisement and the capability have to agree, and the only
+/// honest way to make them agree is to stop advertising what cannot be served.
+///
+/// `onto_import_schema` and `onto_sql_ingest` need EITHER `postgres` or
+/// `duckdb`: they dispatch on the connection URL and the two schemes they
+/// accept are the two features. A build with one of them keeps both tools,
+/// because one scheme still works and the other reports a clear error about
+/// the scheme rather than about the tool.
+pub const FEATURE_GATED_TOOLS: &[(&str, &str)] = &[
+ ("onto_plugin_list", "plugins"),
+ ("onto_plugin_call", "plugins"),
+ ("onto_embed", "embeddings"),
+ ("onto_hnsw_build", "embeddings"),
+ ("onto_search", "embeddings"),
+ ("onto_similarity", "embeddings"),
+ ("onto_import_schema", "postgres or duckdb"),
+ ("onto_sql_ingest", "postgres or duckdb"),
+];
+
+/// Of those, the ones THIS build cannot serve. Empty when every feature is on.
+pub fn unavailable_in_this_build() -> Vec<&'static str> {
+ let mut out: Vec<&'static str> = Vec::new();
+ if !cfg!(feature = "plugins") {
+ out.extend(["onto_plugin_list", "onto_plugin_call"]);
+ }
+ if !cfg!(feature = "embeddings") {
+ out.extend(["onto_embed", "onto_hnsw_build", "onto_search", "onto_similarity"]);
+ }
+ if !cfg!(feature = "postgres") && !cfg!(feature = "duckdb") {
+ out.extend(["onto_import_schema", "onto_sql_ingest"]);
+ }
+ out.sort_unstable();
+ out
+}
+
+/// Remove every tool this build cannot serve from `router`, returning what was
+/// removed with the feature that would bring each one back.
+///
+/// Called before the operator's own filter and independently of its mode, so a
+/// `Mode::All` server still does not advertise a tool guaranteed to fail.
+pub fn remove_unavailable<S>(router: &mut ToolRouter<S>) -> Vec<(&'static str, &'static str)>
+where
+ S: Send + Sync + 'static,
+{
+ let gone = unavailable_in_this_build();
+ let mut removed = Vec::new();
+ for (name, feature) in FEATURE_GATED_TOOLS {
+ if gone.contains(name) {
+ router.remove_route(name);
+ removed.push((*name, *feature));
+ }
+ }
+ removed
+}
+
/// Curated tool groups. Tool names must match the ones registered with
/// `#[tool(name = "...")]` in `src/server.rs`.
pub fn expand_group(name: &str) -> &'static [&'static str] {
diff --git a/src/verdict.rs b/src/verdict.rs
new file mode 100644
index 00000000..82862efd
--- /dev/null
+++ b/src/verdict.rs
@@ -0,0 +1,502 @@
+//! Certified verdicts that cannot be spelled without the evidence.
+//!
+//! Every certified word this engine prints — `model_checked`, the OWL-level
+//! `not_entailed_under_unproved_translation`, `preserved_checked`,
+//! `preserved_under_supplied_rules_checked`, `checked`, and the theorem names
+//! `OOCert.certificate_sound` / `OOCert.horn_certificate_sound` /
+//! `Fol.satisfiable_of_check` — is now a variant that CARRIES a [`Certified`],
+//! and [`Certified`] has no public constructor. The only value of that type in
+//! the whole crate comes out of [`CheckerRun::accepted`], and the only way to
+//! obtain a [`CheckerRun`] is [`CheckerRun::spawn`], which runs the checker
+//! itself and reads its exit status.
+//!
+//! # What this replaces
+//!
+//! Until this module existed the discipline was carried by comments and by
+//! tests. Three files each had a line saying "the ONE place this word is
+//! produced", and a suite that failed if the word appeared with no exit code
+//! behind it. Those tests were right and they still run. But a test only
+//! covers the paths someone pointed it at: a new report type that formatted
+//! `"model_checked"` in a new module would pass every one of them until
+//! somebody noticed and wrote a guard.
+//!
+//! Now it is a privacy error. `FolVerdict::ModelChecked(..)` cannot be named
+//! outside this module without a `Certified`, `Certified` cannot be built
+//! outside this module at all, and this module hands one out only after
+//! `std::process::Command::output` returned and `ExitStatus::code()` was zero.
+//! The compile-fail doctests below are the executable form of that claim; they
+//! run under `cargo test` like any other test.
+//!
+//! # What it does NOT claim
+//!
+//! Three residual holes, stated rather than papered over.
+//!
+//! 1. **Which binary ran.** [`CheckerBinary::found_at`] is public and takes
+//! any path, so the wrapper documents where a path is supposed to come from
+//! and does not enforce it; and the discovery routines that call it honour
+//! `$OO_CERT` / `$OO_HORN` / `$OO_FOLMODEL`, so an operator who points one
+//! of those at a script that exits zero gets a certified word for free. The
+//! type system cannot tell a proved-sound Lean binary from a shell builtin.
+//! What it does guarantee is that SOMETHING was executed and exited zero,
+//! which is strictly more than a string literal guarantees, and it is the
+//! property the tests were checking by hand.
+//! 2. **Which artefact was accepted.** A [`Certified`] is `Copy`. Code that
+//! ran the checker over goal A could attach the token to goal B. Callers
+//! mint one token per run, inside the arm that owns that run's output, and
+//! the token carries the theorem name so at least the WARRANT cannot drift
+//! from the run that earned it. Binding the token to an artefact digest is
+//! the obvious next tightening and is not done here.
+//! 3. **Deserialisation.** None of these verdict types implements
+//! `Deserialize`, deliberately. Reading `"model_checked"` out of somebody
+//! else's JSON is not the same act as earning it, and a `Deserialize` impl
+//! would be a public constructor for every certified variant. Reports are
+//! read back as `serde_json::Value`.
+//!
+//! # The words that belong to a Lean checker
+//!
+//! [`CHECKER_OWNED_WORDS`] lists the verdicts the Lean binaries print for
+//! themselves. No `word()` in this module returns one, and
+//! [`no_engine_word_is_a_checker_word`] asserts that over every vocabulary
+//! defined here. Rust states its own words; it quotes the checker's only by
+//! echoing bytes it read from the checker's stdout.
+
+use std::path::{Path, PathBuf};
+use std::process::Command;
+
+// ───────────────────────────────────────────────────────────────────────────
+// The evidence
+// ───────────────────────────────────────────────────────────────────────────
+
+/// A path this process resolved to a checker binary.
+///
+/// The field is private, so a caller cannot conjure one from a `PathBuf`: it
+/// has to come through [`CheckerBinary::found_at`], which is what every
+/// `find_checker` in the crate calls once it has a path that exists. This is a
+/// thin wrapper and it earns its place by making [`CheckerRun::spawn`]'s
+/// signature say "this ran a checker" rather than "this ran a command".
+#[derive(Clone, Debug)]
+pub struct CheckerBinary(PathBuf);
+
+impl CheckerBinary {
+ /// Wrap a path a discovery routine has already resolved.
+ pub fn found_at(path: PathBuf) -> CheckerBinary {
+ CheckerBinary(path)
+ }
+ pub fn path(&self) -> &Path {
+ &self.0
+ }
+}
+
+/// A checker that RAN, with the exit status this process read off it.
+///
+/// Every field is private and there is exactly one constructor, and that
+/// constructor spawns a process. No module can hand this type a number.
+#[derive(Clone, Debug)]
+pub struct CheckerRun {
+ binary: PathBuf,
+ code: Option<i32>,
+ exit: i32,
+ stdout: String,
+ stderr: String,
+}
+
+impl CheckerRun {
+ /// Run `cmd` and capture what it said. THE ONLY CONSTRUCTOR.
+ ///
+ /// `cmd` is the caller's, because the argument vector differs per checker
+ /// (`oo-cert A D`, `oo-horn check R A D`, `oo-folmodel P M`), but the exit
+ /// code is read here and nowhere else. An error from the spawn itself is
+ /// returned as an error and never as a run: a checker that could not be
+ /// started did not accept anything.
+ pub fn spawn(binary: &CheckerBinary, mut cmd: Command) -> std::io::Result<CheckerRun> {
+ let out = cmd.output()?;
+ Ok(CheckerRun {
+ binary: binary.path().to_path_buf(),
+ // Kept as the `Option` the OS gave, because `None` (killed by a
+ // signal) and `Some(n)` are different facts and one report prints
+ // the difference.
+ code: out.status.code(),
+ // `-1` for a signal death, which is not an acceptance under any
+ // reading and must not collide with 0.
+ exit: out.status.code().unwrap_or(-1),
+ stdout: String::from_utf8_lossy(&out.stdout).into_owned(),
+ stderr: String::from_utf8_lossy(&out.stderr).into_owned(),
+ })
+ }
+
+ pub fn binary(&self) -> &Path {
+ &self.binary
+ }
+ /// The exit code, reported verbatim so a caller can distinguish `lean/`'s
+ /// reserved 1 (rejected) from 2 (unreadable). A process killed by a signal
+ /// reads as `-1`, which no exit status can be.
+ pub fn exit(&self) -> i32 {
+ self.exit
+ }
+ /// The raw `ExitStatus::code()`, for the one diagnostic that prints
+ /// `None` and `Some(n)` differently.
+ pub fn code(&self) -> Option<i32> {
+ self.code
+ }
+ /// The checker's own stdout. Its JSON report, where it writes one.
+ pub fn stdout(&self) -> &str {
+ &self.stdout
+ }
+ /// stdout then stderr, the spelling `run_checker` has always reported.
+ ///
+ /// These are the only bytes in a report that may carry a CHECKER's verdict
+ /// word, because they came from the checker.
+ pub fn output(&self) -> String {
+ format!("{}{}", self.stdout, self.stderr)
+ }
+
+ /// The one function in this crate that returns a [`Certified`].
+ ///
+ /// `Some` exactly when the checker exited zero. `theorem` is the Lean
+ /// statement that binary's acceptance discharges, and it travels inside
+ /// the token so that no report can name a theorem without an acceptance.
+ pub fn accepted(&self, theorem: &'static str) -> Option<Certified> {
+ (self.exit == 0).then_some(Certified { theorem })
+ }
+}
+
+/// Evidence that a verified checker accepted something, and the name of the
+/// theorem its acceptance discharges.
+///
+/// The field is private to this module. A value of this type exists only
+/// because [`CheckerRun::accepted`] read a zero exit code, so a variant that
+/// carries one is unreachable on any path that did not run a checker.
+///
+/// ```compile_fail
+/// // A struct literal: the field is private.
+/// let c = open_ontologies::verdict::Certified { theorem: "OOCert.certificate_sound" };
+/// ```
+///
+/// ```compile_fail
+/// // And there is no constructor function to reach for either.
+/// let c = open_ontologies::verdict::Certified::new("OOCert.certificate_sound");
+/// ```
+#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
+pub struct Certified {
+ theorem: &'static str,
+}
+
+impl Certified {
+ /// The machine-checked statement behind the word.
+ pub fn theorem(self) -> &'static str {
+ self.theorem
+ }
+}
+
+// ───────────────────────────────────────────────────────────────────────────
+// The first-order model pipeline (decision 0006)
+// ───────────────────────────────────────────────────────────────────────────
+
+/// The five words `onto_fol_model` may print, and no sixth.
+///
+/// `ModelChecked` is the only certified one. It carries the evidence, so the
+/// line that used to be a one-word assignment is now a compile error unless a
+/// checker ran:
+///
+/// ```compile_fail
+/// use open_ontologies::verdict::{Certified, FolVerdict};
+/// // The laundering line, as it would have to be written today.
+/// let v = FolVerdict::ModelChecked(Certified { theorem: "Fol.satisfiable_of_check" });
+/// ```
+#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
+pub enum FolVerdict {
+ /// CERTIFIED. `oo-folmodel` accepted the structure. Requires exit 0.
+ ModelChecked(Certified),
+ /// A solver said `sat` and nothing checked it.
+ SatisfiableOracle,
+ /// A BOUNDED search was exhausted. Not unsatisfiability.
+ NoModelUpToSizeK,
+ /// A solver said `unsat` on the UNBOUNDED encoding. An opinion for ever.
+ UnsatisfiableOracle,
+ /// Timeout or give-up.
+ UnknownOracle,
+}
+
+impl FolVerdict {
+ /// The wire word. Byte-identical to the string literals this replaced.
+ pub fn word(self) -> &'static str {
+ match self {
+ FolVerdict::ModelChecked(_) => "model_checked",
+ FolVerdict::SatisfiableOracle => "satisfiable_oracle",
+ FolVerdict::NoModelUpToSizeK => "no_model_up_to_size_k",
+ FolVerdict::UnsatisfiableOracle => "unsatisfiable_oracle",
+ FolVerdict::UnknownOracle => "unknown_oracle",
+ }
+ }
+ /// The theorem, named only where one stands behind the word.
+ pub fn theorem(self) -> Option<&'static str> {
+ match self {
+ FolVerdict::ModelChecked(c) => Some(c.theorem()),
+ _ => None,
+ }
+ }
+ pub fn is_certified(self) -> bool {
+ self.theorem().is_some()
+ }
+ /// Every word, for a suite that wants to enumerate the vocabulary without
+ /// being able to build the certified variant.
+ pub const WORDS: [&'static str; 5] = [
+ "model_checked",
+ "satisfiable_oracle",
+ "no_model_up_to_size_k",
+ "unsatisfiable_oracle",
+ "unknown_oracle",
+ ];
+}
+
+/// The OWL-level reading, which is a SECOND certified word on the same
+/// boundary and was a second place to launder one.
+///
+/// Decision 0006 item 4: non-null only when the CHECKER reported
+/// `goal_negated_present` AND the verdict is `model_checked`. Both conditions
+/// are now arguments that cannot be faked — the report is read off
+/// [`CheckerRun::output`], and the `Certified` is the verdict's own evidence.
+#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
+pub struct OwlReading(Certified);
+
+impl OwlReading {
+ /// The word, never shortened to "not entailed": it rides on
+ /// `OwlLean.adequacy` in a sibling project AND on a Rust-to-Lean
+ /// correspondence that decision 0005 item 2 says is pinned by tests and
+ /// NOT proved.
+ pub fn word(self) -> &'static str {
+ "not_entailed_under_unproved_translation"
+ }
+}
+
+impl CheckerRun {
+ /// Mint the OWL-level reading, if this run earned it.
+ ///
+ /// Takes the verdict's own [`Certified`] so the "and the verdict is
+ /// `model_checked`" half of the rule is carried by the signature rather
+ /// than by a comment, and reads `goal_negated_present` back out of the
+ /// checker's report rather than out of this side's intention.
+ pub fn owl_reading(&self, certified: Certified) -> Option<OwlReading> {
+ self.stdout
+ .contains("\"goal_negated_present\":true")
+ .then_some(OwlReading(certified))
+ }
+}
+
+// ───────────────────────────────────────────────────────────────────────────
+// The closure-certificate pipeline (decision 0002)
+// ───────────────────────────────────────────────────────────────────────────
+
+/// Why a run is entitled to the conclusions in its closure. NEVER COLLAPSED.
+///
+/// ```compile_fail
+/// use open_ontologies::verdict::{Certified, ClosureVerdict};
+/// let v = ClosureVerdict::Checked(Certified { theorem: "OOCert.certificate_sound" });
+/// ```
+#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
+pub enum ClosureVerdict {
+ /// CERTIFIED. `oo-cert` or `oo-horn` accepted the whole certificate.
+ Checked(Certified),
+ /// The checker rejected it. A defect report, never a weaker result.
+ Rejected,
+ /// The checker was absent, unreadable-in, or not needed. The engine's own
+ /// opinion about its own output.
+ EngineOpinion,
+}
+
+impl ClosureVerdict {
+ pub fn word(self) -> &'static str {
+ match self {
+ ClosureVerdict::Checked(_) => "checked",
+ ClosureVerdict::Rejected => "rejected",
+ ClosureVerdict::EngineOpinion => "engine_opinion",
+ }
+ }
+ pub fn theorem(self) -> Option<&'static str> {
+ match self {
+ ClosureVerdict::Checked(c) => Some(c.theorem()),
+ _ => None,
+ }
+ }
+ pub fn is_checked(self) -> bool {
+ matches!(self, ClosureVerdict::Checked(_))
+ }
+}
+
+// ───────────────────────────────────────────────────────────────────────────
+// The engine's own words
+// ───────────────────────────────────────────────────────────────────────────
+
+/// What THIS ENGINE may say about a contradiction it found in its own closure.
+///
+/// There is deliberately no certified variant. Nothing in the Rust tree runs
+/// `oo-refute`, so there is no code path that could mint the evidence one
+/// would need, and adding an unreachable variant would put the checker's word
+/// into the binary for the first time. When a Rust caller for `oo-refute` is
+/// written, it mints a [`Certified`] through [`CheckerRun::accepted`] like
+/// every other checker and a variant is added here — not before.
+#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
+pub enum EngineRefutation {
+ /// This engine found a clash in the closure it computed and NOTHING has
+ /// checked that. Deliberately not the checker's word.
+ ClashFoundByThisEngine,
+ /// A `refutation.tsv` was written in the format `oo-refute` reads. That it
+ /// was WRITTEN is all this says: exit 0 from `oo-refute check` is the
+ /// result that means anything.
+ RefutationWrittenNotYetChecked,
+}
+
+impl EngineRefutation {
+ pub fn word(self) -> &'static str {
+ match self {
+ EngineRefutation::ClashFoundByThisEngine => "clash_found_by_this_engine",
+ EngineRefutation::RefutationWrittenNotYetChecked => {
+ "refutation_written_not_yet_checked"
+ }
+ }
+ }
+}
+
+/// The verdicts the LEAN binaries print for themselves.
+///
+/// Rust may put one of these in a report only by echoing
+/// [`CheckerRun::output`] verbatim, or by naming a word a rule table is
+/// ELIGIBLE FOR under a key that says so — `src/rulesyntax.rs` writes
+/// `verdict_this_table_is_eligible_for`, which is a statement about what
+/// `oo-horn` could conclude and never a verdict this side is pronouncing.
+/// Nothing in this module returns one of these from a `word()`, and
+/// [`no_engine_word_is_a_checker_word`] fails if that ever changes.
+pub const CHECKER_OWNED_WORDS: &[&str] = &[
+ // `oo-cert` / `oo-horn`, lean/Main.lean.
+ "entailed",
+ "entailed_under_supplied_rules",
+ // `oo-refute`, lean/OOCert/Refute.lean.
+ "unsatisfiable_under_disjointness",
+];
+
+/// The word a SUPPLIED Horn table can earn from `oo-horn`, for the one place
+/// that is allowed to name it: an eligibility statement, never a verdict.
+///
+/// Held here so the string exists once in the crate and a reader who greps for
+/// it lands on this paragraph.
+pub const ELIGIBLE_UNDER_SUPPLIED_RULES: &str = "entailed_under_supplied_rules";
+
+// ───────────────────────────────────────────────────────────────────────────
+// Serialisation: the wire word, and nothing but the wire word
+// ───────────────────────────────────────────────────────────────────────────
+
+macro_rules! serialize_as_word {
+ ($t:ty) => {
+ impl serde::Serialize for $t {
+ fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
+ s.serialize_str(self.word())
+ }
+ }
+ impl std::fmt::Display for $t {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.write_str(self.word())
+ }
+ }
+ // So the suite can keep asserting against the wire word without
+ // being able to build the certified variant to compare with.
+ impl PartialEq<str> for $t {
+ fn eq(&self, other: &str) -> bool {
+ self.word() == other
+ }
+ }
+ impl PartialEq<&str> for $t {
+ fn eq(&self, other: &&str) -> bool {
+ self.word() == *other
+ }
+ }
+ };
+}
+
+serialize_as_word!(FolVerdict);
+serialize_as_word!(OwlReading);
+serialize_as_word!(ClosureVerdict);
+serialize_as_word!(EngineRefutation);
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ /// The structural half of "the Rust never reprints a Lean verdict".
+ ///
+ /// Every verdict string the crate prints is now a `word()` of one of these
+ /// vocabularies. None of them may be a word a Lean binary prints for
+ /// itself, or an engine opinion and a machine-checked result share a
+ /// string and a consumer cannot tell them apart.
+ #[test]
+ fn no_engine_word_is_a_checker_word() {
+ let mut ours: Vec<&str> = Vec::new();
+ ours.extend(FolVerdict::WORDS);
+ ours.push(OwlReading::word(OwlReading(Certified { theorem: "x" })));
+ ours.push(ClosureVerdict::Rejected.word());
+ ours.push(ClosureVerdict::EngineOpinion.word());
+ ours.push(ClosureVerdict::Checked(Certified { theorem: "x" }).word());
+ ours.push(EngineRefutation::ClashFoundByThisEngine.word());
+ ours.push(EngineRefutation::RefutationWrittenNotYetChecked.word());
+ for w in ours {
+ assert!(
+ !CHECKER_OWNED_WORDS.contains(&w),
+ "the engine states {w:?}, which is a word a Lean checker prints for itself"
+ );
+ }
+ }
+
+ /// A non-zero exit mints nothing, and there is no other route to a token.
+ #[test]
+ fn a_non_zero_exit_yields_no_certificate() {
+ let bin = CheckerBinary::found_at(PathBuf::from("/bin/sh"));
+ let mut c = Command::new("/bin/sh");
+ c.arg("-c").arg("exit 1");
+ let run = CheckerRun::spawn(&bin, c).expect("sh runs");
+ assert_eq!(run.exit(), 1);
+ assert!(run.accepted("OOCert.certificate_sound").is_none());
+ }
+
+ #[test]
+ fn a_zero_exit_mints_the_theorem_it_was_given() {
+ let bin = CheckerBinary::found_at(PathBuf::from("/bin/sh"));
+ let mut c = Command::new("/bin/sh");
+ c.arg("-c").arg("exit 0");
+ let run = CheckerRun::spawn(&bin, c).expect("sh runs");
+ let cert = run.accepted("OOCert.certificate_sound").expect("exit 0");
+ assert_eq!(cert.theorem(), "OOCert.certificate_sound");
+ assert_eq!(FolVerdict::ModelChecked(cert).word(), "model_checked");
+ assert_eq!(FolVerdict::ModelChecked(cert).theorem(), Some("OOCert.certificate_sound"));
+ }
+
+ /// A checker that could not be started is an error, not a run, so it can
+ /// never be asked whether it accepted anything.
+ #[test]
+ fn a_checker_that_cannot_start_is_not_a_run() {
+ let bin = CheckerBinary::found_at(PathBuf::from("/nonexistent/oo-cert"));
+ let c = Command::new("/nonexistent/oo-cert");
+ assert!(CheckerRun::spawn(&bin, c).is_err());
+ }
+
+ /// The wire words, pinned as literals. A rename that changed one of these
+ /// would change an MCP response and a CLI JSON field.
+ #[test]
+ fn the_wire_words_are_unchanged() {
+ assert_eq!(serde_json::to_string(&FolVerdict::SatisfiableOracle).unwrap(), "\"satisfiable_oracle\"");
+ assert_eq!(serde_json::to_string(&FolVerdict::NoModelUpToSizeK).unwrap(), "\"no_model_up_to_size_k\"");
+ assert_eq!(serde_json::to_string(&FolVerdict::UnsatisfiableOracle).unwrap(), "\"unsatisfiable_oracle\"");
+ assert_eq!(serde_json::to_string(&FolVerdict::UnknownOracle).unwrap(), "\"unknown_oracle\"");
+ assert_eq!(serde_json::to_string(&ClosureVerdict::Rejected).unwrap(), "\"rejected\"");
+ assert_eq!(serde_json::to_string(&ClosureVerdict::EngineOpinion).unwrap(), "\"engine_opinion\"");
+ assert_eq!(
+ serde_json::to_string(&EngineRefutation::ClashFoundByThisEngine).unwrap(),
+ "\"clash_found_by_this_engine\""
+ );
+ let cert = Certified { theorem: "Fol.satisfiable_of_check" };
+ assert_eq!(serde_json::to_string(&FolVerdict::ModelChecked(cert)).unwrap(), "\"model_checked\"");
+ assert_eq!(serde_json::to_string(&ClosureVerdict::Checked(cert)).unwrap(), "\"checked\"");
+ assert_eq!(
+ serde_json::to_string(&OwlReading(cert)).unwrap(),
+ "\"not_entailed_under_unproved_translation\""
+ );
+ }
+}
diff --git a/tests/closure_diff_test.rs b/tests/closure_diff_test.rs
index 5056ea09..c2e421ac 100644
--- a/tests/closure_diff_test.rs
+++ b/tests/closure_diff_test.rs
@@ -12,7 +12,7 @@
mod common;
use open_ontologies::closure_diff as cd;
-use open_ontologies::closure_diff::{DiffOptions, Warrant};
+use open_ontologies::closure_diff::DiffOptions;
use open_ontologies::graph::GraphStore;
use std::collections::{HashMap, HashSet};
use std::path::{Path, PathBuf};
@@ -209,7 +209,7 @@ fn an_unchecked_run_never_prints_the_checked_word() {
r.source_certificate
);
assert!(
- r.entailments_lost.iter().all(|e| e.warrant != Warrant::Checked),
+ r.entailments_lost.iter().all(|e| !e.warrant.is_checked()),
"an unchecked result printed the checked word"
);
let json = serde_json::to_string(&r).unwrap();
@@ -240,7 +240,7 @@ fn an_assertion_is_never_counted_as_checked() {
r.lost_by_warrant
);
for e in &r.entailments_lost {
- assert_eq!(e.theorem.is_some(), e.warrant == Warrant::Checked);
+ assert_eq!(e.theorem.is_some(), e.warrant.is_checked());
}
}
@@ -269,7 +269,7 @@ fn a_rejected_source_certificate_demotes_every_row() {
assert_eq!(r.source_certificate.checker_exit, Some(1));
assert_eq!(r.source_certificate.theorem, None);
assert!(
- r.entailments_lost.iter().all(|e| e.warrant != Warrant::Checked),
+ r.entailments_lost.iter().all(|e| !e.warrant.is_checked()),
"a rejected certificate leaves nothing checked"
);
let json = serde_json::to_string(&r).unwrap();
@@ -302,7 +302,7 @@ fn the_monotonicity_gate_fires() {
// And `from_parts` exists so the same hole can be built at the report level.
let verdict = cd::CertificateVerdict {
- verdict: "engine_opinion",
+ verdict: open_ontologies::verdict::ClosureVerdict::EngineOpinion,
theorem: None,
asserted: 1,
derivations: 0,
diff --git a/tests/fol_solver_verdict_test.rs b/tests/fol_solver_verdict_test.rs
index f0dc93c1..3348849e 100644
--- a/tests/fol_solver_verdict_test.rs
+++ b/tests/fol_solver_verdict_test.rs
@@ -294,7 +294,7 @@ fn a_bounded_unsat_is_not_unsatisfiability() {
assert_eq!(at_one.encoding, "finite(1)");
assert_eq!(at_one.unbounded, None, "no unbounded run happened");
assert!(at_one.bounded_search.contains("exhausted"), "{at_one:?}");
- assert!(verdict_means(at_one.verdict).contains("NOT"));
+ assert!(verdict_means(at_one.verdict.word()).contains("NOT"));
let at_two = solve(&needs_two(), &opts(2), &d.join("k2")).expect("runs");
assert_eq!(at_two.verdict, "model_checked", "{at_two:?}");
@@ -348,8 +348,11 @@ fn the_owl_reading_is_read_off_the_checkers_own_report() {
let d = scratch("owl");
let withgoal = solve(&not_entailed(), &opts(3), &d.join("goal")).expect("runs");
assert_eq!(withgoal.verdict, "model_checked", "{withgoal:?}");
+ // `OwlReading` has no public constructor either: the word is compared, and
+ // the presence of the value is what says the checker reported a negated
+ // goal on a run it accepted.
assert_eq!(
- withgoal.owl_reading,
+ withgoal.owl_reading.map(|r| r.word()),
Some("not_entailed_under_unproved_translation")
);
assert!(
diff --git a/tests/gate_demonstration_test.rs b/tests/gate_demonstration_test.rs
index c5023420..8cb56c98 100644
--- a/tests/gate_demonstration_test.rs
+++ b/tests/gate_demonstration_test.rs
@@ -350,7 +350,7 @@ fn every_gate_fires_on_its_own_broken_input() {
);
eprintln!(" SKIPPED: {}", r.source_certificate.skipped.clone().unwrap_or_default());
assert_eq!(r.source_certificate.verdict, "rejected");
- assert!(r.entailments_lost.iter().all(|e| e.warrant != cd::Warrant::Checked));
+ assert!(r.entailments_lost.iter().all(|e| !e.warrant.is_checked()));
}
// ── 13 ───────────────────────────────────────────────────────────────
diff --git a/tests/lean_projection_entailment_test.rs b/tests/lean_projection_entailment_test.rs
index 458c0fbb..38048388 100644
--- a/tests/lean_projection_entailment_test.rs
+++ b/tests/lean_projection_entailment_test.rs
@@ -279,7 +279,7 @@ fn a_low_coverage_slice_can_preserve_every_claim() {
);
assert_eq!(r.exit_code, 0, "{}", r.headline);
for gr in &r.per_goal {
- assert_eq!(gr.verdict, GoalVerdict::PreservedChecked);
+ assert_eq!(gr.verdict, "preserved_checked");
assert_eq!(gr.warrant, "OOCert.certificate_sound");
let c = gr.certificate.as_ref().expect("a checked goal carries its certificate");
assert!(c.check_with.contains("oo-cert"), "{c:?}");
@@ -344,7 +344,7 @@ fn a_preserved_claim_is_checked() {
&format!("{PREFIXES}:a a :C .\n"),
&opts("cell-preserved", &["http://ex.org/a".into()]),
);
- assert_eq!(r.per_goal[0].verdict, GoalVerdict::PreservedChecked, "{}", r.headline);
+ assert_eq!(r.per_goal[0].verdict, "preserved_checked", "{}", r.headline);
assert_eq!(r.per_goal[0].warrant, "OOCert.certificate_sound");
assert_eq!(r.exit_code, 0);
}
@@ -401,7 +401,7 @@ fn an_asserted_goal_is_preserved_asserted_not_lost() {
let gr = &r.per_goal[0];
assert_eq!(gr.projection, Membership::Asserted, "{gr:?}");
assert_eq!(gr.verdict, GoalVerdict::PreservedAsserted);
- assert_ne!(gr.verdict, GoalVerdict::PreservedChecked, "a lookup is not a theorem");
+ assert_ne!(gr.verdict, "preserved_checked", "a lookup is not a theorem");
assert_eq!(gr.warrant, "none", "and it names no theorem");
assert!(gr.certificate.is_none());
assert_eq!(r.exit_code, 0);
@@ -521,11 +521,11 @@ fn a_user_rule_run_never_earns_the_plain_preserved_word() {
for gr in &r.per_goal {
assert_ne!(
gr.verdict,
- GoalVerdict::PreservedChecked,
+ "preserved_checked",
"a run over a SUPPLIED rule table must not report the plain preserved word: {json}"
);
if gr.verdict.is_checked() {
- assert_eq!(gr.verdict, GoalVerdict::PreservedUnderSuppliedRulesChecked);
+ assert_eq!(gr.verdict, "preserved_under_supplied_rules_checked");
assert_eq!(gr.warrant, "OOCert.horn_certificate_sound");
}
}
@@ -534,7 +534,7 @@ fn a_user_rule_run_never_earns_the_plain_preserved_word() {
"the guard must not be vacuous: the goal has to be PRESERVED under the supplied table, \
or this test would pass on a run that proved nothing.\n{json}"
);
- assert_eq!(r.per_goal[0].verdict, GoalVerdict::PreservedUnderSuppliedRulesChecked);
+ assert_eq!(r.per_goal[0].verdict, "preserved_under_supplied_rules_checked");
assert!(
r.rules_sha256.is_some(),
"the table that was in force must be identified: {json}"
@@ -566,7 +566,7 @@ fn a_rejected_sub_certificate_stops_the_line() {
&format!("{PREFIXES}:a a :C .\n"),
&o,
);
- assert_eq!(honest.per_goal[0].verdict, GoalVerdict::PreservedChecked);
+ assert_eq!(honest.per_goal[0].verdict, "preserved_checked");
// Now forge the projection's derivation file: a well-formed rdfs9 step
// whose subClassOf premise is neither asserted nor derived earlier, with
@@ -606,7 +606,7 @@ fn a_rejected_sub_certificate_stops_the_line() {
"a premise in neither asserted.tsv nor an earlier line must be rejected: {status:?}"
);
assert!(
- !matches!(status, pe::CheckerStatus::Accepted { .. }),
+ !matches!(status, pe::CheckerStatus::Accepted(..)),
"and it must NOT be downgraded to an accepted or unchecked result"
);
@@ -651,7 +651,7 @@ fn a_rejected_slice_never_downgrades_to_preserved_unchecked() {
);
let v = r.per_goal[0].verdict;
assert_ne!(v, GoalVerdict::PreservedUnchecked, "a rejection must NOT downgrade: {v:?}");
- assert_ne!(v, GoalVerdict::PreservedChecked);
+ assert_ne!(v, "preserved_checked");
assert!(!v.is_preserved(), "a rejected sub-certificate is not a preserved goal: {v:?}");
assert_eq!(
v,
@@ -1057,7 +1057,7 @@ fn a_named_graph_projection_is_compared_over_every_triple() {
assert_eq!(r.subset.decided_over, "all triples", "{:?}", r.subset);
assert!(r.subset.verified);
assert_eq!(r.monotonicity.status, "armed");
- assert_eq!(r.per_goal[0].verdict, GoalVerdict::PreservedChecked, "{}", r.headline);
+ assert_eq!(r.per_goal[0].verdict, "preserved_checked", "{}", r.headline);
}
/// An earlier `reason` run materialising into the store makes `asserted.tsv` a
diff --git a/tests/readme_claims_test.rs b/tests/readme_claims_test.rs
index 0b3f2fe8..e555039b 100644
--- a/tests/readme_claims_test.rs
+++ b/tests/readme_claims_test.rs
@@ -35,14 +35,32 @@ fn exposed_tool_count() -> usize {
fn total_claims(n: usize) -> Vec<(&'static str, &'static str, String)> {
vec![
("README.md", "the lead paragraph", format!("**{n} tools**")),
- ("README.md", "the default-build sentence", format!("A default build advertises all {n} tools.")),
+ (
+ "README.md",
+ "the default-build sentence",
+ format!("A default build advertises {} tools.", n - gated_tool_count()),
+ ),
("docs/architecture.md", "the architecture diagram", format!("ToolGroups[\"{n} Tools\"]")),
- // Found by a merge conflict, not by this test: the MCP server tells every client
- // its own tool count in its instructions string, and that copy was stale at 110
- // while three others had been corrected. A gate that covers three of four places
- // is a gate that makes the fourth harder to notice.
- ("src/server.rs", "the MCP server's instructions string", format!("MCP server with {n} tools")),
]
+ // The MCP server's instructions string used to be checked here as a literal, and
+ // that row is gone on purpose. It stated TWO totals, 114 and 112, and neither was
+ // the number the router advertised: a hand-typed figure with a second hand-typed
+ // figure beside it, which is the disease this file exists to treat and not a case
+ // of it being caught. The string is now formatted from `tool_router.list_all()` at
+ // call time, so there is no literal left to go stale, and
+ // `the_instructions_string_states_the_count_it_advertises` below checks the live
+ // server instead of the source text.
+}
+
+/// How many registered tools a DEFAULT build does not advertise.
+///
+/// Derived from the same list `toolfilter::remove_unavailable` removes routes with, so
+/// the README's second number cannot drift from the server's behaviour. It is the whole
+/// list rather than `unavailable_in_this_build()` on purpose: the README's sentence is
+/// about a default build, which has none of the features, and reading it off THIS build
+/// would make the claim pass or fail depending on the flags the suite was run with.
+fn gated_tool_count() -> usize {
+ open_ontologies::toolfilter::FEATURE_GATED_TOOLS.len()
}
#[test]
@@ -81,13 +99,32 @@ fn no_stale_tool_count_survives_anywhere() {
.collect::<Vec<_>>()
.join("\n");
- // The shapes a total is written in here. Any number in one of them that is not the
- // measured count is a leftover from a partial edit.
- let shapes: [(&str, &str); 4] =
- [("**", " tools**"), ("advertises all ", " tools."), ("", " tools organized by function"), ("ToolGroups[\"", " Tools\"]")];
+ // The shapes a total is written in here, each with the number it must state. Two
+ // different totals are correct now: how many tools are REGISTERED, and how many a
+ // build with this feature set ADVERTISES. Conflating them is what produced a
+ // sentence claiming a default build advertised all 114 while eight of them could
+ // only return "Compiled without X feature".
+ let advertised = n - gated_tool_count();
+ let shapes: [(&str, &str, usize); 4] = [
+ ("**", " tools**", n),
+ ("advertises ", " tools.", advertised),
+ ("", " tools organized by function", n),
+ ("ToolGroups[\"", " Tools\"]", n),
+ ];
+
+ // The sentence that was wrong, named so a revert cannot pass quietly. There is no
+ // number a build can put in it that is true: the eight gated tools are registered
+ // and not advertised, so "all N" is false for every N.
+ assert!(
+ !readme.contains("advertises all "),
+ "\"advertises all N tools\" is back. It cannot be true: {} of the {n} registered \
+ tools are behind a Cargo feature and are not advertised by a build that lacks it. \
+ Say how many are advertised, not that all of them are.",
+ gated_tool_count().max(1)
+ );
let mut stale = Vec::new();
- for (prefix, suffix) in shapes {
+ for (prefix, suffix, n) in shapes {
let mut rest = readme.as_str();
while let Some(i) = rest.find(suffix) {
let head = &rest[..i];
diff --git a/tests/toolfilter_test.rs b/tests/toolfilter_test.rs
index 4ff3d8cd..dacdbbcf 100644
--- a/tests/toolfilter_test.rs
+++ b/tests/toolfilter_test.rs
@@ -181,3 +181,84 @@ fn mode_parse_is_case_insensitive_and_supports_aliases() {
assert_eq!(Mode::parse("denylist").unwrap(), Mode::Deny);
assert!(Mode::parse("garbage").is_err());
}
+
+// ────────────────────────────────────────────────────────────────────────────
+// Tools this build cannot serve
+// ────────────────────────────────────────────────────────────────────────────
+//
+// A tool in `tools/list` is a promise. Eight of the registered tools have a
+// body that is `#[cfg(not(feature = ...))] { return "Compiled without X
+// feature" }`, so on a build without that feature the promise cannot be kept
+// for any input at all: the client reads a description about embeddings or
+// WASM plugins or a Postgres URL, calls the tool, and gets an error that has
+// nothing to do with what it asked. That is the advertisement and the
+// capability disagreeing, and it is the same shape as a verdict claimed but
+// not earned, one layer up.
+
+/// The default filter exposes everything the build CAN serve, which is not the
+/// same as everything that is registered.
+#[test]
+fn a_tool_this_build_cannot_serve_is_not_advertised() {
+ let (_tmp, server) = build_server(ToolFilter::default());
+ let names = tool_names(&server);
+ for gone in open_ontologies::toolfilter::unavailable_in_this_build() {
+ assert!(
+ !names.contains(&gone.to_string()),
+ "{gone} is advertised by a build that can only answer it with \"Compiled \
+ without ... feature\""
+ );
+ }
+ // And the ones it CAN serve are still there, so this is not a blanket
+ // removal of the gated list.
+ for (tool, _feature) in open_ontologies::toolfilter::FEATURE_GATED_TOOLS {
+ let withheld = open_ontologies::toolfilter::unavailable_in_this_build().contains(tool);
+ assert_eq!(
+ names.contains(&tool.to_string()),
+ !withheld,
+ "{tool} advertised={} withheld={withheld}",
+ names.contains(&tool.to_string())
+ );
+ }
+}
+
+/// The count, derived on both sides. `#[tool(name = ...)]` attributes in
+/// `src/server.rs` are the registration, the router is the advertisement, and
+/// the difference is exactly what this build cannot serve.
+#[test]
+fn the_advertised_count_is_the_registered_count_minus_what_cannot_be_served() {
+ let registered = std::fs::read_to_string(
+ std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("src/server.rs"),
+ )
+ .unwrap()
+ .matches("#[tool(name = ")
+ .count();
+ let (_tmp, server) = build_server(ToolFilter::default());
+ assert_eq!(
+ tool_names(&server).len(),
+ registered - open_ontologies::toolfilter::unavailable_in_this_build().len()
+ );
+}
+
+/// The instructions string is what an MCP client reads before it calls
+/// anything, and it used to state two hand-typed totals, 114 and 112, neither
+/// of which was the number the router advertised. It is formatted from the
+/// router now, so this checks the live server rather than the source text.
+#[test]
+fn the_instructions_string_states_the_count_it_advertises() {
+ use rmcp::ServerHandler;
+ let (_tmp, server) = build_server(ToolFilter::default());
+ let advertised = tool_names(&server).len();
+ let info = server.get_info();
+ let text = info.instructions.expect("the server carries instructions");
+ assert!(
+ text.contains(&format!("MCP server with {advertised} tools")),
+ "the instructions must state the number the router advertises: {text}"
+ );
+ for gone in open_ontologies::toolfilter::unavailable_in_this_build() {
+ assert!(
+ text.contains(gone),
+ "a tool withheld from tools/list must be NAMED in the instructions, with the \
+ feature that brings it back, or its absence is silent: {text}"
+ );
+ }
+}
diff --git a/tests/verdict_vocabulary_test.rs b/tests/verdict_vocabulary_test.rs
new file mode 100644
index 00000000..3e087c5c
--- /dev/null
+++ b/tests/verdict_vocabulary_test.rs
@@ -0,0 +1,299 @@
+//! The whole certified vocabulary, in one place, checked from outside the crate.
+//!
+//! `src/verdict.rs` makes a certified verdict unconstructible without evidence:
+//! `Certified` has a private field, `CheckerRun::accepted` is its only
+//! producer, and the only constructor of a `CheckerRun` spawns a process and
+//! reads its exit status. The `compile_fail` doctests in that module are the
+//! gate on the CONSTRUCTION side.
+//!
+//! This file is the gate on the other two sides, and it runs as an ordinary
+//! integration test, from outside the crate, where privacy actually applies.
+//!
+//! 1. **The wire words are pinned as literals.** A rename inside the crate that
+//! changed one of them would change an MCP tool response, a CLI JSON field
+//! and every downstream consumer, silently, because the strings are produced
+//! by `word()` now and not typed at each site. This file types them.
+//! 2. **No word the engine states is a word a Lean checker states.** An engine
+//! opinion and a machine-checked result must never share a string, or a
+//! consumer cannot tell them apart. `tests/lean_refutation_producer_test.rs
+//! ::the_engine_never_states_the_checkers_verdict` checks that over a
+//! RESPONSE; this checks it over the vocabulary the responses are drawn
+//! from, so a word added tomorrow is covered before anyone writes a run that
+//! prints it.
+//!
+//! Where a certified word has to be named, this file EARNS the token the way
+//! the engine does: it runs a process that exits zero through the crate's own
+//! `run_checker`. There is no other way to get one, which is the point.
+
+use std::path::{Path, PathBuf};
+
+use open_ontologies::closure_diff::Warrant;
+use open_ontologies::projection_entailment::{self as pe, CertKind, CheckerStatus, GoalVerdict};
+use open_ontologies::verdict::{
+ CHECKER_OWNED_WORDS, CheckerBinary, CheckerRun, Certified, ClosureVerdict, EngineRefutation,
+ FolVerdict,
+};
+
+/// A shell script that exits with `code`, made executable.
+///
+/// Not `/bin/true`: that is `/usr/bin/true` on macOS and absent from `/bin`
+/// entirely, which this suite discovered by failing. A script written here
+/// runs the same everywhere and covers the non-zero codes too.
+fn exits_with(code: i32) -> PathBuf {
+ let dir = std::env::temp_dir().join("oo-verdict-vocabulary");
+ std::fs::create_dir_all(&dir).unwrap();
+ let p = dir.join(format!("exit{code}.sh"));
+ std::fs::write(&p, format!("#!/bin/sh\nexit {code}\n")).unwrap();
+ #[cfg(unix)]
+ {
+ use std::os::unix::fs::PermissionsExt as _;
+ std::fs::set_permissions(&p, std::fs::Permissions::from_mode(0o755)).unwrap();
+ }
+ p
+}
+
+/// A `Certified`, obtained the only way anything can obtain one: by running
+/// something that exits zero.
+///
+/// A shell script is not `oo-cert`, and `src/verdict.rs` says plainly that the
+/// type system cannot tell the two apart. What it CAN say is that a process
+/// ran and exited zero, and that is exactly what this borrows in order to name
+/// the certified variants below.
+fn earned(theorem: &'static str) -> Certified {
+ let script = exits_with(0);
+ let bin = CheckerBinary::found_at(script.clone());
+ let run = CheckerRun::spawn(&bin, std::process::Command::new(&script))
+ .expect("a script this test just wrote must be runnable");
+ assert_eq!(run.exit(), 0);
+ run.accepted(theorem).expect("exit 0 mints the token")
+}
+
+/// Every word this crate may print as a verdict, with the exact bytes it must
+/// put on the wire. Typed here on purpose: this file is the pin.
+fn every_word() -> Vec<(&'static str, String)> {
+ let cert = earned("OOCert.certificate_sound");
+ vec![
+ // decision 0006, `onto_fol_model`
+ ("FolVerdict::ModelChecked", FolVerdict::ModelChecked(cert).word().to_string()),
+ ("FolVerdict::SatisfiableOracle", FolVerdict::SatisfiableOracle.word().to_string()),
+ ("FolVerdict::NoModelUpToSizeK", FolVerdict::NoModelUpToSizeK.word().to_string()),
+ ("FolVerdict::UnsatisfiableOracle", FolVerdict::UnsatisfiableOracle.word().to_string()),
+ ("FolVerdict::UnknownOracle", FolVerdict::UnknownOracle.word().to_string()),
+ // decision 0002 / 0007, the closure certificate
+ ("ClosureVerdict::Checked", ClosureVerdict::Checked(cert).word().to_string()),
+ ("ClosureVerdict::Rejected", ClosureVerdict::Rejected.word().to_string()),
+ ("ClosureVerdict::EngineOpinion", ClosureVerdict::EngineOpinion.word().to_string()),
+ ("Warrant::Checked", Warrant::Checked(cert).name().to_string()),
+ ("Warrant::AssertedInSource", Warrant::AssertedInSource.name().to_string()),
+ ("Warrant::EngineOpinion", Warrant::EngineOpinion.name().to_string()),
+ // decision 0007, per goal
+ ("GoalVerdict::PreservedChecked", GoalVerdict::PreservedChecked(cert).word().to_string()),
+ (
+ "GoalVerdict::PreservedUnderSuppliedRulesChecked",
+ GoalVerdict::PreservedUnderSuppliedRulesChecked(cert).word().to_string(),
+ ),
+ ("GoalVerdict::PreservedAsserted", GoalVerdict::PreservedAsserted.word().to_string()),
+ ("GoalVerdict::PreservedUnchecked", GoalVerdict::PreservedUnchecked.word().to_string()),
+ (
+ "GoalVerdict::LostUnderProfileUnchecked",
+ GoalVerdict::LostUnderProfileUnchecked.word().to_string(),
+ ),
+ ("GoalVerdict::UngroundedInSource", GoalVerdict::UngroundedInSource.word().to_string()),
+ ("GoalVerdict::ProjectionOnly", GoalVerdict::ProjectionOnly.word().to_string()),
+ ("GoalVerdict::CertificateRejected", GoalVerdict::CertificateRejected.word().to_string()),
+ ("GoalVerdict::Refused", GoalVerdict::Refused.word().to_string()),
+ // the engine's own words about a contradiction it found itself
+ (
+ "EngineRefutation::ClashFoundByThisEngine",
+ EngineRefutation::ClashFoundByThisEngine.word().to_string(),
+ ),
+ (
+ "EngineRefutation::RefutationWrittenNotYetChecked",
+ EngineRefutation::RefutationWrittenNotYetChecked.word().to_string(),
+ ),
+ ]
+}
+
+/// The wire format, pinned. These bytes are in MCP tool responses, in CLI JSON
+/// and in fixtures, so a rename is a breaking change to every consumer and must
+/// be a deliberate one.
+#[test]
+fn the_wire_words_are_exactly_these() {
+ let want: Vec<(&str, &str)> = vec![
+ ("FolVerdict::ModelChecked", "model_checked"),
+ ("FolVerdict::SatisfiableOracle", "satisfiable_oracle"),
+ ("FolVerdict::NoModelUpToSizeK", "no_model_up_to_size_k"),
+ ("FolVerdict::UnsatisfiableOracle", "unsatisfiable_oracle"),
+ ("FolVerdict::UnknownOracle", "unknown_oracle"),
+ ("ClosureVerdict::Checked", "checked"),
+ ("ClosureVerdict::Rejected", "rejected"),
+ ("ClosureVerdict::EngineOpinion", "engine_opinion"),
+ ("Warrant::Checked", "checked"),
+ ("Warrant::AssertedInSource", "asserted_in_source"),
+ ("Warrant::EngineOpinion", "engine_opinion"),
+ ("GoalVerdict::PreservedChecked", "preserved_checked"),
+ (
+ "GoalVerdict::PreservedUnderSuppliedRulesChecked",
+ "preserved_under_supplied_rules_checked",
+ ),
+ ("GoalVerdict::PreservedAsserted", "preserved_asserted"),
+ ("GoalVerdict::PreservedUnchecked", "preserved_unchecked"),
+ ("GoalVerdict::LostUnderProfileUnchecked", "lost_under_profile_unchecked"),
+ ("GoalVerdict::UngroundedInSource", "ungrounded_in_source"),
+ ("GoalVerdict::ProjectionOnly", "projection_only"),
+ ("GoalVerdict::CertificateRejected", "certificate_rejected"),
+ ("GoalVerdict::Refused", "refused"),
+ ("EngineRefutation::ClashFoundByThisEngine", "clash_found_by_this_engine"),
+ ("EngineRefutation::RefutationWrittenNotYetChecked", "refutation_written_not_yet_checked"),
+ ];
+ let got = every_word();
+ assert_eq!(got.len(), want.len(), "a verdict was added or removed without pinning its word");
+ for ((gname, gword), (wname, wword)) in got.iter().zip(want.iter()) {
+ assert_eq!(gname, wname, "the vocabularies are listed in different orders");
+ assert_eq!(
+ gword, wword,
+ "{gname} now writes {gword:?} and used to write {wword:?}. That string is in MCP \
+ responses and CLI JSON. If the rename is deliberate, change it here and say so in \
+ the CHANGELOG; if it is not, this is the bug."
+ );
+ }
+}
+
+/// `serde` writes the same bare string the derives used to write, which is what
+/// keeps the wire format unchanged now that the certified variants carry a
+/// payload serde would otherwise have wrapped in an object.
+#[test]
+fn serde_writes_the_bare_word_and_never_an_object() {
+ let cert = earned("OOCert.certificate_sound");
+ let cases: Vec<(String, &str)> = vec![
+ (serde_json::to_string(&FolVerdict::ModelChecked(cert)).unwrap(), "\"model_checked\""),
+ (
+ serde_json::to_string(&FolVerdict::SatisfiableOracle).unwrap(),
+ "\"satisfiable_oracle\"",
+ ),
+ (serde_json::to_string(&ClosureVerdict::Checked(cert)).unwrap(), "\"checked\""),
+ (serde_json::to_string(&Warrant::Checked(cert)).unwrap(), "\"checked\""),
+ (serde_json::to_string(&Warrant::AssertedInSource).unwrap(), "\"asserted_in_source\""),
+ (
+ serde_json::to_string(&GoalVerdict::PreservedChecked(cert)).unwrap(),
+ "\"preserved_checked\"",
+ ),
+ (
+ serde_json::to_string(&GoalVerdict::PreservedUnderSuppliedRulesChecked(cert)).unwrap(),
+ "\"preserved_under_supplied_rules_checked\"",
+ ),
+ (
+ serde_json::to_string(&EngineRefutation::ClashFoundByThisEngine).unwrap(),
+ "\"clash_found_by_this_engine\"",
+ ),
+ ];
+ for (got, want) in cases {
+ assert_eq!(got, want, "a verdict serialised as something other than its bare word");
+ }
+}
+
+/// An engine opinion and a machine-checked result must never share a string.
+///
+/// The response-level version of this lives in
+/// `tests/lean_refutation_producer_test.rs::the_engine_never_states_the_checkers_verdict`.
+/// This is the vocabulary-level version, so a word added to any of these enums
+/// is covered before a run exists that could print it.
+#[test]
+fn no_word_the_engine_states_is_a_word_a_lean_checker_states() {
+ for (name, word) in every_word() {
+ assert!(
+ !CHECKER_OWNED_WORDS.contains(&word.as_str()),
+ "{name} states {word:?}, which is a verdict a Lean binary prints for itself. \
+ Rust may put one of those in a report only by echoing the checker's own bytes."
+ );
+ }
+}
+
+/// The theorem name is as unspeakable as the verdict, because it travels inside
+/// the evidence rather than beside it.
+///
+/// `tests/closure_diff_test.rs::an_unchecked_run_never_prints_the_checked_word`
+/// asserts that `OOCert.certificate_sound` appears nowhere in an unchecked
+/// report. It can now only appear where a `Certified` does.
+#[test]
+fn a_theorem_is_named_only_where_the_evidence_is() {
+ let cert = earned("OOCert.certificate_sound");
+ assert_eq!(GoalVerdict::PreservedChecked(cert).warrant(), "OOCert.certificate_sound");
+ assert_eq!(Warrant::Checked(cert).theorem(), Some("OOCert.certificate_sound"));
+ assert_eq!(ClosureVerdict::Checked(cert).theorem(), Some("OOCert.certificate_sound"));
+
+ for v in [
+ GoalVerdict::PreservedAsserted,
+ GoalVerdict::PreservedUnchecked,
+ GoalVerdict::LostUnderProfileUnchecked,
+ GoalVerdict::UngroundedInSource,
+ GoalVerdict::ProjectionOnly,
+ GoalVerdict::CertificateRejected,
+ GoalVerdict::Refused,
+ ] {
+ assert_eq!(v.warrant(), "none", "{v} named a theorem with no evidence behind it");
+ assert!(!v.is_checked());
+ }
+ for w in [Warrant::AssertedInSource, Warrant::EngineOpinion] {
+ assert_eq!(w.theorem(), None);
+ assert!(!w.is_checked());
+ }
+ for v in [ClosureVerdict::Rejected, ClosureVerdict::EngineOpinion] {
+ assert_eq!(v.theorem(), None);
+ assert!(!v.is_checked());
+ }
+ for v in [
+ FolVerdict::SatisfiableOracle,
+ FolVerdict::NoModelUpToSizeK,
+ FolVerdict::UnsatisfiableOracle,
+ FolVerdict::UnknownOracle,
+ ] {
+ assert_eq!(v.theorem(), None);
+ assert!(!v.is_certified());
+ }
+}
+
+/// The token comes from a zero exit code and from nothing else, checked through
+/// the crate's own `run_checker` rather than through the primitive.
+///
+/// `sh -c "exit 1"` is `lean/Main.lean`'s REJECTED, `exit 2` is its UNREADABLE,
+/// and neither is an acceptance. A run that could not start is `Absent`.
+#[test]
+fn only_a_zero_exit_produces_an_acceptance() {
+ let dir = std::env::temp_dir().join("oo-verdict-vocabulary");
+ std::fs::create_dir_all(&dir).unwrap();
+ let a = dir.join("asserted.tsv");
+ let d = dir.join("derivations.tsv");
+ std::fs::write(&a, "").unwrap();
+ std::fs::write(&d, "").unwrap();
+
+ let run = |code: i32| {
+ let script = exits_with(code);
+ pe::run_checker(CertKind::OoCert, Some(script.as_path()), &a, &d, None)
+ };
+
+ assert!(matches!(run(0), CheckerStatus::Accepted(_)));
+ assert!(matches!(run(1), CheckerStatus::Rejected { .. }));
+ assert!(matches!(run(2), CheckerStatus::Unreadable { .. }));
+ assert!(matches!(run(3), CheckerStatus::Unreadable { .. }));
+
+ let absent = pe::run_checker(
+ CertKind::OoCert,
+ Some(Path::new("/nonexistent/oo-cert")),
+ &a,
+ &d,
+ None,
+ );
+ assert!(absent.is_absent(), "a checker that cannot be found accepted nothing");
+
+ // And the acceptance carries the theorem the KIND names, not one the
+ // caller chose afterwards.
+ let script = exits_with(0);
+ match pe::run_checker(CertKind::OoHorn, Some(script.as_path()), &a, &d, Some(a.as_path())) {
+ CheckerStatus::Accepted(acc) => {
+ assert_eq!(acc.theorem(), "OOCert.horn_certificate_sound");
+ assert_eq!(acc.certified().theorem(), "OOCert.horn_certificate_sound");
+ }
+ other => panic!("exit 0 must be an acceptance: {other:?}"),
+ }
+}