feat(ms-ai-architect): Sesjon 2 - registry-skjema (authority_source + course reservert)
build-registry leser na **Source:**/**Primary source:**-header via ny lib/kb-headers.mjs (parseSourceHeader, 7 enhetstester) og logger dekning (0/N i dag). Hver URL-entry far reserverte felt authority_source:null + course:null (bakoverkompatibelt). Populering med korrekt semantikk utsatt til verifiseringslaget (lag 3) - minimal-reservert per operator-valg. Eksisterende status-felt (poll: tracked/not_in_sitemap/unpolled) urort for a unnga kollisjon. kb-update 56 tester gronne. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01REiKFhP4w6xGXXqWKpPCJJ
This commit is contained in:
parent
8bea3a224a
commit
eb2a002c2c
3 changed files with 90 additions and 0 deletions
52
tests/kb-update/test-kb-headers.test.mjs
Normal file
52
tests/kb-update/test-kb-headers.test.mjs
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
// tests/kb-update/test-kb-headers.test.mjs
|
||||
// Unit tests for scripts/kb-update/lib/kb-headers.mjs — parses the optional
|
||||
// **Source:** / **Primary source:** authority header from a KB reference file.
|
||||
// Coverage is 0% today (no file declares one yet); the parser is wired into
|
||||
// build-registry so authority_source can populate as files adopt the header.
|
||||
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { parseSourceHeader } from '../../scripts/kb-update/lib/kb-headers.mjs';
|
||||
|
||||
test('parseSourceHeader — **Source:** header', () => {
|
||||
const content = '# Title\n\n**Source:** https://learn.microsoft.com/azure/foundry/concepts/x\n**Status:** GA\n';
|
||||
assert.equal(
|
||||
parseSourceHeader(content),
|
||||
'https://learn.microsoft.com/azure/foundry/concepts/x'
|
||||
);
|
||||
});
|
||||
|
||||
test('parseSourceHeader — **Primary source:** alias', () => {
|
||||
const content = '# Title\n\n**Primary source:** https://learn.microsoft.com/azure/ai-services/y\n';
|
||||
assert.equal(
|
||||
parseSourceHeader(content),
|
||||
'https://learn.microsoft.com/azure/ai-services/y'
|
||||
);
|
||||
});
|
||||
|
||||
test('parseSourceHeader — case-insensitive label', () => {
|
||||
const content = '**source:** https://learn.microsoft.com/azure/z\n';
|
||||
assert.equal(parseSourceHeader(content), 'https://learn.microsoft.com/azure/z');
|
||||
});
|
||||
|
||||
test('parseSourceHeader — no header returns null', () => {
|
||||
const content = '# Title\n\n**Last updated:** 2026-04\n**Status:** GA\n**Category:** RAG\n';
|
||||
assert.equal(parseSourceHeader(content), null);
|
||||
});
|
||||
|
||||
test('parseSourceHeader — empty/garbage input returns null', () => {
|
||||
assert.equal(parseSourceHeader(''), null);
|
||||
assert.equal(parseSourceHeader(null), null);
|
||||
assert.equal(parseSourceHeader(undefined), null);
|
||||
});
|
||||
|
||||
test('parseSourceHeader — only scans the top of the file (header region)', () => {
|
||||
// A Source-like line buried far below the header region must NOT be picked up.
|
||||
const buried = '# Title\n' + 'x'.repeat(800) + '\n**Source:** https://learn.microsoft.com/late\n';
|
||||
assert.equal(parseSourceHeader(buried), null);
|
||||
});
|
||||
|
||||
test('parseSourceHeader — trims trailing whitespace from URL', () => {
|
||||
const content = '**Source:** https://learn.microsoft.com/azure/trim \n';
|
||||
assert.equal(parseSourceHeader(content), 'https://learn.microsoft.com/azure/trim');
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue