Plan, apply and roll back changes to a production ontology, with a blast radius report and a proof an auditor can re-check.
Rust ai-nativedescription-logicsformal-verificationinfrastructure-as-codeisabelle-languageknowledge-graphleanlean4mcpmcp-serverontologyowlowl2reasoningrustshaclsparqltheorem-proving
Give the tableaux a live second opinion, and make it a checked model (#199)
Fabio Rovaie483d755ae7b
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex c828f9ac..c81c5572 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -571,6 +571,14 @@ jobs:# whose bounded search was exhausted must say `no_model_up_to_size_k`# and never `unsatisfiable_oracle`. See docs/decisions/0006 item 4.run: OO_REQUIRE_FIXTURES=1 cargo test --test fol_solver_verdict_test -- --nocapture+ - name: Check the tableaux verdict against a CHECKED model, not an oracle+ # The owl-dl path was the only layer with no live second opinion: its+ # conformance expectations are sourced from frozen `HermiT:` comments+ # and nothing re-runs HermiT, which is not installed here. This asks+ # for a MODEL instead and hands it to oo-folmodel, so a consistent+ # verdict is corroborated by a machine-checked theorem rather than by+ # another reasoner agreeing. Uses the z3 this job already installs.+ run: OO_REQUIRE_FIXTURES=1 cargo test --test dl_consistency_differential_test -- --nocapture- name: Check the model ingestion, both front endsrun: OO_REQUIRE_FIXTURES=1 cargo test --test fol_model_ingest_test -- --nocapture- name: Build the release binary the SMT differential drivesdiff --git a/docs/ci-gates.md b/docs/ci-gates.mdindex 940c58ea..9f8dda93 100644--- a/docs/ci-gates.md+++ b/docs/ci-gates.md@@ -68,6 +68,7 @@ job invokes the file at all.| `lean_fol_model_test.rs` | lake + `oo-folmodel` + z3 | `lean` job | **strict** || `fol_solver_verdict_test.rs` | z3 + `oo-folmodel` + the debug CLI | `lean` job | **strict** || `smt_second_oracle_test.rs` | z3 **and** cvc5 1.3.4 + `oo-folmodel` + the release binary | `lean` job installs cvc5 by digest and builds the release binary | **strict** |+| `dl_consistency_differential_test.rs` | z3 + `oo-folmodel` | `lean` job | **strict** || `lean_projection_entailment_test.rs` | lake | `lean` job | **strict** || `closure_diff_test.rs` | lake | `lean` job | **strict** || `projection_monotonicity_corpus_test.rs` | lake | `lean` job | **strict** |diff --git a/tests/dl_consistency_differential_test.rs b/tests/dl_consistency_differential_test.rsnew file mode 100644index 00000000..b1b9b679--- /dev/null+++ b/tests/dl_consistency_differential_test.rs@@ -0,0 +1,155 @@+//! **The tableaux verdict, checked against a model rather than against an oracle.**+//!+//! `tests/owl2_conformance_test.rs` asserts what this engine's `owl-dl` path+//! says, and every expectation in it is sourced from a comment reading+//! `HermiT: consistent ✓`. Those assertions are real, so the file is a gate on+//! this engine. What it is not is a LIVE second opinion: HermiT is not a+//! dependency here, it is not installed, and nothing re-runs it. Twenty+//! expectations rest on a transcription nobody can re-check.+//!+//! Every other layer has a live differential. First-order has E and Vampire,+//! SHACL has pySHACL, the certificate layer has Isabelle and now Rocq. The+//! description-logic path had none.+//!+//! This closes that, and closes it BETTER than HermiT would. Decision 0006:+//! a model is a finite object a verified checker can validate, so a `sat`+//! answer becomes a certificate, while `unsat` stays testimony. So when the+//! tableaux says an ontology is consistent, this does not ask a second+//! reasoner whether it agrees. It asks for a MODEL and hands that model to+//! `oo-folmodel`, which re-evaluates every formula against the structure. The+//! verdict `model_checked` is a machine-checked statement that the ontology+//! has a model, and a second reasoner's agreement is not.+//!+//! It also needs no Java. HermiT would mean a JDK and the OWL API in CI; this+//! uses Z3, which the `lean` job already installs for exactly this layer.+//!+//! **The inconsistent direction is deliberately weaker, and says so.** When+//! the tableaux reports an inconsistency, no model exists, so there is nothing+//! to check and the solver's `unsat` is an oracle opinion. What is asserted+//! there is only the thing that would be a real defect: that no CHECKED MODEL+//! is produced for an ontology this engine called inconsistent. A checked+//! model for an inconsistent ontology would mean one of the two is wrong, and+//! that is worth catching even though its absence proves nothing.++mod common;++use open_ontologies::fol_solve::{SolveOptions, Solver, solve_export};+use open_ontologies::graph::GraphStore;+use open_ontologies::reason::Reasoner;+use std::sync::Arc;++const PREFIXES: &str = r#"+ @prefix ex: <http://example.org/> .+ @prefix owl: <http://www.w3.org/2002/07/owl#> .+ @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .+"#;++/// Cases the conformance file states with a frozen `HermiT:` comment, and what+/// this engine says about each.+fn consistent_cases() -> Vec<(&'static str, &'static str)> {+ vec![+ ("a subsumption chain", "ex:A a owl:Class . ex:B a owl:Class . ex:C a owl:Class . \+ ex:A rdfs:subClassOf ex:B . ex:B rdfs:subClassOf ex:C ."),+ ("disjoint classes with no shared member", "ex:A a owl:Class . ex:B a owl:Class . \+ ex:A owl:disjointWith ex:B . ex:x a ex:A ."),+ ("a domain and a range", "ex:p a owl:ObjectProperty . ex:p rdfs:domain ex:A . \+ ex:p rdfs:range ex:B . ex:x ex:p ex:y ."),+ ]+}++fn inconsistent_cases() -> Vec<(&'static str, &'static str)> {+ vec![+ ("an individual in two disjoint classes", "ex:A a owl:Class . ex:B a owl:Class . \+ ex:A owl:disjointWith ex:B . ex:x a ex:A . ex:x a ex:B ."),+ ]+}++fn store(body: &str) -> Arc<GraphStore> {+ let g = Arc::new(GraphStore::new());+ g.load_turtle(&format!("{PREFIXES}{body}"), None).expect("ontology must parse");+ g+}++fn tableaux_says_consistent(g: &Arc<GraphStore>) -> bool {+ let out = Reasoner::run(g, "owl-dl", false).expect("owl-dl run");+ let v: serde_json::Value = serde_json::from_str(&out).expect("report is JSON");+ v["consistent"].as_bool().expect("the owl-dl report states consistency")+}++/// The ontology-level verdict from the model layer.+fn model_verdict(g: &Arc<GraphStore>, name: &str) -> String {+ let dir = std::env::temp_dir().join(format!("oo-dl-diff-{}-{}", std::process::id(), name.len()));+ let _ = std::fs::remove_dir_all(&dir);+ std::fs::create_dir_all(&dir).expect("scratch dir");+ let opts = SolveOptions {+ solver: Solver::Z3,+ // Small, because these are three-class ontologies and the ladder stops+ // at the first model. A large ceiling would only slow the negative+ // case, which has to exhaust it.+ max_domain: 4,+ timeout_secs: 20,+ unbounded_probe: false,+ checker: None,+ };+ let report = solve_export(g, &dir, &opts, None, 0).expect("solve_export");+ let v: serde_json::Value = serde_json::from_str(&report).expect("report is JSON");+ let verdict = v["ontology"]["verdict"].as_str().unwrap_or("<none>").to_string();+ let _ = std::fs::remove_dir_all(&dir);+ verdict+}++fn skip() -> bool {+ let has_z3 = std::process::Command::new("z3").arg("--version").output().is_ok();+ let checker = open_ontologies::fol_solve::find_checker(None).is_ok();+ common::skip_unless(+ has_z3 && checker,+ "z3 and the oo-folmodel checker",+ "install z3, and build lean/ with `cd lean && lake build`",+ )+}++#[test]+fn a_consistent_ontology_gets_a_checked_model_and_not_merely_a_second_opinion() {+ if skip() {+ return;+ }+ for (name, body) in consistent_cases() {+ let g = store(body);+ assert!(+ tableaux_says_consistent(&g),+ "{name}: this engine called it inconsistent, so the case is mislabelled here"+ );+ let verdict = model_verdict(&g, name);+ assert_eq!(+ verdict, "model_checked",+ "{name}: the tableaux says consistent and the model layer returned {verdict:?}. \+ `model_checked` is the only verdict that rests on a machine-checked theorem: the \+ structure was handed to oo-folmodel and every formula re-evaluated against it. \+ Anything else means the two halves of this engine disagree, or the model could \+ not be checked, and both are worth stopping for"+ );+ }+}++#[test]+fn an_inconsistent_ontology_never_gets_a_checked_model() {+ if skip() {+ return;+ }+ for (name, body) in inconsistent_cases() {+ let g = store(body);+ assert!(+ !tableaux_says_consistent(&g),+ "{name}: this engine called it consistent, so the case is mislabelled here"+ );+ let verdict = model_verdict(&g, name);+ assert_ne!(+ verdict, "model_checked",+ "{name}: this engine's tableaux says the ontology is inconsistent and the model \+ layer produced a CHECKED model of it. One of the two is wrong, and the checked \+ half is the one carrying a theorem. This is the assertion in this file worth \+ having: the other direction only establishes that no model was found, which is \+ not evidence of inconsistency"+ );+ }+}diff --git a/tests/owl2_conformance_test.rs b/tests/owl2_conformance_test.rsindex 83f847b7..b7d8123b 100644--- a/tests/owl2_conformance_test.rs+++ b/tests/owl2_conformance_test.rs@@ -42,7 +42,18 @@ fn disable_reasoner_timeouts() {// ── W3C-style Consistency Tests ─────────────────────────────────────────// Reference: OWL 2 Structural Specification §11 (consistency)-// Oracle: HermiT 1.4.3+// Oracle: HermiT 1.4.3, TRANSCRIBED. HermiT is not a dependency of this+// repository, is not installed, and nothing here re-runs it, so every+// `HermiT:` comment below is a record of an answer somebody obtained once.+// The assertions ARE live and do gate this engine; what is frozen is where+// the expected value came from.+//+// The live second opinion for this path is+// `tests/dl_consistency_differential_test.rs`, which does not ask another+// reasoner whether it agrees. It asks for a MODEL and hands it to+// `oo-folmodel`, so a consistent verdict rests on a machine-checked theorem+// rather than on agreement. Decision 0006 is why that is the stronger of the+// two, and why the inconsistent direction stays an oracle opinion.#[test]fn w3c_consistent_empty_ontology() {