3 new test files, 24 cases (8 per validator): - baseline (no annotation fields) still valid - revision: 0 / revision: 5 accepted - source_annotations list-of-dict accepted - annotation_digest string accepted - revision_reason accepted - all 4 fields together accepted - unrecognized future field tolerated (forward-compat policy) Pin against future strict-key refactors. No production code change — pure regression pin.
87 lines
3.7 KiB
JavaScript
87 lines
3.7 KiB
JavaScript
// tests/validators/brief-validator-annotation-fields.test.mjs
|
|
// Pin forward-compat for v4.2 annotation frontmatter fields on brief.md.
|
|
// Adding revision/source_annotations/annotation_digest/revision_reason must NOT
|
|
// trigger BRIEF_UNKNOWN_FIELD or similar — validator is purely additive-tolerant
|
|
// per source_findings precedent. No code change required; this test pins the policy.
|
|
|
|
import { test } from 'node:test';
|
|
import { strict as assert } from 'node:assert';
|
|
import { validateBriefContent } from '../../lib/validators/brief-validator.mjs';
|
|
|
|
const BASE_BRIEF = `---
|
|
type: trekbrief
|
|
brief_version: "2.0"
|
|
created: 2026-05-09
|
|
task: "Annotated revision for testing forward-compat"
|
|
slug: ann-fwd-compat
|
|
project_dir: .claude/projects/2026-05-09-ann-fwd-compat/
|
|
research_topics: 0
|
|
research_status: skipped
|
|
auto_research: false
|
|
interview_turns: 1
|
|
source: interview
|
|
---
|
|
|
|
# Task: Annotated revision
|
|
|
|
## Intent
|
|
|
|
Why.
|
|
|
|
## Goal
|
|
|
|
What.
|
|
|
|
## Success Criteria
|
|
|
|
- Done.
|
|
`;
|
|
|
|
test('brief-validator forward-compat — baseline (no annotation fields) still valid', () => {
|
|
const r = validateBriefContent(BASE_BRIEF, { strict: true });
|
|
assert.equal(r.valid, true, JSON.stringify(r.errors));
|
|
});
|
|
|
|
test('brief-validator forward-compat — accepts revision: 0', () => {
|
|
const t = BASE_BRIEF.replace('---\ninterview_turns: 1', '---\ninterview_turns: 1\nrevision: 0');
|
|
const r = validateBriefContent(t, { strict: true });
|
|
assert.equal(r.valid, true, JSON.stringify(r.errors));
|
|
});
|
|
|
|
test('brief-validator forward-compat — accepts revision: 5', () => {
|
|
const t = BASE_BRIEF.replace('source: interview', 'source: interview\nrevision: 5');
|
|
const r = validateBriefContent(t, { strict: true });
|
|
assert.equal(r.valid, true, JSON.stringify(r.errors));
|
|
});
|
|
|
|
test('brief-validator forward-compat — accepts source_annotations list-of-dict', () => {
|
|
const inject = `\nrevision: 1\nsource_annotations:\n - id: ANN-0001\n target_artifact: brief.md\n target_anchor: intent\n intent: change\n comment: "tighten the intent paragraph"\n timestamp: "2026-05-09T10:00:00Z"`;
|
|
const t = BASE_BRIEF.replace('source: interview', 'source: interview' + inject);
|
|
const r = validateBriefContent(t, { strict: true });
|
|
assert.equal(r.valid, true, JSON.stringify(r.errors));
|
|
});
|
|
|
|
test('brief-validator forward-compat — accepts annotation_digest string', () => {
|
|
const t = BASE_BRIEF.replace('source: interview', 'source: interview\nrevision: 1\nannotation_digest: abc123def4567890');
|
|
const r = validateBriefContent(t, { strict: true });
|
|
assert.equal(r.valid, true, JSON.stringify(r.errors));
|
|
});
|
|
|
|
test('brief-validator forward-compat — accepts revision_reason for non-additive revision', () => {
|
|
const t = BASE_BRIEF.replace('source: interview', 'source: interview\nrevision: 2\nrevision_reason: "restructured Goals section"');
|
|
const r = validateBriefContent(t, { strict: true });
|
|
assert.equal(r.valid, true, JSON.stringify(r.errors));
|
|
});
|
|
|
|
test('brief-validator forward-compat — all 4 fields together still valid', () => {
|
|
const inject = `\nrevision: 3\nrevision_reason: "applied 5 annotations"\nannotation_digest: 0123456789abcdef\nsource_annotations:\n - id: ANN-0001\n target_artifact: brief.md\n target_anchor: goal\n intent: change`;
|
|
const t = BASE_BRIEF.replace('source: interview', 'source: interview' + inject);
|
|
const r = validateBriefContent(t, { strict: true });
|
|
assert.equal(r.valid, true, JSON.stringify(r.errors));
|
|
});
|
|
|
|
test('brief-validator forward-compat — unrecognized future field still tolerated (forward-compat policy)', () => {
|
|
const t = BASE_BRIEF.replace('source: interview', 'source: interview\nfuture_v4_3_field: "anything"');
|
|
const r = validateBriefContent(t, { strict: true });
|
|
assert.equal(r.valid, true, JSON.stringify(r.errors));
|
|
});
|