Files
msd-core/tests/kimi-variant-disambiguation.test.cjs
Tom Boucher 4fc89497d0 fix(#2505): set USERPROFILE in kimi-variant test env + add issue refs on allow-test-rule exemptions (#2545)
The kimi-variant-disambiguation test set only HOME in the spawnSync env,
but os.homedir() on Windows resolves USERPROFILE — so the installer never
found the probe config files and the 'variant mismatch' warning never
fired. Every other installer test in the repo sets both HOME and
USERPROFILE (agent-skills, augment-upgrades, antigravity-upgrades, etc.);
this one was newly written for Phase 5 and missed the pattern.

Also: both new test files carried allow-test-rule exemptions without the
'see #NNN' issue reference required by ADR-456, failing lint-allow-test-rule-refs.
2026-07-22 20:58:29 -04:00

95 lines
3.5 KiB
JavaScript

// allow-test-rule: behavioral-subprocess-test — see #2505 — 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, USERPROFILE: 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();
}
});
});