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>
74 lines
2.7 KiB
JavaScript
74 lines
2.7 KiB
JavaScript
import { test } from 'node:test';
|
||
import { strict as assert } from 'node:assert';
|
||
import { splitFrontmatter, parseFrontmatter, parseDocument } from '../../lib/util/frontmatter.mjs';
|
||
|
||
test('splitFrontmatter — basic LF', () => {
|
||
const r = splitFrontmatter('---\nfoo: bar\n---\nbody here\n');
|
||
assert.equal(r.hasFrontmatter, true);
|
||
assert.equal(r.frontmatter, 'foo: bar');
|
||
assert.equal(r.body, 'body here\n');
|
||
});
|
||
|
||
test('splitFrontmatter — CRLF tolerated', () => {
|
||
const r = splitFrontmatter('---\r\nfoo: bar\r\n---\r\nbody\r\n');
|
||
assert.equal(r.hasFrontmatter, true);
|
||
assert.equal(r.frontmatter, 'foo: bar');
|
||
});
|
||
|
||
test('splitFrontmatter — BOM stripped', () => {
|
||
const r = splitFrontmatter('---\nfoo: bar\n---\n');
|
||
assert.equal(r.hasFrontmatter, true);
|
||
});
|
||
|
||
test('splitFrontmatter — no frontmatter', () => {
|
||
const r = splitFrontmatter('# title\nbody only\n');
|
||
assert.equal(r.hasFrontmatter, false);
|
||
assert.match(r.body, /title/);
|
||
});
|
||
|
||
test('parseFrontmatter — string scalars', () => {
|
||
const r = parseFrontmatter('type: ultrabrief\nslug: jwt-auth\n');
|
||
assert.equal(r.valid, true);
|
||
assert.equal(r.parsed.type, 'ultrabrief');
|
||
assert.equal(r.parsed.slug, 'jwt-auth');
|
||
});
|
||
|
||
test('parseFrontmatter — number, bool, null', () => {
|
||
const r = parseFrontmatter('research_topics: 3\nautoResearch: true\nfoo: false\nbar: null\n');
|
||
assert.equal(r.parsed.research_topics, 3);
|
||
assert.equal(r.parsed.autoResearch, true);
|
||
assert.equal(r.parsed.foo, false);
|
||
assert.equal(r.parsed.bar, null);
|
||
});
|
||
|
||
test('parseFrontmatter — quoted strings', () => {
|
||
const r = parseFrontmatter('plan_version: "1.7"\nname: \'test thing\'\n');
|
||
assert.equal(r.parsed.plan_version, '1.7');
|
||
assert.equal(r.parsed.name, 'test thing');
|
||
});
|
||
|
||
test('parseFrontmatter — list of scalars', () => {
|
||
const r = parseFrontmatter('keywords:\n - planning\n - research\n - agents\n');
|
||
assert.equal(r.valid, true);
|
||
assert.deepEqual(r.parsed.keywords, ['planning', 'research', 'agents']);
|
||
});
|
||
|
||
test('parseFrontmatter — rejects nested dict', () => {
|
||
const r = parseFrontmatter('a: 1\n b: 2\n');
|
||
assert.equal(r.valid, false);
|
||
assert.ok(r.errors.find(e => e.code === 'FM_INDENT'));
|
||
});
|
||
|
||
test('parseDocument — full pipeline', () => {
|
||
const text = '---\ntype: ultrabrief\nresearch_topics: 2\n---\n\n# Body\n\ncontent\n';
|
||
const r = parseDocument(text);
|
||
assert.equal(r.valid, true);
|
||
assert.equal(r.parsed.frontmatter.type, 'ultrabrief');
|
||
assert.match(r.parsed.body, /content/);
|
||
});
|
||
|
||
test('parseDocument — missing frontmatter is an error', () => {
|
||
const r = parseDocument('# just markdown\nno frontmatter here\n');
|
||
assert.equal(r.valid, false);
|
||
assert.ok(r.errors.find(e => e.code === 'FM_MISSING'));
|
||
});
|