feat(ultraplan-local): Spor 1 wave 2 — 5 validators + doc-consistency, 108 tests grønn [skip-docs]

5 nye validator-moduler (alle m/ CLI-shim for invokering fra commands):
- brief-validator.mjs — frontmatter (type, brief_version, task, slug, research_topics, research_status), state machine (research_topics > 0 + skipped requires brief_quality: partial), body sections (Intent/Goal/Success Criteria)
- research-validator.mjs — type=ultraresearch-brief, confidence ∈ [0,1], dimensions ≥ 1, body sections, --dir mode for batch validering
- plan-validator.mjs — wrapper over plan-schema + manifest-yaml; håndhever step-count == manifest-count, plan_version=1.7
- progress-validator.mjs — schema_version, status enum, current_step in range, step shape, checkResumeReadiness
- architecture-discovery.mjs — EKSTERN KONTRAKT: drift-WARN ikke drift-FAIL; tolererer non-canonical filnavn, surfacer loose files som warnings

Doc-consistency-test pinning prose vs source-of-truth:
- agents/*.md count == CLAUDE.md agent-tabell rader
- commands/*.md mentioned i CLAUDE.md
- command frontmatter.name == filnavn
- templates/plan-template.md plan_version 1.7 invariant
- settings.json kun kjente scopes (ultraplan, ultraresearch)
- settings.json ingen exploration eller agentTeam (vestigial guard etter Spor 0)
- CLAUDE.md refererer alle 4 pipeline-commands

Wave 1 + Wave 2 = 108 tester grønn.

[skip-docs]: Test-infrastrukturen er ikke user-facing før Spor 1 wiring lander; README/CLAUDE.md oppdateres når commands faktisk endrer atferd (neste commit).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Kjell Tore Guttormsen 2026-05-01 05:39:47 +02:00
commit 65c9242160
11 changed files with 999 additions and 0 deletions

View file

@ -0,0 +1,81 @@
import { test } from 'node:test';
import { strict as assert } from 'node:assert';
import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { discoverArchitecture } from '../../lib/validators/architecture-discovery.mjs';
function setup(structure) {
const root = mkdtempSync(join(tmpdir(), 'ultraplan-arch-'));
for (const [path, content] of Object.entries(structure)) {
const full = join(root, path);
mkdirSync(join(full, '..'), { recursive: true });
writeFileSync(full, content);
}
return root;
}
test('discoverArchitecture — canonical overview.md found cleanly', () => {
const root = setup({ 'architecture/overview.md': '# Overview\n' });
try {
const r = discoverArchitecture(root);
assert.equal(r.found, true);
assert.match(r.overview, /architecture\/overview\.md$/);
assert.equal(r.warnings.length, 0);
assert.equal(r.firstHeading, 'Overview');
} finally { rmSync(root, { recursive: true, force: true }); }
});
test('discoverArchitecture — no architecture dir = not found, no warnings', () => {
const root = setup({ 'brief.md': 'b' });
try {
const r = discoverArchitecture(root);
assert.equal(r.found, false);
assert.equal(r.warnings.length, 0);
} finally { rmSync(root, { recursive: true, force: true }); }
});
test('discoverArchitecture — non-canonical name discovered with warning (drift-WARN)', () => {
const root = setup({ 'architecture/architecture-overview.md': '# Drifted\n' });
try {
const r = discoverArchitecture(root);
assert.equal(r.found, true);
assert.ok(r.warnings.find(w => w.code === 'ARCH_NON_CANONICAL_OVERVIEW'));
} finally { rmSync(root, { recursive: true, force: true }); }
});
test('discoverArchitecture — loose unknown files surfaced as drift warning', () => {
const root = setup({
'architecture/overview.md': '# OK\n',
'architecture/random-note.md': 'x',
'architecture/another.md': 'y',
});
try {
const r = discoverArchitecture(root);
assert.equal(r.found, true);
assert.ok(r.warnings.find(w => w.code === 'ARCH_LOOSE_FILES'));
assert.equal(r.looseFiles.length, 2);
} finally { rmSync(root, { recursive: true, force: true }); }
});
test('discoverArchitecture — gaps.md detected when present', () => {
const root = setup({
'architecture/overview.md': '# OK\n',
'architecture/gaps.md': '# Gaps\n',
});
try {
const r = discoverArchitecture(root);
assert.match(r.gaps, /architecture\/gaps\.md$/);
} finally { rmSync(root, { recursive: true, force: true }); }
});
test('discoverArchitecture — never reads body beyond first heading', () => {
const root = setup({
'architecture/overview.md': '# Overview\n\n## Components\n\nlots of detail that we MUST NOT validate\n',
});
try {
const r = discoverArchitecture(root);
assert.equal(r.firstHeading, 'Overview');
// Validator does not assert on Components section — that's the contract.
} finally { rmSync(root, { recursive: true, force: true }); }
});

View file

@ -0,0 +1,94 @@
import { test } from 'node:test';
import { strict as assert } from 'node:assert';
import { validateBriefContent } from '../../lib/validators/brief-validator.mjs';
const GOOD_BRIEF = `---
type: ultrabrief
brief_version: "2.0"
created: 2026-04-30
task: "Add JWT auth to API"
slug: jwt-auth
project_dir: .claude/projects/2026-04-30-jwt-auth/
research_topics: 2
research_status: pending
auto_research: false
interview_turns: 5
source: interview
---
# Task: JWT auth
## Intent
Why this matters.
## Goal
What success looks like.
## Success Criteria
- All tests pass.
`;
test('validateBrief — happy path', () => {
const r = validateBriefContent(GOOD_BRIEF, { strict: true });
assert.equal(r.valid, true, JSON.stringify(r.errors));
});
test('validateBrief — wrong type rejected', () => {
const t = GOOD_BRIEF.replace('type: ultrabrief', 'type: notabrief');
const r = validateBriefContent(t);
assert.equal(r.valid, false);
assert.ok(r.errors.find(e => e.code === 'BRIEF_WRONG_TYPE'));
});
test('validateBrief — missing required field', () => {
const t = GOOD_BRIEF.replace(/^research_topics: 2\n/m, '');
const r = validateBriefContent(t);
assert.equal(r.valid, false);
assert.ok(r.errors.find(e => e.code === 'BRIEF_MISSING_FIELD' && /research_topics/.test(e.message)));
});
test('validateBrief — bad research_status value', () => {
const t = GOOD_BRIEF.replace('research_status: pending', 'research_status: maybe');
const r = validateBriefContent(t);
assert.equal(r.valid, false);
assert.ok(r.errors.find(e => e.code === 'BRIEF_BAD_STATUS'));
});
test('validateBrief — state machine: research_topics > 0 + skipped without partial = error', () => {
const t = GOOD_BRIEF.replace('research_status: pending', 'research_status: skipped');
const r = validateBriefContent(t);
assert.equal(r.valid, false);
assert.ok(r.errors.find(e => e.code === 'BRIEF_STATE_INCOHERENT'));
});
test('validateBrief — state machine: skipped + brief_quality: partial = warning only', () => {
const t = GOOD_BRIEF
.replace('research_status: pending', 'research_status: skipped')
.replace('source: interview', 'source: interview\nbrief_quality: partial');
const r = validateBriefContent(t);
assert.equal(r.valid, true, JSON.stringify(r.errors));
assert.ok(r.warnings.find(w => w.code === 'BRIEF_PARTIAL_SKIPPED'));
});
test('validateBrief — strict requires body sections', () => {
const t = GOOD_BRIEF.replace(/## Intent\n\nWhy this matters\.\n\n/, '');
const r = validateBriefContent(t, { strict: true });
assert.equal(r.valid, false);
assert.ok(r.errors.find(e => e.code === 'BRIEF_MISSING_SECTION'));
});
test('validateBrief — soft demotes section errors to warnings', () => {
const t = GOOD_BRIEF.replace(/## Goal\n\nWhat success looks like\.\n\n/, '');
const r = validateBriefContent(t, { strict: false });
assert.equal(r.valid, true);
assert.ok(r.warnings.find(w => w.code === 'BRIEF_MISSING_SECTION'));
});
test('validateBrief — missing frontmatter is hard error', () => {
const r = validateBriefContent('# just markdown\n\nno frontmatter\n');
assert.equal(r.valid, false);
assert.ok(r.errors.find(e => e.code === 'FM_MISSING'));
});

View file

@ -0,0 +1,99 @@
import { test } from 'node:test';
import { strict as assert } from 'node:assert';
import { validatePlanContent } from '../../lib/validators/plan-validator.mjs';
const VALID_PLAN = `---
plan_version: "1.7"
---
# Plan
## Implementation Plan
### Step 1: Add foo
- Files: a.ts
- Manifest:
\`\`\`yaml
manifest:
expected_paths:
- a.ts
min_file_count: 1
commit_message_pattern: "^feat:"
bash_syntax_check: []
forbidden_paths: []
must_contain: []
\`\`\`
### Step 2: Add bar
- Files: b.ts
- Manifest:
\`\`\`yaml
manifest:
expected_paths:
- b.ts
min_file_count: 1
commit_message_pattern: "^feat:"
bash_syntax_check: []
forbidden_paths: []
must_contain: []
\`\`\`
`;
const FORBIDDEN_PLAN = `---
plan_version: "1.7"
---
## Fase 1: Drift form
content
`;
const STEP_WITHOUT_MANIFEST = `### Step 1: oops
no manifest
### Step 2: ok
- Manifest:
\`\`\`yaml
manifest:
expected_paths: [foo]
min_file_count: 1
commit_message_pattern: "^x:"
bash_syntax_check: []
forbidden_paths: []
must_contain: []
\`\`\`
`;
test('validatePlan — strict accepts canonical v1.7 plan', () => {
const r = validatePlanContent(VALID_PLAN, { strict: true });
assert.equal(r.valid, true, JSON.stringify(r.errors));
assert.equal(r.parsed.steps.length, 2);
assert.equal(r.parsed.planVersion, '1.7');
});
test('validatePlan — forbidden Fase form blocks in strict mode', () => {
const r = validatePlanContent(FORBIDDEN_PLAN, { strict: true });
assert.equal(r.valid, false);
assert.ok(r.errors.find(e => e.code === 'PLAN_FORBIDDEN_HEADING'));
});
test('validatePlan — manifest count mismatch caught', () => {
const r = validatePlanContent(STEP_WITHOUT_MANIFEST, { strict: true });
assert.equal(r.valid, false);
assert.ok(r.errors.find(e => /Step 1/.test(e.message) && /MANIFEST_MISSING/.test(e.code)));
});
test('validatePlan — version warning when missing', () => {
const noVersion = VALID_PLAN.replace(/plan_version: "1\.7"\n/, '');
const r = validatePlanContent(noVersion, { strict: true });
assert.ok(r.warnings.find(w => w.code === 'PLAN_NO_VERSION'));
});
test('validatePlan — older version triggers warning', () => {
const old = VALID_PLAN.replace('plan_version: "1.7"', 'plan_version: "1.5"');
const r = validatePlanContent(old, { strict: true });
assert.ok(r.warnings.find(w => w.code === 'PLAN_VERSION_MISMATCH'));
});

View file

@ -0,0 +1,79 @@
import { test } from 'node:test';
import { strict as assert } from 'node:assert';
import { validateProgressObject, checkResumeReadiness } from '../../lib/validators/progress-validator.mjs';
function goodProgress() {
return {
schema_version: '1',
plan: '.claude/projects/x/plan.md',
plan_type: 'plan',
plan_version: '1.7',
started_at: '2026-04-18T12:00:00Z',
updated_at: '2026-04-18T13:00:00Z',
mode: 'execute',
total_steps: 2,
current_step: 1,
status: 'in_progress',
steps: {
'1': { status: 'completed', attempts: 1, error: null, completed_at: '2026-04-18T12:30:00Z', commit: 'abc123', manifest_audit: 'pass' },
'2': { status: 'pending', attempts: 0, error: null, completed_at: null, commit: null, manifest_audit: null },
},
};
}
test('validateProgress — happy path', () => {
const r = validateProgressObject(goodProgress());
assert.equal(r.valid, true, JSON.stringify(r.errors));
});
test('validateProgress — wrong schema_version', () => {
const p = goodProgress();
p.schema_version = '2';
const r = validateProgressObject(p);
assert.equal(r.valid, false);
assert.ok(r.errors.find(e => e.code === 'PROGRESS_SCHEMA_MISMATCH'));
});
test('validateProgress — missing required field', () => {
const p = goodProgress();
delete p.total_steps;
const r = validateProgressObject(p);
assert.equal(r.valid, false);
assert.ok(r.errors.find(e => e.code === 'PROGRESS_MISSING_FIELD' && /total_steps/.test(e.message)));
});
test('validateProgress — bad status', () => {
const p = goodProgress();
p.status = 'maybe';
const r = validateProgressObject(p);
assert.equal(r.valid, false);
assert.ok(r.errors.find(e => e.code === 'PROGRESS_BAD_STATUS'));
});
test('validateProgress — current_step out of range', () => {
const p = goodProgress();
p.current_step = 99;
const r = validateProgressObject(p);
assert.equal(r.valid, false);
assert.ok(r.errors.find(e => e.code === 'PROGRESS_STEP_RANGE'));
});
test('validateProgress — step count mismatch is warning', () => {
const p = goodProgress();
p.total_steps = 5;
const r = validateProgressObject(p);
assert.ok(r.warnings.find(w => w.code === 'PROGRESS_STEP_COUNT_MISMATCH'));
});
test('checkResumeReadiness — completed run cannot resume', () => {
const p = goodProgress();
p.status = 'completed';
const r = checkResumeReadiness(p);
assert.equal(r.valid, false);
assert.ok(r.errors.find(e => e.code === 'PROGRESS_ALREADY_DONE'));
});
test('checkResumeReadiness — in-progress is resumable', () => {
const r = checkResumeReadiness(goodProgress());
assert.equal(r.valid, true);
});

View file

@ -0,0 +1,60 @@
import { test } from 'node:test';
import { strict as assert } from 'node:assert';
import { validateResearchContent } from '../../lib/validators/research-validator.mjs';
const GOOD = `---
type: ultraresearch-brief
created: 2026-04-30
question: "How to do X?"
confidence: 0.8
dimensions: 3
---
## Executive Summary
3 sentences.
## Dimensions
### Dim A Confidence: high
`;
test('validateResearch — happy path', () => {
const r = validateResearchContent(GOOD);
assert.equal(r.valid, true, JSON.stringify(r.errors));
});
test('validateResearch — wrong type', () => {
const t = GOOD.replace('type: ultraresearch-brief', 'type: random');
const r = validateResearchContent(t);
assert.equal(r.valid, false);
assert.ok(r.errors.find(e => e.code === 'RESEARCH_WRONG_TYPE'));
});
test('validateResearch — confidence out of range', () => {
const t = GOOD.replace('confidence: 0.8', 'confidence: 1.5');
const r = validateResearchContent(t);
assert.equal(r.valid, false);
assert.ok(r.errors.find(e => e.code === 'RESEARCH_BAD_CONFIDENCE'));
});
test('validateResearch — missing confidence is warning, not error', () => {
const t = GOOD.replace(/^confidence: 0\.8\n/m, '');
const r = validateResearchContent(t);
assert.equal(r.valid, true);
assert.ok(r.warnings.find(w => w.code === 'RESEARCH_NO_CONFIDENCE'));
});
test('validateResearch — strict missing body section is error', () => {
const t = GOOD.replace(/## Dimensions\n\n### Dim A — Confidence: high\n/, '');
const r = validateResearchContent(t, { strict: true });
assert.equal(r.valid, false);
assert.ok(r.errors.find(e => e.code === 'RESEARCH_MISSING_SECTION'));
});
test('validateResearch — bad dimensions value', () => {
const t = GOOD.replace('dimensions: 3', 'dimensions: 0');
const r = validateResearchContent(t);
assert.equal(r.valid, false);
assert.ok(r.errors.find(e => e.code === 'RESEARCH_BAD_DIMENSIONS'));
});