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 worked example that runs, at the top of the README (#176)
Fabio Rovai307d68f4dcdc
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 99612cf3..f6ed8144 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -438,6 +438,13 @@ jobs:# fact, and it is the reason this job exists rather than being folded# into the line above.run: OO_REQUIRE_FIXTURES=1 cargo test --test lean_horn_certificate_test -- --nocapture+ - name: Check the README animation against the checker it depicts+ # docs/assets/demo-certify.svg draws counts, a verdict word and a+ # theorem name in the first screen of the README, and nothing about an+ # SVG stops those drifting from the code. This re-runs oo-horn over the+ # fixtures the picture is of and compares. It needs lake for the same+ # reason every step above does.+ run: OO_REQUIRE_FIXTURES=1 cargo test --test demo_asset_claims_test -- --nocapture- name: Install the model finders# Z3 reads SMT-LIB and is the only one of the two that can be asked the# UNBOUNDED question, which is the only route to `unsatisfiable_oracle`.diff --git a/README.md b/README.mdindex 5323f219..9b2d2416 100644--- a/README.md+++ b/README.md@@ -58,13 +58,19 @@ that talks to it.## See it in action<p align="center">- <img src="docs/assets/certified-inference.svg" alt="A supplier ontology with asserted and derived edges, and the certificate the run produced" width="100%">+ <img src="https://raw.githubusercontent.com/fabio-rovai/open-ontologies/main/docs/assets/demo-certify.svg" alt="A terminal runs the Lean certificate checker while a supplier graph lights up beside it: three asserted edges in grey, three derived edges in green that the checker accepts, then one conclusion forged and the same checker refusing it in red" width="940"></p>-Four triples in, three out. `ex:Northwind` was only ever asserted to be in a sanctioned+Three triples in, three out. `ex:Northwind` was only ever asserted to be in a sanctionedjurisdiction; that it needs enhanced due diligence was *derived*, and the derivation is checkable bysomeone who does not trust you, your engine, or the model that wrote the ontology.+The last few seconds are the part worth watching. One conclusion is forged, both of its premises are+left exactly as they were, and the same checker refuses it and names the rule. Every line in that+terminal is output `oo-horn` actually printed for the fixtures in+[`tests/fixtures/horn/supplier/`](tests/fixtures/horn/supplier), and a test re-runs the checker and+fails if the picture and the checker ever disagree.+## With a proof, and without oneThe same query, answered by an ordinary reasoner and by this one.diff --git a/docs/assets/certified-inference.svg b/docs/assets/certified-inference.svgdeleted file mode 100644index 8c90a558..00000000--- a/docs/assets/certified-inference.svg+++ /dev/null@@ -1,78 +0,0 @@-<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 760 520" width="760" height="520" font-family="ui-sans-serif,-apple-system,Segoe UI,Roboto,Helvetica,Arial,sans-serif">- <style>- .bg { fill: #0b1020; }- .card { fill: #111827; stroke: #1f2937; stroke-width: 1; }- .cls { fill: #1e293b; stroke: #475569; stroke-width: 1.5; }- .ind { fill: #172554; stroke: #3b82f6; stroke-width: 1.5; }- .lbl { fill: #e5e7eb; font-size: 13px; }- .lblb { fill: #f8fafc; font-size: 13px; font-weight: 600; }- .asserted { stroke: #64748b; stroke-width: 2; fill: none; }- .derived { stroke: #22c55e; stroke-width: 2; fill: none; stroke-dasharray: 6 4; }- .edgelbl { fill: #94a3b8; font-size: 11px; }- .rulelbl { fill: #22c55e; font-size: 11px; font-weight: 700; }- .title { fill: #f8fafc; font-size: 15px; font-weight: 700; }- .sub { fill: #94a3b8; font-size: 11.5px; }- .ok { fill: #22c55e; font-size: 12.5px; font-weight: 700; }- .mono { font-family: ui-monospace,SFMono-Regular,Menlo,monospace; font-size: 11px; fill: #cbd5e1; }- .key { fill: #94a3b8; font-size: 11px; }- </style>-- <rect class="bg" x="0" y="0" width="760" height="520" rx="10"/>-- <text class="title" x="28" y="34">Which suppliers need enhanced due diligence?</text>- <text class="sub" x="28" y="54">Grey edges you asserted. Green edges the engine derived.</text>-- <!-- ── class chain ── -->- <rect class="cls" x="150" y="88" width="196" height="38" rx="8"/>- <text class="lbl" x="166" y="112">ex:SanctionedJurisdiction</text>-- <rect class="cls" x="150" y="188" width="196" height="38" rx="8"/>- <text class="lbl" x="166" y="212">ex:HighRiskSupplier</text>-- <rect class="cls" x="126" y="288" width="244" height="38" rx="8"/>- <text class="lblb" x="142" y="312">ex:NeedsEnhancedDueDiligence</text>-- <!-- ── individual ── -->- <rect class="ind" x="470" y="88" width="136" height="38" rx="8"/>- <text class="lblb" x="488" y="112">ex:Northwind</text>-- <!-- ── asserted ── -->- <path class="asserted" d="M248,126 L248,188" marker-end="url(#grey)"/>- <text class="edgelbl" x="256" y="161">rdfs:subClassOf</text>-- <path class="asserted" d="M248,226 L248,288" marker-end="url(#grey)"/>- <text class="edgelbl" x="256" y="261">rdfs:subClassOf</text>-- <path class="asserted" d="M470,107 L346,107" marker-end="url(#grey)"/>- <text class="edgelbl" x="380" y="99">rdf:type</text>-- <!-- ── derived ── -->- <path class="derived" d="M506,126 C506,160 430,198 350,205" marker-end="url(#green)"/>- <text class="rulelbl" x="418" y="152">rdfs9</text>-- <path class="derived" d="M556,126 C592,230 500,306 376,307" marker-end="url(#green)"/>- <text class="rulelbl" x="494" y="230">rdfs9</text>-- <path class="derived" d="M150,110 C88,142 88,268 122,302" marker-end="url(#green)"/>- <text class="rulelbl" x="36" y="210">rdfs11</text>-- <!-- ── verdict strip ── -->- <rect class="card" x="28" y="362" width="704" height="128" rx="10"/>- <text class="ok" x="50" y="390">✓ certificate accepted</text>- <text class="sub" x="214" y="390">by a Lean 4 proof, not by the engine that produced it</text>-- <text class="mono" x="50" y="420">$ lake exe oo-cert cert/asserted.tsv cert/derivations.tsv</text>- <text class="mono" x="50" y="442">{"ok": true, "asserted": 4, "derivations": 3,</text>- <text class="mono" x="50" y="460"> "theorem": "OOCert.certificate_sound"}</text>-- <text class="key" x="50" y="482">Forge one line and it exits 1, naming the rule that failed and printing its premises.</text>-- <defs>- <marker id="grey" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse">- <path d="M 0 0 L 10 5 L 0 10 z" fill="#64748b"/>- </marker>- <marker id="green" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse">- <path d="M 0 0 L 10 5 L 0 10 z" fill="#22c55e"/>- </marker>- </defs>-</svg>diff --git a/docs/assets/demo-certify.py b/docs/assets/demo-certify.pynew file mode 100644index 00000000..4e93e069--- /dev/null+++ b/docs/assets/demo-certify.py@@ -0,0 +1,150 @@+#!/usr/bin/env python3+"""Regenerate docs/assets/demo-certify.svg.++Run: python3 docs/assets/demo-certify.py docs/assets/demo-certify.svg++A split pane in the manner of a screen recording, but vector and tiny: the+terminal on the left runs the checker, the graph on the right lights up in+step with it. Every line of terminal text is output this repository's Lean+binary actually printed for the certificate in tests, not a mock-up, and the+timings are computed here rather than typed one animate element at a time.+"""+import re++DUR = 22.0+W, H, SPLIT = 940, 430, 370++def k(t): # seconds -> keyTime+ return max(0.0, min(1.0, t / DUR))++def anim(t0, t1=None):+ """Opacity keyframes: invisible, appear at t0, gone again at t1."""+ e = 0.004+ if t1 is None:+ t1 = DUR - 1.0+ a, b = k(t0), k(t1)+ vals = "0;0;1;1;0;0"+ keys = f"0;{a:.4f};{min(a+e,1):.4f};{b:.4f};{min(b+e,1):.4f};1"+ return (f'<animate attributeName="opacity" values="{vals}" keyTimes="{keys}" '+ f'dur="{DUR}s" repeatCount="indefinite"/>')++out = []+A = out.append++A(f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 {W} {H}" width="{W}" height="{H}" '+ f'font-family="ui-monospace,SFMono-Regular,Menlo,Consolas,monospace" role="img" '+ f'aria-label="A terminal runs the Lean certificate checker while a supplier graph lights up: '+ f'three asserted edges in grey, three derived edges in green accepted by the checker, then one '+ f'conclusion forged and the same checker refusing it in red">')++# ---- chrome ----+A('<defs>'+ '<linearGradient id="bg" x1="0" y1="0" x2="1" y2="1">'+ '<stop offset="0" stop-color="#0b1020"/><stop offset="1" stop-color="#0d1526"/></linearGradient>'+ '<marker id="mg" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse">'+ '<path d="M0 0 L10 5 L0 10 z" fill="#64748b"/></marker>'+ '<marker id="mgr" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse">'+ '<path d="M0 0 L10 5 L0 10 z" fill="#34d399"/></marker>'+ '<marker id="mrd" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse">'+ '<path d="M0 0 L10 5 L0 10 z" fill="#fb3b53"/></marker>'+ '</defs>')+A(f'<rect x="1" y="1" width="{W-2}" height="{H-2}" rx="14" fill="url(#bg)" stroke="#1f2937" stroke-width="1.5"/>')+A(f'<line x1="{SPLIT}" y1="16" x2="{SPLIT}" y2="{H-16}" stroke="#1c2534" stroke-width="1"/>')+for i, c in enumerate(('#fb3b53', '#fbbf24', '#34d399')):+ A(f'<circle cx="{26+i*18}" cy="28" r="4.5" fill="{c}"/>')+A('<text x="86" y="32" font-size="10.5" fill="#64748b">oo-horn check</text>')+A(f'<text x="{SPLIT-16}" y="32" text-anchor="end" font-size="9.5" fill="#475569">loops every {int(DUR)}s</text>')+A(f'<text x="{SPLIT+22}" y="32" font-size="10.5" fill="#64748b">the graph it is proving about</text>')++# ---- left: terminal ----+X, Y0, LH, FS = 22, 62, 16.5, 10.5+def line(idx, text, t0, t1=None, fill="#cbd5e1", prompt=False):+ y = Y0 + idx * LH+ body = (f'<tspan fill="#34d399">$ </tspan><tspan fill="{fill}">{text}</tspan>'+ if prompt else f'<tspan fill="{fill}">{text}</tspan>')+ A(f'<text x="{X}" y="{y:.1f}" font-size="{FS}" opacity="0">{body}{anim(t0, t1)}</text>')++ACC_OFF, FORGE_ON = 12.0, 12.4+line(0, 'oo-horn check \\', 0.4, ACC_OFF, prompt=True)+line(1, '  builtin_rules.tsv \\', 0.7, ACC_OFF)+line(2, '  asserted.tsv \\', 1.0, ACC_OFF)+line(3, '  derivations.tsv', 1.3, ACC_OFF)+line(5, '{"ok":true,', 7.6, ACC_OFF, fill="#a7f3d0")+line(6, ' "verdict":"entailed",', 7.9, ACC_OFF, fill="#a7f3d0")+line(7, ' "asserted":3,', 8.2, ACC_OFF, fill="#a7f3d0")+line(8, ' "derivations":3,', 8.5, ACC_OFF, fill="#a7f3d0")+line(9, ' "theorem":', 8.8, ACC_OFF, fill="#a7f3d0")+line(10, '  "OOCert.entails_of_builtin_horn"}', 9.1, ACC_OFF, fill="#a7f3d0")+line(12, 'exit 0', 9.6, ACC_OFF, fill="#34d399")++line(0, '# forge ONE conclusion.', FORGE_ON, prompt=True, fill="#64748b")+line(1, '# leave both premises alone.', 12.7, prompt=True, fill="#64748b")+line(2, 'oo-horn check \\', 13.2, prompt=True)+line(3, '  ... forged.tsv', 13.5)+line(5, '{"ok":false,', 15.2, fill="#fecaca")+line(6, ' "asserted":3,', 15.5, fill="#fecaca")+line(7, ' "derivations":3}', 15.8, fill="#fecaca")+line(9, 'exit 1', 16.2, fill="#fb3b53")+line(11, 'The premises were untouched.', 17.0, fill="#94a3b8")+line(12, 'The conclusion did not follow.', 17.3, fill="#94a3b8")++# ---- right: graph ----+def chip(x, y, label, col, size=10):+ """Edge labels sit on a chip so a line never reads through the text."""+ w = len(re.sub(r"&#[0-9]+;", "-", label)) * 6.0 + 10+ return (f'<rect x="{x-w/2:.1f}" y="{y-11}" width="{w:.1f}" height="15" rx="4" '+ f'fill="#0b1020" opacity="0.92"/>'+ f'<text x="{x}" y="{y}" text-anchor="middle" font-size="{size}" '+ f'font-weight="700" fill="{col}">{label}</text>')++def box(x, y, w, label, t0, kind="cls", t1=None):+ fill, stroke, tc = {"ind": ("#172554", "#3b82f6", "#dbeafe"),+ "bad": ("#3b0710", "#fb3b53", "#fecaca")}.get(+ kind, ("#1e293b", "#475569", "#e2e8f0"))+ A(f'<g opacity="0">{anim(t0, t1)}'+ f'<rect x="{x}" y="{y}" width="{w}" height="32" rx="7" fill="{fill}" stroke="{stroke}" stroke-width="1.5"/>'+ f'<text x="{x+w/2}" y="{y+21}" text-anchor="middle" font-size="11" fill="{tc}">{label}</text></g>')++def edge(d, t0, kind, label=None, lx=0, ly=0, t1=None):+ col, mk, dash = {"a": ("#64748b", "mg", ""),+ "g": ("#34d399", "mgr", ' stroke-dasharray="6 4"'),+ "r": ("#fb3b53", "mrd", ' stroke-dasharray="6 4"')}[kind]+ wdt = 2.8 if kind == "r" else 2+ A(f'<g opacity="0">{anim(t0, t1)}'+ f'<path d="{d}" fill="none" stroke="{col}" stroke-width="{wdt}"{dash} marker-end="url(#{mk})"/>'+ + (chip(lx, ly, label, col) if label else '') + '</g>')++# One column of classes, uniform width, so the right edge is a clean spine.+CX, CW = 436, 252+box(760, 58, 152, 'ex:Northwind', 1.8, kind="ind")+box(CX, 150, CW, 'ex:SanctionedJurisdiction', 2.0)+box(CX, 240, CW, 'ex:HighRiskSupplier', 2.4)+box(CX, 330, CW, 'ex:NeedsEnhancedDueDiligence', 2.8)++# asserted: the type link, then the two subclass steps down the spine+edge('M 757,74 C 700,80 640,108 606,147', 2.2, "a", 'rdf:type', 676, 100)+edge('M 520,182 L 520,238', 2.6, "a", 'rdfs:subClassOf', 520, 215)+edge('M 520,272 L 520,328', 3.0, "a", 'rdfs:subClassOf', 520, 305)++# derived: two concentric arcs down the right, so neither crosses the other+edge('M 832,90 C 800,140 770,196 692,252', 4.0, "g", 'rdfs9', 800, 168)+edge('M 434,166 C 396,214 396,300 432,344', 5.2, "g", 'rdfs11', 400, 258)+edge('M 890,90 C 924,180 900,300 694,344', 6.4, "g", 'rdfs9', 906, 232, t1=14.2)++# the forgery: same premises, a conclusion that does not follow+box(726, 330, 176, 'ex:LowRiskSupplier', 14.2, kind="bad")+edge('M 880,90 C 916,170 900,260 848,326', 14.2, "r", 'rdfs9 refused', 848, 208)++A(f'<g opacity="0">{anim(9.6, ACC_OFF)}'+ '<rect x="430" y="382" width="300" height="30" rx="8" fill="#052e1a" stroke="#34d399" stroke-width="1.5"/>'+ '<text x="580" y="402" text-anchor="middle" font-size="11.5" font-weight="700" fill="#34d399">'+ '✓ certificate accepted by Lean 4</text></g>')+A(f'<g opacity="0">{anim(16.2)}'+ '<rect x="415" y="382" width="330" height="30" rx="8" fill="#3b0710" stroke="#fb3b53" stroke-width="1.5"/>'+ '<text x="580" y="402" text-anchor="middle" font-size="11.5" font-weight="700" fill="#fb3b53">'+ '✗ refused, and it named the rule</text></g>')++A('</svg>')+import pathlib, sys+p = pathlib.Path(sys.argv[1]); p.write_text("\n".join(out))+print(f"wrote {p} ({p.stat().st_size} bytes)")diff --git a/docs/assets/demo-certify.svg b/docs/assets/demo-certify.svgnew file mode 100644index 00000000..2e13bc89--- /dev/null+++ b/docs/assets/demo-certify.svg@@ -0,0 +1,46 @@+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 940 430" width="940" height="430" font-family="ui-monospace,SFMono-Regular,Menlo,Consolas,monospace" role="img" aria-label="A terminal runs the Lean certificate checker while a supplier graph lights up: three asserted edges in grey, three derived edges in green accepted by the checker, then one conclusion forged and the same checker refusing it in red">+<defs><linearGradient id="bg" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#0b1020"/><stop offset="1" stop-color="#0d1526"/></linearGradient><marker id="mg" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"><path d="M0 0 L10 5 L0 10 z" fill="#64748b"/></marker><marker id="mgr" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"><path d="M0 0 L10 5 L0 10 z" fill="#34d399"/></marker><marker id="mrd" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"><path d="M0 0 L10 5 L0 10 z" fill="#fb3b53"/></marker></defs>+<rect x="1" y="1" width="938" height="428" rx="14" fill="url(#bg)" stroke="#1f2937" stroke-width="1.5"/>+<line x1="370" y1="16" x2="370" y2="414" stroke="#1c2534" stroke-width="1"/>+<circle cx="26" cy="28" r="4.5" fill="#fb3b53"/>+<circle cx="44" cy="28" r="4.5" fill="#fbbf24"/>+<circle cx="62" cy="28" r="4.5" fill="#34d399"/>+<text x="86" y="32" font-size="10.5" fill="#64748b">oo-horn check</text>+<text x="354" y="32" text-anchor="end" font-size="9.5" fill="#475569">loops every 22s</text>+<text x="392" y="32" font-size="10.5" fill="#64748b">the graph it is proving about</text>+<text x="22" y="62.0" font-size="10.5" opacity="0"><tspan fill="#34d399">$ </tspan><tspan fill="#cbd5e1">oo-horn check \</tspan><animate attributeName="opacity" values="0;0;1;1;0;0" keyTimes="0;0.0182;0.0222;0.5455;0.5495;1" dur="22.0s" repeatCount="indefinite"/></text>+<text x="22" y="78.5" font-size="10.5" opacity="0"><tspan fill="#cbd5e1">  builtin_rules.tsv \</tspan><animate attributeName="opacity" values="0;0;1;1;0;0" keyTimes="0;0.0318;0.0358;0.5455;0.5495;1" dur="22.0s" repeatCount="indefinite"/></text>+<text x="22" y="95.0" font-size="10.5" opacity="0"><tspan fill="#cbd5e1">  asserted.tsv \</tspan><animate attributeName="opacity" values="0;0;1;1;0;0" keyTimes="0;0.0455;0.0495;0.5455;0.5495;1" dur="22.0s" repeatCount="indefinite"/></text>+<text x="22" y="111.5" font-size="10.5" opacity="0"><tspan fill="#cbd5e1">  derivations.tsv</tspan><animate attributeName="opacity" values="0;0;1;1;0;0" keyTimes="0;0.0591;0.0631;0.5455;0.5495;1" dur="22.0s" repeatCount="indefinite"/></text>+<text x="22" y="144.5" font-size="10.5" opacity="0"><tspan fill="#a7f3d0">{"ok":true,</tspan><animate attributeName="opacity" values="0;0;1;1;0;0" keyTimes="0;0.3455;0.3495;0.5455;0.5495;1" dur="22.0s" repeatCount="indefinite"/></text>+<text x="22" y="161.0" font-size="10.5" opacity="0"><tspan fill="#a7f3d0"> "verdict":"entailed",</tspan><animate attributeName="opacity" values="0;0;1;1;0;0" keyTimes="0;0.3591;0.3631;0.5455;0.5495;1" dur="22.0s" repeatCount="indefinite"/></text>+<text x="22" y="177.5" font-size="10.5" opacity="0"><tspan fill="#a7f3d0"> "asserted":3,</tspan><animate attributeName="opacity" values="0;0;1;1;0;0" keyTimes="0;0.3727;0.3767;0.5455;0.5495;1" dur="22.0s" repeatCount="indefinite"/></text>+<text x="22" y="194.0" font-size="10.5" opacity="0"><tspan fill="#a7f3d0"> "derivations":3,</tspan><animate attributeName="opacity" values="0;0;1;1;0;0" keyTimes="0;0.3864;0.3904;0.5455;0.5495;1" dur="22.0s" repeatCount="indefinite"/></text>+<text x="22" y="210.5" font-size="10.5" opacity="0"><tspan fill="#a7f3d0"> "theorem":</tspan><animate attributeName="opacity" values="0;0;1;1;0;0" keyTimes="0;0.4000;0.4040;0.5455;0.5495;1" dur="22.0s" repeatCount="indefinite"/></text>+<text x="22" y="227.0" font-size="10.5" opacity="0"><tspan fill="#a7f3d0">  "OOCert.entails_of_builtin_horn"}</tspan><animate attributeName="opacity" values="0;0;1;1;0;0" keyTimes="0;0.4136;0.4176;0.5455;0.5495;1" dur="22.0s" repeatCount="indefinite"/></text>+<text x="22" y="260.0" font-size="10.5" opacity="0"><tspan fill="#34d399">exit 0</tspan><animate attributeName="opacity" values="0;0;1;1;0;0" keyTimes="0;0.4364;0.4404;0.5455;0.5495;1" dur="22.0s" repeatCount="indefinite"/></text>+<text x="22" y="62.0" font-size="10.5" opacity="0"><tspan fill="#34d399">$ </tspan><tspan fill="#64748b"># forge ONE conclusion.</tspan><animate attributeName="opacity" values="0;0;1;1;0;0" keyTimes="0;0.5636;0.5676;0.9545;0.9585;1" dur="22.0s" repeatCount="indefinite"/></text>+<text x="22" y="78.5" font-size="10.5" opacity="0"><tspan fill="#34d399">$ </tspan><tspan fill="#64748b"># leave both premises alone.</tspan><animate attributeName="opacity" values="0;0;1;1;0;0" keyTimes="0;0.5773;0.5813;0.9545;0.9585;1" dur="22.0s" repeatCount="indefinite"/></text>+<text x="22" y="95.0" font-size="10.5" opacity="0"><tspan fill="#34d399">$ </tspan><tspan fill="#cbd5e1">oo-horn check \</tspan><animate attributeName="opacity" values="0;0;1;1;0;0" keyTimes="0;0.6000;0.6040;0.9545;0.9585;1" dur="22.0s" repeatCount="indefinite"/></text>+<text x="22" y="111.5" font-size="10.5" opacity="0"><tspan fill="#cbd5e1">  ... forged.tsv</tspan><animate attributeName="opacity" values="0;0;1;1;0;0" keyTimes="0;0.6136;0.6176;0.9545;0.9585;1" dur="22.0s" repeatCount="indefinite"/></text>+<text x="22" y="144.5" font-size="10.5" opacity="0"><tspan fill="#fecaca">{"ok":false,</tspan><animate attributeName="opacity" values="0;0;1;1;0;0" keyTimes="0;0.6909;0.6949;0.9545;0.9585;1" dur="22.0s" repeatCount="indefinite"/></text>+<text x="22" y="161.0" font-size="10.5" opacity="0"><tspan fill="#fecaca"> "asserted":3,</tspan><animate attributeName="opacity" values="0;0;1;1;0;0" keyTimes="0;0.7045;0.7085;0.9545;0.9585;1" dur="22.0s" repeatCount="indefinite"/></text>+<text x="22" y="177.5" font-size="10.5" opacity="0"><tspan fill="#fecaca"> "derivations":3}</tspan><animate attributeName="opacity" values="0;0;1;1;0;0" keyTimes="0;0.7182;0.7222;0.9545;0.9585;1" dur="22.0s" repeatCount="indefinite"/></text>+<text x="22" y="210.5" font-size="10.5" opacity="0"><tspan fill="#fb3b53">exit 1</tspan><animate attributeName="opacity" values="0;0;1;1;0;0" keyTimes="0;0.7364;0.7404;0.9545;0.9585;1" dur="22.0s" repeatCount="indefinite"/></text>+<text x="22" y="243.5" font-size="10.5" opacity="0"><tspan fill="#94a3b8">The premises were untouched.</tspan><animate attributeName="opacity" values="0;0;1;1;0;0" keyTimes="0;0.7727;0.7767;0.9545;0.9585;1" dur="22.0s" repeatCount="indefinite"/></text>+<text x="22" y="260.0" font-size="10.5" opacity="0"><tspan fill="#94a3b8">The conclusion did not follow.</tspan><animate attributeName="opacity" values="0;0;1;1;0;0" keyTimes="0;0.7864;0.7904;0.9545;0.9585;1" dur="22.0s" repeatCount="indefinite"/></text>+<g opacity="0"><animate attributeName="opacity" values="0;0;1;1;0;0" keyTimes="0;0.0818;0.0858;0.9545;0.9585;1" dur="22.0s" repeatCount="indefinite"/><rect x="760" y="58" width="152" height="32" rx="7" fill="#172554" stroke="#3b82f6" stroke-width="1.5"/><text x="836.0" y="79" text-anchor="middle" font-size="11" fill="#dbeafe">ex:Northwind</text></g>+<g opacity="0"><animate attributeName="opacity" values="0;0;1;1;0;0" keyTimes="0;0.0909;0.0949;0.9545;0.9585;1" dur="22.0s" repeatCount="indefinite"/><rect x="436" y="150" width="252" height="32" rx="7" fill="#1e293b" stroke="#475569" stroke-width="1.5"/><text x="562.0" y="171" text-anchor="middle" font-size="11" fill="#e2e8f0">ex:SanctionedJurisdiction</text></g>+<g opacity="0"><animate attributeName="opacity" values="0;0;1;1;0;0" keyTimes="0;0.1091;0.1131;0.9545;0.9585;1" dur="22.0s" repeatCount="indefinite"/><rect x="436" y="240" width="252" height="32" rx="7" fill="#1e293b" stroke="#475569" stroke-width="1.5"/><text x="562.0" y="261" text-anchor="middle" font-size="11" fill="#e2e8f0">ex:HighRiskSupplier</text></g>+<g opacity="0"><animate attributeName="opacity" values="0;0;1;1;0;0" keyTimes="0;0.1273;0.1313;0.9545;0.9585;1" dur="22.0s" repeatCount="indefinite"/><rect x="436" y="330" width="252" height="32" rx="7" fill="#1e293b" stroke="#475569" stroke-width="1.5"/><text x="562.0" y="351" text-anchor="middle" font-size="11" fill="#e2e8f0">ex:NeedsEnhancedDueDiligence</text></g>+<g opacity="0"><animate attributeName="opacity" values="0;0;1;1;0;0" keyTimes="0;0.1000;0.1040;0.9545;0.9585;1" dur="22.0s" repeatCount="indefinite"/><path d="M 757,74 C 700,80 640,108 606,147" fill="none" stroke="#64748b" stroke-width="2" marker-end="url(#mg)"/><rect x="647.0" y="89" width="58.0" height="15" rx="4" fill="#0b1020" opacity="0.92"/><text x="676" y="100" text-anchor="middle" font-size="10" font-weight="700" fill="#64748b">rdf:type</text></g>+<g opacity="0"><animate attributeName="opacity" values="0;0;1;1;0;0" keyTimes="0;0.1182;0.1222;0.9545;0.9585;1" dur="22.0s" repeatCount="indefinite"/><path d="M 520,182 L 520,238" fill="none" stroke="#64748b" stroke-width="2" marker-end="url(#mg)"/><rect x="470.0" y="204" width="100.0" height="15" rx="4" fill="#0b1020" opacity="0.92"/><text x="520" y="215" text-anchor="middle" font-size="10" font-weight="700" fill="#64748b">rdfs:subClassOf</text></g>+<g opacity="0"><animate attributeName="opacity" values="0;0;1;1;0;0" keyTimes="0;0.1364;0.1404;0.9545;0.9585;1" dur="22.0s" repeatCount="indefinite"/><path d="M 520,272 L 520,328" fill="none" stroke="#64748b" stroke-width="2" marker-end="url(#mg)"/><rect x="470.0" y="294" width="100.0" height="15" rx="4" fill="#0b1020" opacity="0.92"/><text x="520" y="305" text-anchor="middle" font-size="10" font-weight="700" fill="#64748b">rdfs:subClassOf</text></g>+<g opacity="0"><animate attributeName="opacity" values="0;0;1;1;0;0" keyTimes="0;0.1818;0.1858;0.9545;0.9585;1" dur="22.0s" repeatCount="indefinite"/><path d="M 832,90 C 800,140 770,196 692,252" fill="none" stroke="#34d399" stroke-width="2" stroke-dasharray="6 4" marker-end="url(#mgr)"/><rect x="780.0" y="157" width="40.0" height="15" rx="4" fill="#0b1020" opacity="0.92"/><text x="800" y="168" text-anchor="middle" font-size="10" font-weight="700" fill="#34d399">rdfs9</text></g>+<g opacity="0"><animate attributeName="opacity" values="0;0;1;1;0;0" keyTimes="0;0.2364;0.2404;0.9545;0.9585;1" dur="22.0s" repeatCount="indefinite"/><path d="M 434,166 C 396,214 396,300 432,344" fill="none" stroke="#34d399" stroke-width="2" stroke-dasharray="6 4" marker-end="url(#mgr)"/><rect x="377.0" y="247" width="46.0" height="15" rx="4" fill="#0b1020" opacity="0.92"/><text x="400" y="258" text-anchor="middle" font-size="10" font-weight="700" fill="#34d399">rdfs11</text></g>+<g opacity="0"><animate attributeName="opacity" values="0;0;1;1;0;0" keyTimes="0;0.2909;0.2949;0.6455;0.6495;1" dur="22.0s" repeatCount="indefinite"/><path d="M 890,90 C 924,180 900,300 694,344" fill="none" stroke="#34d399" stroke-width="2" stroke-dasharray="6 4" marker-end="url(#mgr)"/><rect x="886.0" y="221" width="40.0" height="15" rx="4" fill="#0b1020" opacity="0.92"/><text x="906" y="232" text-anchor="middle" font-size="10" font-weight="700" fill="#34d399">rdfs9</text></g>+<g opacity="0"><animate attributeName="opacity" values="0;0;1;1;0;0" keyTimes="0;0.6455;0.6495;0.9545;0.9585;1" dur="22.0s" repeatCount="indefinite"/><rect x="726" y="330" width="176" height="32" rx="7" fill="#3b0710" stroke="#fb3b53" stroke-width="1.5"/><text x="814.0" y="351" text-anchor="middle" font-size="11" fill="#fecaca">ex:LowRiskSupplier</text></g>+<g opacity="0"><animate attributeName="opacity" values="0;0;1;1;0;0" keyTimes="0;0.6455;0.6495;0.9545;0.9585;1" dur="22.0s" repeatCount="indefinite"/><path d="M 880,90 C 916,170 900,260 848,326" fill="none" stroke="#fb3b53" stroke-width="2.8" stroke-dasharray="6 4" marker-end="url(#mrd)"/><rect x="804.0" y="197" width="88.0" height="15" rx="4" fill="#0b1020" opacity="0.92"/><text x="848" y="208" text-anchor="middle" font-size="10" font-weight="700" fill="#fb3b53">rdfs9 refused</text></g>+<g opacity="0"><animate attributeName="opacity" values="0;0;1;1;0;0" keyTimes="0;0.4364;0.4404;0.5455;0.5495;1" dur="22.0s" repeatCount="indefinite"/><rect x="430" y="382" width="300" height="30" rx="8" fill="#052e1a" stroke="#34d399" stroke-width="1.5"/><text x="580" y="402" text-anchor="middle" font-size="11.5" font-weight="700" fill="#34d399">✓ certificate accepted by Lean 4</text></g>+<g opacity="0"><animate attributeName="opacity" values="0;0;1;1;0;0" keyTimes="0;0.7364;0.7404;0.9545;0.9585;1" dur="22.0s" repeatCount="indefinite"/><rect x="415" y="382" width="330" height="30" rx="8" fill="#3b0710" stroke="#fb3b53" stroke-width="1.5"/><text x="580" y="402" text-anchor="middle" font-size="11.5" font-weight="700" fill="#fb3b53">✗ refused, and it named the rule</text></g>+</svg>\ No newline at end of filediff --git a/docs/ci-gates.md b/docs/ci-gates.mdindex 515f3845..15256389 100644--- a/docs/ci-gates.md+++ b/docs/ci-gates.md@@ -62,6 +62,7 @@ job invokes the file at all.| `lean_refutation_producer_test.rs` | lake + `oo-refute` | `lean` job | **strict** || `lean_mixed_certificate_test.rs` | lake | `lean` job | **strict** || `lean_horn_certificate_test.rs` | lake | `lean` job | **strict** |+| `demo_asset_claims_test.rs` | lake | `lean` job | **strict** || `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** || `lean_projection_entailment_test.rs` | lake | `lean` job | **strict** |diff --git a/tests/demo_asset_claims_test.rs b/tests/demo_asset_claims_test.rsnew file mode 100644index 00000000..11c5ad8c--- /dev/null+++ b/tests/demo_asset_claims_test.rs@@ -0,0 +1,208 @@+//! **The animated asset in the README states the checker's own output.**+//!+//! `docs/assets/demo-certify.svg` shows a terminal printing `"asserted":3`,+//! `"derivations":3`, a theorem name, and then `exit 1` on a forged run. Those+//! are load-bearing claims about this repository, sitting in the first screen+//! a reader sees, and nothing about an SVG stops them drifting away from the+//! code once a fixture or a verdict string changes.+//!+//! So the figures are not trusted here, they are re-derived: the committed+//! fixtures are fed to the same checker the picture depicts, and the numbers+//! it prints must be the numbers drawn. The forged run must fail, because an+//! asset that advertises a refusal while the checker quietly accepts would be+//! worse than no asset at all.+//!+//! The premise test needs no Lean and always runs. The checker test needs a+//! Lean toolchain and skips loudly without one, which the `lean` CI job turns+//! into a failure with `OO_REQUIRE_FIXTURES=1`.++mod common;++use std::path::{Path, PathBuf};+use std::process::Command;++fn repo() -> PathBuf {+ PathBuf::from(env!("CARGO_MANIFEST_DIR"))+}++fn lean_dir() -> PathBuf {+ repo().join("lean")+}++fn fixtures() -> PathBuf {+ repo().join("tests").join("fixtures").join("horn").join("supplier")+}++fn svg() -> String {+ let p = repo().join("docs").join("assets").join("demo-certify.svg");+ std::fs::read_to_string(&p).unwrap_or_else(|e| panic!("read {}: {e}", p.display()))+}++/// Every integer the text writes for `"<key>":`. The asset prints the same+/// count more than once, so this returns all of them and the caller insists+/// they agree.+fn stated(hay: &str, key: &str) -> Vec<u64> {+ let pat = format!("\"{key}\":");+ let mut out = Vec::new();+ let mut i = 0;+ while let Some(p) = hay[i..].find(&pat) {+ let s = i + p + pat.len();+ let digits: String = hay[s..].chars().take_while(|c| c.is_ascii_digit()).collect();+ if !digits.is_empty() {+ out.push(digits.parse().expect("digits parse"));+ }+ i = s;+ }+ out+}++fn rows(path: &Path) -> Vec<Vec<String>> {+ std::fs::read_to_string(path)+ .unwrap_or_else(|e| panic!("read {}: {e}", path.display()))+ .lines()+ .filter(|l| !l.trim().is_empty())+ .map(|l| l.split('\t').map(str::to_string).collect())+ .collect()+}++/// The asset says, in words, "The premises were untouched. The conclusion did+/// not follow." That is the whole argument for why the refusal is interesting:+/// a checker that rejected a certificate whose premises had also been edited+/// would be proving nothing about forged conclusions. So the fixtures have to+/// actually have that shape.+#[test]+fn the_forged_certificate_differs_only_in_a_conclusion() {+ let honest = rows(&fixtures().join("derivations.tsv"));+ let forged = rows(&fixtures().join("forged.tsv"));+ assert_eq!(honest.len(), forged.len(), "the forgery added or dropped a derivation");++ // Layout: 0 rule, 1 binding count, 2..8 bindings, 8..11 conclusion,+ // 11.. premises.+ const CONCLUSION: std::ops::Range<usize> = 8..11;+ const PREMISES_FROM: usize = 11;++ let differing: Vec<usize> = (0..honest.len()).filter(|&i| honest[i] != forged[i]).collect();+ assert_eq!(+ differing.len(),+ 1,+ "exactly one derivation should be forged, {} differ",+ differing.len()+ );++ let i = differing[0];+ assert_ne!(+ honest[i][CONCLUSION], forged[i][CONCLUSION],+ "the forged row must change its conclusion"+ );+ assert_eq!(+ honest[i][PREMISES_FROM..],+ forged[i][PREMISES_FROM..],+ "the forged row must leave its premises exactly as they were, or the \+ refusal shown in the asset would not be about the conclusion"+ );+}++/// The counts drawn in the terminal pane are the counts the checker prints.+#[test]+fn the_asset_states_the_numbers_the_checker_prints() {+ if skip() {+ return;+ }+ let f = fixtures();+ let (ok, accepted) = run(&f.join("derivations.tsv"));+ assert!(ok, "the honest certificate should be accepted:\n{accepted}");++ let art = svg();+ for key in ["asserted", "derivations"] {+ let drawn = stated(&art, key);+ let printed = stated(&accepted, key);+ assert!(!drawn.is_empty(), "the asset draws no \"{key}\" figure any more");+ assert_eq!(printed.len(), 1, "checker printed \"{key}\" {} times", printed.len());+ for d in &drawn {+ assert_eq!(+ *d, printed[0],+ "the asset draws \"{key}\":{d} but the checker printed {}",+ printed[0]+ );+ }+ }++ for fragment in ["\"verdict\":\"entailed\"", "OOCert.entails_of_builtin_horn"] {+ assert!(+ accepted.contains(fragment),+ "the asset shows {fragment}, absent from the checker output:\n{accepted}"+ );+ assert!(art.contains(fragment), "the asset stopped showing {fragment}");+ }+}++/// And the refusal is real. A picture of a rejection is only worth drawing if+/// the checker actually rejects.+#[test]+fn the_asset_shows_a_refusal_the_checker_really_makes() {+ if skip() {+ return;+ }+ let (ok, out) = run(&fixtures().join("forged.tsv"));+ assert!(!ok, "the forged certificate was accepted:\n{out}");+ assert!(out.contains("\"ok\":false"), "expected a refusal, got:\n{out}");++ let art = svg();+ assert!(art.contains("{\"ok\":false"), "the asset stopped showing the refusal");+ assert!(art.contains("exit 1"), "the asset stopped showing the non-zero exit");+}++fn lake_available() -> bool {+ // Run from `lean/`: elan resolves the toolchain from the working+ // directory, and the crate root has no `lean-toolchain` in its ancestry.+ Command::new("lake")+ .arg("--version")+ .current_dir(lean_dir())+ .output()+ .map(|o| o.status.success())+ .unwrap_or(false)+}++fn skip() -> bool {+ common::skip_unless(+ lake_available(),+ "lake (the Lean 4 build tool)",+ "install elan from https://github.com/leanprover/elan; lean/lean-toolchain pins the version",+ )+}++/// Build once, then check the supplier fixtures against the built-in rules.+fn run(derivations: &Path) -> (bool, String) {+ static BUILT: std::sync::OnceLock<PathBuf> = std::sync::OnceLock::new();+ let exe = BUILT.get_or_init(|| {+ let out = Command::new("lake")+ .arg("build")+ .current_dir(lean_dir())+ .output()+ .expect("run lake build");+ assert!(+ out.status.success(),+ "lake build failed:\n{}\n{}",+ String::from_utf8_lossy(&out.stdout),+ String::from_utf8_lossy(&out.stderr)+ );+ let exe = lean_dir().join(".lake").join("build").join("bin").join("oo-horn");+ assert!(exe.exists(), "checker binary missing at {}", exe.display());+ exe+ });+ let out = Command::new(exe)+ .arg("check")+ .arg(repo().join("tests").join("fixtures").join("horn").join("builtin_rules.tsv"))+ .arg(fixtures().join("asserted.tsv"))+ .arg(derivations)+ .output()+ .expect("run oo-horn");+ (+ out.status.success(),+ format!(+ "{}{}",+ String::from_utf8_lossy(&out.stdout),+ String::from_utf8_lossy(&out.stderr)+ ),+ )+}diff --git a/tests/fixtures/horn/supplier/asserted.tsv b/tests/fixtures/horn/supplier/asserted.tsvnew file mode 100644index 00000000..cd542e3f--- /dev/null+++ b/tests/fixtures/horn/supplier/asserted.tsv@@ -0,0 +1,3 @@+<http://ex.org/Northwind> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://ex.org/SanctionedJurisdiction>+<http://ex.org/SanctionedJurisdiction> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://ex.org/HighRiskSupplier>+<http://ex.org/HighRiskSupplier> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://ex.org/NeedsEnhancedDueDiligence>diff --git a/tests/fixtures/horn/supplier/derivations.tsv b/tests/fixtures/horn/supplier/derivations.tsvnew file mode 100644index 00000000..0e1db3a7--- /dev/null+++ b/tests/fixtures/horn/supplier/derivations.tsv@@ -0,0 +1,3 @@+4 3 x <http://ex.org/Northwind> a <http://ex.org/SanctionedJurisdiction> b <http://ex.org/HighRiskSupplier> <http://ex.org/Northwind> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://ex.org/HighRiskSupplier> <http://ex.org/Northwind> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://ex.org/SanctionedJurisdiction> <http://ex.org/SanctionedJurisdiction> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://ex.org/HighRiskSupplier>+5 3 a <http://ex.org/SanctionedJurisdiction> b <http://ex.org/HighRiskSupplier> c <http://ex.org/NeedsEnhancedDueDiligence> <http://ex.org/SanctionedJurisdiction> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://ex.org/NeedsEnhancedDueDiligence> <http://ex.org/SanctionedJurisdiction> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://ex.org/HighRiskSupplier> <http://ex.org/HighRiskSupplier> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://ex.org/NeedsEnhancedDueDiligence>+4 3 x <http://ex.org/Northwind> a <http://ex.org/HighRiskSupplier> b <http://ex.org/NeedsEnhancedDueDiligence> <http://ex.org/Northwind> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://ex.org/NeedsEnhancedDueDiligence> <http://ex.org/Northwind> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://ex.org/HighRiskSupplier> <http://ex.org/HighRiskSupplier> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://ex.org/NeedsEnhancedDueDiligence>diff --git a/tests/fixtures/horn/supplier/forged.tsv b/tests/fixtures/horn/supplier/forged.tsvnew file mode 100644index 00000000..91ff7d89--- /dev/null+++ b/tests/fixtures/horn/supplier/forged.tsv@@ -0,0 +1,3 @@+4 3 x <http://ex.org/Northwind> a <http://ex.org/SanctionedJurisdiction> b <http://ex.org/HighRiskSupplier> <http://ex.org/Northwind> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://ex.org/HighRiskSupplier> <http://ex.org/Northwind> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://ex.org/SanctionedJurisdiction> <http://ex.org/SanctionedJurisdiction> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://ex.org/HighRiskSupplier>+5 3 a <http://ex.org/SanctionedJurisdiction> b <http://ex.org/HighRiskSupplier> c <http://ex.org/NeedsEnhancedDueDiligence> <http://ex.org/SanctionedJurisdiction> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://ex.org/NeedsEnhancedDueDiligence> <http://ex.org/SanctionedJurisdiction> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://ex.org/HighRiskSupplier> <http://ex.org/HighRiskSupplier> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://ex.org/NeedsEnhancedDueDiligence>+4 3 x <http://ex.org/Northwind> a <http://ex.org/HighRiskSupplier> b <http://ex.org/NeedsEnhancedDueDiligence> <http://ex.org/Northwind> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://ex.org/LowRiskSupplier> <http://ex.org/Northwind> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://ex.org/HighRiskSupplier> <http://ex.org/HighRiskSupplier> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://ex.org/NeedsEnhancedDueDiligence>