@zyro-sec/merman 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/package.json +2 -2
  2. package/script/layout-audit.ts +98 -98
  3. package/src/core/canvas.ts +228 -228
  4. package/src/core/color/style.ts +56 -56
  5. package/src/core/drawing.ts +301 -301
  6. package/src/core/geometry.ts +347 -347
  7. package/src/core/mermaid.ts +38 -38
  8. package/src/core/render-grid.ts +51 -51
  9. package/src/core/spatial.ts +243 -243
  10. package/src/core/text-lines.ts +32 -32
  11. package/src/core/text.ts +44 -44
  12. package/src/detect.ts +17 -17
  13. package/src/diagnostics.ts +16 -16
  14. package/src/flowchart/drawing.ts +340 -340
  15. package/src/flowchart/labels.ts +144 -144
  16. package/src/flowchart/layout.ts +1427 -1427
  17. package/src/flowchart/options.ts +12 -12
  18. package/src/flowchart/parser.ts +467 -467
  19. package/src/flowchart/render.ts +10 -10
  20. package/src/flowchart/routing.ts +1542 -1542
  21. package/src/flowchart/style.ts +79 -79
  22. package/src/flowchart/types.ts +65 -65
  23. package/src/gantt/diagram.ts +8 -8
  24. package/src/gantt/drawing.ts +191 -191
  25. package/src/gantt/parser.ts +161 -161
  26. package/src/gantt/render-grid.ts +17 -17
  27. package/src/gantt/style.ts +36 -36
  28. package/src/gantt/types.ts +44 -44
  29. package/src/gitgraph/diagram.ts +8 -8
  30. package/src/gitgraph/drawing.ts +234 -234
  31. package/src/gitgraph/parser.ts +219 -219
  32. package/src/gitgraph/render-grid.ts +17 -17
  33. package/src/gitgraph/style.ts +37 -37
  34. package/src/gitgraph/types.ts +36 -36
  35. package/src/markdown.ts +336 -336
  36. package/src/palette.ts +75 -75
  37. package/src/plugin.ts +15 -15
  38. package/src/sequence/diagram.ts +8 -8
  39. package/src/sequence/drawing.ts +287 -287
  40. package/src/sequence/options.ts +8 -8
  41. package/src/sequence/parser.ts +282 -282
  42. package/src/sequence/placement.ts +684 -684
  43. package/src/sequence/render-grid.ts +22 -22
  44. package/src/sequence/style.ts +81 -81
  45. package/src/sequence/types.ts +74 -74
  46. package/src/state/diagram.ts +8 -8
  47. package/src/state/drawing.ts +360 -360
  48. package/src/state/endpoint.ts +15 -15
  49. package/src/state/layout.ts +1134 -1134
  50. package/src/state/note.ts +59 -59
  51. package/src/state/options.ts +11 -11
  52. package/src/state/parser.ts +224 -224
  53. package/src/state/render-grid.ts +22 -22
  54. package/src/state/routing.ts +1522 -1522
  55. package/src/state/search.ts +103 -103
  56. package/src/state/style.ts +52 -52
  57. package/src/state/types.ts +63 -63
  58. package/src/state/visible-model.ts +77 -77
  59. package/src/test/diagram.ts +32 -32
  60. package/src/test/layout-audit/fixtures.ts +538 -538
  61. package/src/test/layout-audit/harness.ts +522 -522
  62. package/src/timeline/diagram.ts +8 -8
  63. package/src/timeline/drawing.ts +109 -109
  64. package/src/timeline/parser.ts +119 -119
  65. package/src/timeline/render-grid.ts +17 -17
  66. package/src/timeline/style.ts +36 -36
  67. package/src/timeline/types.ts +31 -31
  68. package/tsconfig.json +10 -10
  69. package/src/core/canvas.test.ts +0 -203
  70. package/src/core/color/style.test.ts +0 -24
  71. package/src/core/drawing.test.ts +0 -116
  72. package/src/core/geometry.test.ts +0 -112
  73. package/src/core/spatial.test.ts +0 -87
  74. package/src/core/text.test.ts +0 -33
  75. package/src/flowchart/flowchart.test.ts +0 -2800
  76. package/src/flowchart/labels.test.ts +0 -127
  77. package/src/flowchart/routing.test.ts +0 -368
  78. package/src/gantt/diagram.test.ts +0 -124
  79. package/src/gitgraph/diagram.test.ts +0 -183
  80. package/src/layout-audit.test.ts +0 -92
  81. package/src/palette.test.ts +0 -103
  82. package/src/sequence/diagram.test.ts +0 -757
  83. package/src/sequence/placement.test.ts +0 -219
  84. package/src/state/diagram.test.ts +0 -1386
  85. package/src/state/layout.test.ts +0 -314
  86. package/src/state/routing.test.ts +0 -693
  87. package/src/state/style.test.ts +0 -113
  88. package/src/state/visible-model.test.ts +0 -84
  89. package/src/test/diagnostics.test.ts +0 -129
  90. package/src/test/markdown.test.ts +0 -474
  91. package/src/timeline/diagram.test.ts +0 -188
@@ -1,127 +0,0 @@
1
- import { describe, expect, test } from "bun:test"
2
- import { flowchartEdgeLabelLayout } from "./labels.js"
3
-
4
- const measure = (text: string): number => text.length
5
-
6
- describe("flowchart edge labels", () => {
7
- test("places vertical-route labels beside the bus", () => {
8
- expect(
9
- flowchartEdgeLabelLayout(
10
- [
11
- { x: 22, y: 3 },
12
- { x: 22, y: 7 },
13
- ],
14
- "rollback",
15
- measure,
16
- ).point,
17
- ).toEqual({ x: 23, y: 5 })
18
- })
19
-
20
- test("places labels inline only when padded text fits with clearance", () => {
21
- expect(
22
- flowchartEdgeLabelLayout(
23
- [
24
- { x: 0, y: 2 },
25
- { x: 13, y: 2 },
26
- ],
27
- "rollback",
28
- measure,
29
- ).point,
30
- ).toEqual({ x: 2, y: 2 })
31
-
32
- expect(
33
- flowchartEdgeLabelLayout(
34
- [
35
- { x: 0, y: 2 },
36
- { x: 9, y: 2 },
37
- ],
38
- "rollback",
39
- measure,
40
- ).point,
41
- ).toEqual({ x: 2, y: 1 })
42
-
43
- expect(
44
- flowchartEdgeLabelLayout(
45
- [
46
- { x: 0, y: 2 },
47
- { x: 7, y: 2 },
48
- ],
49
- "rollback",
50
- measure,
51
- ).point,
52
- ).toEqual({ x: 2, y: 1 })
53
- })
54
-
55
- test("uses vertical bus labels before short terminal branches", () => {
56
- expect(
57
- flowchartEdgeLabelLayout(
58
- [
59
- { x: 155, y: 5 },
60
- { x: 150, y: 5 },
61
- { x: 150, y: 9 },
62
- { x: 146, y: 9 },
63
- ],
64
- "rollback",
65
- measure,
66
- ).point,
67
- ).toEqual({ x: 151, y: 7 })
68
- })
69
-
70
- test("keeps side-route labels on the vertical bus when horizontal arms grow", () => {
71
- expect(
72
- flowchartEdgeLabelLayout(
73
- [
74
- { x: 5, y: 2 },
75
- { x: 30, y: 2 },
76
- { x: 30, y: 10 },
77
- { x: 5, y: 10 },
78
- ],
79
- "parallel label",
80
- measure,
81
- "y",
82
- ).point,
83
- ).toEqual({ x: 31, y: 6 })
84
- })
85
-
86
- test("measures br-delimited edge label lines as a block", () => {
87
- const layout = flowchartEdgeLabelLayout(
88
- [
89
- { x: 0, y: 2 },
90
- { x: 20, y: 2 },
91
- ],
92
- "first<br/>second line",
93
- measure,
94
- )
95
-
96
- expect(layout.lines).toEqual([" first ", " second line "])
97
- expect(layout.width).toBe(13)
98
- expect(layout.height).toBe(2)
99
- })
100
-
101
- test("places multiline horizontal edge labels outside the route row", () => {
102
- const layout = flowchartEdgeLabelLayout(
103
- [
104
- { x: 0, y: 5 },
105
- { x: 20, y: 5 },
106
- ],
107
- "first<br/>second",
108
- measure,
109
- )
110
-
111
- expect(layout.point.y + layout.height).toBeLessThanOrEqual(5)
112
- })
113
-
114
- test("centers multiline vertical edge labels beside their route", () => {
115
- const layout = flowchartEdgeLabelLayout(
116
- [
117
- { x: 22, y: 2 },
118
- { x: 22, y: 10 },
119
- ],
120
- "one<br/>two<br/>three",
121
- measure,
122
- )
123
-
124
- expect(layout.point).toEqual({ x: 23, y: 5 })
125
- expect(layout.height).toBe(3)
126
- })
127
- })
@@ -1,368 +0,0 @@
1
- import { describe, expect, test } from "bun:test"
2
- import { diagramTextWidth } from "../core/text.js"
3
- import { flowchartEdgeLabelLayout } from "./labels.js"
4
- import type { FlowchartDiagram, FlowchartNodeBounds } from "./types.js"
5
- import { routeFlowchartEdges } from "./routing.js"
6
-
7
- function bounds(id: string, left: number, top: number): FlowchartNodeBounds {
8
- const width = 5
9
- const height = 3
10
- return {
11
- id,
12
- width,
13
- height,
14
- lines: [id],
15
- left,
16
- top,
17
- centerX: left + Math.floor(width / 2),
18
- centerY: top + Math.floor(height / 2),
19
- }
20
- }
21
-
22
- function diagram(direction: FlowchartDiagram["direction"], edges: FlowchartDiagram["edges"]): FlowchartDiagram {
23
- return { direction, nodes: [], edges, subgraphs: [] }
24
- }
25
-
26
- function routeIntersectsBounds(
27
- points: readonly { x: number; y: number }[],
28
- nodeBounds: { left: number; top: number; width: number; height: number },
29
- ): boolean {
30
- const right = nodeBounds.left + nodeBounds.width - 1
31
- const bottom = nodeBounds.top + nodeBounds.height - 1
32
- return points.slice(1).some((to, index) => {
33
- const from = points[index]!
34
- if (from.x === to.x) {
35
- return (
36
- from.x >= nodeBounds.left &&
37
- from.x <= right &&
38
- Math.max(from.y, to.y) >= nodeBounds.top &&
39
- Math.min(from.y, to.y) <= bottom
40
- )
41
- }
42
- return (
43
- from.y >= nodeBounds.top &&
44
- from.y <= bottom &&
45
- Math.max(from.x, to.x) >= nodeBounds.left &&
46
- Math.min(from.x, to.x) <= right
47
- )
48
- })
49
- }
50
-
51
- describe("flowchart routing", () => {
52
- test("routes a simple horizontal edge from source port to target port", () => {
53
- const edge = { from: "A", to: "B", label: "" }
54
- const routes = routeFlowchartEdges(
55
- diagram("LR", [edge]),
56
- new Map([
57
- ["A", bounds("A", 0, 0)],
58
- ["B", bounds("B", 20, 0)],
59
- ]),
60
- )
61
-
62
- expect(routes).toEqual([
63
- {
64
- edge,
65
- points: [
66
- { x: 5, y: 1 },
67
- { x: 19, y: 1 },
68
- ],
69
- },
70
- ])
71
- })
72
-
73
- test("routes a simple reverse horizontal edge into the target right port", () => {
74
- const edge = { from: "A", to: "B", label: "" }
75
- const routes = routeFlowchartEdges(
76
- diagram("RL", [edge]),
77
- new Map([
78
- ["A", bounds("A", 20, 0)],
79
- ["B", bounds("B", 0, 0)],
80
- ]),
81
- )
82
-
83
- expect(routes).toEqual([
84
- {
85
- edge,
86
- points: [
87
- { x: 19, y: 1 },
88
- { x: 5, y: 1 },
89
- ],
90
- },
91
- ])
92
- })
93
-
94
- test("routes horizontal back-edges above forward lanes", () => {
95
- const edge = { from: "B", to: "A", label: "" }
96
- const routes = routeFlowchartEdges(
97
- diagram("LR", [edge]),
98
- new Map([
99
- ["A", bounds("A", 0, 0)],
100
- ["B", bounds("B", 20, 0)],
101
- ]),
102
- )
103
-
104
- expect(routes).toEqual([
105
- {
106
- edge,
107
- points: [
108
- { x: 22, y: -1 },
109
- { x: 22, y: -4 },
110
- { x: 2, y: -4 },
111
- { x: 2, y: -1 },
112
- ],
113
- },
114
- ])
115
- })
116
-
117
- test("routes parallel horizontal edges on independent lanes", () => {
118
- const edges = [
119
- { from: "A", to: "B", label: "first" },
120
- { from: "A", to: "B", label: "second" },
121
- ]
122
- const routes = routeFlowchartEdges(
123
- diagram("LR", edges),
124
- new Map([
125
- ["A", bounds("A", 0, 0)],
126
- ["B", bounds("B", 20, 0)],
127
- ]),
128
- )
129
-
130
- const laneYs = routes.map(
131
- (route) => route.points.slice(1).find((point, index) => point.y === route.points[index]!.y)?.y,
132
- )
133
- expect(routes).toHaveLength(2)
134
- expect(new Set(routes.map((route) => JSON.stringify(route.points))).size).toBe(2)
135
- expect(new Set(laneYs).size).toBe(2)
136
- })
137
-
138
- test("spaces parallel horizontal lanes for multiline labels", () => {
139
- const edges = [
140
- { from: "A", to: "B", label: "first" },
141
- { from: "A", to: "B", label: "second 1<br/>second 2<br/>second 3" },
142
- { from: "A", to: "B", label: "third 1<br/>third 2<br/>third 3" },
143
- ]
144
- const routes = routeFlowchartEdges(
145
- diagram("LR", edges),
146
- new Map([
147
- ["A", bounds("A", 0, 0)],
148
- ["B", bounds("B", 20, 0)],
149
- ]),
150
- )
151
-
152
- expect(routes[2]!.points[1]!.y).toBeGreaterThan(routes[1]!.points[1]!.y + 3)
153
- })
154
-
155
- test("routes horizontal fan-out through a shared bus lane", () => {
156
- const edges = [
157
- { from: "A", to: "B", label: "" },
158
- { from: "A", to: "C", label: "" },
159
- ]
160
- const routes = routeFlowchartEdges(
161
- diagram("LR", edges),
162
- new Map([
163
- ["A", bounds("A", 0, 6)],
164
- ["B", bounds("B", 20, 0)],
165
- ["C", bounds("C", 20, 12)],
166
- ]),
167
- )
168
-
169
- expect(routes.map((route) => route.points)).toEqual([
170
- [
171
- { x: 5, y: 7 },
172
- { x: 8, y: 7 },
173
- { x: 8, y: 1 },
174
- { x: 19, y: 1 },
175
- ],
176
- [
177
- { x: 5, y: 7 },
178
- { x: 8, y: 7 },
179
- { x: 8, y: 13 },
180
- { x: 19, y: 13 },
181
- ],
182
- ])
183
- })
184
-
185
- test("routes each horizontal edge once when fan-in and fan-out overlap", () => {
186
- const edges = [
187
- { from: "A", to: "C", label: "" },
188
- { from: "A", to: "D", label: "" },
189
- { from: "B", to: "C", label: "" },
190
- { from: "B", to: "D", label: "" },
191
- ]
192
- const routes = routeFlowchartEdges(
193
- diagram("LR", edges),
194
- new Map([
195
- ["A", bounds("A", 0, 0)],
196
- ["B", bounds("B", 0, 12)],
197
- ["C", bounds("C", 24, 0)],
198
- ["D", bounds("D", 24, 12)],
199
- ]),
200
- )
201
-
202
- expect(routes).toHaveLength(edges.length)
203
- expect(routes.map((route) => `${route.edge.from}->${route.edge.to}`).sort()).toEqual([
204
- "A->C",
205
- "A->D",
206
- "B->C",
207
- "B->D",
208
- ])
209
- })
210
-
211
- test("routes vertical back-edges around the left side", () => {
212
- const edge = { from: "B", to: "A", label: "" }
213
- const routes = routeFlowchartEdges(
214
- diagram("TD", [edge]),
215
- new Map([
216
- ["A", bounds("A", 0, 0)],
217
- ["B", bounds("B", 0, 12)],
218
- ]),
219
- )
220
-
221
- expect(routes).toEqual([
222
- {
223
- edge,
224
- points: [
225
- { x: -1, y: 13 },
226
- { x: -4, y: 13 },
227
- { x: -4, y: 1 },
228
- { x: -1, y: 1 },
229
- ],
230
- },
231
- ])
232
- })
233
-
234
- test("routes self edges below the source node", () => {
235
- const edge = { from: "A", to: "A", label: "" }
236
- const routes = routeFlowchartEdges(diagram("TD", [edge]), new Map([["A", bounds("A", 0, 0)]]))
237
-
238
- expect(routes).toEqual([
239
- {
240
- edge,
241
- points: [
242
- { x: 5, y: 1 },
243
- { x: 8, y: 1 },
244
- { x: 8, y: 4 },
245
- { x: 2, y: 4 },
246
- { x: 2, y: 3 },
247
- ],
248
- },
249
- ])
250
- })
251
-
252
- test("routes same-column horizontal-flow edges through vertical ports", () => {
253
- const edge = { from: "A", to: "B", label: "rollback" }
254
- const routes = routeFlowchartEdges(
255
- diagram("LR", [edge]),
256
- new Map([
257
- ["A", bounds("A", 20, 0)],
258
- ["B", bounds("B", 20, 8)],
259
- ]),
260
- )
261
-
262
- expect(routes).toEqual([
263
- {
264
- edge,
265
- points: [
266
- { x: 22, y: 3 },
267
- { x: 22, y: 7 },
268
- ],
269
- },
270
- ])
271
- })
272
-
273
- test("routes overlapping horizontal-flow columns through vertical ports", () => {
274
- const edge = { from: "A", to: "B", label: "merge" }
275
- const routes = routeFlowchartEdges(
276
- diagram("RL", [edge]),
277
- new Map([
278
- ["A", bounds("A", 1, 8)],
279
- ["B", bounds("B", 0, 0)],
280
- ]),
281
- )
282
-
283
- expect(routes).toEqual([
284
- {
285
- edge,
286
- points: [
287
- { x: 2, y: 7 },
288
- { x: 2, y: 3 },
289
- ],
290
- },
291
- ])
292
- })
293
-
294
- test("does not route a fallback through its own source node", () => {
295
- const labeled = { from: "A", to: "B", label: "route" }
296
- const crossing = { from: "C", to: "D", label: "" }
297
- const nodeBounds = new Map([
298
- ["A", bounds("A", 0, 0)],
299
- ["B", bounds("B", 100, 0)],
300
- ["C", bounds("C", 48, -12)],
301
- ["D", bounds("D", 48, 12)],
302
- ])
303
- const routes = routeFlowchartEdges(diagram("LR", [labeled, crossing]), nodeBounds, undefined, new Map())
304
- const route = routes.find((candidate) => candidate.edge === labeled)!
305
-
306
- expect(routeIntersectsBounds(route.points, nodeBounds.get("A")!)).toBe(false)
307
- expect(routeIntersectsBounds(route.points, nodeBounds.get("B")!)).toBe(false)
308
- })
309
-
310
- test("ignores zero-width blank label interiors as route obstacles", () => {
311
- const blankLabel = { from: "A", to: "B", label: "<br/>" }
312
- const crossing = { from: "C", to: "D", label: "" }
313
- const routes = routeFlowchartEdges(
314
- diagram("TD", [blankLabel, crossing]),
315
- new Map([
316
- ["A", bounds("A", 0, 0)],
317
- ["B", bounds("B", 0, 100)],
318
- ["C", bounds("C", -20, 50)],
319
- ["D", bounds("D", 20, 50)],
320
- ]),
321
- (edge) => (edge === blankLabel ? "TD" : "LR"),
322
- new Map(),
323
- )
324
-
325
- expect(routes.find((route) => route.edge === blankLabel)!.points).toEqual([
326
- { x: 2, y: 3 },
327
- { x: 2, y: 99 },
328
- ])
329
- })
330
-
331
- test("checks earlier labels against finalized later fallback routes", () => {
332
- const edges = [
333
- { from: "C", to: "B", label: "alpha" },
334
- { from: "A", to: "F", label: "beta long" },
335
- { from: "C", to: "D", label: "gamma" },
336
- { from: "A", to: "B", label: "" },
337
- ]
338
- const directions = ["TD", "RL", "LR", "BT"] as const
339
- const routes = routeFlowchartEdges(
340
- diagram("LR", edges),
341
- new Map([
342
- ["A", bounds("A", -24, 6)],
343
- ["B", bounds("B", 48, 24)],
344
- ["C", bounds("C", -24, 24)],
345
- ["D", bounds("D", -24, -18)],
346
- ["F", bounds("F", -16, -6)],
347
- ]),
348
- (edge) => directions[edges.indexOf(edge)]!,
349
- new Map(),
350
- )
351
- const labeled = routes.find((route) => route.edge === edges[0])!
352
- const laterFallback = routes.find((route) => route.edge === edges[3])!
353
- const label = flowchartEdgeLabelLayout(labeled.points, labeled.edge.label, diagramTextWidth)
354
-
355
- expect(labeled.points).toEqual([
356
- { x: -19, y: 25 },
357
- { x: 47, y: 25 },
358
- ])
359
- expect(
360
- routeIntersectsBounds(laterFallback.points, {
361
- left: label.point.x + 1,
362
- top: label.point.y,
363
- width: label.width - 2,
364
- height: label.height,
365
- }),
366
- ).toBe(false)
367
- })
368
- })
@@ -1,124 +0,0 @@
1
- import { describe, expect, test } from "bun:test"
2
- import { MermaidSyntaxError } from "../diagnostics.js"
3
- import { expectDiagram } from "../test/diagram.js"
4
- import { renderGanttDiagram } from "./diagram.js"
5
- import { drawGanttDiagramGrid } from "./drawing.js"
6
- import { isMermaidGanttDiagram, parseMermaidGanttDiagram } from "./parser.js"
7
-
8
- const secondsDiagram = `gantt
9
- dateFormat s
10
- axisFormat %Ss
11
- section OLD (blocking)
12
- provider.create (Modal sandbox) :crit, 0, 15
13
- model streams first token :15, 17
14
- section NEW (eager kick)
15
- reserve (DB insert) :0, 1
16
- model streams first token :0, 2
17
- provisioning in background :active, 0, 15
18
- model calls bash → spawn runs :15, 16
19
- section NEW (pure chat thread)
20
- reserve (DB insert) :0, 1
21
- model answers, never calls bash :0, 4`
22
-
23
- describe("GanttDiagram", () => {
24
- test("detects and parses second-based task ranges and states", () => {
25
- const diagram = parseMermaidGanttDiagram(secondsDiagram)
26
-
27
- expect(diagram.dateFormat).toBe("s")
28
- expect(diagram.axisFormat).toBe("%Ss")
29
- expect(diagram.tasks).toHaveLength(8)
30
- expect(diagram.tasks[0]).toMatchObject({
31
- label: "provider.create (Modal sandbox)",
32
- start: 0,
33
- end: 15_000,
34
- state: "critical",
35
- })
36
- expect(diagram.tasks[4]).toMatchObject({
37
- label: "provisioning in background",
38
- start: 0,
39
- end: 15_000,
40
- state: "active",
41
- })
42
- })
43
-
44
- test("renders sections, a formatted axis, and aligned task bars", () => {
45
- expectDiagram(renderGanttDiagram(secondsDiagram, { layoutMaxWidth: 100 })).toContainInOrder(
46
- "00s",
47
- "15s",
48
- "OLD (blocking)",
49
- "provider.create (Modal sandbox)",
50
- "model streams first token",
51
- "NEW (eager kick)",
52
- "provisioning in background",
53
- "NEW (pure chat thread)",
54
- "model answers, never calls bash",
55
- )
56
- expect(renderGanttDiagram(secondsDiagram)).toContain("\n\nNEW (eager kick)")
57
- expect(renderGanttDiagram(secondsDiagram)).not.toContain("·")
58
- })
59
-
60
- test("renders alternate terminal bar styles", () => {
61
- expect(renderGanttDiagram(secondsDiagram, { style: "block" })).toContain("█")
62
- expect(renderGanttDiagram(secondsDiagram, { style: "capsule" })).toContain("╶")
63
- expect(renderGanttDiagram(secondsDiagram, { style: "points" })).toContain("●")
64
- expect(renderGanttDiagram(secondsDiagram, { style: "track", track: "dots" })).toContain("·")
65
- expect(renderGanttDiagram(secondsDiagram, { style: "track", track: "line" })).not.toContain("·")
66
- expect(renderGanttDiagram(secondsDiagram, { style: "track", endpoints: "points" })).toContain("●")
67
- expect(renderGanttDiagram(secondsDiagram, { style: "track", line: "thin" })).toContain("─")
68
- expect(renderGanttDiagram(secondsDiagram, { style: "track", line: "double" })).toContain("═")
69
- expect(renderGanttDiagram(secondsDiagram, { style: "track", line: "dashed" })).toContain("╌")
70
- expect(renderGanttDiagram(secondsDiagram, { labels: "tree" })).toContain("├─ provider.create")
71
- expect(renderGanttDiagram(secondsDiagram, { labels: "tree" })).toContain("└─ model streams first token")
72
- expect(renderGanttDiagram(secondsDiagram, { sections: "spaced" })).toContain("\n\nNEW (eager kick)")
73
-
74
- const points = drawGanttDiagramGrid(parseMermaidGanttDiagram(secondsDiagram), {
75
- style: "track",
76
- endpoints: "points",
77
- trackTone: "faint",
78
- }).rows.flatMap((row) => row.filter((cell) => cell.char === "●"))
79
- expect(points.every((cell) => cell.style === "trackFaint")).toBe(true)
80
- })
81
-
82
- test("resolves task ids, after dependencies, durations, and milestones", () => {
83
- const diagram = parseMermaidGanttDiagram(`gantt
84
- dateFormat YYYY-MM-DD
85
- task one :done, first, 2026-08-01, 2d
86
- deploy :milestone, after first, 0d`)
87
-
88
- expect(diagram.tasks[1]).toMatchObject({
89
- start: Date.UTC(2026, 7, 3),
90
- end: Date.UTC(2026, 7, 3),
91
- state: "milestone",
92
- })
93
- expect(
94
- renderGanttDiagram(`gantt
95
- dateFormat YYYY-MM-DD
96
- task one :first, 2026-08-01, 2d
97
- deploy :milestone, after first, 0d`),
98
- ).toContain("◆")
99
- })
100
-
101
- test("rejects unsupported or ambiguous syntax with source diagnostics", () => {
102
- expect(() => parseMermaidGanttDiagram("gantt\n task :not-a-date, 2d")).toThrow(
103
- new MermaidSyntaxError(
104
- "gantt",
105
- 2,
106
- "task :not-a-date, 2d",
107
- 'Unsupported date "not-a-date" for dateFormat YYYY-MM-DD',
108
- ),
109
- )
110
- expect(() => parseMermaidGanttDiagram("gantt\n task :after missing, 2d")).toThrow('Unknown Gantt task id "missing"')
111
- expect(() => parseMermaidGanttDiagram("gantt\n excludes weekends")).toThrow(
112
- "excludes is not supported in gantt diagram",
113
- )
114
- })
115
-
116
- test("recognizes only Gantt headers", () => {
117
- expect(isMermaidGanttDiagram("%% comment\ngantt\n task :0, 1")).toBe(true)
118
- expect(isMermaidGanttDiagram("timeline\n 2026 : ship")).toBe(false)
119
- })
120
-
121
- test("renders partial diagrams containing only sections", () => {
122
- expect(renderGanttDiagram("gantt\n section Planning")).toBe("Planning")
123
- })
124
- })