import {test} from 'node:test'; import assert from 'node:assert/strict'; import {targetRouting, targetLifecycleOffsets} from './target-routing.mjs'; const fixture = targetLifecycleOffsets.map(({id, from, to, x, y1, y2}) => ` `).join('\n'); test('Target adapter shifts precisely four paths, masks and composition points', () => { const unrelated = ''; const output = targetRouting(fixture + unrelated); assert(output.endsWith(unrelated)); let restored = output; for (const {x, shiftedX, y1, y2} of targetLifecycleOffsets) { assert.equal(output.split(`d="M ${shiftedX} ${y1} L ${shiftedX} ${y2}"`).length, 3); assert(output.includes(`data-composition-points="${shiftedX},${y1};${shiftedX},${y2}"`)); restored = restored.replaceAll(`d="M ${shiftedX} ${y1} L ${shiftedX} ${y2}"`, `d="M ${x} ${y1} L ${x} ${y2}"`) .replace(`data-composition-points="${shiftedX},${y1};${shiftedX},${y2}"`, `data-composition-points="${x},${y1};${x},${y2}"`); } assert.equal(restored, fixture + unrelated, 'all other bytes preserved'); }); test('Target adapter fails closed on missing, duplicate, moved or changed native edges', () => { for (const changed of [fixture.replace('stage-2', 'missing'), fixture + fixture, fixture.replace('870 262.5', '871 262.5'), fixture.replace('870,262.5', '871,262.5'), fixture.replace('data-edge-from="architecture"', 'data-edge-from="scope"'), fixture.replace('automatic-crossover-underlay', 'unknown')]) { assert.throws(() => targetRouting(changed), /Target routing drift/); } assert.throws(() => targetRouting(targetRouting(fixture)), /Target routing drift/); });