test: add behavioral alias dispatch contract

This commit is contained in:
Tom Boucher
2026-05-15 19:34:31 -04:00
parent 823b4ece0a
commit f3f088a03c
4 changed files with 169 additions and 1 deletions

View File

@@ -465,6 +465,7 @@ function loadConfig(cwd, options = {}) {
firecrawl: get('firecrawl') ?? defaults.firecrawl,
exa_search: get('exa_search') ?? defaults.exa_search,
tdd_mode: get('tdd_mode', { section: 'workflow', field: 'tdd_mode' }) ?? false,
mvp_mode: get('mvp_mode', { section: 'workflow', field: 'mvp_mode' }) ?? false,
text_mode: get('text_mode', { section: 'workflow', field: 'text_mode' }) ?? defaults.text_mode,
auto_advance: get('auto_advance', { section: 'workflow', field: 'auto_advance' }) ?? false,
_auto_chain_active: get('_auto_chain_active', { section: 'workflow', field: '_auto_chain_active' }) ?? false,

View File

@@ -15,6 +15,7 @@ function routePhaseCommand({ phase, args, cwd, raw, error }) {
error,
unknownMessage: (_subcommand, available) => `Unknown phase subcommand. Available: ${available.join(', ')}`,
handlers: {
'mvp-mode': () => phase.cmdPhaseMvpMode(cwd, args.slice(2), raw),
'next-decimal': () => phase.cmdPhaseNextDecimal(cwd, args[2], raw),
add: () => {
let customId = null;

View File

@@ -4,7 +4,7 @@
const fs = require('fs');
const path = require('path');
const { escapeRegex, loadConfig, normalizePhaseName, phaseMarkdownRegexSource, comparePhaseNum, findPhaseInternal, getArchivedPhaseDirs, generateSlugInternal, getMilestonePhaseFilter, stripShippedMilestones, extractCurrentMilestone, replaceInCurrentMilestone, toPosixPath, output, error, readSubdirectories, phaseTokenMatches } = require('./core.cjs');
const { escapeRegex, loadConfig, normalizePhaseName, phaseMarkdownRegexSource, comparePhaseNum, findPhaseInternal, getArchivedPhaseDirs, generateSlugInternal, getMilestonePhaseFilter, stripShippedMilestones, extractCurrentMilestone, replaceInCurrentMilestone, toPosixPath, output, error, readSubdirectories, phaseTokenMatches, ERROR_REASON } = require('./core.cjs');
const { platformWriteSync, platformReadSync, platformEnsureDir } = require('./shell-command-projection.cjs');
const { planningDir, withPlanningLock } = require('./planning-workspace.cjs');
const { extractFrontmatter } = require('./frontmatter.cjs');
@@ -210,6 +210,65 @@ function cmdPhaseNextDecimal(cwd, basePhase, raw) {
}
}
function getRoadmapModeForPhase(cwd, phaseNum) {
const roadmapPath = path.join(planningDir(cwd), 'ROADMAP.md');
if (!fs.existsSync(roadmapPath)) return null;
const rawContent = fs.readFileSync(roadmapPath, 'utf-8');
const milestoneContent = extractCurrentMilestone(rawContent, cwd);
const fullContent = stripShippedMilestones(rawContent);
const escapedPhase = phaseMarkdownRegexSource(phaseNum);
const phaseHeader = new RegExp(`#{2,4}\\s*Phase\\s+${escapedPhase}\\s*:`, 'i');
for (const content of [milestoneContent, fullContent]) {
const headerMatch = content.match(phaseHeader);
if (!headerMatch || headerMatch.index === undefined) continue;
const sectionStart = headerMatch.index;
const rest = content.slice(sectionStart);
const nextHeader = rest.slice(headerMatch[0].length).match(/\n#{2,4}\s+Phase\s+\d/i);
const sectionEnd = nextHeader ? sectionStart + headerMatch[0].length + nextHeader.index : content.length;
const section = content.slice(sectionStart, sectionEnd);
const modeMatch = section.match(/\*\*Mode(?::\*\*|\*\*:)\s*([^\n]+)/i);
if (modeMatch) return modeMatch[1].trim().toLowerCase();
}
return null;
}
function cmdPhaseMvpMode(cwd, args, raw) {
const phaseNum = args[0];
if (!phaseNum) {
error('Usage: phase.mvp-mode <phase-number> [--cli-flag]', ERROR_REASON.USAGE);
}
const cliFlagPresent = args.includes('--cli-flag');
const roadmapMode = getRoadmapModeForPhase(cwd, phaseNum);
const config = loadConfig(cwd);
const configMvpMode = Boolean(config.mvp_mode);
let active = false;
let source = 'none';
if (cliFlagPresent) {
active = true;
source = 'cli_flag';
} else if (roadmapMode === 'mvp') {
active = true;
source = 'roadmap';
} else if (configMvpMode) {
active = true;
source = 'config';
}
output({
active,
source,
roadmap_mode: roadmapMode,
config_mvp_mode: configMvpMode,
cli_flag_present: cliFlagPresent,
}, raw);
}
function cmdFindPhase(cwd, phase, raw) {
if (!phase) {
error('phase identifier required');
@@ -1329,6 +1388,7 @@ module.exports = {
cmdPhasePlanIndex,
cmdPhaseAdd,
cmdPhaseAddBatch,
cmdPhaseMvpMode,
cmdPhaseInsert,
cmdPhaseRemove,
cmdPhaseComplete,

View File

@@ -10,7 +10,10 @@
const { describe, test } = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const os = require('node:os');
const path = require('path');
const { spawnSync } = require('node:child_process');
const REPO_ROOT = path.join(__dirname, '..');
const COMMAND_ALIASES_FILE = path.join(
@@ -20,6 +23,7 @@ const COMMAND_ALIASES_FILE = path.join(
'lib',
'command-aliases.generated.cjs',
);
const GSD_TOOLS = path.join(REPO_ROOT, 'get-shit-done', 'bin', 'gsd-tools.cjs');
const MISSING_14 = [
'check.decision-coverage-plan',
@@ -126,3 +130,105 @@ describe('feat-3251: command-aliases.generated.cjs manifest coverage', () => {
);
});
});
function createProject() {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-3251-dispatch-'));
fs.mkdirSync(path.join(dir, '.planning', 'phases'), { recursive: true });
return dir;
}
function runGsdTools(args, cwd) {
return spawnSync(process.execPath, [GSD_TOOLS, ...args], {
cwd,
encoding: 'utf8',
});
}
function listProjectFiles(projectDir) {
const files = [];
function walk(dir) {
if (!fs.existsSync(dir)) return;
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
const full = path.join(dir, entry.name);
const rel = path.relative(projectDir, full);
if (entry.isDirectory()) walk(full);
else files.push(rel);
}
}
walk(projectDir);
return files.sort();
}
describe('feat-3251: generated aliases dispatch through real gsd-tools behavior', () => {
test('phase.mvp-mode spaced alias resolves CLI flag precedence', () => {
const projectDir = createProject();
try {
const result = runGsdTools(['phase', 'mvp-mode', '1', '--cli-flag'], projectDir);
assert.equal(result.status, 0, result.stderr);
const output = JSON.parse(result.stdout);
assert.deepEqual(output, {
active: true,
source: 'cli_flag',
roadmap_mode: null,
config_mvp_mode: false,
cli_flag_present: true,
});
} finally {
fs.rmSync(projectDir, { recursive: true, force: true });
}
});
test('phase.mvp-mode spaced alias resolves ROADMAP mode without mutating files', () => {
const projectDir = createProject();
try {
fs.writeFileSync(
path.join(projectDir, '.planning', 'ROADMAP.md'),
[
'# Roadmap',
'',
'## v1.0.0',
'',
'### Phase 1: User Auth',
'**Goal:** Users can sign in.',
'**Mode:** mvp',
'',
].join('\n'),
);
const beforeFiles = listProjectFiles(projectDir);
const result = runGsdTools(['phase', 'mvp-mode', '1'], projectDir);
assert.equal(result.status, 0, result.stderr);
const output = JSON.parse(result.stdout);
assert.equal(output.active, true);
assert.equal(output.source, 'roadmap');
assert.equal(output.roadmap_mode, 'mvp');
assert.equal(output.config_mvp_mode, false);
assert.equal(output.cli_flag_present, false);
assert.deepEqual(listProjectFiles(projectDir), beforeFiles);
} finally {
fs.rmSync(projectDir, { recursive: true, force: true });
}
});
test('phase.mvp-mode JSON error is typed and leaves project files untouched', () => {
const projectDir = createProject();
try {
const beforeFiles = listProjectFiles(projectDir);
const result = runGsdTools(['--json-errors', 'phase', 'mvp-mode'], projectDir);
assert.notEqual(result.status, 0);
assert.equal(result.stdout, '');
const error = JSON.parse(result.stderr);
assert.deepEqual(Object.keys(error).sort(), ['message', 'ok', 'reason']);
assert.equal(error.ok, false);
assert.equal(error.reason, 'usage');
assert.equal(typeof error.message, 'string');
assert.equal(/\n\s*at\s/.test(result.stderr), false, 'non-debug failure must not print a stack trace');
assert.deepEqual(listProjectFiles(projectDir), beforeFiles);
} finally {
fs.rmSync(projectDir, { recursive: true, force: true });
}
});
});