* chore(#604): rename get-shit-done/ runtime directory to gsd-core/ Renames the installed runtime directory `get-shit-done/` to `gsd-core/` so the on-disk name matches the package (`@opengsd/gsd-core`), repo, and binary (`gsd-tools`). The npm package name and binary are unchanged; npx/npm consumers are unaffected. Mechanical (bulk, ~90% of the diff): - `git mv get-shit-done gsd-core` - Swept path/identifier references across the repo via `perl -pe 's/get-shit-done(?!-\w)/gsd-core/g'`. The negative lookahead preserves the five legitimate slug variants that are NOT the directory: get-shit-done-{OLD,cc,classic,cli,redux} (old package/repo names). - Build/manifest wiring: package.json (bin, files, coverage globs), tsconfig.build.json (outDir), ~86 .gitignore build-output entries, stryker.config.mjs, scan-ignore files, install.js path strings. - Frozen (not rewritten): CHANGELOG.md history; translated docs (README.<locale>.md and docs/{ja-JP,ko-KR,pt-BR,zh-CN}/). New logic (review here): - src/installer-migrations/003-rename-get-shit-done-to-gsd-core.cts: a proper ADR-0008 installer migration. On upgrade it walks the legacy `~/.claude/get-shit-done/` tree, classifies each file via the prior install manifest, and emits remove-managed / backup-and-remove for managed files while PRESERVING unknown user-added files. Symlink-safe (skips a symlinked root and symlinked entries; bounds-checks every path under configDir). The framework rolls back on install failure. Emptied dirs may remain (framework has no recursive dir-removal primitive) — documented. - scripts/lint-legacy-dir-name.cjs: CI regression guard forbidding the bare `get-shit-done` directory token (split token to avoid self-match; case- insensitive; `(?!-\w)` lookahead allows the slug variants; allowlists CHANGELOG, translated docs, and `gsd-allow-legacy-name` marker lines). Wired into the lint-tests CI job. - Restored scripts/lint-package-identity-drift.cjs detection regexes (the mechanical sweep had wrongly rewritten the old-name patterns it exists to detect) and marked them as intentional legacy references. - TDD tests for the migration and the guard; do.md slash-command guard regex tightened so a `/gsd-core/bin` path segment is not mistaken for a command; changeset + docs/installer-migrations.md row added. Breaking: the installed runtime path moves `~/.claude/get-shit-done/` -> `~/.claude/gsd-core/`. Migration 003 removes the stale legacy dir's managed files (preserving user files) on upgrade. Users with custom hooks/configs hardcoding the old path must update them. Closes #604 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(#604): unsweep pending changesets + allowlist injection-example docs CI fixes for the rename PR: - Do not sweep pending .changeset/*.md (ephemeral release-note fragments, like CHANGELOG); reverted those body edits so 5 pre-existing malformed fragments (missing type/pr) no longer enter the PR diff and trip docs-lint. Allowlisted .changeset/ in the legacy-name guard accordingly. - Allowlisted TEST-EXAMPLES.md and docs/explanation/security-model.md in prompt-injection-scan.sh: they contain intentional injection examples / security-model prose; the path-reference rewrites are kept. CodeQL alerts on this PR are pre-existing (alert lines unchanged by this PR; none in the new migration/guard) and are out of scope for the rename. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(#604): resolve CodeQL alerts surfaced on this PR The rename diff touched files carrying pre-existing CodeQL findings; per the no-pre-existing-dismissal rule, fixing every surfaced alert rather than waving them off. All behavior-preserving: - scripts/ci-test-scope.cjs: build the config-path match from string .includes() instead of a RegExp over an arg-derived value (js/regex-injection). - src/profile-output.cts: escape backslashes before pipe-escaping desc/safeName so the table-cell escape is complete (js/incomplete-sanitization). - tests/{bug-2643,bug-2808,docs-parity-live-registry}: two-pass HTML-comment strip so a bare/unclosed `<!--` cannot survive (js/incomplete-multi-character-sanitization). - tests/inline-plan-threshold: drop the no-op `\s`->`\s` identity replace, keep the meaningful POSIX-class conversion (js/identity-replacement). Verified: build:lib green; the touched test files + ci-test-scope + profile-output suites pass; lint:legacy-name clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(#604): correctly resolve remaining CodeQL alerts (regex-injection + sanitization) The prior commit's fixes for two alerts were ineffective: - ci-test-scope.cjs js/regex-injection: the alert is the CLI-arg-derived `file` reaching static regex `.test(file)` calls (not the config rule). Removed ALL regex over file/t — startsWith/includes/=== string checks + an isWindowsHint helper — so there is no regex sink for the tainted value. - js/incomplete-multi-character-sanitization (3 test files): a single `.replace(/<!--...-->/g,'')` can let `<!--` re-form. Replaced with a fixpoint loop (replace until stable) plus a final bare-opener strip. Verified: no regex over file/t remains; ci-test-scope + the 3 test suites pass; lint:legacy-name clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(#604): make ci-test-scope + comment-strippers regex-free to clear CodeQL CodeQL flags the regex PATTERNS syntactically (regex-injection on the --files arg split; incomplete-multi-character-sanitization on the <!--...--> replace), so loop fixes do not satisfy it. Made these paths regex-free: - ci-test-scope.cjs splitFiles: char-by-char separator tokenizer (no /[,\\s]+/). - 3 test files: indexOf/slice HTML-comment stripper (no .replace(/<!--/)). Behavior preserved; ci-test-scope + the 3 suites pass; guard clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(#604): unblock security base64 scan on the large rename diff The security job hit its 10m timeout: base64-scan.sh choked on the binary test fixture tests/feat-3594-parser-property-style.test.cjs (embedded NUL/ non-UTF8 bytes -> thousands of bogus blobs + "ignored null byte" warnings), and the ~800-file rename diff is slow to scan regardless. - scripts/base64-scan.sh: skip binary-by-content files (grep -Iq .) — they can't carry base64-obfuscated *text* and feeding NUL bytes through the per-line scanner is pathologically slow. collect_files already filtered binary *extensions*; this catches binary *content* in text extensions. - .github/workflows/security-scan.yml: raise the security job timeout 10m->30m to accommodate very large diffs (the scan itself is unchanged). Verified locally: scan skips the fixture, 0 "ignored null byte" warnings, 0 findings, exit 0. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(#604): sweep get-shit-done refs introduced by merging next The branch was updated with next (#614/#384/#618 etc.), which reference the get-shit-done/ dir (still named that on next). Swept the stale references in the merged files to gsd-core so the rename stays consistent and lint:legacy-name passes: - commands/gsd/discuss-phase.md (runtime-launcher shim paths) - src/core.cts (getAgentsDir layout comments) - tests/bug-384-agents-runtime-aware.test.cjs (require path to runtime lib) Verified: guard 0 violations; build green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(#604): exclude gsd-core/ path segments from bug-3683 command cross-ref invariant The #614 runtime-launcher shim added to discuss-phase.md references `${_GSD_RUNTIME_ROOT}/gsd-core/bin/...`. bug-3683's REF_PATTERN excluded path-y refs only via lookbehind, but `}` precedes `/gsd-core/` in the shim, so it mis-read the directory path as a dangling `/gsd-core` command ref (same class as the #604 bug-2954 fix). Added a trailing `(?![\w-]*\/)` so `/gsd-<x>/...` path segments are not treated as slash-command references. Verified locally on BOTH platforms before pushing: - mac (node 26) full suite: 0 failures - gsd-test-runner (linux, node22 image) full suite: 0 failures - bug-3683 + bug-2954 pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(#604): lazily resolve findProjectRoot in gsd-tools (harden flaky CI) CI intermittently failed state.test's gsd-tools subprocess with "findProjectRoot is not a function" (flip-flopping across legs; not reproducible on mac full suite, gsd-test linux full suite, test:unit, or state.test x8). findProjectRoot is a re-export from core.cjs (sourced from project-root.cjs); binding it via destructure at module-load can be undefined under a load-ordering edge. Resolve it lazily at call time via a small wrapper so the lookup happens after core.cjs is fully initialized. Verified green on BOTH platforms before pushing: - mac (node 26) full suite: 0 failures - gsd-test-runner (linux, node22) full suite: 0 failures - state.test.cjs: 106/106; gsd-tools loads cleanly. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(#604): allowlist verification-patterns.md placeholder examples in secret scan The rename git-mv'd references/verification-patterns.md into gsd-core/, pulling it into the secret-scan diff. It documents stub/placeholder RED-FLAG env-var examples (illustrative Stripe test-key / database-URL / API-key placeholders) — not real credentials. Added it to .secretscanignore with the strict annotation, mirroring the existing gsd-core/workflows/plan-phase.md exception. Verified locally: secret-scan-lint --strict OK; secret-scan --diff origin/next exits 0 with 0 findings. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
592 lines
22 KiB
JavaScript
592 lines
22 KiB
JavaScript
/**
|
|
* GSD Tools Tests - frontmatter.cjs
|
|
*
|
|
* Tests for the hand-rolled YAML parser's pure function exports:
|
|
* extractFrontmatter, reconstructFrontmatter, spliceFrontmatter,
|
|
* parseMustHavesBlock, and FRONTMATTER_SCHEMAS.
|
|
*
|
|
* Includes REG-04 regression: quoted comma inline array edge case.
|
|
*/
|
|
|
|
const { test, describe } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
|
|
const {
|
|
extractFrontmatter,
|
|
reconstructFrontmatter,
|
|
spliceFrontmatter,
|
|
parseMustHavesBlock,
|
|
FRONTMATTER_SCHEMAS,
|
|
} = require('../gsd-core/bin/lib/frontmatter.cjs');
|
|
|
|
// ─── extractFrontmatter ─────────────────────────────────────────────────────
|
|
|
|
describe('extractFrontmatter', () => {
|
|
test('parses simple key-value pairs', () => {
|
|
const content = '---\nname: foo\ntype: execute\n---\nbody';
|
|
const result = extractFrontmatter(content);
|
|
assert.strictEqual(result.name, 'foo');
|
|
assert.strictEqual(result.type, 'execute');
|
|
});
|
|
|
|
test('strips quotes from values', () => {
|
|
const doubleQuoted = '---\nname: "foo"\n---\n';
|
|
const singleQuoted = '---\nname: \'foo\'\n---\n';
|
|
assert.strictEqual(extractFrontmatter(doubleQuoted).name, 'foo');
|
|
assert.strictEqual(extractFrontmatter(singleQuoted).name, 'foo');
|
|
});
|
|
|
|
test('parses nested objects', () => {
|
|
const content = '---\ntechstack:\n added: prisma\n patterns: repository\n---\n';
|
|
const result = extractFrontmatter(content);
|
|
assert.deepStrictEqual(result.techstack, { added: 'prisma', patterns: 'repository' });
|
|
});
|
|
|
|
test('parses block arrays', () => {
|
|
const content = '---\nitems:\n - alpha\n - beta\n - gamma\n---\n';
|
|
const result = extractFrontmatter(content);
|
|
assert.deepStrictEqual(result.items, ['alpha', 'beta', 'gamma']);
|
|
});
|
|
|
|
test('parses inline arrays', () => {
|
|
const content = '---\nkey: [a, b, c]\n---\n';
|
|
const result = extractFrontmatter(content);
|
|
assert.deepStrictEqual(result.key, ['a', 'b', 'c']);
|
|
});
|
|
|
|
test('handles quoted commas in inline arrays — REG-04 fixed', () => {
|
|
const content = '---\nkey: ["a, b", c]\n---\n';
|
|
const result = extractFrontmatter(content);
|
|
assert.deepStrictEqual(result.key, ['a, b', 'c']);
|
|
});
|
|
|
|
test('handles single-quoted commas in inline arrays', () => {
|
|
const content = "---\nkey: ['x, y', z]\n---\n";
|
|
const result = extractFrontmatter(content);
|
|
assert.deepStrictEqual(result.key, ['x, y', 'z']);
|
|
});
|
|
|
|
test('handles mixed quotes in inline arrays', () => {
|
|
const content = '---\nkey: ["a, b", \'c, d\', e]\n---\n';
|
|
const result = extractFrontmatter(content);
|
|
assert.deepStrictEqual(result.key, ['a, b', 'c, d', 'e']);
|
|
});
|
|
|
|
test('returns empty object for no frontmatter', () => {
|
|
const content = 'Just plain content, no frontmatter.';
|
|
const result = extractFrontmatter(content);
|
|
assert.deepStrictEqual(result, {});
|
|
});
|
|
|
|
test('returns empty object for empty frontmatter', () => {
|
|
const content = '---\n---\nBody text.';
|
|
const result = extractFrontmatter(content);
|
|
assert.deepStrictEqual(result, {});
|
|
});
|
|
|
|
test('parses frontmatter-only content', () => {
|
|
const content = '---\nkey: val\n---';
|
|
const result = extractFrontmatter(content);
|
|
assert.strictEqual(result.key, 'val');
|
|
});
|
|
|
|
test('handles emoji and non-ASCII in values', () => {
|
|
const content = '---\nname: "Hello World"\nlabel: "cafe"\n---\n';
|
|
const result = extractFrontmatter(content);
|
|
assert.strictEqual(result.name, 'Hello World');
|
|
assert.strictEqual(result.label, 'cafe');
|
|
});
|
|
|
|
test('converts empty-object placeholders to arrays when dash items follow', () => {
|
|
// When a key has no value, it gets an empty {} placeholder.
|
|
// When "- item" lines follow, the parser converts {} to [].
|
|
const content = '---\nrequirements:\n - REQ-01\n - REQ-02\n---\n';
|
|
const result = extractFrontmatter(content);
|
|
assert.ok(Array.isArray(result.requirements), 'should convert placeholder object to array');
|
|
assert.deepStrictEqual(result.requirements, ['REQ-01', 'REQ-02']);
|
|
});
|
|
|
|
test('skips empty lines in YAML body', () => {
|
|
const content = '---\nfirst: one\n\nsecond: two\n\nthird: three\n---\n';
|
|
const result = extractFrontmatter(content);
|
|
assert.strictEqual(result.first, 'one');
|
|
assert.strictEqual(result.second, 'two');
|
|
assert.strictEqual(result.third, 'three');
|
|
});
|
|
|
|
// ─── Bug #2130: body --- sequence mis-parse ──────────────────────────────
|
|
|
|
test('#2130: frontmatter at top with YAML example block in body — returns top frontmatter', () => {
|
|
const content = [
|
|
'---',
|
|
'name: my-agent',
|
|
'type: execute',
|
|
'---',
|
|
'',
|
|
'# Documentation',
|
|
'',
|
|
'Here is a YAML example:',
|
|
'',
|
|
'```yaml',
|
|
'---',
|
|
'key: value',
|
|
'other: stuff',
|
|
'---',
|
|
'```',
|
|
'',
|
|
'End of doc.',
|
|
].join('\n');
|
|
const result = extractFrontmatter(content);
|
|
assert.strictEqual(result.name, 'my-agent', 'should extract name from TOP frontmatter');
|
|
assert.strictEqual(result.type, 'execute', 'should extract type from TOP frontmatter');
|
|
assert.strictEqual(result.key, undefined, 'should NOT extract key from body YAML block');
|
|
assert.strictEqual(result.other, undefined, 'should NOT extract other from body YAML block');
|
|
});
|
|
|
|
test('#2130: frontmatter at top with horizontal rules in body — returns top frontmatter', () => {
|
|
const content = [
|
|
'---',
|
|
'title: My Doc',
|
|
'status: active',
|
|
'---',
|
|
'',
|
|
'# Section One',
|
|
'',
|
|
'Some text.',
|
|
'',
|
|
'---',
|
|
'',
|
|
'# Section Two',
|
|
'',
|
|
'More text.',
|
|
'',
|
|
'---',
|
|
'',
|
|
'# Section Three',
|
|
].join('\n');
|
|
const result = extractFrontmatter(content);
|
|
assert.strictEqual(result.title, 'My Doc', 'should extract title from TOP frontmatter');
|
|
assert.strictEqual(result.status, 'active', 'should extract status from TOP frontmatter');
|
|
});
|
|
|
|
test('#2130: body-only --- block with no frontmatter at byte 0 — returns empty', () => {
|
|
const content = [
|
|
'# My Document',
|
|
'',
|
|
'Some intro text.',
|
|
'',
|
|
'---',
|
|
'key: value',
|
|
'other: stuff',
|
|
'---',
|
|
'',
|
|
'End of doc.',
|
|
].join('\n');
|
|
const result = extractFrontmatter(content);
|
|
assert.deepStrictEqual(result, {}, 'should return empty object when --- block is not at byte 0');
|
|
});
|
|
|
|
test('#2130: valid frontmatter at byte 0 still works (regression guard)', () => {
|
|
const content = [
|
|
'---',
|
|
'phase: 01',
|
|
'plan: 03',
|
|
'type: execute',
|
|
'wave: 1',
|
|
'depends_on: ["01-01", "01-02"]',
|
|
'files_modified:',
|
|
' - src/auth.ts',
|
|
' - src/middleware.ts',
|
|
'autonomous: true',
|
|
'---',
|
|
'',
|
|
'# Plan body here',
|
|
].join('\n');
|
|
const result = extractFrontmatter(content);
|
|
assert.strictEqual(result.phase, '01');
|
|
assert.strictEqual(result.plan, '03');
|
|
assert.strictEqual(result.type, 'execute');
|
|
assert.strictEqual(result.wave, '1');
|
|
assert.deepStrictEqual(result.depends_on, ['01-01', '01-02']);
|
|
assert.deepStrictEqual(result.files_modified, ['src/auth.ts', 'src/middleware.ts']);
|
|
assert.strictEqual(result.autonomous, 'true');
|
|
});
|
|
});
|
|
|
|
// ─── reconstructFrontmatter ─────────────────────────────────────────────────
|
|
|
|
describe('reconstructFrontmatter', () => {
|
|
test('serializes simple key-value', () => {
|
|
const result = reconstructFrontmatter({ name: 'foo' });
|
|
assert.strictEqual(result, 'name: foo');
|
|
});
|
|
|
|
test('serializes empty array as inline []', () => {
|
|
const result = reconstructFrontmatter({ items: [] });
|
|
assert.strictEqual(result, 'items: []');
|
|
});
|
|
|
|
test('serializes short string arrays inline', () => {
|
|
const result = reconstructFrontmatter({ key: ['a', 'b', 'c'] });
|
|
assert.strictEqual(result, 'key: [a, b, c]');
|
|
});
|
|
|
|
test('serializes long arrays as block', () => {
|
|
const result = reconstructFrontmatter({ key: ['one', 'two', 'three', 'four'] });
|
|
assert.ok(result.includes('key:'), 'should have key header');
|
|
assert.ok(result.includes(' - one'), 'should have block array items');
|
|
assert.ok(result.includes(' - four'), 'should have last item');
|
|
});
|
|
|
|
test('quotes values containing colons or hashes', () => {
|
|
const result = reconstructFrontmatter({ url: 'http://example.com' });
|
|
assert.ok(result.includes('"http://example.com"'), 'should quote value with colon');
|
|
|
|
const hashResult = reconstructFrontmatter({ comment: 'value # note' });
|
|
assert.ok(hashResult.includes('"value # note"'), 'should quote value with hash');
|
|
});
|
|
|
|
test('serializes nested objects with proper indentation', () => {
|
|
const result = reconstructFrontmatter({ tech: { added: 'prisma', patterns: 'repo' } });
|
|
assert.ok(result.includes('tech:'), 'should have parent key');
|
|
assert.ok(result.includes(' added: prisma'), 'should have indented child');
|
|
assert.ok(result.includes(' patterns: repo'), 'should have indented child');
|
|
});
|
|
|
|
test('serializes nested arrays within objects', () => {
|
|
const result = reconstructFrontmatter({
|
|
tech: { added: ['prisma', 'jose'] },
|
|
});
|
|
assert.ok(result.includes('tech:'), 'should have parent key');
|
|
assert.ok(result.includes(' added: [prisma, jose]'), 'should serialize nested short array inline');
|
|
});
|
|
|
|
test('skips null and undefined values', () => {
|
|
const result = reconstructFrontmatter({ name: 'foo', skip: null, also: undefined, keep: 'bar' });
|
|
assert.ok(!result.includes('skip'), 'should not include null key');
|
|
assert.ok(!result.includes('also'), 'should not include undefined key');
|
|
assert.ok(result.includes('name: foo'), 'should include non-null key');
|
|
assert.ok(result.includes('keep: bar'), 'should include non-null key');
|
|
});
|
|
|
|
test('round-trip: simple frontmatter', () => {
|
|
const original = '---\nname: test\ntype: execute\nwave: 1\n---\n';
|
|
const extracted1 = extractFrontmatter(original);
|
|
const reconstructed = reconstructFrontmatter(extracted1);
|
|
const roundTrip = `---\n${reconstructed}\n---\n`;
|
|
const extracted2 = extractFrontmatter(roundTrip);
|
|
assert.deepStrictEqual(extracted2, extracted1, 'round-trip should preserve data identity');
|
|
});
|
|
|
|
test('round-trip: nested with arrays', () => {
|
|
const original = '---\nphase: 01\ntech:\n added:\n - prisma\n - jose\n patterns:\n - repository\n - jwt\n---\n';
|
|
const extracted1 = extractFrontmatter(original);
|
|
const reconstructed = reconstructFrontmatter(extracted1);
|
|
const roundTrip = `---\n${reconstructed}\n---\n`;
|
|
const extracted2 = extractFrontmatter(roundTrip);
|
|
assert.deepStrictEqual(extracted2, extracted1, 'round-trip should preserve nested structures');
|
|
});
|
|
|
|
test('round-trip: multiple data types', () => {
|
|
const original = '---\nname: testplan\nwave: 2\ntags: [auth, api, db]\ndeps:\n - dep1\n - dep2\nconfig:\n enabled: true\n count: 5\n---\n';
|
|
const extracted1 = extractFrontmatter(original);
|
|
const reconstructed = reconstructFrontmatter(extracted1);
|
|
const roundTrip = `---\n${reconstructed}\n---\n`;
|
|
const extracted2 = extractFrontmatter(roundTrip);
|
|
assert.deepStrictEqual(extracted2, extracted1, 'round-trip should preserve multiple data types');
|
|
});
|
|
});
|
|
|
|
// ─── spliceFrontmatter ──────────────────────────────────────────────────────
|
|
|
|
describe('spliceFrontmatter', () => {
|
|
test('replaces existing frontmatter preserving body', () => {
|
|
const content = '---\nphase: 01\ntype: execute\n---\n\n# Body Content\n\nParagraph here.';
|
|
const newObj = { phase: '02', type: 'tdd', wave: '1' };
|
|
const result = spliceFrontmatter(content, newObj);
|
|
|
|
// New frontmatter should be present
|
|
const extracted = extractFrontmatter(result);
|
|
assert.strictEqual(extracted.phase, '02');
|
|
assert.strictEqual(extracted.type, 'tdd');
|
|
assert.strictEqual(extracted.wave, '1');
|
|
|
|
// Body should be preserved
|
|
assert.ok(result.includes('# Body Content'), 'body heading should be preserved');
|
|
assert.ok(result.includes('Paragraph here.'), 'body paragraph should be preserved');
|
|
});
|
|
|
|
test('adds frontmatter to content without any', () => {
|
|
const content = 'Plain text with no frontmatter.';
|
|
const newObj = { phase: '01', plan: '01' };
|
|
const result = spliceFrontmatter(content, newObj);
|
|
|
|
// Should start with frontmatter delimiters
|
|
assert.ok(result.startsWith('---\n'), 'should start with opening delimiter');
|
|
assert.ok(result.includes('\n---\n'), 'should have closing delimiter');
|
|
|
|
// Original content should follow
|
|
assert.ok(result.includes('Plain text with no frontmatter.'), 'original content should be preserved');
|
|
|
|
// Frontmatter should be extractable
|
|
const extracted = extractFrontmatter(result);
|
|
assert.strictEqual(extracted.phase, '01');
|
|
assert.strictEqual(extracted.plan, '01');
|
|
});
|
|
|
|
test('preserves content after frontmatter delimiters exactly', () => {
|
|
const body = '\n\nExact content with special chars: $, %, &, <, >\nLine 2\nLine 3';
|
|
const content = '---\nold: value\n---' + body;
|
|
const newObj = { new: 'value' };
|
|
const result = spliceFrontmatter(content, newObj);
|
|
|
|
// The body after the closing --- should be exactly preserved
|
|
const closingIdx = result.indexOf('\n---', 4); // skip the opening ---
|
|
const resultBody = result.slice(closingIdx + 4); // skip \n---
|
|
assert.strictEqual(resultBody, body, 'body content after frontmatter should be exactly preserved');
|
|
});
|
|
});
|
|
|
|
// ─── parseMustHavesBlock ────────────────────────────────────────────────────
|
|
|
|
describe('parseMustHavesBlock', () => {
|
|
test('extracts truths as string array', () => {
|
|
const content = `---
|
|
phase: 01
|
|
must_haves:
|
|
truths:
|
|
- "All tests pass on CI"
|
|
- "Coverage exceeds 80%"
|
|
---
|
|
|
|
Body content.`;
|
|
const result = parseMustHavesBlock(content, 'truths');
|
|
assert.ok(Array.isArray(result), 'should return an array');
|
|
assert.strictEqual(result.length, 2);
|
|
assert.strictEqual(result[0], 'All tests pass on CI');
|
|
assert.strictEqual(result[1], 'Coverage exceeds 80%');
|
|
});
|
|
|
|
test('extracts artifacts as object array', () => {
|
|
const content = `---
|
|
phase: 01
|
|
must_haves:
|
|
artifacts:
|
|
- path: "src/auth.ts"
|
|
provides: "JWT authentication"
|
|
min_lines: 100
|
|
- path: "src/middleware.ts"
|
|
provides: "Route protection"
|
|
min_lines: 50
|
|
---
|
|
|
|
Body.`;
|
|
const result = parseMustHavesBlock(content, 'artifacts');
|
|
assert.ok(Array.isArray(result), 'should return an array');
|
|
assert.strictEqual(result.length, 2);
|
|
assert.strictEqual(result[0].path, 'src/auth.ts');
|
|
assert.strictEqual(result[0].provides, 'JWT authentication');
|
|
assert.strictEqual(result[0].min_lines, 100);
|
|
assert.strictEqual(result[1].path, 'src/middleware.ts');
|
|
assert.strictEqual(result[1].min_lines, 50);
|
|
});
|
|
|
|
test('extracts key_links with from/to/via/pattern fields', () => {
|
|
const content = `---
|
|
phase: 01
|
|
must_haves:
|
|
key_links:
|
|
- from: "tests/auth.test.ts"
|
|
to: "src/auth.ts"
|
|
via: "import statement"
|
|
pattern: "import.*auth"
|
|
---
|
|
`;
|
|
const result = parseMustHavesBlock(content, 'key_links');
|
|
assert.ok(Array.isArray(result), 'should return an array');
|
|
assert.strictEqual(result.length, 1);
|
|
assert.strictEqual(result[0].from, 'tests/auth.test.ts');
|
|
assert.strictEqual(result[0].to, 'src/auth.ts');
|
|
assert.strictEqual(result[0].via, 'import statement');
|
|
assert.strictEqual(result[0].pattern, 'import.*auth');
|
|
});
|
|
|
|
test('returns empty array when block not found', () => {
|
|
const content = `---
|
|
phase: 01
|
|
must_haves:
|
|
truths:
|
|
- "Some truth"
|
|
---
|
|
`;
|
|
const result = parseMustHavesBlock(content, 'nonexistent_block');
|
|
assert.deepStrictEqual(result, []);
|
|
});
|
|
|
|
test('returns empty array when no frontmatter', () => {
|
|
const content = 'Plain text without any frontmatter delimiters.';
|
|
const result = parseMustHavesBlock(content, 'truths');
|
|
assert.deepStrictEqual(result, []);
|
|
});
|
|
|
|
test('parses key_links with 2-space indentation — issue #1356', () => {
|
|
// Real-world YAML uses 2-space indentation, not 4-space.
|
|
// The parser was hardcoded to expect 4-space indentation which caused
|
|
// "No must_haves.key_links found in frontmatter" for valid YAML.
|
|
const content = `---
|
|
phase: 01-conversion-engine-iva-correctness
|
|
plan: 02
|
|
type: execute
|
|
wave: 2
|
|
depends_on: ["01-01"]
|
|
files_modified:
|
|
- src/features/currency/exchange-rate-store.ts
|
|
- src/features/currency/use-currency-config.ts
|
|
autonomous: true
|
|
requirements:
|
|
- CONV-02
|
|
- CONV-03
|
|
|
|
must_haves:
|
|
truths:
|
|
- "All tests pass"
|
|
artifacts:
|
|
- path: "src/features/currency/use-currency-config.ts"
|
|
key_links:
|
|
- from: "src/features/currency/use-currency-config.ts"
|
|
to: "src/api/generated/company-config/company-config.ts"
|
|
via: "getCompanyConfigControllerFindAllQueryOptions"
|
|
pattern: "getCompanyConfigControllerFindAllQueryOptions"
|
|
- from: "src/features/currency/use-currency-config.ts"
|
|
to: "src/features/currency/exchange-rate-store.ts"
|
|
via: "useExchangeRateStore for MMKV persist"
|
|
pattern: "useExchangeRateStore"
|
|
---
|
|
|
|
# Plan body
|
|
`;
|
|
const result = parseMustHavesBlock(content, 'key_links');
|
|
assert.ok(Array.isArray(result), 'should return an array');
|
|
assert.strictEqual(result.length, 2, `expected 2 key_links, got ${result.length}: ${JSON.stringify(result)}`);
|
|
assert.strictEqual(result[0].from, 'src/features/currency/use-currency-config.ts');
|
|
assert.strictEqual(result[0].to, 'src/api/generated/company-config/company-config.ts');
|
|
assert.strictEqual(result[0].via, 'getCompanyConfigControllerFindAllQueryOptions');
|
|
assert.strictEqual(result[0].pattern, 'getCompanyConfigControllerFindAllQueryOptions');
|
|
assert.strictEqual(result[1].from, 'src/features/currency/use-currency-config.ts');
|
|
assert.strictEqual(result[1].to, 'src/features/currency/exchange-rate-store.ts');
|
|
assert.strictEqual(result[1].via, 'useExchangeRateStore for MMKV persist');
|
|
assert.strictEqual(result[1].pattern, 'useExchangeRateStore');
|
|
});
|
|
|
|
test('parses truths with 2-space indentation — issue #1356', () => {
|
|
const content = `---
|
|
phase: 01
|
|
must_haves:
|
|
truths:
|
|
- "All tests pass on CI"
|
|
- "Coverage exceeds 80%"
|
|
---
|
|
`;
|
|
const result = parseMustHavesBlock(content, 'truths');
|
|
assert.ok(Array.isArray(result), 'should return an array');
|
|
assert.strictEqual(result.length, 2);
|
|
assert.strictEqual(result[0], 'All tests pass on CI');
|
|
assert.strictEqual(result[1], 'Coverage exceeds 80%');
|
|
});
|
|
|
|
test('parses artifacts with 2-space indentation — issue #1356', () => {
|
|
const content = `---
|
|
phase: 01
|
|
must_haves:
|
|
artifacts:
|
|
- path: "src/auth.ts"
|
|
provides: "JWT authentication"
|
|
min_lines: 100
|
|
---
|
|
`;
|
|
const result = parseMustHavesBlock(content, 'artifacts');
|
|
assert.ok(Array.isArray(result), 'should return an array');
|
|
assert.strictEqual(result.length, 1);
|
|
assert.strictEqual(result[0].path, 'src/auth.ts');
|
|
assert.strictEqual(result[0].provides, 'JWT authentication');
|
|
assert.strictEqual(result[0].min_lines, 100);
|
|
});
|
|
|
|
test('#2734: quoted truth containing ":" is preserved as a string — not dropped', () => {
|
|
// When a dash-item is a fully-quoted string that contains ':', the old code
|
|
// fell into the key-value branch, failed the kvMatch regex (because the value
|
|
// started with '"'), and silently left current as {}, losing the string.
|
|
const content = `---
|
|
phase: 01
|
|
must_haves:
|
|
truths:
|
|
- "App-side UUIDv4: generated locally"
|
|
- "No colon in this one"
|
|
- "Another colon: example"
|
|
---
|
|
`;
|
|
const result = parseMustHavesBlock(content, 'truths');
|
|
assert.ok(Array.isArray(result), 'should return an array');
|
|
assert.strictEqual(result.length, 3, `expected 3 truths, got ${result.length}: ${JSON.stringify(result)}`);
|
|
assert.strictEqual(result[0], 'App-side UUIDv4: generated locally');
|
|
assert.strictEqual(result[1], 'No colon in this one');
|
|
assert.strictEqual(result[2], 'Another colon: example');
|
|
});
|
|
|
|
test('#2734: single-quoted truth containing ":" is preserved as a string', () => {
|
|
const content = `---
|
|
phase: 01
|
|
must_haves:
|
|
truths:
|
|
- 'Key: value pattern preserved'
|
|
---
|
|
`;
|
|
const result = parseMustHavesBlock(content, 'truths');
|
|
assert.ok(Array.isArray(result), 'should return an array');
|
|
assert.strictEqual(result.length, 1);
|
|
assert.strictEqual(result[0], 'Key: value pattern preserved');
|
|
});
|
|
|
|
test('#2757: unquoted truth containing ":" is preserved as a string — not left as {}', () => {
|
|
// Unquoted strings with colons (e.g. Rails idioms) were falling through the KV
|
|
// regex and leaving current as {}, which caused t.trim() to throw in roadmap.cjs.
|
|
const content = `---
|
|
phase: 01
|
|
must_haves:
|
|
truths:
|
|
- GET /foo/:id resolves to controller#show
|
|
- Service.call(arg:, key:) returns a record
|
|
- Class::Method is idempotent
|
|
---
|
|
`;
|
|
const result = parseMustHavesBlock(content, 'truths');
|
|
assert.ok(Array.isArray(result), 'should return an array');
|
|
assert.strictEqual(result.length, 3, `expected 3, got ${result.length}: ${JSON.stringify(result)}`);
|
|
assert.ok(typeof result[0] === 'string', `result[0] should be string, got ${typeof result[0]}`);
|
|
assert.ok(typeof result[1] === 'string', `result[1] should be string, got ${typeof result[1]}`);
|
|
assert.ok(typeof result[2] === 'string', `result[2] should be string, got ${typeof result[2]}`);
|
|
assert.ok(result[0].includes(':'), 'colon should be preserved in the string');
|
|
});
|
|
|
|
test('handles nested arrays within artifact objects', () => {
|
|
const content = `---
|
|
phase: 01
|
|
must_haves:
|
|
artifacts:
|
|
- path: "src/api.ts"
|
|
provides: "REST endpoints"
|
|
exports:
|
|
- "GET"
|
|
- "POST"
|
|
---
|
|
`;
|
|
const result = parseMustHavesBlock(content, 'artifacts');
|
|
assert.ok(Array.isArray(result), 'should return an array');
|
|
assert.strictEqual(result.length, 1);
|
|
assert.strictEqual(result[0].path, 'src/api.ts');
|
|
// The nested array should be captured
|
|
assert.ok(result[0].exports !== undefined, 'should have exports field');
|
|
});
|
|
});
|
|
|