/** * Regression guards for shipped prompt references to msd-tools.cjs. * * Command and agent prompts must instruct clean installs to use the supported * `msd-tools query` binary, not the removed standalone `msd-sdk query` binary. */ const { describe, test } = require('node:test'); const assert = require('node:assert/strict'); const fs = require('fs'); const path = require('path'); const COMMANDS_DIR = path.join(__dirname, '..', 'commands', 'msd'); const AGENTS_DIR = path.join(__dirname, '..', 'agents'); function mdFiles(dir) { return fs.readdirSync(dir) .filter(f => f.endsWith('.md')) .map(f => path.join(dir, f)); } function rel(file) { return path.relative(path.join(__dirname, '..'), file); } describe('command files: msd-tools path references (#1766)', () => { test('shipped agents and commands do not instruct removed SDK query binaries', () => { const files = [...mdFiles(COMMANDS_DIR), ...mdFiles(AGENTS_DIR)]; const violations = []; for (const file of files) { const content = fs.readFileSync(file, 'utf-8'); const lines = content.split(/\r?\n/); for (let i = 0; i < lines.length; i++) { if (/\bmsd-sdk\s+query\b|\$MSD_SDK\s+query/.test(lines[i])) { violations.push(`${rel(file)}:${i + 1}: ${lines[i].trim()}`); } } } assert.strictEqual(violations.length, 0, 'Shipped agent/command prompts must use msd-tools query, not removed SDK query forms.\n' + 'Violations:\n' + violations.join('\n')); }); test('workstreams.md documents the supported msd-tools query binary', () => { const content = fs.readFileSync( path.join(COMMANDS_DIR, 'workstreams.md'), 'utf-8' ); assert.ok( /msd-tools query workstream\.list/.test(content), 'workstreams.md should document msd-tools query workstream.list' ); }); }); // ──────────────────────────────────────────────────────────────────────── // Folded from tests/bug-3584-runtime-slash-formatter.test.cjs — consolidation epic #1969 (B3 #1972) // ──────────────────────────────────────────────────────────────────────── { const { describe: __foldDescribe } = require('node:test'); __foldDescribe("folded:bug-3584-runtime-slash-formatter (consolidation epic #1969 B3 #1972)", () => { /** * Regression tests for bug #3584 * * Runtime/user-facing strings emitted by msd-core/bin/lib/*.cjs hardcoded * the deprecated `/msd:` colon form (16 files, ~50 occurrences). After * #2808 unified MSD installs to register skills under the hyphen form * (`name: msd-execute-phase`), pasting the emitted `/msd:execute-phase` into * Claude Code yields `Unknown command: /msd:execute-phase. Did you mean * /msd-execute-phase?`. Codex installs require `$msd-` (shell-var) form. * * Fix: a runtime-aware slash formatter (`runtime-slash.cjs`) is now the single * source of truth for emitting `/msd-` (hyphen) for skills-based runtimes * and `$msd-` 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 { formatMsdSlash, resolveRuntime } = require( path.join(ROOT, 'msd-core', 'bin', 'lib', 'runtime-slash.cjs'), ); const { cleanup } = require('./helpers.cjs'); describe('formatMsdSlash — runtime-aware slash command formatter', () => { describe('hyphen-form runtimes (claude, cursor, opencode, etc.)', () => { test('emits /msd- for claude', () => { assert.strictEqual(formatMsdSlash('execute-phase', 'claude'), '/msd-execute-phase'); }); test('emits /msd- for cursor', () => { assert.strictEqual(formatMsdSlash('plan-phase', 'cursor'), '/msd-plan-phase'); }); test('emits /msd- for opencode', () => { assert.strictEqual(formatMsdSlash('discuss-phase', 'opencode'), '/msd-discuss-phase'); }); test('unknown runtime defaults to hyphen form', () => { assert.strictEqual( formatMsdSlash('new-project', 'some-future-runtime'), '/msd-new-project', ); }); test('null/undefined runtime defaults to hyphen form (claude)', () => { assert.strictEqual(formatMsdSlash('new-milestone', null), '/msd-new-milestone'); assert.strictEqual(formatMsdSlash('new-milestone', undefined), '/msd-new-milestone'); }); test('runtime aliases for non-codex runtimes still emit hyphen form', () => { assert.strictEqual(formatMsdSlash('new-project', 'claude-code'), '/msd-new-project'); assert.strictEqual(formatMsdSlash('new-project', 'gemini-cli'), '/msd-new-project'); assert.strictEqual(formatMsdSlash('new-project', 'opencode-cli'), '/msd-new-project'); }); }); describe('codex shell-var form', () => { test('emits $msd- for codex', () => { assert.strictEqual(formatMsdSlash('execute-phase', 'codex'), '$msd-execute-phase'); }); test('emits $msd- for codex aliases (app/cli)', () => { assert.strictEqual(formatMsdSlash('execute-phase', 'codex-app'), '$msd-execute-phase'); assert.strictEqual(formatMsdSlash('execute-phase', 'codex_cli'), '$msd-execute-phase'); }); test('codex output is lowercased', () => { assert.strictEqual( formatMsdSlash('Execute-Phase', 'codex'), '$msd-execute-phase', ); }); }); describe('input normalization', () => { test('strips existing /msd: colon prefix', () => { assert.strictEqual( formatMsdSlash('/msd:execute-phase', 'claude'), '/msd-execute-phase', ); }); test('strips existing /msd- hyphen prefix (idempotent)', () => { assert.strictEqual( formatMsdSlash('/msd-plan-phase', 'claude'), '/msd-plan-phase', ); }); test('strips bare msd: prefix without leading slash', () => { assert.strictEqual( formatMsdSlash('msd:new-project', 'claude'), '/msd-new-project', ); }); test('strips existing $msd- shell prefix (codex idempotent)', () => { assert.strictEqual( formatMsdSlash('$msd-execute-phase', 'codex'), '$msd-execute-phase', ); }); test('runtime swap: /msd:execute-phase + codex → $msd-execute-phase', () => { assert.strictEqual( formatMsdSlash('/msd:execute-phase', 'codex'), '$msd-execute-phase', ); }); test('case-insensitive prefix stripping', () => { assert.strictEqual( formatMsdSlash('MSD:execute-phase', 'claude'), '/msd-execute-phase', ); }); }); describe('defensive returns for unsafe inputs', () => { test('non-string commandName returns input unchanged', () => { assert.strictEqual(formatMsdSlash(null, 'claude'), null); assert.strictEqual(formatMsdSlash(undefined, 'claude'), undefined); assert.strictEqual(formatMsdSlash(42, 'claude'), 42); }); test('empty string returns empty string', () => { assert.strictEqual(formatMsdSlash('', 'claude'), ''); }); test('whitespace-only string returns empty string (no spurious /msd- emission)', () => { assert.strictEqual(formatMsdSlash(' ', 'claude'), ''); assert.strictEqual(formatMsdSlash('\t\n', 'codex'), ''); }); test('degenerate prefix-only input returns empty (does NOT re-emit colon form)', () => { // Regression guard for the CodeRabbit finding on the original PR: // a previous fallback returned `commandName` unchanged when the bare // tail was empty, which re-introduced the deprecated `/msd:` shape for // inputs like `/msd:`, `msd:`, or `msd-`. The formatter must never // emit the colon form — return empty so callers detect "no command" // instead of receiving an unroutable string. assert.strictEqual(formatMsdSlash('/msd:', 'claude'), ''); assert.strictEqual(formatMsdSlash('msd:', 'claude'), ''); assert.strictEqual(formatMsdSlash('msd-', 'claude'), ''); assert.strictEqual(formatMsdSlash('/msd-', 'codex'), ''); assert.strictEqual(formatMsdSlash('$msd-', 'codex'), ''); }); 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( formatMsdSlash('execute-phase 03', 'claude'), '/msd-execute-phase 03', ); assert.strictEqual( formatMsdSlash('/msd:execute-phase 03', 'claude'), '/msd-execute-phase 03', ); }); test('codex form lowercases only the command token, not the argument tail', () => { // Regression for codex review finding: a previous implementation // lowercased the full input including arguments, which would corrupt // Windows paths and case-sensitive flag values passed as args. assert.strictEqual( formatMsdSlash('Map-Codebase --paths C:\\Users\\Me\\Project', 'codex'), '$msd-map-codebase --paths C:\\Users\\Me\\Project', ); assert.strictEqual( formatMsdSlash('execute-phase 03 --Name FooBar', 'codex'), '$msd-execute-phase 03 --Name FooBar', ); }); test('hyphen form preserves token case (it does not get lowercased)', () => { // Symmetry with codex: only codex lowercases the token. Hyphen-form // runtimes preserve whatever case the caller supplied for the token. assert.strictEqual( formatMsdSlash('Plan-Phase 03', 'claude'), '/msd-Plan-Phase 03', ); }); }); }); describe('formatMsdSlash — descriptor-driven commandStyle (ADR-857 phase 5c)', () => { // These three assertions are the non-vacuous equivalence anchor for the // descriptor-driven branch: the formatter reads commandStyle from the // capability registry instead of hardcoding `if (rt === 'codex')`. test('codex (commandStyle=shell-var) → $msd- with lowercased token', () => { // The registry carries commandStyle=shell-var for codex. The formatter // must look it up and emit the shell-var form, lowercasing only the token. assert.strictEqual(formatMsdSlash('Foo', 'codex'), '$msd-foo'); }); test('slash-hyphen runtime (claude) → /msd- with case-preserved token', () => { // claude descriptor has commandStyle=slash-hyphen. Token case is preserved. assert.strictEqual(formatMsdSlash('Foo', 'claude'), '/msd-Foo'); }); test('slash-hyphen runtime (cursor) → /msd- with case-preserved token', () => { // cursor descriptor has commandStyle=slash-hyphen. assert.strictEqual(formatMsdSlash('Foo', 'cursor'), '/msd-Foo'); }); test('unknown runtime (no registry entry) → /msd- default (slash-hyphen fallback)', () => { // An unknown runtime has no descriptor entry → runtimes[rt] is undefined → // style is undefined → not 'shell-var' → falls through to /msd- default. assert.strictEqual(formatMsdSlash('foo', 'doesnotexist'), '/msd-foo'); }); }); describe('formatMsdSlash — registry-parity: prefix and casing are a pure function of commandStyle', () => { // Non-vacuous proof that the REGISTRY drives the decision, not a hardcoded // `rt === 'codex'` check. For every runtime id in capability-registry.cjs we // derive the expected prefix and lowercasing linkage directly from the // registry's commandStyle field and assert that formatMsdSlash matches. // // This fails if: // (a) anyone reverts the formatter to a hardcode that diverges from the // registry (e.g. a future runtime gets commandStyle=shell-var but the // formatter still only special-cases 'codex'); or // (b) a runtime's commandStyle is changed in the registry without // formatMsdSlash following suit. const { runtimes } = require( path.join(ROOT, 'msd-core', 'bin', 'lib', 'capability-registry.cjs'), ); const TOKEN_MIXED = 'SomeCmd'; // mixed-case to distinguish lowercasing behaviour for (const [id, descriptor] of Object.entries(runtimes)) { const style = descriptor.runtime.commandStyle; test(`${id}: commandStyle=${style} → formatMsdSlash prefix and casing match registry`, () => { const result = formatMsdSlash(TOKEN_MIXED, id); if (style === 'shell-var') { // shell-var runtimes must emit $msd- assert.ok( result.startsWith('$msd-'), `[${id}] expected $msd- prefix (commandStyle=shell-var), got: ${result}`, ); assert.strictEqual( result, `$msd-${TOKEN_MIXED.toLowerCase()}`, `[${id}] shell-var must lowercase the token`, ); } else { // slash-hyphen (or any other non-shell-var value) must emit /msd- // with case preserved (no lowercasing) assert.ok( result.startsWith('/msd-'), `[${id}] expected /msd- prefix (commandStyle=${style}), got: ${result}`, ); assert.strictEqual( result, `/msd-${TOKEN_MIXED}`, `[${id}] slash-hyphen must preserve token case`, ); } }); } }); describe('resolveRuntime — env > config > default', () => { test('process.env.MSD_RUNTIME wins over everything', () => { const saved = process.env.MSD_RUNTIME; try { process.env.MSD_RUNTIME = 'codex'; assert.strictEqual(resolveRuntime(null), 'codex'); assert.strictEqual(resolveRuntime('/nonexistent'), 'codex'); } finally { if (saved === undefined) delete process.env.MSD_RUNTIME; else process.env.MSD_RUNTIME = saved; } }); test('canonicalizes codex env aliases', () => { const saved = process.env.MSD_RUNTIME; try { process.env.MSD_RUNTIME = 'codex-app'; assert.strictEqual(resolveRuntime(null), 'codex'); process.env.MSD_RUNTIME = 'codex_cli'; assert.strictEqual(resolveRuntime('/nonexistent'), 'codex'); } finally { if (saved === undefined) delete process.env.MSD_RUNTIME; else process.env.MSD_RUNTIME = saved; } }); test('defaults to claude when env is unset and projectDir missing', () => { const saved = process.env.MSD_RUNTIME; try { delete process.env.MSD_RUNTIME; assert.strictEqual(resolveRuntime(null), 'claude'); assert.strictEqual(resolveRuntime(undefined), 'claude'); } finally { if (saved !== undefined) process.env.MSD_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(), 'msd-3584-')); t.after(() => cleanup(tmp)); fs.mkdirSync(path.join(tmp, '.planning'), { recursive: true }); fs.writeFileSync( path.join(tmp, '.planning', 'config.json'), JSON.stringify({ runtime: 'codex' }), ); const saved = process.env.MSD_RUNTIME; try { delete process.env.MSD_RUNTIME; assert.strictEqual(resolveRuntime(tmp), 'codex'); } finally { if (saved !== undefined) process.env.MSD_RUNTIME = saved; } }); test('canonicalizes codex config aliases', (t) => { const fs = require('fs'); const os = require('os'); const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'msd-3584-')); t.after(() => cleanup(tmp)); fs.mkdirSync(path.join(tmp, '.planning'), { recursive: true }); fs.writeFileSync( path.join(tmp, '.planning', 'config.json'), JSON.stringify({ runtime: 'codex-cli' }), ); const saved = process.env.MSD_RUNTIME; try { delete process.env.MSD_RUNTIME; assert.strictEqual(resolveRuntime(tmp), 'codex'); } finally { if (saved !== undefined) process.env.MSD_RUNTIME = saved; } }); test('canonicalizes non-codex config aliases', (t) => { const fs = require('fs'); const os = require('os'); const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'msd-3584-')); t.after(() => cleanup(tmp)); fs.mkdirSync(path.join(tmp, '.planning'), { recursive: true }); fs.writeFileSync( path.join(tmp, '.planning', 'config.json'), JSON.stringify({ runtime: 'claude-code' }), ); const saved = process.env.MSD_RUNTIME; try { delete process.env.MSD_RUNTIME; assert.strictEqual(resolveRuntime(tmp), 'claude'); } finally { if (saved !== undefined) process.env.MSD_RUNTIME = saved; } }); test('lowercases the resolved runtime', () => { const saved = process.env.MSD_RUNTIME; try { process.env.MSD_RUNTIME = 'CLAUDE'; assert.strictEqual(resolveRuntime(null), 'claude'); } finally { if (saved === undefined) delete process.env.MSD_RUNTIME; else process.env.MSD_RUNTIME = saved; } }); }); }); }