// tests/kb-update/test-strip-stale-verified-pipe.test.mjs // TDD for RX-KB1 — strip the stale plain `| Verified: MCP ` pipe-tail from the // **Last updated:** line across the 87 reference files that carry it in the top-500-byte // header window. This is the same poison class as the 14 bold `**Verified:** MCP` labels // Spor 1 already removed: a plain-text "Verified" claim the judge never made, invisible to // the bold-only contract stack (kb-headers.mjs / audit RE_VERIFIED). "Strip" = remove ONLY // the ` | Verified: …` tail, preserving `**Last updated:** ` byte-exact; the citation, // the date, and the whole body stay untouched. Value-preserving, idempotent, one line edited // in place (never removed). // // The two dialect variants in the real corpus (ground truth 2026-07-16): // 85× `**Last updated:** | Verified: MCP ` // 2× `**Last updated:** | Verified: ` (no "MCP") import { test } from 'node:test'; import assert from 'node:assert/strict'; import { stripVerifiedPipe, MANIFEST } from '../../scripts/kb-update/strip-stale-verified-pipe.mjs'; // A reference-shaped fixture: bold header with the plain Verified pipe-tail, then a body that // itself mentions "Verified:" and even "| Verified:" in prose (must never be touched). const FIXTURE = [ '# Azure AI Search — RAG Setup', '**Type:** reference', '**Last updated:** 2026-06-19 | Verified: MCP 2026-06-19', '**Category:** RAG', '', '---', '', '## Innhold', '', 'A body line mentioning Verified: yesterday and a | Verified: pipe — must be left alone.', '', ].join('\n'); // ── stripVerifiedPipe (pure) ───────────────────────────────────────────────── test('stripVerifiedPipe: removes the `| Verified: MCP ` tail, keeps Last updated byte-exact', () => { const out = stripVerifiedPipe(FIXTURE); const header = out.split('\n---')[0]; assert.ok(header.includes('**Last updated:** 2026-06-19'), 'Last updated + date preserved'); assert.ok(!/Verified:/.test(header), 'no Verified label remains in the header'); assert.ok(!/\|\s*$/.test(header.split('\n')[2]), 'no dangling pipe/whitespace after strip'); assert.equal(header.split('\n')[2], '**Last updated:** 2026-06-19', 'exact stripped line'); }); test('stripVerifiedPipe: strips the non-MCP `| Verified: ` variant too', () => { const nonMcp = FIXTURE.replace('| Verified: MCP 2026-06-19', '| Verified: 2026-06-18'); const out = stripVerifiedPipe(nonMcp); const header = out.split('\n---')[0]; assert.equal(header.split('\n')[2], '**Last updated:** 2026-06-19', 'non-MCP tail stripped, date kept'); assert.ok(!/Verified:/.test(header), 'no Verified label remains'); }); test('stripVerifiedPipe: one line edited in place — total line count unchanged', () => { const out = stripVerifiedPipe(FIXTURE); assert.equal(out.split('\n').length, FIXTURE.split('\n').length, 'no line added or removed'); }); test('stripVerifiedPipe: body is byte-identical (only the header line changes)', () => { const out = stripVerifiedPipe(FIXTURE); const bodyOf = (c) => c.slice(c.indexOf('\n---')); assert.equal(bodyOf(out), bodyOf(FIXTURE), 'body untouched'); }); test('stripVerifiedPipe: never touches a "Verified:" or "| Verified:" in the body', () => { const out = stripVerifiedPipe(FIXTURE); assert.ok(out.includes('mentioning Verified: yesterday and a | Verified: pipe'), 'body prose intact'); }); test('stripVerifiedPipe: idempotent — a second pass is a no-op', () => { const once = stripVerifiedPipe(FIXTURE); assert.equal(stripVerifiedPipe(once), once); }); test('stripVerifiedPipe: no pipe-tail present → unchanged (clean Last updated)', () => { const clean = FIXTURE.replace(' | Verified: MCP 2026-06-19', ''); assert.equal(stripVerifiedPipe(clean), clean); }); test('stripVerifiedPipe: leaves the citation date byte-exact even if it differs from the Verified date', () => { // Last updated 2026-06-24, Verified MCP 2026-06 (the drift the review flagged) — the strip // keeps the authored Last updated date and simply drops the unverifiable Verified claim. const drift = FIXTURE.replace('**Last updated:** 2026-06-19 | Verified: MCP 2026-06-19', '**Last updated:** 2026-06-24 | Verified: MCP 2026-06'); const out = stripVerifiedPipe(drift); assert.equal(out.split('\n')[2], '**Last updated:** 2026-06-24'); }); // ── MANIFEST (frozen ground truth 2026-07-16) ──────────────────────────────── test('MANIFEST: exactly the 87 plain-Verified files, no duplicates', () => { assert.equal(MANIFEST.length, 87, 'frozen count'); assert.equal(new Set(MANIFEST).size, 87, 'no duplicates'); }); test('MANIFEST: per-skill breakdown 18/45/8/16 (advisor/engineering/governance/security)', () => { const bySkill = (skill) => MANIFEST.filter((p) => p.startsWith(`skills/${skill}/`)).length; assert.equal(bySkill('ms-ai-advisor'), 18); assert.equal(bySkill('ms-ai-engineering'), 45); assert.equal(bySkill('ms-ai-governance'), 8); assert.equal(bySkill('ms-ai-security'), 16); }); test('MANIFEST: every entry is a plugin-relative references .md path', () => { for (const p of MANIFEST) { assert.match(p, /^skills\/ms-ai-[a-z]+\/references\/.+\.md$/, `bad path: ${p}`); } }); test('MANIFEST: sorted (deterministic, diff-stable)', () => { const sorted = [...MANIFEST].sort(); assert.deepEqual(MANIFEST, sorted, 'manifest must be sorted'); });