Files
msd-core/tests/kimi-variant-disambiguation.test.cjs
Tom Boucher 557a0b2876 test(#4516): migrate per-runtime install/upgrade adapters to named timeout constants (#4582)
Batch 5 of the ad hoc timeout literal migration (epic #4445). Replaces
every bare numeric timeout/timeoutMs object-literal property across
tests/augment-upgrades.test.cjs, tests/shared-hooks-dir-resolution.test.cjs,
tests/antigravity-upgrades.test.cjs, tests/cursor-hooks.test.cjs,
tests/cursor-hook-workspace-roots.test.cjs, tests/gemini-runtime-removed.test.cjs,
tests/kilo-upgrades.test.cjs, tests/kimi-upgrades.test.cjs,
tests/kimi-variant-disambiguation.test.cjs, tests/opencode-plugin-adapter.test.cjs,
tests/windsurf-hooks-bridge.test.cjs, tests/effort-sync-installed-runtime.test.cjs,
and tests/hooks-commonjs-marker.test.cjs with a named constant, per
eslint-rules/no-adhoc-timeout-literal.cjs. Removes these 13 files from the
rule's allowlist.

Adds one new shared constant to tests/helpers/timeouts.cjs for spawning a
single already-staged hook script directly (a heavier class than the
existing quick-spawn norm), shared across three files in this batch. One
new file-local constant covers a property-test driver process distinct
from any existing class. Every other site reuses an existing shared norm.
No src/bin file touched, no numeric timeout value changed anywhere.

Co-authored-by: sim <sim@local>
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-10 14:11:26 -04:00

96 lines
3.6 KiB
JavaScript

// Phase 5 kimi-variant disambiguation is verified via install.js subprocess
// output capture (regex on printed notices), since disambiguateKimiVariant
// is inline in bin/install.js (not exported) and emits no structured/JSON
// output. Exporting the function and/or adding a --json notice mode is a
// production change out of scope here. Tracked under #3090.
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 { PROBE_TIMEOUT_MS } = require('./helpers/timeouts.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: PROBE_TIMEOUT_MS,
});
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();
}
});
});