7 nye moduler:
- lib/util/result.mjs — Result-shape m/ ok/fail/combine helpers
- lib/util/frontmatter.mjs — håndruller YAML-frontmatter-parser (subset, zero deps)
- lib/parsers/plan-schema.mjs — v1.7 step-regex + forbidden-heading-deteksjon (Fase/Phase/Stage/Steg)
- lib/parsers/manifest-yaml.mjs — per-step Manifest YAML-ekstraksjon m/ regex-validering
- lib/parsers/project-discovery.mjs — finn brief/research/architecture/plan/progress i prosjektmappe
- lib/parsers/arg-parser.mjs — $ARGUMENTS for alle 4 commands m/ flag-schema
- lib/parsers/bash-normalize.mjs — løftet fra hooks/scripts/pre-bash-executor.mjs
6 test-filer (66 tester totalt) — alle grønn:
- frontmatter (CRLF/BOM, scalars, lister, indent-rejection)
- plan-schema (positive Step-form, negative Fase/Phase/Stage/Steg, numbering, slicing)
- manifest-yaml (extraction, parsing, regex-validering, missing-key detection)
- project-discovery (sortert research, architecture-detection, phase-requirements)
- arg-parser (boolean/valued/multi-value flags, kvotert positional, ukjente flag)
- bash-normalize (\${x}/\\\\evasion, ANSI-stripping, full canonicalize-pipeline)
Forbereder Wave 2 (validators) og Spor 1-wiring inn i commands.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
137 lines
3.7 KiB
JavaScript
137 lines
3.7 KiB
JavaScript
import { test } from 'node:test';
|
|
import { strict as assert } from 'node:assert';
|
|
import {
|
|
findSteps,
|
|
findForbiddenHeadings,
|
|
sliceSteps,
|
|
validatePlanHeadings,
|
|
extractPlanVersion,
|
|
} from '../../lib/parsers/plan-schema.mjs';
|
|
|
|
const GOOD_PLAN = `---
|
|
plan_version: "1.7"
|
|
---
|
|
|
|
## Implementation Plan
|
|
|
|
### Step 1: First step
|
|
|
|
- Files: a.ts
|
|
|
|
### Step 2: Second step
|
|
|
|
- Files: b.ts
|
|
|
|
### Step 3: Third step
|
|
|
|
- Files: c.ts
|
|
`;
|
|
|
|
const FORBIDDEN_FASE = `## Implementation Plan
|
|
|
|
## Fase 1: Forberedelse
|
|
|
|
content here
|
|
|
|
## Fase 2: Implementering
|
|
|
|
more content
|
|
`;
|
|
|
|
const FORBIDDEN_PHASE = `### Phase 1: Setup
|
|
|
|
content
|
|
`;
|
|
|
|
const FORBIDDEN_STAGE = `### Stage 1: Initial work
|
|
|
|
content
|
|
`;
|
|
|
|
const FORBIDDEN_STEG = `### Steg 1: Norsk drift
|
|
|
|
content
|
|
`;
|
|
|
|
test('findSteps — locates all canonical step headings', () => {
|
|
const steps = findSteps(GOOD_PLAN);
|
|
assert.equal(steps.length, 3);
|
|
assert.equal(steps[0].n, 1);
|
|
assert.equal(steps[0].title, 'First step');
|
|
assert.equal(steps[2].n, 3);
|
|
assert.equal(steps[2].title, 'Third step');
|
|
});
|
|
|
|
test('findSteps — empty for plan without steps', () => {
|
|
assert.deepEqual(findSteps('## Implementation Plan\n\nno steps yet'), []);
|
|
});
|
|
|
|
test('findForbiddenHeadings — Fase (Norwegian)', () => {
|
|
const f = findForbiddenHeadings(FORBIDDEN_FASE);
|
|
assert.equal(f.length, 2);
|
|
assert.match(f[0].raw, /Fase 1/);
|
|
});
|
|
|
|
test('findForbiddenHeadings — Phase (English)', () => {
|
|
const f = findForbiddenHeadings(FORBIDDEN_PHASE);
|
|
assert.equal(f.length, 1);
|
|
});
|
|
|
|
test('findForbiddenHeadings — Stage', () => {
|
|
assert.equal(findForbiddenHeadings(FORBIDDEN_STAGE).length, 1);
|
|
});
|
|
|
|
test('findForbiddenHeadings — Steg (Norwegian variant)', () => {
|
|
assert.equal(findForbiddenHeadings(FORBIDDEN_STEG).length, 1);
|
|
});
|
|
|
|
test('findForbiddenHeadings — clean plan has zero', () => {
|
|
assert.equal(findForbiddenHeadings(GOOD_PLAN).length, 0);
|
|
});
|
|
|
|
test('sliceSteps — body bounded by next step', () => {
|
|
const sections = sliceSteps(GOOD_PLAN);
|
|
assert.equal(sections.length, 3);
|
|
assert.match(sections[0].body, /First step/);
|
|
assert.match(sections[0].body, /Files: a\.ts/);
|
|
assert.ok(!sections[0].body.includes('Second step'));
|
|
});
|
|
|
|
test('validatePlanHeadings — strict accepts good plan', () => {
|
|
const r = validatePlanHeadings(GOOD_PLAN, { strict: true });
|
|
assert.equal(r.valid, true);
|
|
assert.equal(r.parsed.steps.length, 3);
|
|
});
|
|
|
|
test('validatePlanHeadings — strict rejects forbidden Fase form', () => {
|
|
const r = validatePlanHeadings(FORBIDDEN_FASE, { strict: true });
|
|
assert.equal(r.valid, false);
|
|
assert.ok(r.errors.find(e => e.code === 'PLAN_FORBIDDEN_HEADING'));
|
|
});
|
|
|
|
test('validatePlanHeadings — soft mode demotes forbidden to warning', () => {
|
|
const r = validatePlanHeadings(`### Step 1: ok\n\n### Phase 2: drift\n`, { strict: false });
|
|
assert.equal(r.errors.find(e => e.code === 'PLAN_FORBIDDEN_HEADING'), undefined);
|
|
assert.ok(r.warnings.find(w => w.code === 'PLAN_FORBIDDEN_HEADING'));
|
|
});
|
|
|
|
test('validatePlanHeadings — non-contiguous numbering is an error', () => {
|
|
const broken = '### Step 1: ok\ncontent\n\n### Step 3: skip\ncontent\n';
|
|
const r = validatePlanHeadings(broken, { strict: true });
|
|
assert.equal(r.valid, false);
|
|
assert.ok(r.errors.find(e => e.code === 'PLAN_STEP_NUMBERING'));
|
|
});
|
|
|
|
test('validatePlanHeadings — empty plan errors with PLAN_NO_STEPS', () => {
|
|
const r = validatePlanHeadings('## Implementation Plan\n\nno steps\n');
|
|
assert.ok(r.errors.find(e => e.code === 'PLAN_NO_STEPS'));
|
|
});
|
|
|
|
test('extractPlanVersion — from frontmatter', () => {
|
|
assert.equal(extractPlanVersion('plan_version: "1.7"\nfoo: bar\n'), '1.7');
|
|
assert.equal(extractPlanVersion('plan_version: 1.8\n'), '1.8');
|
|
});
|
|
|
|
test('extractPlanVersion — null when absent', () => {
|
|
assert.equal(extractPlanVersion('foo: bar\n'), null);
|
|
});
|