test(test 目錄): 將 12 個單元測試移至 app/test 並更新 npm test 指令

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jeffery
2026-06-26 14:15:55 +08:00
co-authored by Claude Opus 4.8
parent 51fd223b48
commit 303104bb20
13 changed files with 16 additions and 16 deletions
+51
View File
@@ -0,0 +1,51 @@
import { describe, it, beforeEach, afterEach } from 'node:test';
import assert from 'node:assert/strict';
import { getLLMConfig, getOpenCodeHttpsAgent } from '../config.js';
const ENV_KEYS = [
'OPENCODE_BASE_URL', 'OPENCODE_MODEL', 'OPENCODE_PROVIDER',
];
let saved = {};
beforeEach(() => {
saved = {};
for (const k of ENV_KEYS) { saved[k] = process.env[k]; delete process.env[k]; }
});
afterEach(() => {
for (const k of ENV_KEYS) {
if (saved[k] === undefined) delete process.env[k];
else process.env[k] = saved[k];
}
});
describe('getLLMConfig', () => {
it('returns null provider when no env vars set', () => {
const cfg = getLLMConfig();
assert.equal(cfg.provider, null);
assert.deepEqual(cfg.apiKeys, []);
});
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 opencode server with custom model', () => {
process.env.OPENCODE_BASE_URL = 'http://opencode.local:4096';
process.env.OPENCODE_MODEL = 'google/gemini-2.5-pro';
const cfg = getLLMConfig();
assert.equal(cfg.provider, 'opencode');
assert.equal(cfg.baseURL, 'http://opencode.local:4096');
assert.equal(cfg.model, 'google/gemini-2.5-pro');
});
it('uses an insecure HTTPS agent for OpenCode', () => {
const agent = getOpenCodeHttpsAgent();
assert.equal(agent.options.rejectUnauthorized, false);
});
});