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
Say what a skipped_constraints entry is, and gate the promise (#189)
Fabio Rovaie83878614071
diff --git a/src/server.rs b/src/server.rsindex 718deee2..d14a1c3f 100644--- a/src/server.rs+++ b/src/server.rs@@ -1247,7 +1247,7 @@ impl OpenOntologiesServer {result.to_string()}- #[tool(name = "onto_shacl", description = "Validate the loaded ontology data against SHACL shapes. Checks the core constraint components written under `sh:property`, including `sh:minCount`, `sh:maxCount`, `sh:datatype`, `sh:class`, `sh:nodeKind`, `sh:pattern`, `sh:in`, `sh:hasValue`, `sh:or` and `sh:not`, plus `sh:sparql`. A constraint it cannot execute is listed in `skipped_constraints` and the verdict is null rather than true. Returns a conformance report with violations, `focus_nodes` and `unmatched_shapes`, plus `scope`, which names the graphs the run READ. By default every graph in the store is read. Over a store that describes its named graphs with the temporal vocabulary (https://open-ontologies.org/temporal#) that union is a state that held at no instant, so a run with no instant named is REFUSED rather than answered: pass `valid_at` (what was TRUE then), `as_of` (what was KNOWN then) or `all_versions: true` to say the union is what you meant. A scoped run evaluates every data-side query, `sh:sparql` included, against the in-scope named graphs plus the default graph and nothing else. A snapshot that selects no graph returns `conforms: null` with its own reason rather than conforming vacuously. Class and property DECLARATION lookups are never scoped: a declaration is context-free and has the same answer at every instant.")]+ #[tool(name = "onto_shacl", description = "Validate the loaded ontology data against SHACL shapes. Checks the core constraint components written under `sh:property`, including `sh:minCount`, `sh:maxCount`, `sh:datatype`, `sh:class`, `sh:nodeKind`, `sh:pattern`, `sh:in`, `sh:hasValue`, `sh:or` and `sh:not`, plus `sh:sparql`. A constraint it cannot execute is listed in `skipped_constraints` and the verdict is null rather than true. An entry there is one CONSTRAINT-EVALUATION SITE and not one shape: a single `sh:property` block carrying both `sh:minCount` and `sh:node` can produce a violation from the first and a skip entry from the second, so the SAME shape can appear in `violations` and in `skipped_constraints` at once and that is not a contradiction. Every entry names the `shape` it was written on and the `constraint` predicate that was not evaluated, which is what separates a constraint that did not run from one that ran and selected nothing. Returns a conformance report with violations, `focus_nodes` and `unmatched_shapes`, plus `scope`, which names the graphs the run READ. By default every graph in the store is read. Over a store that describes its named graphs with the temporal vocabulary (https://open-ontologies.org/temporal#) that union is a state that held at no instant, so a run with no instant named is REFUSED rather than answered: pass `valid_at` (what was TRUE then), `as_of` (what was KNOWN then) or `all_versions: true` to say the union is what you meant. A scoped run evaluates every data-side query, `sh:sparql` included, against the in-scope named graphs plus the default graph and nothing else. A snapshot that selects no graph returns `conforms: null` with its own reason rather than conforming vacuously. Class and property DECLARATION lookups are never scoped: a declaration is context-free and has the same answer at every instant.")]async fn onto_shacl(&self, Parameters(input): Parameters<OntoShaclInput>) -> String {use crate::shacl::ShaclValidator;let shapes = if input.inline.unwrap_or(false) {diff --git a/tests/skipped_constraints_shape_test.rs b/tests/skipped_constraints_shape_test.rsnew file mode 100644index 00000000..b480c363--- /dev/null+++ b/tests/skipped_constraints_shape_test.rs@@ -0,0 +1,87 @@+//! **Issue #170.** Every `skipped_constraints` entry names the shape it came from.+//!+//! The field is recorded per constraint-evaluation SITE, not per shape, so one+//! shape can appear in `violations` and in `skipped_constraints` from the same+//! run. Read without knowing that, a report looks self-contradictory: the+//! validator says it skipped a constraint and then emits results for the same+//! shape. That reading cost a consumer real time.+//!+//! The granularity is now stated in the `onto_shacl` description. The sentence+//! makes a promise about the SHAPE of each entry, and this is the promise:+//! an entry without a shape leaves a reader unable to line the two lists up,+//! which is exactly the confusion the sentence exists to remove.+//!+//! A reader distinguishing "this constraint did not run" from "it ran and+//! selected nothing" needs both lists keyed the same way. Getting that+//! backwards is the unsafe direction: a naive reading marks a shape as+//! unchecked when it partly ran.++use open_ontologies::graph::GraphStore;+use open_ontologies::shacl::ShaclValidator;+use std::sync::Arc;++/// `MINUS` is forbidden in a pre-bound query by SHACL 5.2.1, so the validator+/// must refuse the constraint rather than substitute into it. That refusal is+/// a skip, which is what gives this test something to inspect.+const SHAPES: &str = r#"+ @prefix sh: <http://www.w3.org/ns/shacl#> .+ @prefix ex: <http://example.org/> .+ ex:TestShape a sh:NodeShape ;+ sh:targetNode ex:thing ;+ sh:sparql [+ sh:select """+ SELECT $this+ WHERE { $this ?x ?any . MINUS { $this ?x "v" } }"""+ ] .+"#;++const DATA: &str = r#"+ @prefix ex: <http://example.org/> .+ ex:thing ex:p "v" .+"#;++#[test]+fn every_skipped_constraint_names_the_shape_it_was_written_on() {+ let graph = Arc::new(GraphStore::new());+ graph.load_turtle(DATA, None).expect("data");+ let json = ShaclValidator::validate(&graph, SHAPES).expect("validate");+ let r: serde_json::Value = serde_json::from_str(&json).expect("report is JSON");++ let skipped = r["skipped_constraints"]+ .as_array()+ .expect("skipped_constraints is an array");+ assert!(+ !skipped.is_empty(),+ "nothing was skipped, so this test inspected no entry and would pass over a report \+ that dropped the shape from every one of them: {r}"+ );++ for entry in skipped {+ let shape = entry["shape"].as_str();+ assert!(+ shape.is_some_and(|s| !s.is_empty()),+ "a skipped_constraints entry carries no shape, so a reader cannot line it up \+ against violations and cannot tell a constraint that did not run from one that \+ ran and selected nothing: {entry}"+ );+ assert!(+ entry["reason"].as_str().is_some_and(|s| !s.is_empty()),+ "a skip with no reason is indistinguishable from a silent drop: {entry}"+ );+ }+}++/// And the verdict is withheld rather than reported as conforming. A skipped+/// constraint that left `conforms: true` behind would be the false clean this+/// whole field exists to prevent.+#[test]+fn a_skipped_constraint_withholds_the_verdict() {+ let graph = Arc::new(GraphStore::new());+ graph.load_turtle(DATA, None).expect("data");+ let json = ShaclValidator::validate(&graph, SHAPES).expect("validate");+ let r: serde_json::Value = serde_json::from_str(&json).expect("report is JSON");+ assert!(+ r["conforms"].is_null(),+ "a run that skipped a constraint must not claim conformance: {r}"+ );+}