The plan template (templates/plan-template.md:21) emits plan_version ONLY in
the prose blockquote metadata line:
> Generated by trekplan v{version} on {YYYY-MM-DD} — `plan_version: 1.7`
It carries no frontmatter plan_version (the frontmatter block is trekreview-only
and holds source_findings). But PLAN_VERSION_REGEX in lib/parsers/plan-schema.mjs
was `^`-anchored (/m), matching ONLY line-start (frontmatter). The backtick-
wrapped prose form never matched → extractPlanVersion returned null → every real
generated plan got a spurious PLAN_NO_VERSION warning from plan-validator.
Not caught earlier because no test ran the parser against the actual template;
the synthetic fixtures all carry frontmatter plan_version and parse fine.
Internal source contradiction surfaced: the parser comment documents intent
"frontmatter OR doc body", planning-orchestrator.md:228 + the template place it
in the prose line, while HANDOVER-CONTRACTS.md calls it a frontmatter field.
Operator-chosen fix (parser, not template): relax the regex to
`/(?:^|`)plan_version:.../m` so it matches line-start (frontmatter) OR the
backtick-prefixed prose form. Honors the parser's own documented contract,
fixes all existing + future plans, changes no plan output, touches one code
file — vs the template-fix which would alter every plan's shape, contradict
planning-orchestrator.md, and force a 3-file doc reconciliation (scope creep).
TDD (red first): added prose-form + canonical-template regression pins in
plan-schema.test.mjs and a no-PLAN_NO_VERSION pin in plan-validator.test.mjs;
all 3 red on the `^`-anchored regex, green after the relax. The template pin
ties the parser directly to the real generated artifact.
S22 defect closed in docs/S22-happy-path-dogfood.md (§Pipeline defects + log).
Tests: 728 (726 pass / 2 skip / 0 fail; live `node --test`, = 725 baseline +3).
plugin validate passes (1 accepted CLAUDE.md-at-root warning).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LqBYc8Ltrk7LipyJmGxXiB
113 lines
3 KiB
JavaScript
113 lines
3 KiB
JavaScript
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'));
|
|
});
|
|
|
|
test('validatePlan — prose plan_version line parses, no PLAN_NO_VERSION (defect S26)', () => {
|
|
// A plan shaped like the real template: plan_version lives only in the
|
|
// prose "Generated by" blockquote, not frontmatter. Must still parse.
|
|
const prosePlan = VALID_PLAN
|
|
.replace(/---\nplan_version: "1\.7"\n---\n\n/, '')
|
|
.replace(
|
|
'# Plan',
|
|
'# Plan\n\n> Generated by trekplan v4.1.0 on 2026-05-10 — `plan_version: 1.7`',
|
|
);
|
|
const r = validatePlanContent(prosePlan, { strict: true });
|
|
assert.equal(r.parsed.planVersion, '1.7');
|
|
assert.equal(r.warnings.find(w => w.code === 'PLAN_NO_VERSION'), undefined);
|
|
});
|