From d40e3df17ee588d8678fec8b31f335fb3c8326f9 Mon Sep 17 00:00:00 2001 From: SandroMaglione Date: Wed, 19 Aug 2026 16:09:27 +0200 Subject: [PATCH] Fix Mermaid composite activity labels --- test/machine/MermaidVisualization.test.ts | 16 ++++++++++++++-- test/machine/visualization/mermaid.ts | 13 +++++++++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/test/machine/MermaidVisualization.test.ts b/test/machine/MermaidVisualization.test.ts index c0d543a..feaca1c 100644 --- a/test/machine/MermaidVisualization.test.ts +++ b/test/machine/MermaidVisualization.test.ts @@ -61,7 +61,15 @@ const inspection: InspectionApi = { branches: [{ type: "direct", target: "Root.Route" }] } ], - activityDefinitions: () => [{ source: "Root.Route", id: "worker %%\nend note", type: "process" }], + activityDefinitions: () => [ + { + source: "Root", + id: "search", + type: "machine", + child: { id: "search", machineId: null } + }, + { source: "Root.Route", id: "worker %%\nend note", type: "process" } + ], configuration: () => states.slice(0, 2), enabled: () => ["Continue %%\nnow"] } @@ -74,7 +82,11 @@ describe("Mermaid visualization", () => { assert.notInclude(rendered, "%%") assert.include(rendered, "accTitle: Unsafe #37;#37; Machine") - assert.include(rendered, "state \"● Quoted #quot;root#quot; #37;#37; (Root)\" as state_0") + assert.include( + rendered, + "state \"● Quoted #quot;root#quot; #37;#37; (Root) · machine / search → search\" as state_0" + ) + assert.notInclude(rendered, "state_0: machine / search → search") assert.include(rendered, "state \"● Choose route (Route)\" as state_1") assert.include(rendered, "state state_1 <>") assert.include(rendered, "state_1 --> state_2: choice [approved #37;#37; now]") diff --git a/test/machine/visualization/mermaid.ts b/test/machine/visualization/mermaid.ts index 4104aea..e924774 100644 --- a/test/machine/visualization/mermaid.ts +++ b/test/machine/visualization/mermaid.ts @@ -118,11 +118,17 @@ export const makeMermaidRenderer = ( const id = ids.get(node.path) if (id === undefined) return - lines.push(`${indent(depth)}state "${stateLabel(node, active)}" as ${id}`) const ownedActivities = activities.get(node.path) ?? [] - if (ownedActivities.length > 0) { + const descendants = children.get(node.path) ?? [] + const renderedActivities = ownedActivities.map((activity) => escapeText(activityLabel(activity))).join(" · ") + const label = descendants.length > 0 && renderedActivities.length > 0 + ? `${stateLabel(node, active)} · ${renderedActivities}` + : stateLabel(node, active) + + lines.push(`${indent(depth)}state "${label}" as ${id}`) + if (descendants.length === 0 && renderedActivities.length > 0) { lines.push( - `${indent(depth)}${id}: ${ownedActivities.map((activity) => escapeText(activityLabel(activity))).join(" · ")}` + `${indent(depth)}${id}: ${renderedActivities}` ) } if (node.type === "choice") { @@ -130,7 +136,6 @@ export const makeMermaidRenderer = ( return } - const descendants = children.get(node.path) ?? [] if (descendants.length > 0) { lines.push(`${indent(depth)}state ${id} {`) if (node.type === "parallel") {