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 non-canonical literal reaches sh:value canonicalised because the store keeps it by value, and a test now pins that cause (#335)

FABIOTESS9c2477f17429
diff --git a/tests/shacl_validation_report_test.rs b/tests/shacl_validation_report_test.rs
index 81d0e572..498cc1b4 100644
--- a/tests/shacl_validation_report_test.rs
+++ b/tests/shacl_validation_report_test.rs
@@ -285,6 +285,85 @@ ex:SparqlLevel a sh:NodeShape ; sh:targetClass ex:Person ;
assert_eq!(got, want, "{j}");
}
+/// #335, MEASURED AND NOT FIXED IN THIS REPOSITORY. This test pins the loss
+/// so that it cannot be mistaken for a report-writer bug, and so that it fails,
+/// by name, on the day the store starts keeping lexical forms.
+///
+/// W3C `core/node/maxExclusive-001` and `minExclusive-001` expect
+/// `sh:focusNode 4.0 ; sh:value 4.0`, i.e. `"4.0"^^xsd:decimal`, and the
+/// report says `"4"^^xsd:decimal`, a different RDF term. The cause is the
+/// store, not the validator or the writer: oxigraph 0.5.9 (the pinned fork at
+/// abf36ef adds only `Store::snapshot`) encodes a literal of a datatype it
+/// knows by VALUE (`storage/numeric_encoder.rs`: `parse_decimal_str` ->
+/// `EncodedTerm::DecimalLiteral`, and likewise for integer, boolean, double,
+/// float, dateTime and the rest) and decodes it in canonical form
+/// (`Literal::from(Decimal)`). The lexical form is gone at insert, for the
+/// data graph AND for the shapes graph, which `ShaclValidator` parses into a
+/// store of its own, so `sh:targetNode 4.0` already names `"4"` when the
+/// first query runs.
+///
+/// Nothing in this repository can recover the original term. Two distinct
+/// RDF terms, `"4.0"^^xsd:decimal` and `"4"^^xsd:decimal`, become ONE triple
+/// on load (first block below), so no side table keyed by the stored term can
+/// say which one a result was about. The repair belongs in the store's
+/// literal encoding. The same loss reaches verdicts, not only the report: a
+/// lexical constraint judges the canonical string, so `sh:pattern "\\.0$"`
+/// reports `"4.0"^^xsd:decimal`, whose lexical form matches (last block).
+///
+/// When this test fails because the store kept a lexical form: remove
+/// `maxExclusive-001` and `minExclusive-001` from `KNOWN_DIFFERENCES` in
+/// `tests/shacl_validation_report_w3c_test.rs`, raise its floor, close #335,
+/// and turn these assertions round.
+#[test]
+fn a_non_canonical_literal_is_canonicalised_by_the_store_before_validation_sees_it() {
+ const LOST: &str = "the store kept a lexical form it used to canonicalise: #335 may now be \
+ fixable, see this test's doc comment";
+ let decimal = |lex: &str| format!("\"{lex}\"^^<http://www.w3.org/2001/XMLSchema#decimal>");
+
+ // The store: two distinct terms, one triple, written canonically.
+ let g = Arc::new(GraphStore::new());
+ let added = g
+ .load_turtle(
+ r#"@prefix ex: <http://ex.org/> .
+ @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+ ex:a ex:p "4.0"^^xsd:decimal , "4"^^xsd:decimal ."#,
+ None,
+ )
+ .unwrap();
+ assert_eq!(added, 1, "{LOST}");
+ let nt = g.serialize("ntriples").unwrap();
+ assert!(nt.contains(&decimal("4")) && !nt.contains(&decimal("4.0")), "{LOST}:\n{nt}");
+
+ // sh:value of a data-graph value written "4.0".
+ let data = r#"@prefix ex: <http://ex.org/> .
+ @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+ ex:a a ex:Person ; ex:age "4.0"^^xsd:decimal ."#;
+ let datatype = r#"@prefix sh: <http://www.w3.org/ns/shacl#> .
+ @prefix ex: <http://ex.org/> .
+ @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+ ex:S a sh:NodeShape ; sh:targetClass ex:Person ;
+ sh:property [ sh:path ex:age ; sh:datatype xsd:integer ] ."#;
+ let j = json_report(data, datatype);
+ assert_eq!(value_for(&j, "datatype"), Some(decimal("4")), "{LOST}: {j}");
+
+ // A focus node written "4.0" in the shapes graph, handed in as text.
+ let target = r#"@prefix sh: <http://www.w3.org/ns/shacl#> .
+ @prefix ex: <http://ex.org/> .
+ ex:S a sh:NodeShape ; sh:targetNode 4.0 ; sh:maxExclusive 4 ."#;
+ let j = json_report("@prefix ex: <http://ex.org/> . ex:x ex:y ex:z .", target);
+ assert_eq!(j["violations"][0]["focus_node"], decimal("4"), "{LOST}: {j}");
+ assert_eq!(j["violations"][0]["value"], decimal("4"), "{LOST}: {j}");
+
+ // The verdict consequence. SHACL: STR("4.0"^^xsd:decimal) is "4.0", which
+ // matches, so this conforms. The engine sees "4" and reports it.
+ let pattern = r#"@prefix sh: <http://www.w3.org/ns/shacl#> .
+ @prefix ex: <http://ex.org/> .
+ ex:S a sh:NodeShape ; sh:targetClass ex:Person ;
+ sh:property [ sh:path ex:age ; sh:pattern "\\.0$" ] ."#;
+ let j = json_report(data, pattern);
+ assert_eq!(j["violation_count"], 1, "{LOST}: {j}");
+}
+
// ─────────────────────────────────────────────────────────────────────────────
// The command line
// ─────────────────────────────────────────────────────────────────────────────
diff --git a/tests/shacl_validation_report_w3c_test.rs b/tests/shacl_validation_report_w3c_test.rs
index 37ab8a6b..35066bba 100644
--- a/tests/shacl_validation_report_w3c_test.rs
+++ b/tests/shacl_validation_report_w3c_test.rs
@@ -70,8 +70,12 @@ const KNOWN_DIFFERENCES: [(&str, &str); 7] = [
),
(
"core/node/maxExclusive-001",
- "the store keeps xsd:decimal by value, so the data's \"4.0\"^^xsd:decimal comes back as \
- \"4\"^^xsd:decimal in sh:focusNode and sh:value",
+ "#335, measured: oxigraph encodes a known-datatype literal by value at insert \
+ (numeric_encoder.rs, parse_decimal_str) and decodes it canonically, in the shapes \
+ store as in the data store, so sh:targetNode 4.0 is \"4\"^^xsd:decimal before the \
+ first query runs. Not recoverable here: \"4.0\" and \"4\" load as one triple. Pinned \
+ by a_non_canonical_literal_is_canonicalised_by_the_store_before_validation_sees_it \
+ in tests/shacl_validation_report_test.rs",
),
("core/node/minExclusive-001", "same cause as maxExclusive-001"),
(
diff --git a/tests/w3c_shacl_conformance_test.rs b/tests/w3c_shacl_conformance_test.rs
index 282cecfe..69e9821a 100644
--- a/tests/w3c_shacl_conformance_test.rs
+++ b/tests/w3c_shacl_conformance_test.rs
@@ -69,6 +69,15 @@
//! namespace whole, `severity-002` passes, and the column scores PASS 53
//! (measured 2026-10-28, same suite commit). No test now differs in severity.
//!
+//! One gap this column cannot see by construction (#335). The expected report
+//! is read through `load_graph`, an oxigraph `Store`, which encodes a literal
+//! of a known XSD datatype by value and gives it back canonically, exactly as
+//! the engine's own stores do. So `maxExclusive-001`'s expected
+//! `sh:value 4.0` is read as `"4"^^xsd:decimal`, agrees with the engine's
+//! equally canonicalised answer, and scores PASS here, while
+//! `tests/shacl_validation_report_w3c_test.rs`, which parses the expected
+//! report without a store, holds it as a difference.
+//!
//! 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
//! ("the engine's `severity` field is not yet driven by `sh:severity`") is