// Regenerate README diagrams from the checked-in Mermaid sources:
// node utils/diagrams/render-test-architecture.mjs
// Uses the existing Playwright dependency and local Chrome, without networking.
import fs from 'node:fs/promises'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { chromium } from 'playwright'
const root = fileURLToPath(new URL('../../', import.meta.url))
const directory = path.join(root, 'docs/public/diagrams')
const width = 1600, height = 1020
const layout = {
A: { x: 600, y: 78, w: 400, h: 64, color: 'root' },
B: { x: 280, y: 220, w: 400, h: 64, color: 'blue' },
C: { x: 960, y: 220, w: 260, h: 64, color: 'purple' },
D: { x: 1280, y: 220, w: 280, h: 64, color: 'green' },
E: { x: 100, y: 360, w: 340, h: 72, color: 'blue' },
F: { x: 520, y: 360, w: 340, h: 72, color: 'blue' },
G: { x: 100, y: 500, w: 340, h: 70, color: 'blue' },
H: { x: 100, y: 600, w: 340, h: 70, color: 'blue' },
I: { x: 100, y: 700, w: 340, h: 70, color: 'blue' },
J: { x: 100, y: 814, w: 340, h: 90, color: 'orange' },
K: { x: 520, y: 500, w: 340, h: 100, color: 'blue' },
L: { x: 520, y: 700, w: 340, h: 130, color: 'blue' },
M: { x: 960, y: 500, w: 260, h: 160, color: 'purple' },
N: { x: 1280, y: 500, w: 280, h: 160, color: 'green' },
}
const palette = {
root: ['#153462', '#153462', '#ffffff'],
blue: ['#ffffff', '#a8c6ec', '#163e70'],
purple: ['#ffffff', '#c7b7ed', '#593a91'],
green: ['#ffffff', '#9dd5c0', '#17674d'],
orange: ['#fff7e7', '#e6bc6c', '#80530b'],
}
const xml = value => value.replace(/[&<>"']/g, character => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[character])
function parse(source) {
const labels = new Map(), edges = []
for (const line of source.trim().split(/\r?\n/).slice(1)) {
const match = line.trim().match(/^(\w+)(?:\[([^\]]+)\])?\s*-->\s*(\w+)(?:\[([^\]]+)\])?$/)
if (!match) throw new Error(`Unsupported Mermaid line: ${line}`)
const [, from, fromLabel, to, toLabel] = match
for (const [id, label] of [[from, fromLabel], [to, toLabel]]) {
if (!layout[id]) throw new Error(`Missing node layout: ${id}`)
if (label) labels.set(id, label)
}
edges.push([from, to])
}
if (labels.size !== Object.keys(layout).length) throw new Error('Incomplete diagram node labels')
return { labels, edges }
}
function connection(from, to) {
const a = layout[from], b = layout[to]
const x = a.x + a.w / 2, y = a.y + a.h, target = b.x + b.w / 2
if (from === 'A') return `M ${x} ${y} V 178 H ${target} V ${b.y - 4}`
if (from === 'B') return `M ${x} ${y} V 322 H ${target} V ${b.y - 4}`
if (from === 'E') return `M ${x} ${y} V 462 H 68 V ${b.y + b.h / 2} H ${b.x - 4}`
return `M ${x} ${y} V ${(y + b.y) / 2} H ${target} V ${b.y - 4}`
}
function draw({ labels, edges }, wrapped, english) {
const nodes = [...labels].map(([id, label]) => {
const box = layout[id], [fill, stroke, text] = palette[box.color]
const lines = wrapped[id], lineHeight = id === 'A' ? 29 : 26
if (lines.length * lineHeight > box.h - 12) throw new Error(`Label too tall: ${label}`)
const firstY = box.y + box.h / 2 - (lines.length - 1) * lineHeight / 2
return `