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
Two pieces of writing may not sit in the same place (#236)
Fabio Rovai4c420096c47e
diff --git a/docs/assets/knowledge-graph.py b/docs/assets/knowledge-graph.pyindex 8d6d2018..aea878c9 100644--- a/docs/assets/knowledge-graph.py+++ b/docs/assets/knowledge-graph.py@@ -849,8 +849,27 @@ def main(asserted_path, derivations_path, out_path, prove_path=None, mu_path=Nonf'stroke="{C_TOOL}" stroke-width="1.5" stroke-dasharray="4 4"/>')dtxt = "disagreement · stops the line"dw = len(dtxt) * 5.0 + 12- dx, dy = fx0 - dw - 8, fy0 + 4- placed.append((dx - 3, dy - 12, dx + dw + 3, dy + 5))+ # Candidates, like every other badge on this drawing. This one used to take+ # a single computed point, and that point sat on top of the `problem.tsv`+ # label: two pieces of writing, both visible at the same instant, in the+ # same place. Nothing else here places blind, and the overlap guard in+ # `tests/knowledge_graph_asset_test.rs` now refuses the whole asset if one+ # does.+ dcands = [+ (fx0 - dw - 8, fy0 + 4),+ (fx0 - dw - 8, fy0 - 22),+ (fx0 - dw - 8, fy0 + 30),+ (fx0 + 10, fy0 + 30),+ (fx0 - dw / 2, fy0 + 52),+ ]+ dx, dy = dcands[-1]+ for n_, (ccx, ccy) in enumerate(dcands):+ box = (ccx - 3, ccy - 12, ccx + dw + 3, ccy + 5)+ if all(box[2] < o[0] or box[0] > o[2] or box[3] < o[1] or box[1] > o[3]+ for o in placed) or n_ == len(dcands) - 1:+ dx, dy = ccx, ccy+ placed.append(box)+ breakA(f'<rect x="{dx:.1f}" y="{dy - 10:.1f}" width="{dw:.1f}" height="14" rx="7" 'f'fill="#020617" stroke="{C_TOOL}" stroke-width="1" opacity="0.95"/>')A(f'<text x="{dx + dw / 2:.1f}" y="{dy:.1f}" text-anchor="middle" font-size="8.8" 'diff --git a/docs/assets/knowledge-graph.svg b/docs/assets/knowledge-graph.svgindex bdd6d0cd..a537480d 100644--- a/docs/assets/knowledge-graph.svg+++ b/docs/assets/knowledge-graph.svg@@ -336,8 +336,8 @@<path d="M305.3 432.0 Q272.0 432.0 272.0 408.0" fill="none" stroke="#f0abfc" stroke-width="0.9" stroke-dasharray="2 3" opacity="0.8"/><path d="M305.3 480.0 Q272.0 480.0 272.0 408.0" fill="none" stroke="#f0abfc" stroke-width="0.9" stroke-dasharray="2 3" opacity="0.8"/><path d="M272.0 408.0 Q272.0 244.0 196.0 228.7" fill="none" stroke="#f0abfc" stroke-width="1.5" stroke-dasharray="4 4"/>-<rect x="107.0" y="402.0" width="157.0" height="14" rx="7" fill="#020617" stroke="#f0abfc" stroke-width="1" opacity="0.95"/>-<text x="185.5" y="412.0" text-anchor="middle" font-size="8.8" font-weight="700" fill="#f0abfc">disagreement · stops the line</text>+<rect x="107.0" y="428.0" width="157.0" height="14" rx="7" fill="#020617" stroke="#f0abfc" stroke-width="1" opacity="0.95"/>+<text x="185.5" y="438.0" text-anchor="middle" font-size="8.8" font-weight="700" fill="#f0abfc">disagreement · stops the line</text></g><g opacity="0.32"><animate attributeName="opacity" dur="22.0s" repeatCount="indefinite" values="0.32;0.32;1;1;0.32;0.32" keyTimes="0.0000;0.6000;0.6227;0.7545;0.7727;1.0000" calcMode="linear"/><line x1="207.9" y1="209.5" x2="288.9" y2="179.0" stroke="#fb3b53" stroke-width="2.6" stroke-dasharray="7 5"><animate attributeName="stroke-dashoffset" dur="0.9s" repeatCount="indefinite" values="0;-24"/></line>diff --git a/tests/knowledge_graph_asset_test.rs b/tests/knowledge_graph_asset_test.rsindex c0347369..9ae1e64c 100644--- a/tests/knowledge_graph_asset_test.rs+++ b/tests/knowledge_graph_asset_test.rs@@ -617,3 +617,71 @@ fn the_unasked_beat_comes_from_the_mu_run() {// And the question is never drawn as refuted: the two words stay apart.assert!(!s.contains("unasked, refused") && !s.contains("refuted · Accent"));}++/// Two pieces of writing may not sit in the same place.+///+/// Every label and badge on the drawing is a rounded `#020617` rectangle with+/// text over it, placed by a routine that tries a handful of candidate+/// positions and takes the first clear one. One of them did not: the+/// "disagreement · stops the line" badge took a single computed point, and+/// that point landed on the `problem.tsv` label. Both are visible in the same+/// instant, so the drawing showed two sentences through each other, and no+/// test could see it because every number on the page was still correct.+///+/// The rule here is stronger than it has to be: NO two label boxes overlap,+/// even two that are never lit at once. A badge that shares its pixels with+/// another is a badge whose position was not chosen, and the cost of the+/// stricter rule is a few pixels of layout freedom.+#[test]+fn no_two_labels_sit_on_top_of_each_other() {+ let s = svg();+ let mut boxes: Vec<(f64, f64, f64, f64)> = Vec::new();+ let mut at = 0usize;+ while let Some(i) = s[at..].find("<rect x=\"") {+ let start = at + i;+ let Some(end) = s[start..].find("/>") else { break };+ let tag = &s[start..start + end + 2];+ at = start + end + 2;+ // Label chips and badges only: the legend panel and the colour swatches+ // are neither rounded nor this colour.+ if !tag.contains("fill=\"#020617\"") || !tag.contains("rx=\"") {+ continue;+ }+ let num = |k: &str| -> Option<f64> {+ let i = tag.find(&format!("{k}=\""))? + k.len() + 2;+ tag[i..].split('"').next()?.parse().ok()+ };+ if let (Some(x), Some(y), Some(w), Some(h)) =+ (num("x"), num("y"), num("width"), num("height"))+ {+ boxes.push((x, y, x + w, y + h));+ }+ }+ assert!(+ boxes.len() > 20,+ "only {} label boxes were found, so this test is not looking at the labels and \+ cannot fail",+ boxes.len()+ );+ let mut clashes = Vec::new();+ for (i, a) in boxes.iter().enumerate() {+ for b in &boxes[i + 1..] {+ let ix = a.2.min(b.2) - a.0.max(b.0);+ let iy = a.3.min(b.3) - a.1.max(b.1);+ if ix > 0.5 && iy > 0.5 {+ clashes.push(format!(+ " {:?} and {:?} share {ix:.0}x{iy:.0} pixels",+ a, b+ ));+ }+ }+ }+ assert!(+ clashes.is_empty(),+ "{} pair(s) of labels overlap, so the drawing prints two sentences through each \+ other:\n{}\n\nEvery badge is placed by trying candidate positions against \+ `placed`; one that overlaps is one that was placed blind.",+ clashes.len(),+ clashes.join("\n")+ );+}