Files
msd-core/tests/multi-runtime-select.test.cjs
Elwin 66368a42d9 feat: add Trae runtime install support (#1566)
* feat: add Trae runtime install support

- Add Trae as a supported runtime in bin/install.js
- Update README and ARCHITECTURE documentation for Trae support
- Add trae-install.test.cjs test file
- Update multi-runtime-select tests for Trae compatibility

* feat(trae): add TRAE_CONFIG_DIR environment variable support

Add support for TRAE_CONFIG_DIR environment variable as an additional way to specify the config directory for Trae runtime, following the same precedence pattern as other runtimes.

* fix(trae): improve slash command conversion and subagent type mapping

Update the slash command regex pattern to properly match and convert command names. Change subagent type mapping from "general-purpose" to "general_purpose_task" to match Trae's conventions. Also add comprehensive tests for Trae uninstall cleanup behavior.

* docs: add Trae and Windsurf to supported runtimes in translations

Update Korean, Japanese, and Portuguese README files to include Trae and Windsurf as supported runtimes in the documentation. Add installation and uninstallation instructions for Trae.

* fix: update runtime selection logic and path replacements

- Change 'All' shortcut from option 11 to 12 to accommodate new runtime
- Update path replacement regex to handle gsd- prefix more precisely
- Adjust test cases to reflect new runtime selection numbering
- Add configDir to trae install options for proper path resolution

* test(trae-install): add tests for getGlobalDir function

Add test cases to verify behavior of getGlobalDir function with different configurations:
- Default directory when no env var or explicit dir is provided
- Explicit directory takes priority
- Respects TRAE_CONFIG_DIR env var
- Priority of explicit dir over env var
- Compatibility with other runtimes
2026-04-04 08:13:15 -04:00

184 lines
5.9 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.
*/
const { test, describe } = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
// Read install.js source to extract the runtimeMap and parsing logic
const installSrc = fs.readFileSync(
path.join(__dirname, '..', 'bin', 'install.js'),
'utf8'
);
// Extract runtimeMap from source for validation
const runtimeMap = {
'1': 'claude',
'2': 'kilo',
'3': 'opencode',
'4': 'gemini',
'5': 'codex',
'6': 'copilot',
'7': 'antigravity',
'8': 'cursor',
'9': 'windsurf',
'10': 'augment',
'11': 'trae'
};
const allRuntimes = ['claude', 'kilo', 'opencode', 'gemini', 'codex', 'copilot', 'antigravity', 'cursor', 'windsurf', 'augment', 'trae'];
/**
* Simulate the parsing logic from promptRuntime without requiring readline.
* This mirrors the exact logic in the rl.question callback.
*/
function parseRuntimeInput(input) {
input = input.trim() || '1';
if (input === '12') {
return allRuntimes;
}
const choices = input.split(/[\s,]+/).filter(Boolean);
const selected = [];
for (const c of choices) {
const runtime = runtimeMap[c];
if (runtime && !selected.includes(runtime)) {
selected.push(runtime);
}
}
return selected.length > 0 ? selected : ['claude'];
}
describe('multi-runtime selection parsing', () => {
test('single choice returns single runtime', () => {
assert.deepStrictEqual(parseRuntimeInput('1'), ['claude']);
assert.deepStrictEqual(parseRuntimeInput('2'), ['kilo']);
assert.deepStrictEqual(parseRuntimeInput('3'), ['opencode']);
assert.deepStrictEqual(parseRuntimeInput('4'), ['gemini']);
assert.deepStrictEqual(parseRuntimeInput('5'), ['codex']);
assert.deepStrictEqual(parseRuntimeInput('8'), ['cursor']);
});
test('comma-separated choices return multiple runtimes', () => {
assert.deepStrictEqual(parseRuntimeInput('1,5,7'), ['claude', 'codex', 'antigravity']);
assert.deepStrictEqual(parseRuntimeInput('2,3'), ['kilo', 'opencode']);
assert.deepStrictEqual(parseRuntimeInput('3,4'), ['opencode', 'gemini']);
});
test('space-separated choices return multiple runtimes', () => {
assert.deepStrictEqual(parseRuntimeInput('1 5 7'), ['claude', 'codex', 'antigravity']);
assert.deepStrictEqual(parseRuntimeInput('6 8'), ['copilot', 'cursor']);
});
test('mixed comma and space separators work', () => {
assert.deepStrictEqual(parseRuntimeInput('1, 5, 7'), ['claude', 'codex', 'antigravity']);
assert.deepStrictEqual(parseRuntimeInput('2 , 6'), ['kilo', 'copilot']);
});
test('single choice for windsurf', () => {
assert.deepStrictEqual(parseRuntimeInput('9'), ['windsurf']);
});
test('single choice for augment', () => {
assert.deepStrictEqual(parseRuntimeInput('10'), ['augment']);
});
test('single choice for trae', () => {
assert.deepStrictEqual(parseRuntimeInput('11'), ['trae']);
});
test('choice 12 returns all runtimes', () => {
assert.deepStrictEqual(parseRuntimeInput('12'), 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('13'), ['claude']);
assert.deepStrictEqual(parseRuntimeInput('0'), ['claude']);
assert.deepStrictEqual(parseRuntimeInput('abc'), ['claude']);
});
test('invalid choices mixed with valid are filtered out', () => {
assert.deepStrictEqual(parseRuntimeInput('1,13,5'), ['claude', 'codex']);
assert.deepStrictEqual(parseRuntimeInput('abc 3 xyz'), ['opencode']);
});
test('duplicate choices are deduplicated', () => {
assert.deepStrictEqual(parseRuntimeInput('1,1,1'), ['claude']);
assert.deepStrictEqual(parseRuntimeInput('5,5,7,7'), ['codex', 'antigravity']);
});
test('preserves selection order', () => {
assert.deepStrictEqual(parseRuntimeInput('7,1,5'), ['antigravity', 'claude', 'codex']);
assert.deepStrictEqual(parseRuntimeInput('8,2,6'), ['cursor', 'kilo', 'copilot']);
});
});
describe('install.js source contains multi-select support', () => {
test('runtimeMap is defined with all 10 runtimes', () => {
for (const [key, name] of Object.entries(runtimeMap)) {
assert.ok(
installSrc.includes(`'${key}': '${name}'`),
`runtimeMap has ${key} -> ${name}`
);
}
});
test('allRuntimes array contains all runtimes', () => {
const match = installSrc.match(/const allRuntimes = \[([^\]]+)\]/);
assert.ok(match, 'allRuntimes array found');
for (const rt of allRuntimes) {
assert.ok(match[1].includes(`'${rt}'`), `allRuntimes includes ${rt}`);
}
});
test('all shortcut uses option 12', () => {
assert.ok(
installSrc.includes("if (input === '12')"),
'all shortcut uses option 12'
);
});
test('prompt lists Augment as option 10 and All as option 12', () => {
assert.ok(
installSrc.includes('10${reset}) Augment'),
'prompt lists Augment as option 10'
);
assert.ok(
installSrc.includes('12${reset}) All'),
'prompt lists All as option 12'
);
});
test('prompt text shows multi-select hint', () => {
assert.ok(
installSrc.includes('Select multiple'),
'prompt includes multi-select instructions'
);
});
test('parsing uses split with comma and space regex', () => {
assert.ok(
installSrc.includes("split(/[\\s,]+/)"),
'input is split on commas and whitespace'
);
});
test('deduplication check exists', () => {
assert.ok(
installSrc.includes('!selected.includes(runtime)'),
'deduplication guard exists'
);
});
});