Turn any idea, plan, or codebase into a beautiful interactive diagram. An agent skill for Claude Code, Codex, and more.
HTML agent-skillsai-agentsarchitecture-diagramclaude-codeclaude-skillscodexcoding-agentsdeepseek-harnessdeveloper-toolsdiagramsdiagrams-as-codedsh-pluginflowchartllmmermaidopencodesequence-diagramsoftware-architecturesystem-designvisualization
fix(architecture): report component-level diagnostics as structured repairs
zhanhuangchao8bd2d5f7a565
diff --git a/archify.zip b/archify.zipindex d3da6b28..c475887b 100644Binary files a/archify.zip and b/archify.zip differdiff --git a/archify/renderers/architecture/render-architecture.mjs b/archify/renderers/architecture/render-architecture.mjsindex 243d424e..c2039061 100644--- a/archify/renderers/architecture/render-architecture.mjs+++ b/archify/renderers/architecture/render-architecture.mjs@@ -28,6 +28,7 @@ import {cleanLabelRouteClearanceProblems,cleanLabelCanvasContainmentProblems,suggestLabelObstacleFix,+ componentSeparationOptions,suggestComponentSeparation,polylinePath,routePointsValue,@@ -486,19 +487,80 @@ function validateArchitecture() {for (const c of components.values()) {if (!isFinitePoint(c.x, c.y, c.width, c.height)) {- problems.push(`Component "${c.id}" has non-finite pos/size — pos and size must be [number, number].`);+ const message = `Component "${c.id}" has non-finite pos/size — pos and size must be [number, number].`;+ diagnostics.push({+ code: 'architecture/non-finite-component-geometry', severity: 'error', message,+ subject: { diagramType: 'architecture', nodeId: c.id },+ evidence: { pos: c.pos ?? null, size: [c.width, c.height] },+ supportedFixes: [`replace component "${c.id}" pos and size with finite [number, number] values`],+ });+ problems.push(message);continue;}if (c.width <= 0 || c.height <= 0) {- problems.push(`Component "${c.id}" has invalid size ${c.width}x${c.height} — width and height must be greater than 0.`);+ const message = `Component "${c.id}" has invalid size ${c.width}x${c.height} — width and height must be greater than 0.`;+ diagnostics.push({+ code: 'architecture/invalid-component-size', severity: 'error', message,+ subject: { diagramType: 'architecture', nodeId: c.id },+ evidence: { width: c.width, height: c.height },+ supportedFixes: [`set component "${c.id}" width and height to values greater than 0`],+ });+ problems.push(message);continue;}if (c.x < 0 || c.y < 0 || c.x + c.width > viewBox[0] || c.y + c.height > viewBox[1]) {- problems.push(`Component "${c.id}" falls outside the viewBox ${viewBox[0]}x${viewBox[1]} — adjust pos/size or set a larger meta.viewBox.`);+ const message = `Component "${c.id}" falls outside the viewBox ${viewBox[0]}x${viewBox[1]} — adjust pos/size or set a larger meta.viewBox.`;+ const overflow = {+ left: Math.max(0, -c.x),+ top: Math.max(0, -c.y),+ right: Math.max(0, c.x + c.width - viewBox[0]),+ bottom: Math.max(0, c.y + c.height - viewBox[1]),+ };+ const widerThanCanvas = overflow.left > 0 && overflow.right > 0;+ const tallerThanCanvas = overflow.top > 0 && overflow.bottom > 0;+ const supportedFixes = [];+ // Move by exactly the overflow: it lands the edge flush (x + (-x) is exact+ // in IEEE 754), while a rounded-up move pushes the opposite edge past a+ // tight canvas and a rounded-down one leaves the overflow in place. When+ // the component is larger than the canvas, the move must shrink it too.+ if (overflow.left > 0) {+ const shrink = Math.max(0, c.width - viewBox[0]);+ supportedFixes.push(shrink > 0+ ? `move component "${c.id}" right by ${overflow.left}px and shrink its width by at least ${shrink}px`+ : `move component "${c.id}" right by ${overflow.left}px`);+ }+ if (overflow.top > 0) {+ const shrink = Math.max(0, c.height - viewBox[1]);+ supportedFixes.push(shrink > 0+ ? `move component "${c.id}" down by ${overflow.top}px and shrink its height by at least ${shrink}px`+ : `move component "${c.id}" down by ${overflow.top}px`);+ }+ if ((overflow.right > 0 && !widerThanCanvas) || (overflow.bottom > 0 && !tallerThanCanvas)) {+ const coveredWidth = overflow.right > 0 && !widerThanCanvas ? Math.ceil(c.x + c.width) : viewBox[0];+ const coveredHeight = overflow.bottom > 0 && !tallerThanCanvas ? Math.ceil(c.y + c.height) : viewBox[1];+ supportedFixes.push(`set meta.viewBox to at least [${Math.max(viewBox[0], coveredWidth)}, ${Math.max(viewBox[1], coveredHeight)}]`);+ }+ diagnostics.push({+ code: 'layout/component-out-of-bounds', severity: 'error', message,+ subject: { diagramType: 'architecture', nodeId: c.id },+ evidence: { bounds: componentBox(c), viewBox: [...viewBox], overflow },+ supportedFixes,+ });+ problems.push(message);}const estLabelW = textUnits(c.label) * 6.6;if (estLabelW > c.width + 8) {- problems.push(`Label "${c.label}" (~${Math.round(estLabelW)}px) is wider than component "${c.id}" (${c.width}px) — shorten the label or widen size.`);+ const message = `Label "${c.label}" (~${Math.round(estLabelW)}px) is wider than component "${c.id}" (${c.width}px) — shorten the label or widen size.`;+ diagnostics.push({+ code: 'architecture/component-label-overflow', severity: 'error', message,+ subject: { diagramType: 'architecture', nodeId: c.id },+ evidence: { text: c.label, estimatedWidthPx: Math.round(estLabelW), availableWidthPx: c.width },+ supportedFixes: [+ `shorten component "${c.id}" label "${c.label}" while preserving its meaning`,+ `or widen component "${c.id}" to at least ${Math.ceil(estLabelW - 8)}px`,+ ],+ });+ problems.push(message);}const brandRailProblem = brandTopRailProblem(c, c.width, 8, 'Component');if (brandRailProblem) problems.push(brandRailProblem);@@ -512,7 +574,18 @@ function validateArchitecture() {if (!value) continue;const minimumW = minimumNodeTextWidth(value, minimum);if (minimumW > availableTextW) {- problems.push(`${field} "${value}" needs ~${Math.ceil(minimumW)}px at the ${minimum}px legible minimum, but component "${c.id}" provides ${availableTextW}px — shorten the ${field.toLowerCase()} or widen size.`);+ const fieldKey = field.toLowerCase();+ const message = `${field} "${value}" needs ~${Math.ceil(minimumW)}px at the ${minimum}px legible minimum, but component "${c.id}" provides ${availableTextW}px — shorten the ${fieldKey} or widen size.`;+ diagnostics.push({+ code: `architecture/component-${fieldKey}-overflow`, severity: 'error', message,+ subject: { diagramType: 'architecture', nodeId: c.id },+ evidence: { text: value, minimumFontPx: minimum, requiredWidthPx: Math.ceil(minimumW), availableWidthPx: availableTextW },+ supportedFixes: [+ `shorten component "${c.id}" ${fieldKey} "${value}" while preserving its meaning`,+ `or widen component "${c.id}" so the ${fieldKey} keeps at least ${Math.ceil(minimumW)}px of text width at the ${minimum}px legible minimum`,+ ],+ });+ problems.push(message);}}}@@ -522,7 +595,19 @@ function validateArchitecture() {for (let i = 0; i < list.length; i += 1) {for (let j = i + 1; j < list.length; j += 1) {if (rectsOverlap(list[i], list[j], 8)) {- problems.push(`Components "${list[i].id}" and "${list[j].id}" are less than 8px apart — move one or shrink its size.\n${suggestComponentSeparation(list[i], list[j], 8)}`);+ const separation = componentSeparationOptions(list[i], list[j], 8);+ const message = `Components "${list[i].id}" and "${list[j].id}" are less than 8px apart — move one or shrink its size.\n${suggestComponentSeparation(list[i], list[j], 8)}`;+ diagnostics.push({+ code: 'layout/component-overlap', severity: 'error', message,+ subject: { diagramType: 'architecture', nodeId: list[i].id },+ evidence: { otherId: list[j].id, minimumGapPx: 8, boxes: [componentBox(list[i]), componentBox(list[j])] },+ supportedFixes: [+ `move component "${list[j].id}" pos to [${separation[0].pos[0]}, ${separation[0].pos[1]}] (${separation[0].relation})`,+ `or move component "${list[j].id}" pos to [${separation[1].pos[0]}, ${separation[1].pos[1]}] (${separation[1].relation})`,+ `or shrink "${list[i].id}" or "${list[j].id}" while keeping every label and sublabel readable`,+ ],+ });+ problems.push(message);}}}diff --git a/archify/renderers/shared/geometry.mjs b/archify/renderers/shared/geometry.mjsindex 20850751..e5fe5f6e 100644--- a/archify/renderers/shared/geometry.mjs+++ b/archify/renderers/shared/geometry.mjs@@ -1952,12 +1952,26 @@ export function suggestLabelPairFix(a, b) {].join('\n');}+/**+ * The two placements that separate b from a, in the order the prose hint+ * offers them. Shared so the text hint and its structured repair cannot+ * offer different coordinates.+ */+export function componentSeparationOptions(a, b, minGap = 8) {+ // Ceil, not round: on fractional geometry a rounded right/below coordinate+ // can land a fraction of a pixel short of minGap, and the advised position+ // would never clear the diagnostic that offered it.+ return [+ { pos: [Math.ceil(a.x + a.width + minGap), Math.round(b.y)], relation: `right of "${a.id}"` },+ { pos: [Math.round(b.x), Math.ceil(a.y + a.height + minGap)], relation: 'below' },+ ];+}+/** Hint when two components/nodes are too close. */export function suggestComponentSeparation(a, b, minGap = 8) {- const rightX = Math.round(a.x + a.width + minGap);- const belowY = Math.round(a.y + a.height + minGap);+ const [right, below] = componentSeparationOptions(a, b, minGap);return [` "${a.id}" ${formatRect(a)}; "${b.id}" ${formatRect(b)}`,- ` Suggested fix: move "${b.id}" pos to [${rightX}, ${Math.round(b.y)}] (right of "${a.id}") or [${Math.round(b.x)}, ${belowY}] (below)`,+ ` Suggested fix: move "${b.id}" pos to [${right.pos[0]}, ${right.pos[1]}] (${right.relation}) or [${below.pos[0]}, ${below.pos[1]}] (${below.relation})`,].join('\n');}diff --git a/benchmarks/repair-rounds/defects.mjs b/benchmarks/repair-rounds/defects.mjsindex e63a42ff..e2081b75 100644--- a/benchmarks/repair-rounds/defects.mjs+++ b/benchmarks/repair-rounds/defects.mjs@@ -77,7 +77,7 @@ export const DEFECTS = {},'node-long-label': {appliesTo: ALL_TYPES,- expectedCodes: { default: ['layout/constraint'] },+ expectedCodes: { architecture: ['architecture/component-label-overflow'], default: ['layout/constraint'] },inject(doc, { type, nodeIndex } = {}) {const nodes = doc[COLLECTIONS[type].nodes];const node = nodeAt(doc, type, nodeIndex);diff --git a/benchmarks/repair-rounds/repairs.mjs b/benchmarks/repair-rounds/repairs.mjsindex 61f9421a..a9bfdd36 100644--- a/benchmarks/repair-rounds/repairs.mjs+++ b/benchmarks/repair-rounds/repairs.mjs@@ -84,7 +84,9 @@ const RULES = [},{// "Label "X" (~475px) is wider than component "users" (120px)"- match: (diagnostic) => diagnostic.code === 'layout/constraint'+ // Architecture reports this failure as architecture/component-label-overflow;+ // every other renderer still classifies it as layout/constraint.+ match: (diagnostic) => (diagnostic.code === 'layout/constraint' || diagnostic.code === 'architecture/component-label-overflow')&& /Label "(.+)" \(~[\d.]+px\) is wider than component "([^"]+)" \(([\d.]+)px\)/.test(diagnostic.message || ''),apply(diagnostic, doc, context) {const match = diagnostic.message.match(/Label "(.+)" \(~([\d.]+)px\) is wider than component "([^"]+)" \(([\d.]+)px\)/);diff --git a/test/architecture-component-diagnostics.test.mjs b/test/architecture-component-diagnostics.test.mjsnew file mode 100644index 00000000..49091e12--- /dev/null+++ b/test/architecture-component-diagnostics.test.mjs@@ -0,0 +1,269 @@+import assert from 'node:assert/strict';+import { spawnSync } from 'node:child_process';+import fs from 'node:fs';+import os from 'node:os';+import path from 'node:path';+import test from 'node:test';+import { fileURLToPath } from 'node:url';++const root = fileURLToPath(new URL('../archify/', import.meta.url));+const cli = path.join(root, 'bin/archify.mjs');++// Component-level failures are the highest-traffic hand-placement mistakes.+// Their messages already carried the repair; these tests pin the structured+// fields the authoring contract tells agents to consume, and prove the offered+// repairs clear the diagnostics they belong to.+function setup(t, components, viewBox = [640, 360]) {+ const cwd = fs.mkdtempSync(path.join(os.tmpdir(), 'archify-component-diagnostics-'));+ t.after(() => fs.rmSync(cwd, { recursive: true, force: true }));+ const input = path.join(cwd, 'source.json');+ const diagram = {+ schema_version: 1,+ diagram_type: 'architecture',+ meta: { title: 'Component diagnostics', output: 'diagram.html', quality_profile: 'standard', viewBox },+ components,+ connections: [],+ };+ fs.writeFileSync(input, JSON.stringify(diagram, null, 2));+ return { cwd, input, diagram };+}++function validate(input, cwd) {+ const result = spawnSync(process.execPath, [cli, 'validate', 'architecture', input, '--json'], { cwd, encoding: 'utf8' });+ assert.equal(result.stderr, '', result.stderr);+ return JSON.parse(result.stdout);+}++function rewrite(input, diagram) {+ fs.writeFileSync(input, JSON.stringify(diagram, null, 2));+}++const handPlacedFixture = () => [+ { id: 'left', type: 'backend', label: 'Left', pos: [40, 40], size: [200, 80] },+ { id: 'right', type: 'backend', label: 'Right', pos: [244, 40], size: [200, 80] },+ { id: 'outside', type: 'database', label: 'Outside', pos: [520, 300], size: [200, 80] },+ { id: 'narrow', type: 'backend', label: 'A Deliberately Long Label', pos: [40, 180], size: [56, 80], sublabel: 'A very long sublabel that cannot possibly fit' },+];++test('component-level failures carry structured, actionable diagnostics', t => {+ const { cwd, input } = setup(t, handPlacedFixture());+ const receipt = validate(input, cwd);+ assert.equal(receipt.ok, false);+ const byCode = new Map(receipt.diagnostics.map(d => [d.code, d]));++ const outOfBounds = byCode.get('layout/component-out-of-bounds');+ assert.ok(outOfBounds, 'an out-of-bounds component reports a typed diagnostic');+ assert.deepEqual(outOfBounds.subject, { diagramType: 'architecture', nodeId: 'outside' });+ assert.equal(outOfBounds.evidence.bounds.id, 'outside');+ assert.equal(outOfBounds.evidence.overflow.right, 80);+ assert.equal(outOfBounds.evidence.overflow.bottom, 20);+ assert.ok(outOfBounds.supportedFixes.includes('set meta.viewBox to at least [720, 380]'));++ const overlap = byCode.get('layout/component-overlap');+ assert.ok(overlap, 'components under 8px apart report a typed diagnostic');+ assert.deepEqual(overlap.subject, { diagramType: 'architecture', nodeId: 'left' });+ assert.equal(overlap.evidence.otherId, 'right');+ assert.equal(overlap.evidence.minimumGapPx, 8);+ assert.deepEqual(overlap.evidence.boxes.map(b => b.id), ['left', 'right']);+ assert.equal(overlap.supportedFixes[0], 'move component "right" pos to [248, 40] (right of "left")');+ // The prose hint and the structured placements must offer the same coordinates.+ const hinted = [...overlap.message.matchAll(/\[(\d+), (\d+)\]/g)].map(m => `${m[1]},${m[2]}`);+ const offered = [0, 1].map(i => overlap.supportedFixes[i].match(/\[(\d+), (\d+)\]/).slice(1).join(','));+ assert.deepEqual(hinted, offered);++ const label = byCode.get('architecture/component-label-overflow');+ assert.ok(label, 'an over-wide label reports a typed diagnostic');+ assert.equal(label.subject.nodeId, 'narrow');+ assert.equal(label.evidence.availableWidthPx, 56);+ assert.ok(label.supportedFixes[1].startsWith('or widen component "narrow" to at least '));++ const sublabel = byCode.get('architecture/component-sublabel-overflow');+ assert.ok(sublabel, 'an unreadable sublabel reports a typed diagnostic');+ assert.equal(sublabel.evidence.minimumFontPx, 6);+ assert.equal(sublabel.evidence.availableWidthPx, 48);++ // The untyped default would mean a component-level failure lost its fields.+ assert.ok(!receipt.diagnostics.some(d => d.code === 'layout/constraint'));+});++test('the offered repairs clear their own diagnostics', t => {+ const { cwd, input, diagram } = setup(t, handPlacedFixture());+ const receipt = validate(input, cwd);+ const overlap = receipt.diagnostics.find(d => d.code === 'layout/component-overlap');+ const outOfBounds = receipt.diagnostics.find(d => d.code === 'layout/component-out-of-bounds');+ const narrow = diagram.components.find(c => c.id === 'narrow');++ const move = overlap.supportedFixes[0].match(/pos to \[(\d+), (\d+)\]/);+ assert.ok(move, overlap.supportedFixes[0]);+ diagram.components.find(c => c.id === 'right').pos = [Number(move[1]), Number(move[2])];++ const viewBoxFix = outOfBounds.supportedFixes.find(f => /meta\.viewBox to at least/.test(f));+ const box = viewBoxFix.match(/\[(\d+), (\d+)\]/);+ assert.ok(box, viewBoxFix);+ diagram.meta.viewBox = [Number(box[1]), Number(box[2])];++ // The label/sublabel fixes offer "shorten or widen"; apply the shorten branch.+ narrow.label = 'Narrow';+ narrow.sublabel = 'fits';++ rewrite(input, diagram);+ const repaired = validate(input, cwd);+ assert.equal(repaired.ok, true, JSON.stringify(repaired.diagnostics));+});++test('tag overflow reports and its widen fix clears it', t => {+ const { cwd, input, diagram } = setup(t, [+ { id: 'narrow', type: 'backend', label: 'Narrow', pos: [40, 40], size: [56, 80], tag: 'A very long tag value' },+ ]);+ const receipt = validate(input, cwd);+ const tag = receipt.diagnostics.find(d => d.code === 'architecture/component-tag-overflow');+ assert.ok(tag, JSON.stringify(receipt.diagnostics.map(d => d.code)));+ assert.equal(tag.evidence.minimumFontPx, 6);+ assert.equal(tag.evidence.availableWidthPx, 48);+ assert.ok(!receipt.diagnostics.some(d => d.code === 'layout/constraint'));+ const widen = tag.supportedFixes[1].match(/tag keeps at least (\d+)px of text width/);+ assert.ok(widen, tag.supportedFixes[1]);+ // The advised text width plus the renderer's horizontal padding, read back+ // from evidence so a padding retune cannot break this test spuriously.+ const horizontalPadding = 56 - tag.evidence.availableWidthPx;+ diagram.components[0].size = [Number(widen[1]) + horizontalPadding, 80];+ rewrite(input, diagram);+ assert.equal(validate(input, cwd).ok, true);+});++test('the label widen branch clears the label diagnostic', t => {+ const { cwd, input, diagram } = setup(t, [+ { id: 'narrow', type: 'backend', label: 'A Deliberately Long Label', pos: [40, 40], size: [56, 80] },+ ]);+ const label = validate(input, cwd).diagnostics.find(d => d.code === 'architecture/component-label-overflow');+ const widen = label.supportedFixes[1].match(/widen component "narrow" to at least (\d+)px/);+ assert.ok(widen, label.supportedFixes[1]);+ diagram.components[0].size = [Number(widen[1]), 80];+ rewrite(input, diagram);+ assert.equal(validate(input, cwd).ok, true);+});++test('the second overlap placement clears the overlap diagnostic', t => {+ const { cwd, input, diagram } = setup(t, [+ { id: 'left', type: 'backend', label: 'Left', pos: [40, 40], size: [200, 80] },+ { id: 'right', type: 'backend', label: 'Right', pos: [244, 40], size: [200, 80] },+ ]);+ const overlap = validate(input, cwd).diagnostics.find(d => d.code === 'layout/component-overlap');+ const below = overlap.supportedFixes[1].match(/pos to \[(\d+), (\d+)\]/);+ assert.ok(below, overlap.supportedFixes[1]);+ diagram.components[1].pos = [Number(below[1]), Number(below[2])];+ rewrite(input, diagram);+ assert.equal(validate(input, cwd).ok, true);+});++test('several components of the same failure kind keep distinct subjects', t => {+ const { cwd, input } = setup(t, [+ { id: 'a', type: 'backend', label: 'A', pos: [40, 40], size: [200, 80] },+ { id: 'b', type: 'backend', label: 'B', pos: [244, 40], size: [200, 80] },+ { id: 'c', type: 'backend', label: 'C', pos: [448, 40], size: [200, 80] },+ { id: 'd', type: 'database', label: 'D', pos: [520, 300], size: [200, 80] },+ { id: 'e', type: 'database', label: 'E', pos: [760, 300], size: [200, 80] },+ ]);+ const receipt = validate(input, cwd);+ const bounds = receipt.diagnostics.filter(d => d.code === 'layout/component-out-of-bounds');+ assert.deepEqual(bounds.map(d => d.subject.nodeId).sort(), ['c', 'd', 'e']);+ const overlaps = receipt.diagnostics.filter(d => d.code === 'layout/component-overlap');+ assert.deepEqual(overlaps.map(d => `${d.subject.nodeId},${d.evidence.otherId}`).sort(), ['a,b', 'b,c']);+ assert.ok(!receipt.diagnostics.some(d => d.code === 'layout/constraint'));+});++test('left/top overflow offers a directional move instead of a viewBox enlargement', t => {+ const { cwd, input, diagram } = setup(t, [+ { id: 'neg', type: 'backend', label: 'Neg', pos: [-40, -20], size: [120, 60] },+ ]);+ const receipt = validate(input, cwd);+ const outOfBounds = receipt.diagnostics.find(d => d.code === 'layout/component-out-of-bounds');+ assert.equal(outOfBounds.evidence.overflow.left, 40);+ assert.equal(outOfBounds.evidence.overflow.top, 20);+ // Enlarging the viewBox cannot fix left/top overflow; only a move can.+ assert.deepEqual(outOfBounds.supportedFixes, [+ 'move component "neg" right by 40px',+ 'move component "neg" down by 20px',+ ]);+ const right = outOfBounds.supportedFixes[0].match(/right by ([\d.]+)px/);+ const down = outOfBounds.supportedFixes[1].match(/down by ([\d.]+)px/);+ assert.ok(right && down, JSON.stringify(outOfBounds.supportedFixes));+ diagram.components[0].pos = [-40 + Number(right[1]), -20 + Number(down[1])];+ rewrite(input, diagram);+ assert.equal(validate(input, cwd).ok, true);+});++test('fractional geometry gets a separation coordinate that clears the minimum gap', t => {+ const { cwd, input, diagram } = setup(t, [+ { id: 'a', type: 'backend', label: 'A', pos: [10.4, 10], size: [10, 20] },+ { id: 'b', type: 'backend', label: 'B', pos: [21, 10], size: [10, 20] },+ ], [400, 260]);+ const overlap = validate(input, cwd).diagnostics.find(d => d.code === 'layout/component-overlap');+ assert.ok(overlap, 'fractional coordinates still report the overlap');+ const move = overlap.supportedFixes[0].match(/pos to \[(\d+), (\d+)\]/);+ assert.ok(move, overlap.supportedFixes[0]);+ diagram.components[1].pos = [Number(move[1]), Number(move[2])];+ rewrite(input, diagram);+ assert.equal(validate(input, cwd).ok, true, 'a rounded-away fraction must not leave the gap under 8px');+});++test('a component wider than the canvas gets a repair that also shrinks it', t => {+ const { cwd, input, diagram } = setup(t, [+ { id: 'wide', type: 'backend', label: 'Wide', pos: [-50, 40], size: [800, 80] },+ ]);+ const outOfBounds = validate(input, cwd).diagnostics.find(d => d.code === 'layout/component-out-of-bounds');+ assert.equal(outOfBounds.evidence.overflow.left, 50);+ assert.equal(outOfBounds.evidence.overflow.right, 110);+ const fixText = outOfBounds.supportedFixes.join(' ');+ const move = fixText.match(/right by ([\d.]+)px/);+ const shrink = fixText.match(/shrink its width by at least ([\d.]+)px/);+ assert.ok(move && shrink, fixText);+ diagram.components[0].pos = [-50 + Number(move[1]), 40];+ diagram.components[0].size = [800 - Number(shrink[1]), 80];+ rewrite(input, diagram);+ assert.equal(validate(input, cwd).ok, true, 'the only offered repair must clear its own diagnostic');+});++test('a fractional edge overflow moves by the exact overflow, not a rounded pixel', t => {+ const { cwd, input, diagram } = setup(t, [+ { id: 'frac', type: 'backend', label: 'F', pos: [-10.44, 20], size: [320, 40] },+ ], [320, 240]);+ const outOfBounds = validate(input, cwd).diagnostics.find(d => d.code === 'layout/component-out-of-bounds');+ assert.equal(outOfBounds.evidence.overflow.left, 10.44);+ const move = outOfBounds.supportedFixes[0].match(/right by ([\d.]+)px/);+ assert.ok(move, outOfBounds.supportedFixes[0]);+ // Exact, not rounded to any decimal grid: a rounded-down move leaves the+ // overflow in place and a rounded-up one pushes the flush edge over.+ assert.equal(Number(move[1]), outOfBounds.evidence.overflow.left);+ diagram.components[0].pos = [-10.44 + Number(move[1]), 20];+ rewrite(input, diagram);+ assert.equal(validate(input, cwd).ok, true);+});++test('grid components without placement report typed geometry instead of the untyped default', t => {+ const { cwd, input } = setup(t, [{ id: 'x', type: 'backend', label: 'X' }]);+ const diagram = JSON.parse(fs.readFileSync(input, 'utf8'));+ diagram.layout = { mode: 'grid', cols: 4 };+ rewrite(input, diagram);+ const receipt = validate(input, cwd);+ const geometry = receipt.diagnostics.find(d => d.code === 'architecture/non-finite-component-geometry');+ assert.ok(geometry, JSON.stringify(receipt.diagnostics.map(d => d.code)));+ assert.equal(geometry.subject.nodeId, 'x');+ assert.deepEqual(geometry.evidence, { pos: null, size: [120, 60] });+ assert.ok(geometry.supportedFixes.length > 0);+});++test('a component taller than the canvas gets a repair that also shrinks its height', t => {+ const { cwd, input, diagram } = setup(t, [+ { id: 'tall', type: 'backend', label: 'T', pos: [40, -20], size: [120, 800] },+ ]);+ const outOfBounds = validate(input, cwd).diagnostics.find(d => d.code === 'layout/component-out-of-bounds');+ const fixText = outOfBounds.supportedFixes.join(' ');+ const move = fixText.match(/down by ([\d.]+)px/);+ const shrink = fixText.match(/shrink its height by at least ([\d.]+)px/);+ assert.ok(move && shrink, fixText);+ diagram.components[0].pos = [40, -20 + Number(move[1])];+ diagram.components[0].size = [120, 800 - Number(shrink[1])];+ rewrite(input, diagram);+ assert.equal(validate(input, cwd).ok, true);+});diff --git a/test/render-failure-diagnostics.test.mjs b/test/render-failure-diagnostics.test.mjsindex 0110440a..7347d513 100644--- a/test/render-failure-diagnostics.test.mjs+++ b/test/render-failure-diagnostics.test.mjs@@ -113,7 +113,7 @@ test('render layout rejection exposes the existing diagnostic and preserves an e}));fs.writeFileSync(output, 'trusted artifact');const result = run([cli, 'render', 'architecture', input, output], cwd);- assertHumanFailure(result, 'layout/constraint');+ assertHumanFailure(result, 'architecture/component-label-overflow');assert.match(result.stderr, /shorten the label or widen size/);assert.equal(fs.readFileSync(output, 'utf8'), 'trusted artifact');for (const command of ['validate', 'deliver']) {@@ -121,8 +121,8 @@ test('render layout rejection exposes the existing diagnostic and preserves an eassert.equal(machine.status, 1);assert.equal(machine.stderr, '');const failure = JSON.parse(machine.stdout);- assert.equal(failure.diagnostics[0].code, 'layout/constraint');- assert.deepEqual(failure.diagnostics[0].subject, { diagramType: 'architecture' });+ assert.equal(failure.diagnostics[0].code, 'architecture/component-label-overflow');+ assert.deepEqual(failure.diagnostics[0].subject, { diagramType: 'architecture', nodeId: 'node' });}assert.equal(fs.readFileSync(output, 'utf8'), 'trusted artifact');});