import {test} from 'node:test'; import assert from 'node:assert/strict'; import {readFileSync} from 'node:fs'; import {createRouter} from '../vendor/archify/renderers/architecture/routing.mjs'; import {segmentIntersectsRect} from '../vendor/archify/renderers/shared/geometry.mjs'; for (const suffix of ['', '-mobile']) { test(`Target${suffix} uses shared native midpoint ports without node crossings`, () => { const diagram = JSON.parse(readFileSync(`diagrams/strategy-target${suffix}.architecture.json`, 'utf8')); const boxes = new Map(diagram.components.map(({id, pos: [x, y], size: [width, height]}) => [id, {id, x, y, width, height, cx: x + width / 2, cy: y + height / 2}])); const router = createRouter(boxes, diagram.connections, {distinctAutomaticPorts: true}); const agent = boxes.get('agent'); for (const edge of diagram.connections.filter(edge => edge.from === 'agent')) { const side = suffix ? 'left' : ['scope', 'architecture', 'releases'].includes(edge.to) ? 'top' : ['planning', 'delivery', 'uat'].includes(edge.to) ? 'bottom' : edge.to === 'security' ? 'left' : 'right'; assert.equal(edge.fromSide, side, edge.id); assert(edge.via || (edge.route && edge.route !== 'auto'), `${edge.id} must opt out of automatic port spreading`); const expected = {top: [agent.cx, agent.y], bottom: [agent.cx, agent.y + agent.height], left: [agent.x, agent.cy], right: [agent.x + agent.width, agent.cy]}[side]; const points = router.pathFor(edge).points; assert.deepEqual(points[0], expected, edge.id); for (let i = 1; i < points.length; i++) { for (const box of boxes.values()) { if ([edge.from, edge.to].includes(box.id)) continue; assert(!segmentIntersectsRect({start: points[i - 1], end: points[i]}, box), `${edge.id} crosses ${box.id}`); } } } }); }