Introduce `runtime-slash.cjs` as the single source of truth for emitting GSD slash-command references in user-facing runtime output and persisted artifacts. `formatGsdSlash(commandName, runtime)` produces `/gsd-<cmd>` for skills-based runtimes (Claude/Cursor/OpenCode/Kilo/etc.) and `$gsd-<cmd>` for Codex. The deprecated `/gsd:<cmd>` colon form is never emitted — pasting a recommended-action command into Claude Code now routes correctly instead of failing with `Unknown command`. Wired into the high-impact emitters identified in #3584: - `init.cjs` `cmdInitManager` recommended_actions[].command (the original failure path in the bug report) plus the no-ROADMAP / no-STATE error hints. - `phase.cjs` `cmdPhaseAdd`, `cmdPhaseAddBatch`, `cmdPhaseInsert` — ROADMAP.md `Plans:` references now persist the routable form instead of the legacy colon form. - `verify.cjs` `cmdValidateHealth` — every fix-hint addIssue() call (E001/E002/E003/E004/E005, W002/W003/W008/W009/W011/W016/W018) and the persisted STATE.md regenerate / MILESTONES.md backfill notes. - `milestone.cjs` `cmdMilestoneComplete` — Operator Next Steps tail rewrite. - `validate-command-router.cjs` — `validate context` recommendation strings for WARNING/CRITICAL utilization bands. - `workstream.cjs` — missing .planning hint. - `profile-output.cjs` — `generate-claude-md` workflow enforcement block, project/skills fallbacks, profile placeholder, and the dev-preferences refresh hints. - `drift.cjs`, `gsd2-import.cjs`, `commands.cjs scaffold context` — remaining one-off persisted references. Runtime detection: `resolveRuntime(projectDir)` reads `process.env.GSD_RUNTIME` first, then a side-effect-free direct read of `.planning/config.json` (NOT `loadConfig`, which would normalize legacy keys and re-write the file just to read the runtime name). Tests: - `tests/bug-3584-runtime-slash-formatter.test.cjs` — 22 unit tests covering the pure formatter and resolver (hyphen vs codex, prefix normalization, defensive returns, env/config/default chain). - `tests/bug-3584-runtime-slash-emitters.test.cjs` — 6 integration tests exercising `init manager`, `phase add` (via the structured `roadmap get-phase` payload to avoid raw-text matching on the on-disk artifact), `validate health`, `validate context`, and the codex variant. - Existing tests updated to assert the new contract: validate-context recommendations, claude-md workflow block, milestone complete Operator Next Steps. Copilot-install engine-conversion test now asserts against a synthetic input since bin/lib/*.cjs no longer contains literal `/gsd:` references for the install-time converter to rewrite. INVENTORY.md and INVENTORY-MANIFEST.json updated for the new module (64 CLI modules shipped, +1). Fixes #3584 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
210 lines
7.2 KiB
JavaScript
210 lines
7.2 KiB
JavaScript
/**
|
|
* Regression tests for bug #3584
|
|
*
|
|
* Runtime/user-facing strings emitted by get-shit-done/bin/lib/*.cjs hardcoded
|
|
* the deprecated `/gsd:<cmd>` colon form (16 files, ~50 occurrences). After
|
|
* #2808 unified GSD installs to register skills under the hyphen form
|
|
* (`name: gsd-execute-phase`), pasting the emitted `/gsd:execute-phase` into
|
|
* Claude Code yields `Unknown command: /gsd:execute-phase. Did you mean
|
|
* /gsd-execute-phase?`. Codex installs require `$gsd-<cmd>` (shell-var) form.
|
|
*
|
|
* Fix: a runtime-aware slash formatter (`runtime-slash.cjs`) is now the single
|
|
* source of truth for emitting `/gsd-<cmd>` (hyphen) for skills-based runtimes
|
|
* and `$gsd-<cmd>` for Codex. Tests assert on the formatter's typed output and
|
|
* — for the integration tests in `bug-3584-runtime-slash-emitters.test.cjs` —
|
|
* on the structured `--json` payloads from the runtime command handlers.
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
const { describe, test } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const path = require('path');
|
|
|
|
const ROOT = path.join(__dirname, '..');
|
|
const { formatGsdSlash, resolveRuntime } = require(
|
|
path.join(ROOT, 'get-shit-done', 'bin', 'lib', 'runtime-slash.cjs'),
|
|
);
|
|
|
|
describe('formatGsdSlash — runtime-aware slash command formatter', () => {
|
|
describe('hyphen-form runtimes (claude, cursor, opencode, kilo, etc.)', () => {
|
|
test('emits /gsd-<cmd> for claude', () => {
|
|
assert.strictEqual(formatGsdSlash('execute-phase', 'claude'), '/gsd-execute-phase');
|
|
});
|
|
|
|
test('emits /gsd-<cmd> for cursor', () => {
|
|
assert.strictEqual(formatGsdSlash('plan-phase', 'cursor'), '/gsd-plan-phase');
|
|
});
|
|
|
|
test('emits /gsd-<cmd> for opencode', () => {
|
|
assert.strictEqual(formatGsdSlash('discuss-phase', 'opencode'), '/gsd-discuss-phase');
|
|
});
|
|
|
|
test('emits /gsd-<cmd> for kilo', () => {
|
|
assert.strictEqual(formatGsdSlash('health', 'kilo'), '/gsd-health');
|
|
});
|
|
|
|
test('unknown runtime defaults to hyphen form', () => {
|
|
assert.strictEqual(
|
|
formatGsdSlash('new-project', 'some-future-runtime'),
|
|
'/gsd-new-project',
|
|
);
|
|
});
|
|
|
|
test('null/undefined runtime defaults to hyphen form (claude)', () => {
|
|
assert.strictEqual(formatGsdSlash('new-milestone', null), '/gsd-new-milestone');
|
|
assert.strictEqual(formatGsdSlash('new-milestone', undefined), '/gsd-new-milestone');
|
|
});
|
|
});
|
|
|
|
describe('codex shell-var form', () => {
|
|
test('emits $gsd-<cmd> for codex', () => {
|
|
assert.strictEqual(formatGsdSlash('execute-phase', 'codex'), '$gsd-execute-phase');
|
|
});
|
|
|
|
test('codex output is lowercased', () => {
|
|
assert.strictEqual(
|
|
formatGsdSlash('Execute-Phase', 'codex'),
|
|
'$gsd-execute-phase',
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('input normalization', () => {
|
|
test('strips existing /gsd: colon prefix', () => {
|
|
assert.strictEqual(
|
|
formatGsdSlash('/gsd:execute-phase', 'claude'),
|
|
'/gsd-execute-phase',
|
|
);
|
|
});
|
|
|
|
test('strips existing /gsd- hyphen prefix (idempotent)', () => {
|
|
assert.strictEqual(
|
|
formatGsdSlash('/gsd-plan-phase', 'claude'),
|
|
'/gsd-plan-phase',
|
|
);
|
|
});
|
|
|
|
test('strips bare gsd: prefix without leading slash', () => {
|
|
assert.strictEqual(
|
|
formatGsdSlash('gsd:new-project', 'claude'),
|
|
'/gsd-new-project',
|
|
);
|
|
});
|
|
|
|
test('strips existing $gsd- shell prefix (codex idempotent)', () => {
|
|
assert.strictEqual(
|
|
formatGsdSlash('$gsd-execute-phase', 'codex'),
|
|
'$gsd-execute-phase',
|
|
);
|
|
});
|
|
|
|
test('runtime swap: /gsd:execute-phase + codex → $gsd-execute-phase', () => {
|
|
assert.strictEqual(
|
|
formatGsdSlash('/gsd:execute-phase', 'codex'),
|
|
'$gsd-execute-phase',
|
|
);
|
|
});
|
|
|
|
test('case-insensitive prefix stripping', () => {
|
|
assert.strictEqual(
|
|
formatGsdSlash('GSD:execute-phase', 'claude'),
|
|
'/gsd-execute-phase',
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('defensive returns for unsafe inputs', () => {
|
|
test('non-string commandName returns input unchanged', () => {
|
|
assert.strictEqual(formatGsdSlash(null, 'claude'), null);
|
|
assert.strictEqual(formatGsdSlash(undefined, 'claude'), undefined);
|
|
assert.strictEqual(formatGsdSlash(42, 'claude'), 42);
|
|
});
|
|
|
|
test('empty string returns empty string', () => {
|
|
assert.strictEqual(formatGsdSlash('', 'claude'), '');
|
|
});
|
|
|
|
test('whitespace-only string is treated as empty after prefix strip', () => {
|
|
// Whitespace is preserved as-is in the output rather than mangled,
|
|
// so callers can detect "no real command" instead of receiving "/gsd- ".
|
|
const result = formatGsdSlash(' ', 'claude');
|
|
assert.ok(
|
|
result === ' ' || result === '/gsd- ',
|
|
`whitespace input should round-trip or be predictably wrapped, got ${JSON.stringify(result)}`,
|
|
);
|
|
});
|
|
|
|
test('commands with arguments preserve the argument tail', () => {
|
|
// `execute-phase 03` is a valid call shape — the formatter only
|
|
// rewrites the command token; everything after the first whitespace
|
|
// belongs to the caller.
|
|
assert.strictEqual(
|
|
formatGsdSlash('execute-phase 03', 'claude'),
|
|
'/gsd-execute-phase 03',
|
|
);
|
|
assert.strictEqual(
|
|
formatGsdSlash('/gsd:execute-phase 03', 'claude'),
|
|
'/gsd-execute-phase 03',
|
|
);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('resolveRuntime — env > config > default', () => {
|
|
test('process.env.GSD_RUNTIME wins over everything', () => {
|
|
const saved = process.env.GSD_RUNTIME;
|
|
try {
|
|
process.env.GSD_RUNTIME = 'codex';
|
|
assert.strictEqual(resolveRuntime(null), 'codex');
|
|
assert.strictEqual(resolveRuntime('/nonexistent'), 'codex');
|
|
} finally {
|
|
if (saved === undefined) delete process.env.GSD_RUNTIME;
|
|
else process.env.GSD_RUNTIME = saved;
|
|
}
|
|
});
|
|
|
|
test('defaults to claude when env is unset and projectDir missing', () => {
|
|
const saved = process.env.GSD_RUNTIME;
|
|
try {
|
|
delete process.env.GSD_RUNTIME;
|
|
assert.strictEqual(resolveRuntime(null), 'claude');
|
|
assert.strictEqual(resolveRuntime(undefined), 'claude');
|
|
} finally {
|
|
if (saved !== undefined) process.env.GSD_RUNTIME = saved;
|
|
}
|
|
});
|
|
|
|
test('reads config.runtime when env is unset and projectDir has a config', (t) => {
|
|
const fs = require('fs');
|
|
const os = require('os');
|
|
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-3584-'));
|
|
t.after(() => fs.rmSync(tmp, { recursive: true, force: true }));
|
|
|
|
fs.mkdirSync(path.join(tmp, '.planning'), { recursive: true });
|
|
fs.writeFileSync(
|
|
path.join(tmp, '.planning', 'config.json'),
|
|
JSON.stringify({ runtime: 'codex' }),
|
|
);
|
|
|
|
const saved = process.env.GSD_RUNTIME;
|
|
try {
|
|
delete process.env.GSD_RUNTIME;
|
|
assert.strictEqual(resolveRuntime(tmp), 'codex');
|
|
} finally {
|
|
if (saved !== undefined) process.env.GSD_RUNTIME = saved;
|
|
}
|
|
});
|
|
|
|
test('lowercases the resolved runtime', () => {
|
|
const saved = process.env.GSD_RUNTIME;
|
|
try {
|
|
process.env.GSD_RUNTIME = 'CLAUDE';
|
|
assert.strictEqual(resolveRuntime(null), 'claude');
|
|
} finally {
|
|
if (saved === undefined) delete process.env.GSD_RUNTIME;
|
|
else process.env.GSD_RUNTIME = saved;
|
|
}
|
|
});
|
|
});
|