Files
get-shit-done/tests/multi-runtime-select.test.cjs
Tom Boucher 372d3453f5 fix(install): tokenize before ALL_RUNTIMES_OPTION check + isolate HERMES_HOME in test
Two CodeRabbit findings on PR #2920:

1. parseRuntimeInput previously only matched the bare "16" exactly for
   the all-runtimes shortcut. Inputs the prompt explicitly encourages —
   "16,", "16 1", "1,16" — fell through to per-token parsing and
   silently installed only Claude or a partial subset. Move the
   ALL_RUNTIMES_OPTION check after tokenization so any token equal to
   "16" expands. Added regression coverage in
   tests/multi-runtime-select.test.cjs for the four mixed-input forms.

2. The "maps Hermes to ~/.hermes for global installs" test invoked
   getGlobalDir('hermes') without isolating HERMES_HOME. On a developer
   machine that exports HERMES_HOME the assertion would fail even
   though getGlobalDir was behaving correctly. Save/clear/restore the
   env var around the assertion, mirroring the pattern the later
   describe block already uses.

Full suite: 6128/6128 pass.
2026-04-30 22:48:08 -04:00

197 lines
7.4 KiB
JavaScript

/**
* Tests for multi-runtime selection in the interactive installer prompt.
* Verifies that promptRuntime accepts comma-separated, space-separated,
* and single-choice inputs, deduplicates, and falls back to claude.
* See issue #1281.
*
* Per CONTRIBUTING.md "no-source-grep" testing standard, prompt + parser
* behavior is asserted via the install module's exported pure functions
* (`runtimeMap`, `allRuntimes`, `parseRuntimeInput`, `buildRuntimePromptText`)
* instead of regexing bin/install.js source text.
*/
process.env.GSD_TEST_MODE = '1';
const { test, describe } = require('node:test');
const assert = require('node:assert/strict');
const {
runtimeMap,
allRuntimes,
parseRuntimeInput,
buildRuntimePromptText,
} = require('../bin/install.js');
// Strip ANSI color codes for human-readable assertions on prompt text.
function stripAnsi(s) {
// eslint-disable-next-line no-control-regex
return s.replace(/\x1b\[[0-9;]*m/g, '');
}
describe('multi-runtime selection parsing', () => {
test('single choice returns single runtime', () => {
assert.deepStrictEqual(parseRuntimeInput('1'), ['claude']);
assert.deepStrictEqual(parseRuntimeInput('2'), ['antigravity']);
assert.deepStrictEqual(parseRuntimeInput('3'), ['augment']);
assert.deepStrictEqual(parseRuntimeInput('4'), ['cline']);
assert.deepStrictEqual(parseRuntimeInput('5'), ['codebuddy']);
assert.deepStrictEqual(parseRuntimeInput('6'), ['codex']);
assert.deepStrictEqual(parseRuntimeInput('7'), ['copilot']);
assert.deepStrictEqual(parseRuntimeInput('8'), ['cursor']);
});
test('comma-separated choices return multiple runtimes', () => {
assert.deepStrictEqual(parseRuntimeInput('1,7,9'), ['claude', 'copilot', 'gemini']);
assert.deepStrictEqual(parseRuntimeInput('2,3'), ['antigravity', 'augment']);
assert.deepStrictEqual(parseRuntimeInput('3,6'), ['augment', 'codex']);
});
test('space-separated choices return multiple runtimes', () => {
assert.deepStrictEqual(parseRuntimeInput('1 7 9'), ['claude', 'copilot', 'gemini']);
assert.deepStrictEqual(parseRuntimeInput('8 11'), ['cursor', 'kilo']);
});
test('mixed comma and space separators work', () => {
assert.deepStrictEqual(parseRuntimeInput('1, 7, 9'), ['claude', 'copilot', 'gemini']);
assert.deepStrictEqual(parseRuntimeInput('2 , 8'), ['antigravity', 'cursor']);
});
test('single choice for hermes', () => {
assert.deepStrictEqual(parseRuntimeInput('10'), ['hermes']);
});
test('single choice for kilo', () => {
assert.deepStrictEqual(parseRuntimeInput('11'), ['kilo']);
});
test('single choice for opencode', () => {
assert.deepStrictEqual(parseRuntimeInput('12'), ['opencode']);
});
test('single choice for qwen', () => {
assert.deepStrictEqual(parseRuntimeInput('13'), ['qwen']);
});
test('single choice for trae', () => {
assert.deepStrictEqual(parseRuntimeInput('14'), ['trae']);
});
test('single choice for windsurf', () => {
assert.deepStrictEqual(parseRuntimeInput('15'), ['windsurf']);
});
test('choice 16 returns all runtimes', () => {
assert.deepStrictEqual(parseRuntimeInput('16'), allRuntimes);
});
test('choice 16 returns all runtimes when mixed with separators or other tokens', () => {
// CR feedback: tokenized inputs that include 16 (e.g. trailing comma, or
// alongside other choices) must still expand to all-runtimes — previously
// only the bare "16" matched, so "16," or "16 1" silently installed a
// subset.
assert.deepStrictEqual(parseRuntimeInput('16,'), allRuntimes);
assert.deepStrictEqual(parseRuntimeInput('16 1'), allRuntimes);
assert.deepStrictEqual(parseRuntimeInput('1,16'), allRuntimes);
assert.deepStrictEqual(parseRuntimeInput(' 16 '), allRuntimes);
});
test('empty input defaults to claude', () => {
assert.deepStrictEqual(parseRuntimeInput(''), ['claude']);
assert.deepStrictEqual(parseRuntimeInput(' '), ['claude']);
});
test('invalid choices are ignored, falls back to claude if all invalid', () => {
assert.deepStrictEqual(parseRuntimeInput('17'), ['claude']);
assert.deepStrictEqual(parseRuntimeInput('0'), ['claude']);
assert.deepStrictEqual(parseRuntimeInput('abc'), ['claude']);
});
test('invalid choices mixed with valid are filtered out', () => {
assert.deepStrictEqual(parseRuntimeInput('1,17,7'), ['claude', 'copilot']);
assert.deepStrictEqual(parseRuntimeInput('abc 3 xyz'), ['augment']);
});
test('duplicate choices are deduplicated', () => {
assert.deepStrictEqual(parseRuntimeInput('1,1,1'), ['claude']);
assert.deepStrictEqual(parseRuntimeInput('7,7,9,9'), ['copilot', 'gemini']);
});
test('preserves selection order', () => {
assert.deepStrictEqual(parseRuntimeInput('9,1,7'), ['gemini', 'claude', 'copilot']);
assert.deepStrictEqual(parseRuntimeInput('11,2,8'), ['kilo', 'antigravity', 'cursor']);
});
});
describe('install.js exports multi-select runtime metadata', () => {
const expectedRuntimeMap = {
'1': 'claude',
'2': 'antigravity',
'3': 'augment',
'4': 'cline',
'5': 'codebuddy',
'6': 'codex',
'7': 'copilot',
'8': 'cursor',
'9': 'gemini',
'10': 'hermes',
'11': 'kilo',
'12': 'opencode',
'13': 'qwen',
'14': 'trae',
'15': 'windsurf',
};
const expectedRuntimes = [
'claude', 'antigravity', 'augment', 'cline', 'codebuddy', 'codex',
'copilot', 'cursor', 'gemini', 'hermes', 'kilo', 'opencode', 'qwen',
'trae', 'windsurf',
];
test('runtimeMap exports every option key bound to the right runtime', () => {
assert.deepStrictEqual(runtimeMap, expectedRuntimeMap,
'exported runtimeMap matches the canonical option list');
});
test('allRuntimes contains every runtime exactly once', () => {
assert.strictEqual(allRuntimes.length, expectedRuntimes.length);
for (const rt of expectedRuntimes) {
assert.ok(allRuntimes.includes(rt), `allRuntimes contains ${rt}`);
}
assert.strictEqual(new Set(allRuntimes).size, allRuntimes.length,
'allRuntimes has no duplicates');
});
test('"All" shortcut (option 16) selects every runtime', () => {
assert.deepStrictEqual(parseRuntimeInput('16'), allRuntimes);
});
test('prompt lists Hermes Agent (10), Qwen Code (13), Trae (14), and All (16)', () => {
const prompt = stripAnsi(buildRuntimePromptText());
assert.ok(/\b10\)\s*Hermes Agent\b/.test(prompt),
'prompt lists Hermes Agent as option 10');
assert.ok(/\b13\)\s*Qwen Code\b/.test(prompt),
'prompt lists Qwen Code as option 13');
assert.ok(/\b14\)\s*Trae\b/.test(prompt),
'prompt lists Trae as option 14');
assert.ok(/\b16\)\s*All\b/.test(prompt),
'prompt lists All as option 16');
});
test('prompt text shows multi-select hint', () => {
const prompt = stripAnsi(buildRuntimePromptText());
assert.ok(/Select multiple/i.test(prompt),
'prompt includes multi-select instructions');
});
test('parser splits on commas and whitespace and deduplicates', () => {
// Behavioral assertion: same set of choices in different separators
// produces the same selection, and duplicates collapse.
assert.deepStrictEqual(
parseRuntimeInput('1,7,9'),
parseRuntimeInput('1 7 9'),
'comma- and space-separated input yield identical selections'
);
assert.deepStrictEqual(parseRuntimeInput('1,1,7,7'), ['claude', 'copilot'],
'duplicates collapsed in order');
});
});