ktg-plugin-marketplace/plugins/ultraplan-local/tests/validators/research-validator.test.mjs
Kjell Tore Guttormsen 65c9242160 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>
2026-05-01 05:39:47 +02:00

60 lines
1.9 KiB
JavaScript

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'));
});