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
A custom sh:severity keeps its namespace in the JSON report (#334)
FABIOTESS033a6d720891
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 2be5fde6..4dbaaf4d 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -939,8 +939,9 @@ jobs:# and no named PASS may regress against tests/w3c_shacl_baseline.json, in each# of two columns: the (focus, source shape, component) set, 61 of 120 PASS on# 24 Oct 2026, and the full tuple with path, value and severity as a multiset,- # 52 of 120 on 28 Oct 2026 (#319; 12 before #318 put sh:value on default-path- # results, 51 before #333 fixed the sh:or datatype false negative).+ # 53 of 120 on 28 Oct 2026 (#319; 12 before #318 put sh:value on default-path+ # results, 51 before #333 fixed the sh:or datatype false negative, 52 before+ # #334 kept a custom severity's namespace).# Pretending otherwise would be exactly the silent success# this repository keeps finding elsewhere. See the module docs in# tests/w3c_shacl_conformance_test.rs.diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 11bc9a6e..5a4c59f6 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -46,6 +46,16 @@ All notable changes to Open Ontologies are documented here.### Fixed+- **A custom `sh:severity` keeps its namespace in the JSON report** (#334).+ Every path set `severity` to the text after the last `#` of the declared+ IRI, and every reader takes a bare name as `sh:`, so W3C+ `core/misc/severity-002`'s `ex:MySeverity` read back as `sh:MySeverity`+ (one in a slash namespace survived whole only because it has no `#`).+ `sh:Violation`, `sh:Warning` and `sh:Info` are still `"Violation"`,+ `"Warning"` and `"Info"`; any IRI outside the SHACL namespace is now written+ whole, on node-shape, property-shape, qualified and `sh:sparql` results. The+ RDF report already wrote the declared term. W3C full-tuple column 52 to 53+ PASS; gated column unchanged at 61.- **A value that is not a well-typed literal of D no longer satisfies a`sh:datatype D` test anywhere in the SHACL engine** (#333). The test wasspliced as `DATATYPE(?v) = <D>`, a SPARQL type error for an IRI or blankdiff --git a/src/shacl.rs b/src/shacl.rsindex 7421015e..5101b805 100644--- a/src/shacl.rs+++ b/src/shacl.rs@@ -529,10 +529,7 @@ impl ShaclValidator {let pick = |k: &str| own.iter().find(|(p, _)| p == k).map(|(_, v)| v.clone());let own_message = pick("message").map(|m| strip_quotes(&m)).unwrap_or_default();let own_severity = pick("severity")- .map(|s| {- let s = strip_angle_brackets(&s);- s.rsplit('#').next().unwrap_or("Violation").to_string()- })+ .map(|s| severity_name(&s)).unwrap_or_else(|| "Violation".to_string());let own_flags = pick("flags").map(|f| strip_quotes(&f));let own_rdf = RdfTerms::new(@@ -1180,13 +1177,7 @@ impl ShaclValidator {let q_message = row.get("message").map(|m| strip_quotes(m)).unwrap_or_default();let q_severity = row.get("severity")- .map(|s| {- strip_angle_brackets(s)- .rsplit('#')- .next()- .unwrap_or("Violation")- .to_string()- })+ .map(|s| severity_name(s)).unwrap_or_else(|| "Violation".to_string());let q_rdf = RdfTerms::new(row.get("severity").cloned(),@@ -1345,10 +1336,7 @@ impl ShaclValidator {// sh:severity, defaulting to sh:Violation per the SHACL spec.let severity = prop.get("severity")- .map(|s| {- let s = strip_angle_brackets(s);- s.rsplit('#').next().unwrap_or("Violation").to_string()- })+ .map(|s| severity_name(s)).unwrap_or_else(|| "Violation".to_string());let rdf = RdfTerms::new(prop.get("severity").cloned(),@@ -2090,13 +2078,7 @@ impl ShaclValidator {.unwrap_or_default();let severity = constraint.get("severity")- .map(|s| {- strip_angle_brackets(s)- .rsplit('#')- .next()- .unwrap_or("Violation")- .to_string()- })+ .map(|s| severity_name(s)).unwrap_or_else(|| "Violation".to_string());// SHACL-SPARQL 5.3.2: `$this` is pre-bound to the focus node,@@ -3231,12 +3213,11 @@ fn attribute(/// store printed them, for the RDF report and for nothing else.////// The JSON report keeps a reduced form of both and cannot be changed without-/// breaking its readers: `severity` is the IRI's local name and `message` is-/// the literal's lexical value. Neither reduction is reversible. W3C-/// `core/misc/severity-002` declares `sh:severity ex:MySeverity`, which the-/// JSON carries as `"MySeverity"` and a writer reading it back can only guess-/// the namespace of; `core/misc/message-001` declares `"Test message"@en`, and-/// the language tag is gone. SHACL 3.6.2 makes `sh:resultSeverity` the shape's+/// breaking its readers: `severity` is [`severity_name`], the local name for+/// SHACL's own severities and the full IRI for any other, and `message` is+/// the literal's lexical value. The message reduction is not reversible:+/// `core/misc/message-001` declares `"Test message"@en`, and the language tag+/// is gone. SHACL 3.6.2 makes `sh:resultSeverity` the shape's/// `sh:severity` and `sh:resultMessage` a copy of its `sh:message`, so the/// writer needs the terms as written. They travel inside each violation under/// [`crate::shacl_report::RDF_TERMS_KEY`] and the JSON renderer removes them.@@ -3333,6 +3314,26 @@ fn lexical_space_regex(datatype: &str) -> Option<String> {Some(re.replace('\\', "\\\\"))}+/// The JSON `severity` of a declared `sh:severity` term: the local name for+/// an IRI in the SHACL namespace (`"Violation"`, `"Warning"`, `"Info"`, which+/// existing readers match on), and the full IRI for any other.+///+/// Every path used to take the text after the last `#` (#334). That is+/// reversible only if the reader knows the namespace, and the readers,+/// `tests/w3c_shacl_conformance_test.rs` and `tools/shacl_differential.py`,+/// read a bare name as `sh:`. So W3C `core/misc/severity-002`'s+/// `ex:MySeverity`, in a hash namespace, came back as `sh:MySeverity`, a+/// different severity, while one in a slash namespace survived whole by+/// accident of where the cut fell. Both readers already take a name+/// containing `:` as a full IRI, so they now read every severity exactly.+fn severity_name(raw: &str) -> String {+ let iri = strip_angle_brackets(raw);+ match iri.strip_prefix("http://www.w3.org/ns/shacl#") {+ Some(local) => local.to_string(),+ None => iri,+ }+}+/// `<http://www.w3.org/ns/shacl#class>` -> `class`, for the node-level rows.fn short_sh(pred: &str) -> String {strip_angle_brackets(pred).rsplit('#').next().unwrap_or_default().to_string()diff --git a/tests/shacl_validation_report_test.rs b/tests/shacl_validation_report_test.rsindex dd011228..81d0e572 100644--- a/tests/shacl_validation_report_test.rs+++ b/tests/shacl_validation_report_test.rs@@ -211,7 +211,9 @@ ex:S a sh:NodeShape ; sh:targetClass ex:Nobody ;#[test]fn a_custom_severity_iri_and_a_language_tag_survive_into_the_graph() {- // The JSON keeps `"MySeverity"` and `"Too old"`; the graph needs the terms.+ // The JSON keeps `"Too old"` without its tag; the graph needs the terms.+ // The severity is outside the SHACL namespace, so the JSON carries its+ // full IRI (#334) rather than a local name read back as `sh:MySeverity`.let shapes = r#"@prefix sh: <http://www.w3.org/ns/shacl#> .@prefix ex: <http://ex.org/> .@@ -222,7 +224,7 @@ ex:S a sh:NodeShape ; sh:targetClass ex:Person ;sh:severity sev:MySeverity ; sh:message "Too old"@en ] ."#;let j = json_report(DATA, shapes);- assert_eq!(j["violations"][0]["severity"], "MySeverity", "{j}");+ assert_eq!(j["violations"][0]["severity"], "http://ex.org/sev#MySeverity", "{j}");assert_eq!(j["violations"][0]["message"], "Too old", "{j}");let s = parsed(&rdf_report(DATA, shapes, ReportFormat::Turtle), RdfFormat::Turtle);assert!(ask(@@ -231,6 +233,58 @@ ex:S a sh:NodeShape ; sh:targetClass ex:Person ;));}+/// #334, W3C `core/misc/severity-002`. The JSON `severity` was `sh:severity`+/// cut after its last `#` on every path, so a custom severity in a hash+/// namespace came out as `"MySeverity"` and every reader, the W3C full-tuple+/// comparison included, had to guess its namespace and guessed `sh:`. (One in+/// a slash namespace survived whole, by accident of where the cut fell.) The+/// three SHACL severities keep their local name, which is what existing+/// readers match on; any other IRI is carried whole. Checked on each path that+/// reads `sh:severity`: a node shape's own constraint, a property shape, a+/// qualified shape and `sh:sparql`.+#[test]+fn a_custom_severity_keeps_its_namespace_in_the_json_on_every_path() {+ let shapes = r#"+@prefix sh: <http://www.w3.org/ns/shacl#> .+@prefix ex: <http://ex.org/> .+@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .+@prefix sev: <http://ex.org/sev#> .+ex:NodeLevel a sh:NodeShape ; sh:targetNode ex:alice ;+ sh:nodeKind sh:BlankNode ; sh:severity sev:MySeverity .+ex:PropLevel a sh:NodeShape ; sh:targetClass ex:Person ;+ sh:property [ sh:path ex:age ; sh:datatype xsd:integer ; sh:severity sev:MySeverity ] ;+ sh:property [ sh:path ex:home ; sh:nodeKind sh:IRI ; sh:severity sh:Warning ] ;+ sh:property [ sh:path ex:code ; sh:pattern "^[0-9]+$" ] ;+ sh:property [ sh:path ex:knows ; sh:qualifiedValueShape [ sh:class ex:Person ] ;+ sh:qualifiedMinCount 1 ; sh:severity sev:MySeverity ] .+ex:SparqlLevel a sh:NodeShape ; sh:targetClass ex:Person ;+ sh:sparql [ sh:severity sev:MySeverity ;+ sh:select "SELECT $this WHERE { $this <http://ex.org/home> ?h }" ] .+"#;+ let j = json_report(DATA, shapes);+ let mut got: Vec<(String, String)> = j["violations"]+ .as_array()+ .unwrap()+ .iter()+ .map(|v| (v["constraint"].as_str().unwrap().to_string(), v["severity"].as_str().unwrap().to_string()))+ .collect();+ got.sort();+ let custom = "http://ex.org/sev#MySeverity";+ let mut want: Vec<(String, String)> = [+ ("datatype", custom),+ ("nodeKind", custom),+ ("nodeKind", "Warning"),+ ("pattern", "Violation"),+ ("qualifiedMinCount", custom),+ ("sparql", custom),+ ]+ .iter()+ .map(|(c, s)| (c.to_string(), s.to_string()))+ .collect();+ want.sort();+ assert_eq!(got, want, "{j}");+}+// ─────────────────────────────────────────────────────────────────────────────// The command line// ─────────────────────────────────────────────────────────────────────────────diff --git a/tests/w3c_shacl_baseline.json b/tests/w3c_shacl_baseline.jsonindex d5504050..af6372a5 100644--- a/tests/w3c_shacl_baseline.json+++ b/tests/w3c_shacl_baseline.json@@ -134,8 +134,8 @@"full_tuple": {"counts": {"total": 120,- "pass": 52,- "fail": 24,+ "pass": 53,+ "fail": 23,"undetermined": 44,"error": 0},@@ -146,7 +146,7 @@"core/misc/deactivated-002": "PASS","core/misc/message-001": "PASS","core/misc/severity-001": "PASS",- "core/misc/severity-002": "FAIL",+ "core/misc/severity-002": "PASS","core/node/and-001": "UNDETERMINED","core/node/and-002": "UNDETERMINED","core/node/class-001": "PASS",diff --git a/tests/w3c_shacl_conformance_test.rs b/tests/w3c_shacl_conformance_test.rsindex 88e3f0c0..282cecfe 100644--- a/tests/w3c_shacl_conformance_test.rs+++ b/tests/w3c_shacl_conformance_test.rs@@ -65,6 +65,9 @@//! With #333 fixed, `or-datatypes-001` reports all three of its violations//! (an IRI value and an ill-typed `"none"^^xsd:boolean` had been dropped) and//! the column scores PASS 52 (measured 2026-10-28, same suite commit).+//! With #334 fixed, the JSON `severity` carries any IRI outside the SHACL+//! namespace whole, `severity-002` passes, and the column scores PASS 53+//! (measured 2026-10-28, same suite commit). No test now differs in severity.//!//! Severity is in the full-tuple column and NOT in the gated one, by//! measurement rather than by principle. The old reason for leaving it out@@ -73,6 +76,8 @@//! gated key drops that column from 61 to 60 PASS (`severity-002` above), and//! the gated column is a ratchet in a required check. The defect is held by//! the full-tuple column's ratchet instead, where fixing it shows as a gain.+//! #334 fixed it, and it showed as that gain. Moving severity into the gated+//! key is a separate decision and is not made here.//!//! IGNORED by both columns, each for a stated reason//! * `sh:resultMessage`. The suite itself only compares messages that thediff --git a/tools/shacl_differential.py b/tools/shacl_differential.pyindex 12c38451..9ff39bad 100644--- a/tools/shacl_differential.py+++ b/tools/shacl_differential.py@@ -155,8 +155,9 @@ def shape_key(parent, path):def severity_iri(s):- """The engine reports the local name of sh:severity; read a bare name as- being in the SHACL namespace, as tests/w3c_shacl_conformance_test.rs does."""+ """The engine reports SHACL's own severities by local name and any other+ sh:severity as its full IRI (#334); read a bare name as being in the SHACL+ namespace, as tests/w3c_shacl_conformance_test.rs does."""if not s:return Nonereturn s if ":" in s else SH + s