ms-ai-architect/tests/kb-update/test-backfill-status.test.mjs
Kjell Tore Guttormsen de0d94cbc1 feat(ms-ai-architect): R22 decision-b Enhet 3 — Status-backfill 25 none + ai-act dual-header-dedup 4 (Missing Status/Last-updated 29+4→0) [skip-docs]
To operasjoner, én økt (⊥ R7), begge ren metadata-normalisering (verdi aldri fabrikkert).

Premiss-korreksjon (ground truth 2026-07-07): roadmap sa «27 none + 4 ai-act».
Målt: 29 mangler bold **Status:** = 25 rene none + 4 ai-act (plain Status: GA).
De «27» inkluderte 2 for mye — 2 filer (custom-dashboards-ai-operations,
zero-trust-ai-services) har bold **Status:** KUN forbi byte 500 (present for
full-fil-audit, usynlig for 500B header-parser) → egen header-slanking-residual
(§8-register), utenfor Enhet 3.

Op A — Status-backfill 25 rene none: utvidet backfill-status.mjs MANIFEST 14→39
(samme statusForFile + insertMetaField + hard per-fil-invariant, idempotent skip
på de 14 R21-gjorte). Alle 25 → **Status:** Established Practice (ingen matcher
template|matrix|benchmarks|register). Diff +25/-0.

Op B — ai-act dual-header-dedup (4 filer): ny driver dedup-plain-header.mjs + 2
rene primitiver i transform.mjs — boldifyPlainField (plain→bold, verdi bevart
byte-eksakt, header-scoped, idempotent) + dropRedundantPlainField (sletter plain
KUN når bold m/ identisk verdi beviser redundans; kaster ved avvik/manglende bold).
Per fil: plain Last updated: + Status: GA → bold (2026-06-18/2026-02, GA bevart),
redundant plain Category: fjernet. Hard per-fil-invariant (net -1 linje, begge
felt bold m/ bevart verdi, ingen plain-header igjen, body byte-identisk). Diff -12/+8.

Verifisering: test-backfill-status 8/8 + test-dedup-plain-header 13/13; audit
Missing Status 29→0, Missing English Last updated 4→0; skills-diff 29 filer
+33/-12 (kun **Status:** + 8 bold-swaps), diff-kontekst inspisert per fil; begge
drivere idempotent (re-run 0 writes); suite 806/806 exit 0; none=8 uendret (Enhet 4).
2026-07-07 07:45:27 +02:00

131 lines
7.1 KiB
JavaScript

// tests/kb-update/test-backfill-status.test.mjs
// TDD for the Status-backfill mechanism (R21 + Enhet 3). The applier (backfill-status.mjs)
// is a manifest-driven driver over the already-tested insertMetaField primitive; the ONLY
// new production logic is the pure deterministic value rule statusForFile() + the frozen
// MANIFEST. This suite pins both:
// - statusForFile: filename token (template|matrix|benchmarks|register) → 'Reference',
// else 'Established Practice'. Operator-approved vocabulary (2026-07-06).
// - MANIFEST self-consistency: distinct entries, each value === statusForFile(path).
//
// Scope history:
// R21 (2026-07-06) — 14 English-dialect advisor/architecture files (7 Reference + 7 EP).
// Enhet 3 (2026-07-07) — +25 non-advisor "none"-dialect files that lack **Status:** entirely
// (ground-truth measured: 25, NOT the roadmap's "27" — 2 of the roadmap count were files
// whose bold **Status:** sits past byte 500, i.e. present-but-header-invisible, a separate
// header-slanking residual, not a missing-Status file). None of the 25 match the artifact
// token → all 'Established Practice'. The 4 dual-header ai-act-* files are handled by the
// plain→bold dedup driver (dedup-plain-header.mjs), NOT here — they carry an authored
// `Status: GA` we preserve, so they must stay OUT of this derive-a-value manifest.
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { statusForFile, MANIFEST, ALLOWED_STATUS } from '../../scripts/kb-update/backfill-status.mjs';
// The 14 R21 advisor targets (clean advisor/architecture).
const ADVISOR_REFERENCE = [
'adr-template.md',
'ai-utredning-template.md',
'capacity-feasibility-benchmarks.md',
'diagram-prompt-templates.md',
'licensing-matrix.md',
'poc-template.md',
'source-traceability-assumption-register.md',
];
const ADVISOR_ESTABLISHED = [
'alternativanalyse-methodology.md',
'cost-models.md',
'decision-trees.md',
'migration-patterns.md',
'public-sector-checklist.md',
'regional-availability-verification.md',
'security.md',
];
// The 25 Enhet-3 non-advisor targets (missing **Status:** entirely). All → Established
// Practice (none carries a template/matrix/benchmarks/register token).
const NON_ADVISOR_ESTABLISHED = [
'skills/ms-ai-engineering/references/mlops-genaiops/cost-optimization-mlops-pipelines.md',
'skills/ms-ai-engineering/references/mlops-genaiops/feedback-loops-continuous-improvement.md',
'skills/ms-ai-engineering/references/mlops-genaiops/genaiops-llm-specific-practices.md',
'skills/ms-ai-engineering/references/mlops-genaiops/governance-audit-ml-operations.md',
'skills/ms-ai-engineering/references/mlops-genaiops/inferencing-optimization-caching.md',
'skills/ms-ai-engineering/references/mlops-genaiops/infrastructure-as-code-mlops.md',
'skills/ms-ai-engineering/references/mlops-genaiops/llm-evaluation-production.md',
'skills/ms-ai-engineering/references/mlops-genaiops/mlops-security-access-control.md',
'skills/ms-ai-engineering/references/mlops-genaiops/mlops-teams-collaboration-tools.md',
'skills/ms-ai-engineering/references/mlops-genaiops/model-deployment-strategies-azure.md',
'skills/ms-ai-engineering/references/mlops-genaiops/monitoring-observability-ml-systems.md',
'skills/ms-ai-engineering/references/mlops-genaiops/prompt-flow-production-deployment.md',
'skills/ms-ai-engineering/references/mlops-genaiops/responsible-ai-mlops-integration.md',
'skills/ms-ai-governance/references/monitoring-observability/anomaly-detection-ai-systems.md',
'skills/ms-ai-governance/references/monitoring-observability/azure-monitor-setup-ai-workloads.md',
'skills/ms-ai-governance/references/monitoring-observability/log-analytics-kql-ai-queries.md',
'skills/ms-ai-governance/references/monitoring-observability/token-usage-tracking-attribution.md',
'skills/ms-ai-governance/references/responsible-ai/ai-center-of-excellence-setup.md',
'skills/ms-ai-governance/references/responsible-ai/ai-governance-structure-framework.md',
'skills/ms-ai-governance/references/responsible-ai/red-teaming-ai-models.md',
'skills/ms-ai-security/references/ai-security-engineering/ai-red-team-operations-practical.md',
'skills/ms-ai-security/references/ai-security-engineering/data-leakage-prevention-ai.md',
'skills/ms-ai-security/references/ai-security-engineering/secure-model-deployment-hardening.md',
'skills/ms-ai-security/references/ai-security-engineering/security-copilot-integration.md',
'skills/ms-ai-security/references/ai-security-engineering/supply-chain-security-ai-models.md',
];
test('statusForFile: artifact-token filenames → Reference', () => {
for (const b of ADVISOR_REFERENCE) assert.equal(statusForFile(b), 'Reference', b);
});
test('statusForFile: methodology/guidance/obligation filenames → Established Practice', () => {
for (const b of ADVISOR_ESTABLISHED) assert.equal(statusForFile(b), 'Established Practice', b);
});
test('statusForFile: keys on basename only, not on ancestor folders', () => {
// A folder named "templates" must not flip a guidance file to Reference.
assert.equal(statusForFile('skills/x/references/templates/migration-patterns.md'), 'Established Practice');
// Full plugin-relative path resolves to the same value as the bare basename.
assert.equal(statusForFile('skills/ms-ai-advisor/references/architecture/poc-template.md'), 'Reference');
});
test('statusForFile: always returns an allowed value', () => {
for (const b of [...ADVISOR_REFERENCE, ...ADVISOR_ESTABLISHED, 'anything-else.md']) {
assert.ok(ALLOWED_STATUS.includes(statusForFile(b)), b);
}
});
test('MANIFEST: exactly 39 distinct entries, each value === statusForFile(path)', () => {
assert.equal(MANIFEST.length, 39);
const paths = new Set(MANIFEST.map((m) => m.path));
assert.equal(paths.size, 39, 'duplicate path in MANIFEST');
for (const { path, status } of MANIFEST) {
assert.ok(ALLOWED_STATUS.includes(status), `bad status for ${path}`);
assert.equal(status, statusForFile(path), `manifest/rule mismatch for ${path}`);
}
});
test('MANIFEST: 7 Reference + 32 Established Practice (R21 14 + Enhet 3 25)', () => {
const ref = MANIFEST.filter((m) => m.status === 'Reference').length;
const est = MANIFEST.filter((m) => m.status === 'Established Practice').length;
assert.equal(ref, 7);
assert.equal(est, 32);
});
test('MANIFEST: all 25 Enhet-3 non-advisor targets present and Established Practice', () => {
for (const p of NON_ADVISOR_ESTABLISHED) {
const entry = MANIFEST.find((m) => m.path === p);
assert.ok(entry, `missing from MANIFEST: ${p}`);
assert.equal(entry.status, 'Established Practice', p);
assert.equal(statusForFile(p), 'Established Practice', p);
}
});
test('MANIFEST: excludes the 4 dual-header ai-act-* files (handled by dedup driver, authored Status: GA preserved)', () => {
const deferred = [
'ai-act-classification-methodology.md',
'ai-act-deployer-obligations.md',
'ai-act-fria-template.md',
'ai-act-provider-obligations.md',
];
for (const d of deferred) {
assert.ok(!MANIFEST.some((m) => m.path.endsWith(d)), `${d} must not be in the Status-derive MANIFEST`);
}
});