* fix(commands): normalize gsd slash namespace drift * fix(#2855): address CodeRabbit findings on namespace drift PR Three CR findings, all valid: 1. autonomous.md line 783 still had `gsd:discuss-phase` (the PR's own normalization missed this line). Switched to `gsd-discuss-phase` and updated the matching test in autonomous-interactive.test.cjs that was asserting the now-retired colon form. 2. tests/bug-2543-gsd-slash-namespace.test.cjs source-grepped the fix-slash-commands.cjs script with .includes() rather than driving its transform behaviour. Refactored fix-slash-commands.cjs to export a pure transformContent(src, cmdNames) function, kept the CLI behaviour unchanged via require.main, and replaced the source-grep block with five behavioural cases: rewrite, multi-occurrence, idempotence on canonical input, no-op on gsd-sdk/gsd-tools, and word-boundary safety. 3. tests/bug-2808-skill-hyphen-name.test.cjs matched `name:` anywhere in SKILL.md; a stray name: in the body could satisfy the assertion. Scoped the lookup to the YAML frontmatter block via the suggested diff (parse the leading --- ... --- region first, then find name: inside it). Full suite: 5854/5854 passing. * fix(#2855): address remaining CodeRabbit findings on PR #2858 Three structural concerns flagged on the namespace-drift fix PR: 1. scripts/fix-slash-commands.cjs:24 — `buildPattern([])` compiled `/gsd:()(?=[^a-zA-Z0-9_-]|$)/g`. The empty capture group still matches any `/gsd:` token followed by a non-word boundary (whitespace, EOL, punctuation), rewriting it to a stray `/gsd-`. Verified live: `transformContent("/gsd:", [])` → `"/gsd-"`. Added a guard returning null from `buildPattern` on empty input and updated `transformContent` and `processDir` to no-op when the pattern is null. 2. tests/autonomous-interactive.test.cjs:44-47 — assertion was `content.includes('gsd-discuss-phase') && content.includes('INTERACTIVE')`, which would false-pass on any unrelated co-occurrence (e.g. `INTERACTIVE=""` initialization plus a stray `gsd-discuss-phase` prose mention). Replaced with a structural extraction: locate the `**If \`INTERACTIVE\` is set:**` branch, bound it by the next `**If` / `<step>` boundary, and assert the `Skill(skill="gsd-discuss-phase", ...)` invocation lives inside that region. Tolerates whitespace around `(`, `skill`, and `=`. 3. tests/bug-2808-skill-hyphen-name.test.cjs:104 — colon-call regex was `Skill\(skill=...` and missed valid formatting like `Skill(skill = "gsd:cmd")` or `Skill( skill = ...)`. Loosened to `Skill\(\s*skill\s*=\s*...` so reformatting drift can't slip past the namespace guard. Verification: 5854/5854 pass on `npm test` from the rebased branch. * fix(#2855): drop pre-validation filter that hid namespace drift CR finding on tests/bug-2808-skill-hyphen-name.test.cjs:128: the test collected generated skill directories with `.filter(entry => entry.isDirectory() && entry.name.startsWith('gsd-'))`, then validated namespace invariants over that filtered list. Anything that violated the prefix invariant — `gsd:extract-learnings` (colon form), `extract_learnings` without prefix, `Gsd-foo` mis-cased — would silently disappear from the iteration and the test would falsely pass. Drop the `startsWith('gsd-')` filter so every generated directory shows up. Add explicit assertions before the existing per-skill loop: - directory list is non-empty (catches a broken converter that produces nothing) - every directory begins with `gsd-` - every directory contains no `:` - every directory contains no `_` Re-audited the full PR diff for the same anti-pattern: only this one site filtered before validating the namespace; bug-2643 and commands-doc-parity also use `readdirSync().filter()` but only by file extension, which is correct. 5854/5854 on `npm test`. * fix(#2855): address remaining CR findings (1 active + 2 nitpicks) Three findings on PR #2858, all the same root cause: input narrowing before validation lets drift slip past the guards. 1. tests/bug-2808-...:104 (active) — `colonCallRe` captured local names with `[a-z0-9-]+`, which excluded the underscore. A drift like `Skill(skill="gsd:extract_learnings")` (deprecated colon syntax with the old underscore filename) silently slid through. Broadened the capture to `[^'"\s)]+` so any malformed local name is surfaced; surrounding pattern (whitespace tolerance, escape support, flags) unchanged. 2. tests/bug-2643-...:43 (nitpick) — `extractSkillNamesHyphen` and `extractSkillNamesColon` had the same over-strict capture plus relied on a single regex over raw bytes, which the project test- rigor memory bans (`feedback_no_source_grep_tests.md`). Replaced with `extractSkillCalls(content)` — a small structural extractor that walks `Skill(` openers, locates each call's matching `)`, parses the body's `skill = "..."` keyword argument with permissive whitespace + quoting + escape handling, and returns `{ name, raw }` records. The two namespace-form helpers become thin filters over the structured output. Tightened the body class to `[^'"\\]+` so a trailing escape `\` before the closing quote (as in `Skill(skill=\"gsd-foo\", …)` written inside another string context) doesn't get included in the captured name. 3. tests/bug-2543-...:44 (nitpick) — `DOC_SEARCH_FILES` was a hand- curated 7-entry array. Every doc added in the future would silently weaken drift detection until someone remembered to extend the list. Replaced with `discoverDocSearchFiles(ROOT)`: globs every `.md` under `docs/` and adds `README.md` if present. New docs are picked up automatically. Re-audited the diff surface for similar narrowings; no other sites filter or constrain before validating namespace invariants. 5854/5854 on `npm test`. * fix(#2855): recurse docs/ tree so localized translations are scanned too CR finding: discoverDocSearchFiles() stopped at docs/*.md, leaving localized translation trees (docs/ja-JP/, docs/zh-CN/, docs/ko-KR/, docs/pt-BR/) and other nested doc collections (docs/skills/, docs/superpowers/) invisible to the namespace-drift invariant. Verified the gap: docs/ has 6 nested directories with ~30 .md files that the previous top-level-only scan was skipping. None contain /gsd: references today, but a future translation update or new doc subdir could leak drift. Switch to an iterative stack walk so every .md under docs/ is scanned regardless of depth. Stack form (rather than recursion) avoids the risk of running into the call-stack limit on deep doc trees. 5854/5854 on `npm test`. --------- Co-authored-by: Tom Boucher <trekkie@nomorestars.com>
178 lines
7.9 KiB
JavaScript
178 lines
7.9 KiB
JavaScript
/**
|
|
* Regression test for bug #2808
|
|
*
|
|
* All 85 GSD SKILL.md files declared `name: gsd:<cmd>` (colon), the deprecated
|
|
* form. Claude Code surfaces the `name:` frontmatter field in autocomplete, so
|
|
* users saw `/gsd:add-phase` suggestions instead of the canonical `/gsd-add-phase`.
|
|
*
|
|
* Root cause: skillFrontmatterName() in bin/install.js converted hyphenated
|
|
* skill dir names to colon form (gsd-add-phase → gsd:add-phase) because
|
|
* workflows called Skill(skill="gsd:<cmd>"). That was the original fix for
|
|
* #2643. Since then, workflows have been updated to use hyphen form (#2808).
|
|
*
|
|
* Fix: skillFrontmatterName() now returns the hyphen form unchanged.
|
|
* Workflow Skill() colon calls are updated to hyphen.
|
|
*
|
|
* This test verifies:
|
|
* 1. skillFrontmatterName returns hyphen form (not colon).
|
|
* 2. Installed SKILL.md would emit name: gsd-<cmd> (not gsd:<cmd>).
|
|
* 3. No workflow contains a Skill(skill="gsd:<cmd>") colon call.
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
process.env.GSD_TEST_MODE = '1';
|
|
|
|
const { describe, test } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const { cleanup, createTempDir } = require('./helpers.cjs');
|
|
|
|
const ROOT = path.join(__dirname, '..');
|
|
const { convertClaudeCommandToClaudeSkill, copyCommandsAsClaudeSkills, skillFrontmatterName } =
|
|
require(path.join(ROOT, 'bin', 'install.js'));
|
|
|
|
const WORKFLOWS_DIR = path.join(ROOT, 'get-shit-done', 'workflows');
|
|
const COMMANDS_DIR = path.join(ROOT, 'commands', 'gsd');
|
|
|
|
function walkMd(dir) {
|
|
const files = [];
|
|
try {
|
|
for (const e of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
const full = path.join(dir, e.name);
|
|
if (e.isDirectory()) files.push(...walkMd(full));
|
|
else if (e.name.endsWith('.md')) files.push(full);
|
|
}
|
|
} catch (err) {
|
|
assert.fail(`failed to read markdown files from ${dir}: ${err.message}`);
|
|
}
|
|
return files;
|
|
}
|
|
|
|
describe('bug-2808: SKILL.md name: uses hyphen form', () => {
|
|
test('skillFrontmatterName returns hyphen form (not colon)', () => {
|
|
assert.strictEqual(skillFrontmatterName('gsd-add-phase'), 'gsd-add-phase');
|
|
assert.strictEqual(skillFrontmatterName('gsd-plan-phase'), 'gsd-plan-phase');
|
|
assert.strictEqual(skillFrontmatterName('gsd-autonomous'), 'gsd-autonomous');
|
|
});
|
|
|
|
test('generated SKILL.md contains name: gsd-<cmd> (not gsd:<cmd>)', () => {
|
|
const cmdFiles = fs.readdirSync(COMMANDS_DIR).filter(f => f.endsWith('.md'));
|
|
assert.ok(cmdFiles.length > 0, 'expected GSD command files');
|
|
|
|
for (const cmd of cmdFiles) {
|
|
const base = cmd.replace(/\.md$/, '');
|
|
const skillDirName = 'gsd-' + base;
|
|
const src = fs.readFileSync(path.join(COMMANDS_DIR, cmd), 'utf-8');
|
|
const skillContent = convertClaudeCommandToClaudeSkill(src, skillDirName);
|
|
|
|
// Parse frontmatter structurally: extract name: line from the --- block.
|
|
const fmMatch = skillContent.match(/^---\n([\s\S]*?)\n---/);
|
|
assert.ok(fmMatch, `${cmd}: generated skill content must have a frontmatter block`);
|
|
const fmLines = fmMatch[1].split('\n');
|
|
const nameEntry = fmLines.find((l) => l.startsWith('name:'));
|
|
assert.ok(nameEntry, `${cmd}: generated SKILL.md is missing required name: field`);
|
|
|
|
const name = nameEntry.replace(/^name:\s*/, '').trim();
|
|
assert.ok(
|
|
!name.includes(':'),
|
|
`${cmd}: SKILL.md name should be hyphen form, got "${name}"`
|
|
);
|
|
assert.ok(
|
|
name.startsWith('gsd-'),
|
|
`${cmd}: SKILL.md name should start with gsd-, got "${name}"`
|
|
);
|
|
}
|
|
});
|
|
|
|
test('no workflow contains Skill(skill="gsd:<cmd>") colon form', () => {
|
|
const workflowFiles = walkMd(WORKFLOWS_DIR);
|
|
assert.ok(
|
|
workflowFiles.length > 0,
|
|
`expected workflow markdown files under ${WORKFLOWS_DIR}`
|
|
);
|
|
const colonCalls = [];
|
|
for (const f of workflowFiles) {
|
|
const src = fs.readFileSync(f, 'utf-8');
|
|
// Strip HTML comments to avoid matching commented-out examples.
|
|
const stripped = src.replace(/<!--[\s\S]*?-->/g, '');
|
|
// Scan each line for Skill() calls using the colon form.
|
|
// Parsing line-by-line is more precise than a multi-line regex
|
|
// and avoids false positives from incidental matches in prose.
|
|
for (const line of stripped.split('\n')) {
|
|
// Tolerate whitespace around the parenthesis, the `skill` keyword,
|
|
// and the `=` so variants like `Skill( skill = "gsd:foo" )` are still
|
|
// flagged. Without the `\s*` allowances, drift slips through this guard.
|
|
//
|
|
// The local-name capture must be permissive (`[^'"\s)]+`, not
|
|
// `[a-z0-9-]+`) — the whole purpose of this guard is to surface
|
|
// *malformed* drift, including legacy underscore-form names like
|
|
// `gsd:extract_learnings`. A character-class that excludes the very
|
|
// characters we need to flag would silently let drift through.
|
|
const colonCallRe = /Skill\(\s*skill\s*=\s*\\?['"]gsd:([^'"\s)]+)\\?['"]/gi;
|
|
let m;
|
|
while ((m = colonCallRe.exec(line)) !== null) {
|
|
colonCalls.push(`${path.basename(f)}: Skill(skill="gsd:${m[1]}")`);
|
|
}
|
|
}
|
|
}
|
|
assert.deepStrictEqual(
|
|
colonCalls,
|
|
[],
|
|
'deprecated colon-form Skill() calls found — update to gsd-<cmd>: ' + colonCalls.join(', ')
|
|
);
|
|
});
|
|
|
|
test('generated autocomplete skill surface uses hyphen names without underscores', (t) => {
|
|
const tmp = createTempDir('gsd-autocomplete-surface-');
|
|
t.after(() => cleanup(tmp));
|
|
const skillsDir = path.join(tmp, 'skills');
|
|
copyCommandsAsClaudeSkills(COMMANDS_DIR, skillsDir, 'gsd', '$HOME/.claude/', 'claude', true);
|
|
|
|
// Don't filter the directory listing by `startsWith('gsd-')` — that
|
|
// would silently hide exactly the kind of drift this test exists to
|
|
// catch (a `gsd:extract-learnings` colon variant or a bare
|
|
// `extract-learnings` without the namespace prefix would never be
|
|
// collected, and the loop below would never see them). Capture every
|
|
// generated directory and assert the namespace invariants explicitly.
|
|
const skillDirs = fs.readdirSync(skillsDir, { withFileTypes: true })
|
|
.filter((entry) => entry.isDirectory())
|
|
.map((entry) => entry.name)
|
|
.sort();
|
|
|
|
assert.ok(skillDirs.length > 0, 'expected generated skill directories under skillsDir');
|
|
for (const dir of skillDirs) {
|
|
assert.ok(
|
|
dir.startsWith('gsd-'),
|
|
`${dir}: generated skill directory must start with the canonical 'gsd-' namespace`,
|
|
);
|
|
assert.ok(
|
|
!dir.includes(':'),
|
|
`${dir}: generated skill directory must not contain the retired colon namespace separator`,
|
|
);
|
|
assert.ok(
|
|
!dir.includes('_'),
|
|
`${dir}: generated skill directory must use hyphens, not underscores`,
|
|
);
|
|
}
|
|
|
|
assert.ok(skillDirs.includes('gsd-extract-learnings'), 'autocomplete surface must include gsd-extract-learnings');
|
|
assert.ok(!skillDirs.includes('gsd-extract_learnings'), 'autocomplete surface must not include gsd-extract_learnings');
|
|
|
|
for (const skillDir of skillDirs) {
|
|
const skillContent = fs.readFileSync(path.join(skillsDir, skillDir, 'SKILL.md'), 'utf-8');
|
|
// Scope the name: lookup to the YAML frontmatter block so a stray
|
|
// `name:` line in the body cannot satisfy the assertion.
|
|
const fmMatch = skillContent.match(/^---\n([\s\S]*?)\n---/);
|
|
assert.ok(fmMatch, `${skillDir}: generated SKILL.md must include frontmatter`);
|
|
const nameLine = fmMatch[1].split('\n').find((l) => /^name:\s*/.test(l));
|
|
assert.ok(nameLine, `${skillDir}: generated SKILL.md is missing name: frontmatter`);
|
|
const name = nameLine.replace(/^name:\s*/, '').trim();
|
|
assert.ok(name.startsWith('gsd-'), `${skillDir}: autocomplete name must start with gsd-, got ${name}`);
|
|
assert.ok(!name.includes(':'), `${skillDir}: autocomplete name must not contain colon, got ${name}`);
|
|
assert.ok(!name.includes('_'), `${skillDir}: autocomplete name must not contain underscore, got ${name}`);
|
|
}
|
|
});
|
|
});
|