Files
msd-core/tests/multi-runtime-select.test.cjs
Tom Boucher bf8f320083 feat(#2505): Phase 1 — EoS descriptor split (kimi-code capability.json + drift-guard registration) (#2519)
* feat(#2454): add kimi-code as an EoS capability (Node Kimi Code CLI)

PR 1 of N for #2454. Establishes the EoS descriptor foundation for splitting
GSD's kimi support into two distinct products per the user's directive:
- kimi       (existing): Moonshot's Python kimi-cli (~/.kimi, runtime: python)
- kimi-code  (new):      Moonshot's Node Kimi Code CLI (~/.kimi-code,
                         runtime: node, KIMI_CODE_HOME env)

Per ADR-1239 EoS, runtime behavior is driven by capabilities/<id>/capability.json
descriptors, not hardcoded branches in install.js. The new descriptor uses
the existing primitives (dot-home configHome, skills artifactLayout, kimi-hooks-toml
hooksSurface — same TOML [[hooks]] format Kimi Code reads per its docs).

Critical Kimi Code constraint reflected in the descriptor:
  hostIntegration.dispatch.namedDispatch: false
  hostIntegration.dispatch.builtInSubagents: ['coder', 'explore', 'plan']
  hostBehaviors.namedSubagentsSupported: false
Kimi Code's official docs confirm only 3 built-in subagents with NO custom-
subagent registration (the [subagent] table only has timeout_ms). The
kimi-agents YAML layout (used by Python kimi-cli) is therefore NOT in
kimi-code's artifactLayout.

Schema adjustments:
- subagentToolkit set to 'undocumented' (the existing escape hatch); the
  schema enum (full/read-only) lacks a 'limited'/'built-in-only' value.
  A follow-up PR can extend the schema enum to add 'built-in-only' as a
  first-class axis value reflecting Kimi Code's documented model.

Registration:
- capabilities/kimi-code/capability.json (new descriptor, modeled on codex)
- bin/install.js: allRuntimes array + --all list + --kimi-code flag
- gsd-core/bin/shared/runtime-aliases.manifest.json: kimi-code aliases
  (kimi-code, kimicode, kimi_code)
- src/runtime-name-policy.cts: FALLBACK_ALIASES map
- gsd-core/bin/lib/capability-registry.cjs: regenerated via
  scripts/gen-capability-registry.cjs --write

Tests:
- tests/multi-runtime-select.test.cjs updated for the new runtime count (18)
  + new --kimi-code flag test + 'All' shortcut renumbered 18 → 19.

Out of scope for PR 1 (follow-up PRs in the sequence):
- Install-time decision logic (kimi vs kimi-code detection / prompt)
- agent-install-check semantics for kimi-code (verify Agent Skills presence)
- cmdAgentSkills fallback returning subagent prompt content
- Workflow template mapping (named agents → built-in coder/explore/plan)
- Migration guidance for users currently on 'kimi' who are actually on Kimi Code
- Schema enum extension for subagentToolkit: 'built-in-only'

Refs #2454, #2095 (EoS/kimi migration epic), ADR-1239 (EoS).

* fix(#2454): complete drift-guard registrations for kimi-code runtime

The drift guards caught every surface that pins runtime enumeration. Each
update is mechanical, driven by the guard's named failure mode:

- src/runtime-name-policy.cts RUNTIME_LABELS: 'Kimi Code' label for kimi-code
- src/runtime-name-policy.cts RUNTIME_FLAG_IDS: add kimi-code to the
  isKimiCode predicate generator
- bin/install.js runtimeMap: option '11' → 'kimi-code', renumber downstream
  entries (11..17 → 12..18), ALL_RUNTIMES_OPTION 18 → 19
- gsd-core/bin/shared/model-catalog.json runtimeTierDefaults: kimi-code entry
  (null/null/null — same as kimi, no model tier defaults until configured)
- docs/reference/capability-matrix.md: regenerated via
  scripts/gen-capability-matrix.cjs --write (kimi-code row added)
- tests/global-config-home-fragment.test.cjs GOLDEN_FRAGMENT_MAP:
  kimi-code → '.kimi-code'
- tests/fixtures/golden-install-parity/*.json: regenerated via npm run gen:golden
  (the runtime-aliases.manifest.json hash changed; all 17 runtime fixtures updated)

The capability-registry is already regenerated from the prior commit.

* test(#2454): update drift-guard tests for kimi-code runtime registration

Multiple drift guards pin runtime enumeration counts and option numbering.
Each update is mechanical, driven by the guard's named failure mode:

- tests/runtime-flags.test.cjs: EXPECTED_FLAGS gains isKimiCode (16 → 17);
  'all 16 flags' → 'all 17 flags' in test names + messages.
- tests/multi-runtime-select.test.cjs: parseRuntimeInput option renumbering
  cascade — kilo moves 11→12, opencode 12→13, pi 13→14, qwen 14→15,
  trae 15→16, windsurf 16→17, zcode 17→18, All 18→19. New single-choice
  test for kimi-code (option 11). Prompt test updated for new numbering.
- tests/host-integration-descriptors.test.cjs: EXPECTED_PROFILES gains
  kimi-code → 'programmatic-cli' (terminal CLI per Kimi Code docs);
  EXPECTED_FLATTEN gains kimi-code → false (backgroundDispatch:true per
  docs, same as Python kimi/opencode).
- tests/global-config-home-fragment.test.cjs: table-count test renamed
  13 → 14 table runtimes (kimi-code added to GOLDEN_FRAGMENT_MAP earlier).

* fix(#2454): empty artifactLayout for kimi-code (PR 1 scope)

The skills kind requires a converter (existing converters are per-runtime
like convertClaudeCommandToKimiSkill). PR 1 of this multi-PR sequence only
registers the descriptor; the actual Agent Skills converter (and a new
'convertClaudeCommandToKimiCodeSkill' function) lands in PR 2 alongside
the install-time decision logic. Empty artifactLayout.global is valid and
means 'nothing to install yet via the layout seam'.

Also: added kimi-code to RUNTIME_META in tests/helpers/install-shared.cjs
(localDir .kimi-code, globalSuffix .kimi-code), and added Kimi Code as
option 11 in install.js's buildRuntimePromptText (renumbered downstream
options 11..17 → 12..18, All 18 → 19).

* fix(#2454): camelCase runtimeFlags for hyphenated ids (kimi-code → isKimiCode)

The runtimeFlags generator previously produced 'isKimi-code' (hyphen preserved)
for the new kimi-code runtime id. Property names with hyphens are awkward for
consumers (flags['isKimi-code'] instead of flags.isKimiCode). The new
runtimeIdToFlagName helper folds -[a-z] boundaries to uppercase, producing
the conventional PascalCase flag name. The 16 prior single-word runtime ids
are unaffected (the regex finds no hyphens).

* fix(#2454): update remaining drift-guard tests + gen kimi-code fixtures

- tests/runtime-flags.test.cjs drift guard: use proper kebab-case
  conversion (isKimiCode → kimi-code, not 'kimicode') so the registry
  comparison doesn't false-positive on hyphenated runtime ids.
- tests/multi-runtime-select.test.cjs: fix kilo/opencode/pi/qwen/trae
  single-choice tests for the renumbered options (kilo 11→12, opencode
  12→13, pi 13→14, qwen 14→15, trae 15→16).
- tests/install.test.cjs: Kilo integration option 11→12, prompt test
  regex updated.
- tests/fixtures/golden-install-parity/kimi-code.json + install-tree/
  kimi-code.json: generated via UPDATE_GOLDEN=1 + UPDATE_INSTALL_TREE=1.
  The kimi-code install produces the standard GSD install layout (skills,
  contexts, references, etc.) — 436 paths, same shape as other runtimes
  that have no custom converter yet.

* fix(#2454): add kimi-code install contract + global config home fragment

- src/runtime-name-policy.cts GLOBAL_CONFIG_HOME_FRAGMENTS: add kimi-code
  → '.kimi-code' so getGlobalConfigHomeFragment returns the correct path
  instead of falling through to the default '.claude'.
- tests/installer-migration-install.integration.test.cjs
  RUNTIME_INSTALL_CONTRACTS: kimi-code entry (same surface as kimi for
  PR 1; PR 2 will specialize once the Agent Skills converter lands).
- tests/multi-runtime-select.test.cjs: fix space-separated-choices test
  for the renumbered kilo option (11 → 12).
- tests/fixtures/golden-install-parity/kimi-code.json + install-tree/
  kimi-code.json: regenerated after rebasing onto current next (new
  planner-reversibility.md from #2471 etc. now included).

* test(#2454): skip kimi-code install contract until PR 2 ships install layout

The end-to-end install test (tests/installer-migration-install.integration
.test.cjs) asserts every allRuntimes entry installs a runtime-specific
artifact surface. PR 1 of #2454 registers kimi-code in allRuntimes + the
capability descriptor + flags + labels, but the install LAYOUT (Agent
Skills converter + global AGENTS.md at $KIMI_CODE_HOME/AGENTS.md) lands
in PR 2. The SKIP_INSTALL_CONTRACT set marks this exclusion explicit and
self-removing — PR 2 removes the entry alongside adding the install
surface, restoring the contract loop to full coverage.

* fix(#2454): restore compact model-catalog.json format (M1 review)

Per code-review M1: my prior 'fix(#2454): complete drift-guard registrations'
commit used python json.dump(indent=2) which inflated the file from 165→607
lines (every nested entry got expanded) and lost the trailing newline. The
semantic change was just a 3-line kimi-code entry. Restored the original
hybrid format (top-level indent=2 + inner entries' one-line style) and
added kimi-code in matching form.

Regenerated golden install parity + install tree fixtures since the
model-catalog.json hash changed.

* fix(#2454): update CONTEXT.md allRuntimes glossary (17 → 18, add kimi-code)

CI lint-tests job failed on the glossary drift guard
(scripts/check-glossary-refs.cjs --check):
  ✗ CONTEXT.md's allRuntimes enum-count sentence claims 17 values but
    bin/install.js's allRuntimes array has 18.
  ✗ CONTEXT.md's allRuntimes member list has drifted from bin/install.js
    (missing from CONTEXT.md's list: kimi-code).

Missed in the prior commits because gsd-test does not run the glossary
check (it's a CI lint-tests-only check). Updating CONTEXT.md's two claims
to 18 values + kimi-code in the member list.

* chore(#2505): regen capability-registry + stamp kimi-code version 1.8.0 (#2511)

* docs(changeset): Phase 1 kimi-code runtime Added (#2511)

* test(#2511): regen kimi-code golden parity fixture after Phase 0 guard normalization lands

* docs(changeset): backfill PR #2519 for Phase 1 (#2511)
2026-07-22 00:27:35 -04:00

280 lines
11 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.
*
* #1928: Google sunset Gemini CLI (2026-06-18) and the `gemini` runtime was
* removed from GSD (Antigravity CLI is the successor). The runtime option
* numbering below is renumbered accordingly — option 9 (formerly gemini) is
* now hermes, and the "All" shortcut moved from 17 to 16.
*
* #1925: ZCode (Z.ai) added as option 16; the "All" shortcut moved from 16 to 17.
*
* #2102: pi added as option 13 (alphabetical slot between opencode and qwen) —
* qwen/trae/windsurf/zcode each shift up one slot (14/15/16/17), and the "All"
* shortcut moves from 17 to 18.
*/
process.env.GSD_TEST_MODE = '1';
const { test, describe } = require('node:test');
const assert = require('node:assert/strict');
const {
runtimeMap,
allRuntimes,
selectRuntimesFromArgs,
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', 'hermes']);
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', 'hermes']);
assert.deepStrictEqual(parseRuntimeInput('8 12'), ['cursor', 'kilo']);
});
test('mixed comma and space separators work', () => {
assert.deepStrictEqual(parseRuntimeInput('1, 7, 9'), ['claude', 'copilot', 'hermes']);
assert.deepStrictEqual(parseRuntimeInput('2 , 8'), ['antigravity', 'cursor']);
});
test('single choice for hermes', () => {
assert.deepStrictEqual(parseRuntimeInput('9'), ['hermes']);
});
test('single choice for kilo', () => {
assert.deepStrictEqual(parseRuntimeInput('12'), ['kilo']);
});
test('single choice for opencode', () => {
assert.deepStrictEqual(parseRuntimeInput('13'), ['opencode']);
});
test('single choice for pi', () => {
assert.deepStrictEqual(parseRuntimeInput('14'), ['pi']);
});
test('single choice for qwen', () => {
assert.deepStrictEqual(parseRuntimeInput('15'), ['qwen']);
});
test('single choice for trae', () => {
assert.deepStrictEqual(parseRuntimeInput('16'), ['trae']);
});
test('single choice for windsurf', () => {
assert.deepStrictEqual(parseRuntimeInput('17'), ['windsurf']);
});
test('single choice for zcode', () => {
assert.deepStrictEqual(parseRuntimeInput('18'), ['zcode']);
});
test('single choice for kimi', () => {
assert.deepStrictEqual(parseRuntimeInput('10'), ['kimi']);
});
test('single choice for kimi-code (#2454)', () => {
assert.deepStrictEqual(parseRuntimeInput('11'), ['kimi-code']);
});
test('choice 19 returns all runtimes', () => {
assert.deepStrictEqual(parseRuntimeInput('19'), allRuntimes);
});
test('choice 19 returns all runtimes when mixed with separators or other tokens', () => {
// CR feedback: tokenized inputs that include 19 (e.g. trailing comma, or
// alongside other choices) must still expand to all-runtimes — previously
// only the bare all-runtimes option matched, so "19," or "19 1" silently installed a
// subset.
assert.deepStrictEqual(parseRuntimeInput('19,'), allRuntimes);
assert.deepStrictEqual(parseRuntimeInput('19 1'), allRuntimes);
assert.deepStrictEqual(parseRuntimeInput('1,19'), allRuntimes);
assert.deepStrictEqual(parseRuntimeInput(' 19 '), 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('20'), ['claude']);
assert.deepStrictEqual(parseRuntimeInput('0'), ['claude']);
assert.deepStrictEqual(parseRuntimeInput('abc'), ['claude']);
});
test('invalid choices mixed with valid are filtered out', () => {
assert.deepStrictEqual(parseRuntimeInput('1,20,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', 'hermes']);
});
test('preserves selection order', () => {
assert.deepStrictEqual(parseRuntimeInput('9,1,7'), ['hermes', 'claude', 'copilot']);
assert.deepStrictEqual(parseRuntimeInput('12,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': 'hermes',
'10': 'kimi',
'11': 'kimi-code',
'12': 'kilo',
'13': 'opencode',
'14': 'pi',
'15': 'qwen',
'16': 'trae',
'17': 'windsurf',
'18': 'zcode',
};
const expectedRuntimes = [
'claude', 'antigravity', 'augment', 'cline', 'codebuddy', 'codex',
'copilot', 'cursor', 'hermes', 'kimi', 'kimi-code', 'kilo', 'opencode', 'pi',
'qwen', 'trae', 'windsurf', 'zcode',
];
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 19) selects every runtime', () => {
assert.deepStrictEqual(parseRuntimeInput('19'), allRuntimes);
});
test('--kimi flag selects Kimi (Python kimi-cli) without interactive prompt', () => {
assert.deepStrictEqual(selectRuntimesFromArgs(['--kimi']), ['kimi']);
});
test('--kimi-code flag selects Kimi Code (Node CLI) without interactive prompt (#2454)', () => {
assert.deepStrictEqual(selectRuntimesFromArgs(['--kimi-code']), ['kimi-code']);
});
test('--zcode flag selects ZCode without interactive prompt', () => {
assert.deepStrictEqual(selectRuntimesFromArgs(['--zcode']), ['zcode']);
});
test('--pi flag selects pi without interactive prompt', () => {
assert.deepStrictEqual(selectRuntimesFromArgs(['--pi']), ['pi']);
});
test('--all flag includes Kimi exactly once', () => {
const selected = selectRuntimesFromArgs(['--all']);
assert.ok(selected.includes('kimi'), '--all includes kimi');
assert.strictEqual(selected.filter((runtime) => runtime === 'kimi').length, 1,
'--all includes kimi exactly once');
});
test('--all flag includes ZCode exactly once', () => {
const selected = selectRuntimesFromArgs(['--all']);
assert.ok(selected.includes('zcode'), '--all includes zcode');
assert.strictEqual(selected.filter((runtime) => runtime === 'zcode').length, 1,
'--all includes zcode exactly once');
});
test('--all flag includes pi exactly once', () => {
const selected = selectRuntimesFromArgs(['--all']);
assert.ok(selected.includes('pi'), '--all includes pi');
assert.strictEqual(selected.filter((runtime) => runtime === 'pi').length, 1,
'--all includes pi exactly once');
});
test('prompt lists pi (14), ZCode (18), and All (19)', () => {
const prompt = stripAnsi(buildRuntimePromptText());
assert.ok(/\b9\)\s*Hermes Agent\b/.test(prompt),
'prompt lists Hermes Agent as option 9');
assert.ok(/\b10\)\s*Kimi\b/.test(prompt),
'prompt lists Kimi as option 10');
assert.ok(/Kimi\s+\(~\/\.config\/agents, then ~\/\.agents if existing\)/.test(prompt),
'prompt shows the Kimi first-existing generic root policy');
assert.ok(/\b11\)\s*Kimi Code\b/.test(prompt),
'prompt lists Kimi Code as option 11 (#2454)');
assert.ok(/\b14\)\s*pi\b/.test(prompt),
'prompt lists pi as option 14');
assert.ok(/\b15\)\s*Qwen Code\b/.test(prompt),
'prompt lists Qwen Code as option 15');
assert.ok(/\b16\)\s*Trae\b/.test(prompt),
'prompt lists Trae as option 16');
assert.ok(/\b18\)\s*ZCode\b/.test(prompt),
'prompt lists ZCode as option 18');
assert.ok(/\b19\)\s*All\b/.test(prompt),
'prompt lists All as option 19');
});
test('prompt does not list Gemini (removed #1928)', () => {
const prompt = stripAnsi(buildRuntimePromptText());
assert.ok(!/Gemini/.test(prompt), 'prompt must not mention Gemini');
});
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');
});
});