98 lines
4.6 KiB
JavaScript
98 lines
4.6 KiB
JavaScript
// tests/kb-update/test-backfill-last-updated.test.mjs
|
|
// TDD for the Last-updated backfill mechanism (Enhet 4, ⊥ R7). The applier
|
|
// (backfill-last-updated.mjs) is a manifest-driven driver over the already-tested
|
|
// insertMetaField primitive — the same shape as backfill-status.mjs. The ONLY new production
|
|
// data is the frozen single-entry MANIFEST whose value is a git "content-commit" date.
|
|
//
|
|
// Scope: decision-trees.md is the corpus's ONE dateless file — the only skills/**/*.md whose
|
|
// header lacks an English **Last updated:** (ground truth 2026-07-16). Its date is the authored
|
|
// date of the last commit that changed the BODY (03d596e, 2026-06-23 — a Foundry namesweep),
|
|
// EXCLUDING the R20/R21 metadata passes (a583599/5a0e8d7, which inserted only a header meta line
|
|
// and changed no body). The "never today" rule is enforced against MEASURED_TODAY so a naive
|
|
// last-commit date can never leak in.
|
|
//
|
|
// This suite pins:
|
|
// - MANIFEST self-consistency: one distinct entry, the known dateless path, a YYYY-MM-DD value
|
|
// that is not MEASURED_TODAY.
|
|
// - insertMetaField placement/idempotency on an advisor-shaped header fixture.
|
|
// - Corpus-state guard (the gap-discipline lock): the committed decision-trees.md carries
|
|
// **Last updated:** 2026-06-23 in its 500-byte header window, with title + Category + Status
|
|
// and body intact.
|
|
|
|
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { readFileSync } from 'node:fs';
|
|
import { join, dirname } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { MANIFEST, MEASURED_TODAY } from '../../scripts/kb-update/backfill-last-updated.mjs';
|
|
import { insertMetaField } from '../../scripts/kb-update/lib/transform.mjs';
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
const PLUGIN_ROOT = join(__dirname, '..', '..');
|
|
|
|
const RE_ISO_DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
const DECISION_TREES = 'skills/ms-ai-advisor/references/architecture/decision-trees.md';
|
|
|
|
test('MANIFEST: exactly one distinct entry, the known dateless advisor file', () => {
|
|
assert.equal(MANIFEST.length, 1);
|
|
const paths = new Set(MANIFEST.map((m) => m.path));
|
|
assert.equal(paths.size, 1, 'duplicate path in MANIFEST');
|
|
assert.equal(MANIFEST[0].path, DECISION_TREES);
|
|
});
|
|
|
|
test('MANIFEST: value is a YYYY-MM-DD date and NOT MEASURED_TODAY (never-today guard)', () => {
|
|
for (const { path, lastUpdated } of MANIFEST) {
|
|
assert.ok(RE_ISO_DATE.test(lastUpdated), `${path}: '${lastUpdated}' is not YYYY-MM-DD`);
|
|
assert.notEqual(lastUpdated, MEASURED_TODAY, `${path}: date must never equal 'today'`);
|
|
}
|
|
});
|
|
|
|
test('MANIFEST: the frozen date is the measured content-commit date 2026-06-23', () => {
|
|
assert.equal(MANIFEST[0].lastUpdated, '2026-06-23');
|
|
});
|
|
|
|
test('insertMetaField: Last updated lands after the meta run, one line, body byte-identical', () => {
|
|
const fixture = [
|
|
'# Decision Trees for Microsoft AI',
|
|
'**Category:** Solution Architecture & Advisory',
|
|
'**Status:** Established Practice',
|
|
'',
|
|
'Akkumulerte beslutningstrær.',
|
|
'',
|
|
'## 1. Section',
|
|
'body',
|
|
].join('\n');
|
|
const out = insertMetaField(fixture, 'Last updated', '2026-06-23');
|
|
const o = fixture.split('\n');
|
|
const n = out.split('\n');
|
|
// Exactly one line added.
|
|
assert.equal(n.length, o.length + 1);
|
|
// It lands immediately after the last meta line (Status), before the blank line.
|
|
assert.equal(n[3], '**Last updated:** 2026-06-23');
|
|
assert.equal(n[1], '**Category:** Solution Architecture & Advisory');
|
|
assert.equal(n[2], '**Status:** Established Practice');
|
|
// Everything from the insertion point down is byte-identical to the original tail.
|
|
assert.equal(o.slice(3).join('\n'), n.slice(4).join('\n'));
|
|
});
|
|
|
|
test('insertMetaField: idempotent — a file already carrying Last updated is unchanged', () => {
|
|
const withField = [
|
|
'# Title',
|
|
'**Last updated:** 2026-06-23',
|
|
'**Status:** Established Practice',
|
|
'',
|
|
'## S',
|
|
].join('\n');
|
|
assert.equal(insertMetaField(withField, 'Last updated', '2026-01-01'), withField);
|
|
});
|
|
|
|
test('corpus guard: committed decision-trees.md carries Last updated 2026-06-23 in header window', () => {
|
|
const content = readFileSync(join(PLUGIN_ROOT, DECISION_TREES), 'utf8');
|
|
const head = content.slice(0, 500);
|
|
assert.match(head, /\*\*Last updated:\*\* 2026-06-23/, 'missing frozen Last updated in header window');
|
|
// Title + the R20/R21 base fields survive, body intact (regression lock).
|
|
assert.match(head, /^# Decision Trees for Microsoft AI/);
|
|
assert.match(head, /\*\*Category:\*\*/);
|
|
assert.match(head, /\*\*Status:\*\*/);
|
|
assert.match(content, /## 1\. Plattformvalg/);
|
|
});
|