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: measure sublabel and tag in every renderer (#56)
Calabe K. Davised9e91f6f9ca
diff --git a/archify.zip b/archify.zipindex f69f05bb..4cf93221 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 2e484b97..c44d095d 100644--- a/archify/renderers/architecture/render-architecture.mjs+++ b/archify/renderers/architecture/render-architecture.mjs@@ -1,6 +1,15 @@import path from 'node:path';import { fileURLToPath } from 'node:url';import { esc, renderDefinitions, renderSemanticSigil, textUnits } from '../shared/utils.mjs';+import { availableNodeTextWidth, fittedNodeFontSize, minimumNodeTextWidth } from '../shared/text-fit.mjs';++// Font sizes for this renderer's component text; the fitting geometry is shared.+const componentTextFit = {+ sublabelPreferred: 9,+ sublabelMinimum: 6,+ tagPreferred: 7,+ tagMinimum: 6,+};import { animateAttr, focusEdgeAttrs, focusNodeAttrs, focusNodeTitle, loadDiagram, writeDiagram, svgAccessibleText, svgRootAttrs } from '../shared/cli.mjs';import { componentBox, boundaryBox, connectionPath } from '../shared/layout-report.mjs';import { throwDiagnosticProblems } from '../shared/diagnostics.mjs';@@ -197,7 +206,20 @@ function validateArchitecture() {}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, move detail to sublabel, or widen size.`);+ problems.push(`Label "${c.label}" (~${Math.round(estLabelW)}px) is wider than component "${c.id}" (${c.width}px) — shorten the label or widen size.`);+ }+ // sublabel and tag render as single unwrapped <text> elements; shrink-to-fit+ // handles the ordinary case, this rejects what it cannot rescue.+ const availableTextW = availableNodeTextWidth(c.width);+ for (const [field, value, minimum] of [+ ['Sublabel', c.sublabel, componentTextFit.sublabelMinimum],+ ['Tag', c.tag, componentTextFit.tagMinimum],+ ]) {+ 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.`);+ }}}@@ -616,10 +638,10 @@ function renderComponent(c) {const hasSub = c.sublabel != null && c.sublabel !== '';const labelY = hasSub ? c.y + c.height / 2 - 2 : c.y + c.height / 2 + 4;const sub = hasSub- ? `\n <text data-detail="context" x="${cx}" y="${c.y + c.height / 2 + 14}" class="t-muted" font-size="9" text-anchor="middle">${esc(c.sublabel)}</text>`+ ? `\n <text data-detail="context" x="${cx}" y="${c.y + c.height / 2 + 14}" class="t-muted" font-size="${fittedNodeFontSize(c.sublabel, c.width, componentTextFit.sublabelPreferred, componentTextFit.sublabelMinimum)}" text-anchor="middle">${esc(c.sublabel)}</text>`: '';const tag = c.tag- ? `\n <text data-detail="fine" x="${cx}" y="${c.y + c.height - 8}" class="${accent}" font-size="7" text-anchor="middle">${esc(c.tag)}</text>`+ ? `\n <text data-detail="fine" x="${cx}" y="${c.y + c.height - 8}" class="${accent}" font-size="${fittedNodeFontSize(c.tag, c.width, componentTextFit.tagPreferred, componentTextFit.tagMinimum)}" text-anchor="middle">${esc(c.tag)}</text>`: '';const passport = { kind: c.type, sublabel: c.sublabel, tag: c.tag, context: componentContext(c) };return ` <g ${focusNodeAttrs(c.id, c.label, passport)}>diff --git a/archify/renderers/dataflow/render-dataflow.mjs b/archify/renderers/dataflow/render-dataflow.mjsindex 743d308f..917036f5 100644--- a/archify/renderers/dataflow/render-dataflow.mjs+++ b/archify/renderers/dataflow/render-dataflow.mjs@@ -1,6 +1,15 @@import path from 'node:path';import { fileURLToPath } from 'node:url';import { esc, renderDefinitions, renderSemanticSigil, textUnits } from '../shared/utils.mjs';+import { availableNodeTextWidth, fittedNodeFontSize, minimumNodeTextWidth } from '../shared/text-fit.mjs';++// Font sizes for this renderer's node text; the fitting geometry is shared.+const nodeTextFit = {+ sublabelPreferred: 7,+ sublabelMinimum: 6,+ tagPreferred: 7,+ tagMinimum: 6,+};import { animateAttr, focusEdgeAttrs, focusNodeAttrs, focusNodeTitle, loadDiagram, writeDiagram, svgAccessibleText, svgRootAttrs } from '../shared/cli.mjs';import { throwDiagnosticProblems } from '../shared/diagnostics.mjs';import { resolveLegend, renderLegend as renderResolvedLegend } from '../shared/legend.mjs';@@ -139,7 +148,20 @@ function validateDataflow() {}const estLabelW = textUnits(node.label) * 6.2;if (estLabelW > node.width + 6) {- problems.push(`Label "${node.label}" (~${Math.round(estLabelW)}px) is wider than node "${node.id}" (${node.width}px) — shorten the label, move detail to sublabel, or increase node.width.`);+ problems.push(`Label "${node.label}" (~${Math.round(estLabelW)}px) is wider than node "${node.id}" (${node.width}px) — shorten the label or increase node.width.`);+ }+ // sublabel and tag render as single unwrapped <text> elements; shrink-to-fit+ // handles the ordinary case, this rejects what it cannot rescue.+ const availableTextW = availableNodeTextWidth(node.width);+ for (const [field, value, minimum] of [+ ['Sublabel', node.sublabel, nodeTextFit.sublabelMinimum],+ ['Tag', node.tag, nodeTextFit.tagMinimum],+ ]) {+ 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 node "${node.id}" provides ${availableTextW}px — shorten the ${field.toLowerCase()} or increase node.width.`);+ }}}@@ -324,10 +346,10 @@ function renderNode(node) {const accent = componentText[node.type] || 't-muted';const hasSub = node.sublabel != null && node.sublabel !== '';const sub = hasSub- ? `\n <text data-detail="context" x="${node.cx}" y="${node.y + 37}" class="t-muted" font-size="7" text-anchor="middle">${esc(node.sublabel)}</text>`+ ? `\n <text data-detail="context" x="${node.cx}" y="${node.y + 37}" class="t-muted" font-size="${fittedNodeFontSize(node.sublabel, node.width, nodeTextFit.sublabelPreferred, nodeTextFit.sublabelMinimum)}" text-anchor="middle">${esc(node.sublabel)}</text>`: '';const tag = node.tag- ? `\n <text data-detail="fine" x="${node.cx}" y="${node.y + node.height - 11}" class="${accent}" font-size="7" text-anchor="middle">${esc(node.tag)}</text>`+ ? `\n <text data-detail="fine" x="${node.cx}" y="${node.y + node.height - 11}" class="${accent}" font-size="${fittedNodeFontSize(node.tag, node.width, nodeTextFit.tagPreferred, nodeTextFit.tagMinimum)}" text-anchor="middle">${esc(node.tag)}</text>`: '';const stage = asArray(dataflow.stages)[node.stage];const context = stage ? `${String(node.stage + 1).padStart(2, '0')} / ${stage.label}` : 'Data-flow node';diff --git a/archify/renderers/lifecycle/render-lifecycle.mjs b/archify/renderers/lifecycle/render-lifecycle.mjsindex 1c73934e..31f94896 100644--- a/archify/renderers/lifecycle/render-lifecycle.mjs+++ b/archify/renderers/lifecycle/render-lifecycle.mjs@@ -1,6 +1,15 @@import path from 'node:path';import { fileURLToPath } from 'node:url';import { esc, renderDefinitions, renderSemanticSigil, textUnits } from '../shared/utils.mjs';+import { availableNodeTextWidth, fittedNodeFontSize, minimumNodeTextWidth } from '../shared/text-fit.mjs';++// Font sizes for this renderer's state text; the fitting geometry is shared.+const stateTextFit = {+ sublabelPreferred: 7,+ sublabelMinimum: 6,+ tagPreferred: 7,+ tagMinimum: 6,+};import { animateAttr, focusEdgeAttrs, focusNodeAttrs, focusNodeTitle, loadDiagram, writeDiagram, svgAccessibleText, svgRootAttrs } from '../shared/cli.mjs';import { throwDiagnosticProblems } from '../shared/diagnostics.mjs';import { resolveLegend, renderLegend as renderResolvedLegend } from '../shared/legend.mjs';@@ -177,7 +186,20 @@ function validateLifecycle() {}const estLabelW = textUnits(state.label) * 6.2;if (estLabelW > state.width + 6) {- problems.push(`Label "${state.label}" (~${Math.round(estLabelW)}px) is wider than state "${state.id}" (${state.width}px) — shorten the label, move detail to sublabel, or increase state.width.`);+ problems.push(`Label "${state.label}" (~${Math.round(estLabelW)}px) is wider than state "${state.id}" (${state.width}px) — shorten the label or increase state.width.`);+ }+ // sublabel and tag render as single unwrapped <text> elements; shrink-to-fit+ // handles the ordinary case, this rejects what it cannot rescue.+ const availableTextW = availableNodeTextWidth(state.width);+ for (const [field, value, minimum] of [+ ['Sublabel', state.sublabel, stateTextFit.sublabelMinimum],+ ['Tag', state.tag, stateTextFit.tagMinimum],+ ]) {+ 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 state "${state.id}" provides ${availableTextW}px — shorten the ${field.toLowerCase()} or increase state.width.`);+ }}}@@ -380,10 +402,10 @@ function renderState(state) {const accent = textClass[state.type] || 't-muted';const hasSub = state.sublabel != null && state.sublabel !== '';const sub = hasSub- ? `\n <text data-detail="context" x="${state.cx}" y="${state.y + 37}" class="t-muted" font-size="7" text-anchor="middle">${esc(state.sublabel)}</text>`+ ? `\n <text data-detail="context" x="${state.cx}" y="${state.y + 37}" class="t-muted" font-size="${fittedNodeFontSize(state.sublabel, state.width, stateTextFit.sublabelPreferred, stateTextFit.sublabelMinimum)}" text-anchor="middle">${esc(state.sublabel)}</text>`: '';const tag = state.tag- ? `\n <text data-detail="fine" x="${state.cx}" y="${state.y + state.height - 11}" class="${accent}" font-size="7" text-anchor="middle">${esc(state.tag)}</text>`+ ? `\n <text data-detail="fine" x="${state.cx}" y="${state.y + state.height - 11}" class="${accent}" font-size="${fittedNodeFontSize(state.tag, state.width, stateTextFit.tagPreferred, stateTextFit.tagMinimum)}" text-anchor="middle">${esc(state.tag)}</text>`: '';const step = state.step? `\n <text data-detail="fine" x="${state.x + 10}" y="${state.y + 14}" class="${accent}" font-size="7" font-weight="700">${esc(state.step)}</text>`diff --git a/archify/renderers/sequence/render-sequence.mjs b/archify/renderers/sequence/render-sequence.mjsindex 3f68b542..510a494f 100644--- a/archify/renderers/sequence/render-sequence.mjs+++ b/archify/renderers/sequence/render-sequence.mjs@@ -1,6 +1,15 @@import path from 'node:path';import { fileURLToPath } from 'node:url';import { esc, renderDefinitions, renderSemanticSigil, textUnits } from '../shared/utils.mjs';+import { availableNodeTextWidth, fittedNodeFontSize, minimumNodeTextWidth } from '../shared/text-fit.mjs';++// Font sizes for this renderer's participant text; the fitting geometry is+// shared. Participant boxes are a fixed layout width with no author-facing+// knob, so the only remedy the messages can offer is shorter text.+const participantTextFit = {+ sublabelPreferred: 7,+ sublabelMinimum: 6,+};import { animateAttr, focusEdgeAttrs, focusNodeAttrs, focusNodeTitle, loadDiagram, writeDiagram, svgAccessibleText, svgRootAttrs } from '../shared/cli.mjs';import { throwDiagnosticProblems } from '../shared/diagnostics.mjs';import { resolveLegend, renderLegend as renderResolvedLegend } from '../shared/legend.mjs';@@ -130,7 +139,16 @@ function validateSequence() {for (const participant of participants.values()) {const estLabelW = textUnits(participant.label) * 6.8;if (estLabelW > layout.participantW + 6) {- problems.push(`Label "${participant.label}" (~${Math.round(estLabelW)}px) is wider than the ${layout.participantW}px participant box — shorten it or move detail to sublabel.`);+ problems.push(`Label "${participant.label}" (~${Math.round(estLabelW)}px) is wider than the ${layout.participantW}px participant box — shorten it.`);+ }+ // sublabel renders as a single unwrapped <text>; shrink-to-fit handles the+ // ordinary case, this rejects what it cannot rescue.+ if (participant.sublabel) {+ const availableTextW = availableNodeTextWidth(layout.participantW);+ const minimumW = minimumNodeTextWidth(participant.sublabel, participantTextFit.sublabelMinimum);+ if (minimumW > availableTextW) {+ problems.push(`Sublabel "${participant.sublabel}" needs ~${Math.ceil(minimumW)}px at the ${participantTextFit.sublabelMinimum}px legible minimum, but participant "${participant.id}" provides ${availableTextW}px — shorten the sublabel (participant boxes are a fixed ${layout.participantW}px).`);+ }}}@@ -272,7 +290,7 @@ function renderParticipant(participant) {const fill = componentFill[participant.type] || 'c-external';const hasSub = participant.sublabel != null && participant.sublabel !== '';const sub = hasSub- ? `\n <text data-detail="context" x="${participant.cx}" y="${layout.topY + 39}" class="t-muted" font-size="7" text-anchor="middle">${esc(participant.sublabel)}</text>`+ ? `\n <text data-detail="context" x="${participant.cx}" y="${layout.topY + 39}" class="t-muted" font-size="${fittedNodeFontSize(participant.sublabel, layout.participantW, participantTextFit.sublabelPreferred, participantTextFit.sublabelMinimum)}" text-anchor="middle">${esc(participant.sublabel)}</text>`: '';const passport = { kind: participant.type, sublabel: participant.sublabel, context: 'Sequence participant' };return ` <g ${focusNodeAttrs(participant.id, participant.label, passport)}>diff --git a/archify/renderers/shared/text-fit.mjs b/archify/renderers/shared/text-fit.mjsnew file mode 100644index 00000000..31c0b179--- /dev/null+++ b/archify/renderers/shared/text-fit.mjs@@ -0,0 +1,49 @@+// Single-line node text fitting, shared by every renderer.+//+// Node text (`label`, `sublabel`, `tag`) renders as one <text> element with+// text-anchor="middle" and is never wrapped. Left unmeasured, an over-long+// value silently spills across its neighbours while validation still reports+// a clean receipt — the failure mode this module exists to close.+//+// Two halves, always used together:+// - fittedNodeFontSize shrinks the text toward a legible minimum at render+// time, so ordinary overruns simply get smaller instead of overlapping.+// - minimumNodeTextWidth reports the width the text still needs once it has+// shrunk as far as it may, so validation can reject what shrinking cannot+// save.+//+// The geometry constants below are shared; the per-field `preferred` and+// `minimum` font sizes are not, because renderers set node text at different+// sizes (architecture sublabels are 9px, the rest are 7px).++import { textUnits } from './utils.mjs';++// widthFactor: px of advance width per text unit, per px of font size.+// horizontalPadding: total px reserved inside the box so text never touches+// the border.+export const nodeTextFit = {+ widthFactor: 0.6,+ horizontalPadding: 8,+};++// Largest font size at or below `preferred` that fits `text` inside `width`,+// floored at `minimum` — below that the text is no longer legible and the+// caller should be reporting a problem instead.+export function fittedNodeFontSize(text, width, preferred, minimum) {+ const units = Math.max(1, textUnits(text));+ const available = Math.max(1, width - nodeTextFit.horizontalPadding);+ const fitted = Math.min(preferred, available / (units * nodeTextFit.widthFactor));+ return Math.max(minimum, Math.floor(fitted * 10) / 10);+}++// Width `text` occupies at its legible minimum. Compare against+// `width - nodeTextFit.horizontalPadding` to decide whether shrink-to-fit can+// rescue it.+export function minimumNodeTextWidth(text, minimum) {+ return textUnits(text) * minimum * nodeTextFit.widthFactor;+}++// Available text width inside a box of `width`.+export function availableNodeTextWidth(width) {+ return width - nodeTextFit.horizontalPadding;+}diff --git a/archify/renderers/workflow/render-workflow.mjs b/archify/renderers/workflow/render-workflow.mjsindex 14a1ab7b..8bd2eb7f 100644--- a/archify/renderers/workflow/render-workflow.mjs+++ b/archify/renderers/workflow/render-workflow.mjs@@ -1,6 +1,7 @@import path from 'node:path';import { fileURLToPath } from 'node:url';import { esc, renderDefinitions, renderSemanticSigil, textUnits } from '../shared/utils.mjs';+import { availableNodeTextWidth, fittedNodeFontSize, minimumNodeTextWidth } from '../shared/text-fit.mjs';import { animateAttr, focusEdgeAttrs, focusNodeAttrs, focusNodeTitle, loadDiagram, writeDiagram, svgAccessibleText, svgRootAttrs } from '../shared/cli.mjs';import { throwDiagnosticProblems } from '../shared/diagnostics.mjs';import { resolveLegend, renderLegend as renderResolvedLegend } from '../shared/legend.mjs';@@ -98,26 +99,16 @@ function measureNode(node) {};}+// Font sizes for this renderer's node text; the fitting geometry is shared.const nodeTextFit = {- widthFactor: 0.6,- horizontalPadding: 8,labelPreferred: 11,labelMinimum: 9,sublabelPreferred: 8,sublabelMinimum: 6,+ tagPreferred: 7,+ tagMinimum: 6,};-function fittedNodeFontSize(text, width, preferred, minimum) {- const units = Math.max(1, textUnits(text));- const available = Math.max(1, width - nodeTextFit.horizontalPadding);- const fitted = Math.min(preferred, available / (units * nodeTextFit.widthFactor));- return Math.max(minimum, Math.floor(fitted * 10) / 10);-}--function minimumNodeTextWidth(text, minimum) {- return textUnits(text) * minimum * nodeTextFit.widthFactor;-}-const nodes = new Map(asArray(workflow.nodes).map((node) => [node.id, measureNode(node)]));function workflowCompositionFrames() {@@ -226,13 +217,17 @@ function validateWorkflow() {}const estLabelW = textUnits(node.label) * 6.8;if (estLabelW > node.width + 6) {- problems.push(`Label "${node.label}" (~${Math.round(estLabelW)}px) is wider than node "${node.id}" (${node.width}px) — shorten the label, move detail to sublabel, or increase node.width.`);+ problems.push(`Label "${node.label}" (~${Math.round(estLabelW)}px) is wider than node "${node.id}" (${node.width}px) — shorten the label or increase node.width.`);}- if (node.sublabel) {- const minimumSublabelW = minimumNodeTextWidth(node.sublabel, nodeTextFit.sublabelMinimum);- const availableSublabelW = node.width - nodeTextFit.horizontalPadding;- if (minimumSublabelW > availableSublabelW) {- problems.push(`Sublabel "${node.sublabel}" needs ~${Math.ceil(minimumSublabelW)}px at the ${nodeTextFit.sublabelMinimum}px legible minimum, but node "${node.id}" provides ${availableSublabelW}px — shorten the sublabel or increase node.width.`);+ const availableTextW = availableNodeTextWidth(node.width);+ for (const [field, value, minimum] of [+ ['Sublabel', node.sublabel, nodeTextFit.sublabelMinimum],+ ['Tag', node.tag, nodeTextFit.tagMinimum],+ ]) {+ 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 node "${node.id}" provides ${availableTextW}px — shorten the ${field.toLowerCase()} or increase node.width.`);}}@@ -547,7 +542,7 @@ function renderNode(node) {? `\n <text data-detail="context" x="${node.cx}" y="${node.y + 38}" class="t-muted" font-size="${sublabelFontSize}" text-anchor="middle">${esc(node.sublabel)}</text>`: '';const tag = node.tag- ? `\n <text data-detail="fine" x="${node.cx}" y="${node.y + node.height - 12}" class="${accent}" font-size="7" text-anchor="middle">${esc(node.tag)}</text>`+ ? `\n <text data-detail="fine" x="${node.cx}" y="${node.y + node.height - 12}" class="${accent}" font-size="${fittedNodeFontSize(node.tag, node.width, nodeTextFit.tagPreferred, nodeTextFit.tagMinimum)}" text-anchor="middle">${esc(node.tag)}</text>`: '';const passport = { kind: node.type, sublabel: node.sublabel, tag: node.tag, context: nodeContext(node) };return ` <g ${focusNodeAttrs(node.id, node.label, passport)}>diff --git a/archify/test/layout-rules.test.mjs b/archify/test/layout-rules.test.mjsindex c1c5d815..98355839 100644--- a/archify/test/layout-rules.test.mjs+++ b/archify/test/layout-rules.test.mjs@@ -124,6 +124,35 @@ const CASES = [(d) => { d.components[0].label = 'An Extremely Long Component Label Overflow'; }, ['wider than component', 'shorten the label']],['architecture: component overlap suggests fix', 'architecture',(d) => { d.components[1].pos = [...d.components[0].pos]; }, ['Suggested fix', 'move "']],++ // ---- sublabel/tag fit: the same rule workflow has always had, on the rest ----+ // These fields render as one unwrapped <text> per node. Without a width+ // rule an over-long one passes validation and then paints over its+ // neighbours, so every renderer must reject what shrink-to-fit cannot save.+ ['architecture: component sublabel wider than its legible minimum', 'architecture',+ (d) => { d.components[0].sublabel = 'This supporting sentence is far too long for one architecture component'; },+ ['Sublabel', 'legible', 'widen size']],+ ['architecture: component tag wider than its legible minimum', 'architecture',+ (d) => { d.components[0].tag = 'This tag is far too long to sit inside one architecture component box'; },+ ['Tag', 'legible', 'widen size']],+ ['sequence: participant sublabel wider than its legible minimum', 'sequence',+ (d) => { d.participants[0].sublabel = 'This supporting sentence is far too long for one sequence participant'; },+ ['Sublabel', 'legible', 'shorten the sublabel']],+ ['dataflow: node sublabel wider than its legible minimum', 'dataflow',+ (d) => { d.nodes[0].sublabel = 'This supporting sentence is far too long for one data-flow node box'; },+ ['Sublabel', 'legible', 'increase node.width']],+ ['dataflow: node tag wider than its legible minimum', 'dataflow',+ (d) => { d.nodes[0].tag = 'This tag is far too long to sit inside one data-flow node box'; },+ ['Tag', 'legible', 'increase node.width']],+ ['lifecycle: state sublabel wider than its legible minimum', 'lifecycle',+ (d) => { d.states[0].sublabel = 'This supporting sentence is far too long for one lifecycle state box'; },+ ['Sublabel', 'legible', 'increase state.width']],+ ['lifecycle: state tag wider than its legible minimum', 'lifecycle',+ (d) => { d.states[0].tag = 'This tag is far too long to sit inside one lifecycle state box'; },+ ['Tag', 'legible', 'increase state.width']],+ ['workflow: node tag wider than its legible minimum', 'workflow',+ (d) => { d.nodes[0].tag = 'This tag is far too long to sit inside one workflow node box'; },+ ['Tag', 'legible', 'increase node.width']],];for (const [name, mode, mutate, expected] of CASES) {@@ -139,6 +168,93 @@ for (const [name, mode, mutate, expected] of CASES) {});}+// ---- sublabel/tag shrink-to-fit: the render half of the same rule ----+// Validation only rejects text that cannot fit even at its legible minimum.+// Everything between "fits at the preferred size" and that floor must shrink,+// not overflow — otherwise the common case still paints over its neighbours.+const SHRINK_CASES = [+ // [mode, mutate(doc), preferredFontSize, selector for the sublabel <text>]+ ['architecture', (d) => { d.components[0].sublabel = 'Browser and mobile apps'; }, 9],+ ['sequence', (d) => { d.participants[0].sublabel = 'long browser session'; }, 7],+ ['dataflow', (d) => { d.nodes[0].sublabel = 'browser SDK and mobile SDK'; }, 7],+ ['lifecycle', (d) => { d.states[0].sublabel = 'request accepted and queued'; }, 7],+];++for (const [mode, mutate, preferred] of SHRINK_CASES) {+ test(`${mode}: an over-long sublabel shrinks to fit instead of overflowing`, () => {+ const d = load(mode);+ mutate(d);+ const { code, stderr, outPath } = render(mode, d);+ assert.equal(code, 0, stderr);+ const html = fs.readFileSync(outPath, 'utf8');+ const sub = html.match(/<text data-detail="context"[^>]*font-size="([\d.]+)"[^>]*>/);+ assert.ok(sub, 'expected a sublabel <text> in the rendered SVG');+ const fontSize = Number(sub[1]);+ assert.ok(+ fontSize < preferred,+ `expected the sublabel to shrink below the ${preferred}px preferred size, got ${fontSize}`,+ );+ assert.ok(fontSize >= 6, `expected the sublabel to stay legible, got ${fontSize}`);+ });+}++const TAG_SHRINK_CASES = [+ // [mode, collection, tag, preferredFontSize]+ ['architecture', 'components', 'owner: platform operations team', 7],+ ['dataflow', 'nodes', 'owner: analytics platform', 7],+ ['lifecycle', 'states', 'owner: platform operations pod', 7],+ ['workflow', 'nodes', 'owner: runtime squad A', 7],+];++for (const [mode, collection, tag, preferred] of TAG_SHRINK_CASES) {+ test(`${mode}: an over-long tag shrinks to fit instead of overflowing`, () => {+ const d = load(mode);+ d[collection][0].tag = tag;+ const { code, stderr, outPath } = render(mode, d);+ assert.equal(code, 0, stderr);+ const html = fs.readFileSync(outPath, 'utf8');+ const escapedTag = tag.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');+ const match = html.match(new RegExp(+ `<text data-detail="fine"[^>]*font-size="([\\d.]+)"[^>]*>${escapedTag}</text>`,+ ));+ assert.ok(match, `expected a tag <text> for "${tag}" in the rendered SVG`);+ const fontSize = Number(match[1]);+ assert.ok(+ fontSize < preferred,+ `expected the tag to shrink below the ${preferred}px preferred size, got ${fontSize}`,+ );+ assert.ok(fontSize >= 6, `expected the tag to stay legible, got ${fontSize}`);+ });+}++test('contract: a too-wide label is never redirected into sublabel', () => {+ // Every renderer used to advise "move detail to sublabel" for an over-long+ // label. Sublabels are measured now, so that advice would move the problem+ // rather than fix it.+ const LABELS = {+ workflow: 'An Extremely Long Node Label That Overflows',+ sequence: 'An Extremely Long Participant Label That Overflows',+ dataflow: 'An Extremely Long Node Label That Overflows',+ lifecycle: 'An Extremely Long State Label That Overflows',+ architecture: 'An Extremely Long Component Label Overflow',+ };+ const FIELD = {+ workflow: 'nodes', sequence: 'participants', dataflow: 'nodes',+ lifecycle: 'states', architecture: 'components',+ };+ for (const [mode, label] of Object.entries(LABELS)) {+ const d = load(mode);+ d[FIELD[mode]][0].label = label;+ const { code, stderr } = render(mode, d);+ assert.notEqual(code, 0, `${mode}: expected non-zero exit; stderr:\n${stderr}`);+ assert.ok(stderr.includes('wider than'), `${mode}: expected a width message:\n${stderr}`);+ assert.ok(+ !/move detail to sublabel/.test(stderr),+ `${mode}: label advice still points at the measured sublabel field:\n${stderr}`,+ );+ }+});+// ---- error-message contract: threshold + remediation, not just a path ----test('contract: short-edge message carries both the px minimum and a fix verb', () => {const d = load('workflow');diff --git a/docs/gallery.html b/docs/gallery.htmlindex 795e6572..c178714c 100644--- a/docs/gallery.html+++ b/docs/gallery.html@@ -427,7 +427,7 @@<div class="receipt-cell"><span class="receipt-label">Artifact</span><span class="receipt-value ok">9/9 pass</span></div><div class="receipt-cell"><span class="receipt-label">Composition</span><span class="receipt-value ok" title="0 crossings · 0 border runs · 0 micro segments · 0 cramped turns">SHOWCASE · PASS</span></div><div class="receipt-cell"><span class="receipt-label">Graph</span><span class="receipt-value">10N · 10E</span></div>- <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="16a2c7ca3bab20569b7e4be3893356f2e441d936f8d156b9895c5811d5b4ef7b">16a2c7ca3bab</span></div>+ <div class="receipt-cell"><span class="receipt-label">SHA-256</span><span class="receipt-value" title="e8f3e972360d4bc19d23599e9e1ec66160f1d2e7e0308c80edf601910f4de43d">e8f3e972360d</span></div></div><div class="card-actions"><a class="card-link primary" href="gallery/artifacts/release-delivery.workflow.html?present=1&play=1#view=approval-to-production" target="_blank" rel="noopener" data-en="Play named chapter ↗" data-zh="播放命名章节 ↗">Play named chapter ↗</a>@@ -1010,8 +1010,8 @@ receipt 99 checks / 11 artifacts / deterministic hashes</pre>"engineeringProfile": null,"nodeCount": 10,"edgeCount": 10,- "artifactBytes": 616845,- "artifactSha256": "16a2c7ca3bab20569b7e4be3893356f2e441d936f8d156b9895c5811d5b4ef7b",+ "artifactBytes": 616847,+ "artifactSha256": "e8f3e972360d4bc19d23599e9e1ec66160f1d2e7e0308c80edf601910f4de43d","sourceBytes": 5256,"sourceSha256": "44aa56ac6ca807937dfe84a6404e8b07d6394a38ae2ac53248a1985337dfd671","checks": [diff --git a/docs/gallery/artifacts/release-delivery.workflow.html b/docs/gallery/artifacts/release-delivery.workflow.htmlindex eda0a20a..47959ae3 100644--- a/docs/gallery/artifacts/release-delivery.workflow.html+++ b/docs/gallery/artifacts/release-delivery.workflow.html@@ -4744,7 +4744,7 @@</g><text data-detail-anchor x="500" y="726" class="t-primary" font-size="11" font-weight="600" text-anchor="middle">Rollback</text><text data-detail="context" x="500" y="743" class="t-muted" font-size="6.2" text-anchor="middle">last good image</text>- <text data-detail="fine" x="500" y="761" class="t-messagebus" font-size="7" text-anchor="middle">owner: on-call</text>+ <text data-detail="fine" x="500" y="761" class="t-messagebus" font-size="6.6" text-anchor="middle">owner: on-call</text></g><!-- Edge labels -->diff --git a/docs/gallery/manifest.json b/docs/gallery/manifest.jsonindex 78e65908..d301e249 100644--- a/docs/gallery/manifest.json+++ b/docs/gallery/manifest.json@@ -321,8 +321,8 @@"engineeringProfile": null,"nodeCount": 10,"edgeCount": 10,- "artifactBytes": 616845,- "artifactSha256": "16a2c7ca3bab20569b7e4be3893356f2e441d936f8d156b9895c5811d5b4ef7b",+ "artifactBytes": 616847,+ "artifactSha256": "e8f3e972360d4bc19d23599e9e1ec66160f1d2e7e0308c80edf601910f4de43d","sourceBytes": 5256,"sourceSha256": "44aa56ac6ca807937dfe84a6404e8b07d6394a38ae2ac53248a1985337dfd671","checks": [