Files
msd-core/tests/kimi-variant-disambiguation.test.cjs
Tom Boucher 28f79e6e22 feat(#2505): Phase 5 — Kimi variant install-time disambiguation (#2535)
* feat(#2513): Phase 5 — Kimi variant install-time disambiguation (descriptions + mismatch warning)

* fix #2513: use helpers.cleanup (Windows-EBUSY retry budget) not raw fs.rmSync

* fix #2513: spawnSync captures stderr (execFileSync drops it on exit-0)

* docs(changeset): backfill PR #2535 for Phase 5 (#2513)
2026-07-22 13:49:31 -04:00

95 lines
3.5 KiB
JavaScript

// allow-test-rule: behavioral-subprocess-test — Phase 5 kimi-variant
// disambiguation is verified via install.js subprocess output capture, since
// the disambiguateKimiVariant function is inline in bin/install.js (not
// exported). The test sets a disposable HOME, creates the probe config files,
// and asserts on the printed notices.
process.env.GSD_TEST_MODE = '1';
const { test, describe, before, after } = require('node:test');
const assert = require('node:assert/strict');
const { spawnSync } = require('node:child_process');
const fs = require('node:fs');
const os = require('node:os');
const path = require('node:path');
const { cleanup } = require('./helpers.cjs');
const INSTALL_JS = path.join(__dirname, '..', 'bin', 'install.js');
function makeDisposableHome() {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-kimi-disambig-'));
return {
dir,
cleanup() { cleanup(dir); },
};
}
function runInstall(args, home) {
// spawnSync captures stdout AND stderr separately regardless of exit code
// (execFileSync drops stderr on success, which hid the console.error warnings).
const r = spawnSync('node', [INSTALL_JS, ...args], {
env: { ...process.env, HOME: home, GSD_TEST_MODE: '1' },
encoding: 'utf8',
timeout: 15000,
});
return { stdout: r.stdout || '', stderr: r.stderr || '', exit: r.status };
}
describe('Kimi variant disambiguation (#2505 Phase 5 / #2513)', () => {
let home;
before(() => { home = makeDisposableHome(); });
after(() => home.cleanup());
test('--kimi prints the Kimi CLI (Python) description', () => {
const r = runInstall(['--kimi', '--help'], home.dir);
const combined = r.stdout + r.stderr;
assert.match(combined, /Kimi CLI \(Python kimi-cli\).*named subagents.*~\/\.kimi\//);
});
test('--kimi-code prints the Kimi Code (Node CLI) description', () => {
const r = runInstall(['--kimi-code', '--help'], home.dir);
const combined = r.stdout + r.stderr;
assert.match(combined, /Kimi Code \(Node CLI\).*coder\/explore\/plan.*~\/\.kimi-code\//);
});
test('--kimi warns when only ~/.kimi-code/config.toml exists', () => {
const h = makeDisposableHome();
try {
fs.mkdirSync(path.join(h.dir, '.kimi-code'), { recursive: true });
fs.writeFileSync(path.join(h.dir, '.kimi-code', 'config.toml'), '# kimi-code');
const r = runInstall(['--kimi', '--help'], h.dir);
const combined = r.stdout + r.stderr;
assert.match(combined, /variant mismatch/i);
assert.match(combined, /Detected ~\/\.kimi-code\/config\.toml/);
assert.match(combined, /Re-run with --kimi-code/);
} finally {
h.cleanup();
}
});
test('--kimi-code warns when only ~/.kimi/config.toml exists', () => {
const h = makeDisposableHome();
try {
fs.mkdirSync(path.join(h.dir, '.kimi'), { recursive: true });
fs.writeFileSync(path.join(h.dir, '.kimi', 'config.toml'), '# kimi-cli');
const r = runInstall(['--kimi-code', '--help'], h.dir);
const combined = r.stdout + r.stderr;
assert.match(combined, /variant mismatch/i);
assert.match(combined, /Detected ~\/\.kimi\/config\.toml/);
assert.match(combined, /Re-run with --kimi/);
} finally {
h.cleanup();
}
});
test('no warning when neither config exists (fresh install)', () => {
const h = makeDisposableHome();
try {
const r = runInstall(['--kimi', '--help'], h.dir);
const combined = r.stdout + r.stderr;
assert.doesNotMatch(combined, /variant mismatch/i);
} finally {
h.cleanup();
}
});
});