'use strict'; /** ADR-612 PR-5: the bracket convention card has one runtime source. */ const { describe, test } = require('node:test'); const assert = require('node:assert/strict'); const fs = require('node:fs'); const path = require('node:path'); const { normalizeEol } = require('../msd-core/bin/lib/text-lines.cjs'); const { phaseIdCard, PHASE_ID_CARD, PHASE_ID_LEGEND, } = require('../msd-core/bin/lib/phase-id-card.cjs'); const REFERENCE_PATH = path.join( __dirname, '..', 'msd-core', 'references', 'phase-id-convention.md', ); describe('#3638: phase ID convention card single source', () => { test('the runtime card labels every identity dimension', () => { const rendered = phaseIdCard(); assert.match(rendered, /^\[MSD\.02\] 05\.03-01/m); assert.match(rendered, /plan\s+01/); assert.match(rendered, /subphase\s+03/); assert.match(rendered, /phase\s+05/); assert.match(rendered, /milestone\s+02/); assert.match(rendered, /project\s+MSD/); assert.match(PHASE_ID_LEGEND, /no 'Phase' word, no vX\.Y/); assert.equal(PHASE_ID_CARD.split('\n').length, 7); }); test('an optional title composes without mutating the canonical card', () => { assert.equal( phaseIdCard({ title: 'Bracket convention:' }), `Bracket convention:\n\n${PHASE_ID_CARD}\n\n${PHASE_ID_LEGEND}`, ); assert.equal(phaseIdCard(), `${PHASE_ID_CARD}\n\n${PHASE_ID_LEGEND}`); }); test('the reference card block is generated byte-for-byte from the runtime source', () => { const reference = normalizeEol(fs.readFileSync(REFERENCE_PATH, 'utf8')); const opener = '\n```text\n'; const closer = '\n```\n'; const start = reference.indexOf(opener); const end = reference.indexOf(closer, start + opener.length); assert.notEqual(start, -1, 'generated card opener must remain present'); assert.notEqual(end, -1, 'generated card closer must remain present'); assert.equal(reference.slice(start + opener.length, end), phaseIdCard()); }); });