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.

fix(studio): never present a vacuous SHACL result as clean

FABIOTESS6cf16e7eb491
diff --git a/studio/src/lib/__tests__/live-source.test.ts b/studio/src/lib/__tests__/live-source.test.ts
index ec6d54cc..8d9b4ca6 100644
--- a/studio/src/lib/__tests__/live-source.test.ts
+++ b/studio/src/lib/__tests__/live-source.test.ts
@@ -98,6 +98,31 @@ describe('LiveSource', () => {
await expect(src.findings()).rejects.toThrow('Cannot read shapes file')
})
+ // src/shacl.rs (~lines 552-567) deliberately returns conforms: null with a
+ // warning when the shapes graph selects zero focus nodes, rather than lying
+ // with conforms: true over nothing. This is precisely the profile-as-
+ // published case this demonstration exists to show. Before this fix,
+ // findings() read only report.violations, defaulted to [], and returned an
+ // empty array here -- rendering as "no findings", indistinguishable from a
+ // real clean pass.
+ it('throws on a vacuous SHACL result (conforms: null) rather than reporting it as clean', async () => {
+ const callTool = vi.fn(async () =>
+ JSON.stringify({
+ conforms: null,
+ violation_count: 0,
+ violations: [],
+ focus_nodes: 0,
+ warning:
+ 'no focus nodes matched: all 34 shape(s) target classes absent from the data, so conformance is undetermined. See unmatched_shapes.',
+ }),
+ )
+ const sparqlQuery = vi.fn(async () => sparqlJson([]))
+ const src = createLiveSource({ sparqlQuery, callTool })
+
+ await expect(src.findings()).rejects.toThrow(/undetermined/i)
+ await expect(src.findings()).rejects.toThrow(/focus node/i)
+ })
+
// corpus_documents is not a real MCP tool, and no Tauri command in
// corpus.rs (corpus_presets, ingest_corpus, read_store, list_graphs,
// read_decisions, revert_type, list_saved, pick_ontology_file) returns
diff --git a/studio/src/lib/live-source.ts b/studio/src/lib/live-source.ts
index b8bd033d..10c35ac0 100644
--- a/studio/src/lib/live-source.ts
+++ b/studio/src/lib/live-source.ts
@@ -63,6 +63,7 @@ interface ShaclReport {
conforms?: boolean | null
violation_count?: number
violations?: ShaclViolation[]
+ focus_nodes?: number
warning?: string
}
@@ -121,6 +122,20 @@ export function createLiveSource(deps: LiveDeps): DemoSource {
if (report.error) {
throw new Error(`SHACL validation failed: ${report.error}`)
}
+ // The engine deliberately reports `conforms: null` (src/shacl.rs, the
+ // block just above `report["conforms"] = serde_json::Value::Null`) when
+ // the shapes graph selects zero focus nodes: reporting `conforms: true`
+ // over nothing checked would be exactly the lie this demonstration
+ // exists to expose, and this is precisely the profile-as-published
+ // case (0 focus nodes). Returning [] here would render as "no
+ // findings" in the panel -- indistinguishable from a genuine clean
+ // pass -- so an undetermined result throws instead of going quiet.
+ if (report.conforms === null || report.conforms === undefined) {
+ throw new Error(
+ `SHACL validation is undetermined, not clean: conforms is null with ` +
+ `${report.focus_nodes ?? 0} focus node(s). ${report.warning ?? 'The shapes graph selected nothing in the data.'}`,
+ )
+ }
const violations = report.violations ?? []
const provenance = rows(await deps.sparqlQuery(PROVENANCE))