* 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>
355 lines
16 KiB
JavaScript
355 lines
16 KiB
JavaScript
'use strict';
|
|
|
|
// allow-test-rule: source-text-is-the-product
|
|
// `workflows/help/modes/*.md` files ARE the help output — their text is what
|
|
// the runtime emits when the user runs `/gsd:help [--brief|--full|<topic>]`.
|
|
// Asserting on their structure tests the deployed contract directly.
|
|
|
|
/**
|
|
* Feature #3039: tiered /gsd:help output.
|
|
*
|
|
* The legacy single-file 747-line help is replaced by:
|
|
* - workflows/help.md — small dispatcher (progressive disclosure)
|
|
* - workflows/help/modes/brief.md — ~one-liner refresher
|
|
* - workflows/help/modes/default.md — one-page newcomer tour
|
|
* - workflows/help/modes/full.md — complete reference (former help.md body)
|
|
* - workflows/help/modes/topic.md — section-extraction logic + alias table
|
|
*
|
|
* This test enforces the contract:
|
|
* 1. All four mode files exist with a single `<reference>` block.
|
|
* 2. brief and default fit a "one screen" budget; full stays under LARGE tier cap.
|
|
* 3. The dispatcher routes on $ARGUMENTS to all four mode files (structural parse).
|
|
* 4. Dispatcher conflict-resolution rules are documented:
|
|
* - `--brief` + `--full` without a topic → prefer `--full`
|
|
* - `--brief <topic>` → topic.md in compact scope (composable)
|
|
* - bare or `--full <topic>` → topic.md in full scope
|
|
* 5. topic.md documents an explicit routing preamble + compact-scope rule.
|
|
* 6. Every topic alias in topic.md resolves to a heading that exists in full.md.
|
|
* 7. Every /gsd:* sub-block token in topic.md's alias table appears in full.md.
|
|
* 8. Every full.md heading is either aliased or in the intentional-orphan allowlist.
|
|
* 9. The `commands/gsd/help.md` shim passes `$ARGUMENTS` through and advertises
|
|
* the composable `--brief <topic>` form.
|
|
*
|
|
* Tighten-only invariant (issue #597): ceilings track the per-tier high-water mark
|
|
* within GRACE lines. Budgets may only decrease, never silently creep upward.
|
|
* The assertTightCeiling() calls below enforce this automatically.
|
|
*/
|
|
|
|
const { test, describe } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const { assertTightCeiling } = require('../scripts/lib/allowlist-ratchet.cjs');
|
|
|
|
const ROOT = path.join(__dirname, '..');
|
|
const WORKFLOWS = path.join(ROOT, 'gsd-core', 'workflows');
|
|
const MODES = path.join(WORKFLOWS, 'help', 'modes');
|
|
const DISPATCHER = path.join(WORKFLOWS, 'help.md');
|
|
const COMMAND_SHIM = path.join(ROOT, 'commands', 'gsd', 'help.md');
|
|
|
|
const MODE_FILES = ['brief.md', 'default.md', 'full.md', 'topic.md'];
|
|
|
|
// "One screen" budgets, including frontmatter/<purpose>/<reference> tags.
|
|
// These are conservative (one-page conceptual size of ~25 lines of usable
|
|
// content) but allow for the wrapping tags. Tighten as content stabilizes.
|
|
//
|
|
// Ceilings tightened to actualMax + SMALL_GRACE per the ratchet-down rule (#597).
|
|
// BRIEF ceiling kept at 30 (actualMax=22, slack=8 ≤ SMALL_GRACE=10).
|
|
const BRIEF_BUDGET = 30;
|
|
// DEFAULT ceiling lowered from 70 → 60 (actualMax=50; #597 ratchet-down).
|
|
const DEFAULT_BUDGET = 60;
|
|
// full.md is the LARGE tier (see workflow-size-budget.test.cjs — LARGE_BUDGET = 1500).
|
|
// The size-budget test is non-recursive so full.md is not covered there; cap it here.
|
|
// FULL ceiling lowered from 1500 → 844 (actualMax=784; #597 ratchet-down).
|
|
const FULL_BUDGET = 844;
|
|
|
|
// Grace bands:
|
|
// SMALL_GRACE — for the tiny brief/default/dispatcher files (≤ ~70 lines):
|
|
// 10 lines of breathing room is proportionate and prevents trivial edits from
|
|
// failing while still catching any meaningful upward creep.
|
|
// LARGE_GRACE — for full.md where content fluctuates more:
|
|
// 60 lines matches the line-budget GRACE used in the other size-budget tests.
|
|
const SMALL_GRACE = 10;
|
|
const LARGE_GRACE = 60;
|
|
|
|
function read(file) {
|
|
return fs.readFileSync(file, 'utf8');
|
|
}
|
|
|
|
function lineCount(file) {
|
|
const c = read(file);
|
|
if (c.length === 0) return 0;
|
|
const trail = c.endsWith('\n') ? 1 : 0;
|
|
return c.split('\n').length - trail;
|
|
}
|
|
|
|
describe('feature #3039: tiered help — file structure', () => {
|
|
for (const f of MODE_FILES) {
|
|
test(`mode file exists: ${f}`, () => {
|
|
assert.ok(fs.existsSync(path.join(MODES, f)), `missing ${path.join(MODES, f)}`);
|
|
});
|
|
}
|
|
|
|
// Dispatcher ceiling lowered from 40 → 34 (actualMax=24; #597 ratchet-down).
|
|
const DISPATCHER_BUDGET = 34;
|
|
test(`dispatcher exists and is small (≤ ${DISPATCHER_BUDGET} lines)`, () => {
|
|
assert.ok(fs.existsSync(DISPATCHER));
|
|
const n = lineCount(DISPATCHER);
|
|
assert.ok(n <= DISPATCHER_BUDGET, `dispatcher should be small; got ${n} lines`);
|
|
assertTightCeiling({ label: 'dispatcher', actualMax: n, ceiling: DISPATCHER_BUDGET, grace: SMALL_GRACE, fail: assert.fail });
|
|
});
|
|
|
|
for (const f of MODE_FILES) {
|
|
test(`${f} has exactly one <reference> block (line-anchored)`, () => {
|
|
const content = read(path.join(MODES, f));
|
|
// Anchor on start-of-line so prose mentions of `<reference>` inside
|
|
// <purpose> blocks aren't counted.
|
|
const opens = (content.match(/^<reference>$/gm) || []).length;
|
|
const closes = (content.match(/^<\/reference>$/gm) || []).length;
|
|
assert.equal(opens, 1, `${f}: expected 1 <reference> opening line, got ${opens}`);
|
|
assert.equal(closes, 1, `${f}: expected 1 </reference> closing line, got ${closes}`);
|
|
});
|
|
}
|
|
});
|
|
|
|
describe('feature #3039: tiered help — size budgets', () => {
|
|
test(`brief.md fits one screen (≤ ${BRIEF_BUDGET} lines)`, () => {
|
|
const n = lineCount(path.join(MODES, 'brief.md'));
|
|
assert.ok(n <= BRIEF_BUDGET, `brief.md is ${n} lines, budget ${BRIEF_BUDGET}`);
|
|
assertTightCeiling({ label: 'BRIEF', actualMax: n, ceiling: BRIEF_BUDGET, grace: SMALL_GRACE, fail: assert.fail });
|
|
});
|
|
|
|
test(`default.md fits one screen (≤ ${DEFAULT_BUDGET} lines)`, () => {
|
|
const n = lineCount(path.join(MODES, 'default.md'));
|
|
assert.ok(n <= DEFAULT_BUDGET, `default.md is ${n} lines, budget ${DEFAULT_BUDGET}`);
|
|
assertTightCeiling({ label: 'DEFAULT', actualMax: n, ceiling: DEFAULT_BUDGET, grace: SMALL_GRACE, fail: assert.fail });
|
|
});
|
|
|
|
test('full.md preserves the complete reference (≥ 600 lines)', () => {
|
|
// The pre-#3039 reference was 747 lines. Guard against accidental shrinkage
|
|
// that would amount to silently removing content from --full.
|
|
const n = lineCount(path.join(MODES, 'full.md'));
|
|
assert.ok(n >= 600, `full.md is ${n} lines — too small, content may have been lost`);
|
|
});
|
|
|
|
test(`full.md stays under LARGE workflow budget (≤ ${FULL_BUDGET} lines)`, () => {
|
|
// full.md lives in a subdirectory and is not enumerated by the non-recursive
|
|
// workflow-size-budget.test.cjs. Cap it here at the LARGE tier limit.
|
|
const n = lineCount(path.join(MODES, 'full.md'));
|
|
assert.ok(n <= FULL_BUDGET, `full.md grew to ${n} lines (LARGE budget: ${FULL_BUDGET})`);
|
|
assertTightCeiling({ label: 'FULL', actualMax: n, ceiling: FULL_BUDGET, grace: LARGE_GRACE, fail: assert.fail });
|
|
});
|
|
});
|
|
|
|
describe('feature #3039: tiered help — dispatcher routing (structural)', () => {
|
|
const dispatcher = read(DISPATCHER);
|
|
|
|
function extractDisclosureBlock(src) {
|
|
const m = src.match(/<progressive_disclosure>([\s\S]*?)<\/progressive_disclosure>/);
|
|
assert.ok(m, 'dispatcher must contain a <progressive_disclosure> block');
|
|
return m[1];
|
|
}
|
|
|
|
test('dispatcher <progressive_disclosure> block has exactly 5 routing rows', () => {
|
|
// 4 base tiers (brief, full, default, topic) + 1 composable row (--brief <topic>).
|
|
const block = extractDisclosureBlock(dispatcher);
|
|
// Table rows are lines starting with `|`, excluding the header and separator rows.
|
|
const rows = block.split('\n')
|
|
.filter(l => /^\|/.test(l))
|
|
.filter(l => !/^\|\s*[-:]+\s*\|/.test(l)) // strip separator rows
|
|
.filter(l => !/when.*arguments/i.test(l)); // strip header row
|
|
assert.equal(rows.length, 5,
|
|
`dispatcher routing table must have exactly 5 rows; got ${rows.length}:\n${rows.join('\n')}`);
|
|
});
|
|
|
|
test('dispatcher routes --brief to brief.md', () => {
|
|
const block = extractDisclosureBlock(dispatcher);
|
|
assert.match(block, /`--brief`[\s\S]*?brief\.md/);
|
|
});
|
|
|
|
test('dispatcher routes --full to full.md', () => {
|
|
const block = extractDisclosureBlock(dispatcher);
|
|
assert.match(block, /`--full`[\s\S]*?full\.md/);
|
|
});
|
|
|
|
test('dispatcher routes empty/no-flag args to default.md', () => {
|
|
const block = extractDisclosureBlock(dispatcher);
|
|
assert.match(block, /(empty|unset)[\s\S]*?default\.md/i);
|
|
});
|
|
|
|
test('dispatcher routes topic args to topic.md', () => {
|
|
const block = extractDisclosureBlock(dispatcher);
|
|
assert.match(block, /topic[\s\S]*?topic\.md/i);
|
|
});
|
|
});
|
|
|
|
describe('feature #3039: tiered help — dispatcher conflict-resolution rules', () => {
|
|
const dispatcher = read(DISPATCHER);
|
|
|
|
test('dispatcher documents --brief + --full (without topic) conflict resolution (prefer --full)', () => {
|
|
// help.md argument parsing rules: "if both appear *without* a topic, prefer `--full`"
|
|
assert.match(dispatcher, /prefer.*--full/);
|
|
});
|
|
|
|
test('dispatcher routes --brief <topic> to topic.md in compact scope (composable)', () => {
|
|
// help.md argument parsing rules: "--brief combined with a topic invokes topic.md
|
|
// in compact scope" — the composable scoped-lookup form (trek-e review finding #4).
|
|
assert.match(dispatcher, /--brief[^|]*<topic>[\s\S]*?topic\.md[\s\S]*?compact/i);
|
|
});
|
|
|
|
test('dispatcher routes --full <topic> (or bare topic) to topic.md in full scope', () => {
|
|
// Bare topic, `--full <topic>`, or topic with leading `--` → full scope.
|
|
assert.match(dispatcher, /(bare topic|--full <topic>)[\s\S]*?full scope/i);
|
|
});
|
|
|
|
test('dispatcher tells topic.md to retain --brief when delegating', () => {
|
|
// The dispatcher passes $ARGUMENTS through; topic.md needs to see --brief to
|
|
// choose compact scope. Guard against accidental flag-stripping.
|
|
assert.match(dispatcher, /retain.*--brief|pass.*--brief/i);
|
|
});
|
|
});
|
|
|
|
describe('feature #3039: tiered help — command shim passes $ARGUMENTS', () => {
|
|
const shim = read(COMMAND_SHIM);
|
|
|
|
test('shim references $ARGUMENTS', () => {
|
|
assert.match(shim, /\$ARGUMENTS/);
|
|
});
|
|
|
|
test('shim declares argument-hint frontmatter', () => {
|
|
assert.match(shim, /argument-hint:/);
|
|
});
|
|
|
|
test('shim argument-hint advertises composable --brief <topic>', () => {
|
|
// Discoverability: users need to know the composable form is supported
|
|
// (trek-e review finding #4).
|
|
assert.match(shim, /argument-hint:[^\n]*--brief[^\n]*<topic>/);
|
|
});
|
|
|
|
test('shim references the help workflow', () => {
|
|
assert.match(shim, /workflows\/help\.md/);
|
|
});
|
|
});
|
|
|
|
describe('feature #3039: tiered help — topic.md routing visibility + compact scope', () => {
|
|
const topicSrc = read(path.join(MODES, 'topic.md'));
|
|
|
|
test('topic.md documents an explicit resolved-routing preamble', () => {
|
|
// Trek-e review finding #3: routing must be explicit in output so the user
|
|
// can see which alias matched which heading and at what scope.
|
|
assert.match(topicSrc, /\*\*Topic:\*\*[\s\S]*<alias>[\s\S]*<heading>/);
|
|
assert.match(topicSrc, /scope:.*full.*\|.*compact/i);
|
|
});
|
|
|
|
test('topic.md documents a compact scope distinct from full scope', () => {
|
|
// Trek-e review finding #4: --brief <topic> must produce a compact
|
|
// scoped lookup (signature + one-line summary), not the full section.
|
|
assert.match(topicSrc, /compact scope/i);
|
|
assert.match(topicSrc, /signature.*one-line summary|signature \+ one-line/i);
|
|
});
|
|
|
|
test('topic.md parses --brief flag and strips it before resolving the alias', () => {
|
|
// Compact scope must trigger off the --brief flag in $ARGUMENTS; the
|
|
// remaining token is the alias.
|
|
assert.match(topicSrc, /--brief.*-b.*compact scope|compact scope[\s\S]*--brief/i);
|
|
});
|
|
|
|
test('topic.md closing "More:" line advertises the composable form', () => {
|
|
assert.match(topicSrc, /More:[\s\S]*--brief <topic>/);
|
|
});
|
|
});
|
|
|
|
describe('feature #3039: tiered help — topic alias coverage', () => {
|
|
const topicSrc = read(path.join(MODES, 'topic.md'));
|
|
const fullSrc = read(path.join(MODES, 'full.md'));
|
|
|
|
// Extract the alias table portion of topic.md (before "**Output rules:**")
|
|
function aliasTableSection(src) {
|
|
return src.split('**Output rules:**')[0];
|
|
}
|
|
|
|
// Extract the canonical heading text referenced from each row of the
|
|
// alias table. Rows look like: `| aliases | \`## Heading\` ... |`.
|
|
// We accept either ## or ### and pull the literal heading text.
|
|
function extractReferencedHeadings(src) {
|
|
const headings = new Set();
|
|
const re = /`(#{2,3} [^`]+?)`/g;
|
|
let m;
|
|
while ((m = re.exec(src)) !== null) {
|
|
headings.add(m[1].trim());
|
|
}
|
|
return headings;
|
|
}
|
|
|
|
function fullHeadings(src) {
|
|
const set = new Set();
|
|
for (const line of src.split('\n')) {
|
|
const m = line.match(/^(#{2,3}) (.+?)\s*$/);
|
|
if (m) set.add(`${m[1]} ${m[2]}`);
|
|
}
|
|
return set;
|
|
}
|
|
|
|
test('every heading referenced in topic.md exists in full.md', () => {
|
|
const referenced = extractReferencedHeadings(aliasTableSection(topicSrc));
|
|
const present = fullHeadings(fullSrc);
|
|
const missing = [...referenced].filter((h) => !present.has(h)).sort();
|
|
assert.deepEqual(missing, [],
|
|
`topic.md references headings not present in full.md: ${missing.join(' | ')}`);
|
|
});
|
|
|
|
test('every /gsd:* sub-block token in topic.md alias table exists in full.md', () => {
|
|
// Validates fix for review finding #2: sub-block aliases reference bold-line
|
|
// anchors (**`/gsd:X`**) — assert each token actually appears in full.md.
|
|
const tableSection = aliasTableSection(topicSrc);
|
|
const tokens = [...tableSection.matchAll(/`(\/gsd:[a-z-]+(?:\s+--[a-z-]+)?)`/g)].map(m => m[1]);
|
|
assert.ok(tokens.length > 0, 'expected at least one /gsd:* token in alias table');
|
|
const missing = tokens.filter(t => !fullSrc.includes(t));
|
|
assert.deepEqual(missing, [],
|
|
`topic.md references /gsd:* tokens not present in full.md: ${missing.join(' | ')}`);
|
|
});
|
|
|
|
test('every full.md heading is either aliased or in the intentional-orphan allowlist', () => {
|
|
// Catches newly added headings that have no alias (contributor must either
|
|
// alias the section or explicitly add it to INTENTIONAL_ORPHANS below).
|
|
const INTENTIONAL_ORPHANS = new Set([
|
|
'## Quick Start',
|
|
'## Staying Updated',
|
|
'### Utility Commands', // covered by cleanup/update sub-block aliases
|
|
'## Additional Commands',
|
|
'### Discovery & Specification',
|
|
'### Planning & Execution',
|
|
'### Quality, Review & Verification',
|
|
'### Diagnostics & Maintenance',
|
|
'### Knowledge & Context',
|
|
'### Workflow & Orchestration',
|
|
'### Repository Integration',
|
|
'### Namespace Routers (model-facing meta-skills)',
|
|
]);
|
|
|
|
const allHeadings = fullSrc.split('\n')
|
|
.filter(l => /^#{2,3} /.test(l))
|
|
.map(l => l.trim());
|
|
|
|
const aliased = extractReferencedHeadings(aliasTableSection(topicSrc));
|
|
|
|
const orphans = allHeadings.filter(h => !aliased.has(h) && !INTENTIONAL_ORPHANS.has(h));
|
|
assert.deepEqual(orphans, [],
|
|
`full.md headings not aliased in topic.md (add to INTENTIONAL_ORPHANS if intentional): ${orphans.join(' | ')}`);
|
|
});
|
|
|
|
test('topic.md covers the core topics promised in default.md', () => {
|
|
// Surface contract: default.md advertises a "Topics:" line. Each alias
|
|
// there must appear as a recognized topic in topic.md's alias table.
|
|
const def = read(path.join(MODES, 'default.md'));
|
|
const topicsLine = def.split('\n').find((l) => /^Topics:/i.test(l));
|
|
assert.ok(topicsLine, 'default.md must advertise a "Topics:" line for users');
|
|
// Strip the leading "Topics:" prefix, then pull every backticked token.
|
|
const aliases = [...topicsLine.matchAll(/`([a-z][a-z0-9-]*)`/g)].map((m) => m[1]);
|
|
assert.ok(aliases.length >= 5, `expected at least 5 promoted topic aliases; got ${aliases.length}`);
|
|
const missing = aliases.filter((a) => !new RegExp(`\`${a}\``).test(topicSrc));
|
|
assert.deepEqual(missing, [],
|
|
`default.md promotes topic aliases that topic.md does not recognize: ${missing.join(', ')}`);
|
|
});
|
|
});
|