test(ai-code-review): 更新 CLI 呼叫與前置驗證測試

This commit is contained in:
2026-06-27 13:30:45 +00:00
parent 08a72a8c7f
commit 4fcb240208
3 changed files with 115 additions and 167 deletions
+22 -13
View File
@@ -3,7 +3,7 @@ import assert from 'node:assert/strict';
import { getLLMConfig, getOpenCodeHttpsAgent } from '../config.js';
const ENV_KEYS = [
'OPENCODE_BASE_URL', 'OPENCODE_MODEL', 'OPENCODE_PROVIDER',
'AI_ASSISTANT_CLI', 'MODEL', 'OPENCODE_MODEL',
];
let saved = {};
@@ -20,26 +20,35 @@ afterEach(() => {
describe('getLLMConfig', () => {
it('returns null provider when no env vars set', () => {
const cfg = getLLMConfig();
const cfg = getLLMConfig({ commandExistsFn: () => false });
assert.equal(cfg.provider, null);
assert.deepEqual(cfg.apiKeys, []);
assert.equal(cfg.command, null);
});
it('detects opencode server with defaults', () => {
process.env.OPENCODE_BASE_URL = 'http://opencode.local:4096';
const cfg = getLLMConfig();
assert.equal(cfg.provider, 'opencode');
assert.deepEqual(cfg.apiKeys, ['opencode']);
assert.equal(cfg.baseURL, 'http://opencode.local:4096');
assert.equal(cfg.model, 'gemini-2.5-flash');
it('detects the first installed assistant CLI with defaults', () => {
const cfg = getLLMConfig({ commandExistsFn: command => command === 'claude' });
assert.equal(cfg.provider, 'claude');
assert.deepEqual(cfg.apiKeys, ['claude']);
assert.equal(cfg.baseURL, null);
assert.equal(cfg.command, 'claude');
assert.equal(cfg.model, 'sonnet');
});
it('detects opencode server with custom model', () => {
process.env.OPENCODE_BASE_URL = 'http://opencode.local:4096';
it('uses MODEL for the selected assistant CLI', () => {
process.env.MODEL = 'gpt-5-mini';
const cfg = getLLMConfig({ commandExistsFn: command => command === 'codex' });
assert.equal(cfg.provider, 'codex');
assert.equal(cfg.command, 'codex');
assert.equal(cfg.model, 'gpt-5-mini');
});
it('can force a CLI with AI_ASSISTANT_CLI', () => {
process.env.AI_ASSISTANT_CLI = 'opencode';
process.env.OPENCODE_MODEL = 'google/gemini-2.5-pro';
const cfg = getLLMConfig();
const cfg = getLLMConfig({ commandExistsFn: command => command === 'codex' || command === 'opencode' });
assert.equal(cfg.provider, 'opencode');
assert.equal(cfg.baseURL, 'http://opencode.local:4096');
assert.equal(cfg.command, 'opencode');
assert.equal(cfg.model, 'google/gemini-2.5-pro');
});