ktg-plugin-marketplace/plugins/voyage/tests/lib/plan-schema.test.mjs
Kjell Tore Guttormsen 7a90d348ad feat(voyage)!: marketplace handoff — rename plugins/ultraplan-local to plugins/voyage [skip-docs]
Session 5 of voyage-rebrand (V6). Operator-authorized cross-plugin scope.

- git mv plugins/ultraplan-local plugins/voyage (rename detected, history preserved)
- .claude-plugin/marketplace.json: voyage entry replaces ultraplan-local
- CLAUDE.md: voyage row in plugin list, voyage in design-system consumer list
- README.md: bulk rename ultra*-local commands -> trek* commands; ultraplan-local refs -> voyage; type discriminators (type: trekbrief/trekreview); session-title pattern (voyage:<command>:<slug>); v4.0.0 release-note paragraph
- plugins/voyage/.claude-plugin/plugin.json: homepage/repository URLs point to monorepo voyage path
- plugins/voyage/verify.sh: drop URL whitelist exception (no longer needed)

Closes voyage-rebrand. bash plugins/voyage/verify.sh PASS 7/7. npm test 361/361.
2026-05-05 15:37:52 +02:00

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