feat(OpenCode TLS): 預設跳過 TLS 驗證 #24
+11
-1
@@ -1,6 +1,6 @@
|
|||||||
import { describe, it, beforeEach, afterEach } from 'node:test';
|
import { describe, it, beforeEach, afterEach } from 'node:test';
|
||||||
import assert from 'node:assert/strict';
|
import assert from 'node:assert/strict';
|
||||||
import { getLLMConfig } from './config.js';
|
import { getLLMConfig, shouldSkipOpenCodeTLSVerify } from './config.js';
|
||||||
|
|
||||||
const ENV_KEYS = [
|
const ENV_KEYS = [
|
||||||
'OPENAI_API_KEY', 'OPENAI_BASE_URL', 'OPENAI_MODEL',
|
'OPENAI_API_KEY', 'OPENAI_BASE_URL', 'OPENAI_MODEL',
|
||||||
@@ -10,6 +10,7 @@ const ENV_KEYS = [
|
|||||||
'AMAZONQ_API_KEY', 'AMAZONQ_BASE_URL', 'AMAZONQ_MODEL',
|
'AMAZONQ_API_KEY', 'AMAZONQ_BASE_URL', 'AMAZONQ_MODEL',
|
||||||
'OPENCODE_BASE_URL', 'OPENCODE_MODEL', 'OPENCODE_PROVIDER',
|
'OPENCODE_BASE_URL', 'OPENCODE_MODEL', 'OPENCODE_PROVIDER',
|
||||||
'OPENCODE_SERVER_USERNAME', 'OPENCODE_SERVER_PASSWORD',
|
'OPENCODE_SERVER_USERNAME', 'OPENCODE_SERVER_PASSWORD',
|
||||||
|
'OPENCODE_SKIP_TLS_VERIFY',
|
||||||
];
|
];
|
||||||
|
|
||||||
let saved = {};
|
let saved = {};
|
||||||
@@ -104,6 +105,15 @@ describe('getLLMConfig', () => {
|
|||||||
assert.equal(cfg.model, 'google/gemini-2.5-pro');
|
assert.equal(cfg.model, 'google/gemini-2.5-pro');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('skips OpenCode TLS verification by default', () => {
|
||||||
|
assert.equal(shouldSkipOpenCodeTLSVerify(), true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('allows explicitly enabling OpenCode TLS verification', () => {
|
||||||
|
process.env.OPENCODE_SKIP_TLS_VERIFY = 'false';
|
||||||
|
assert.equal(shouldSkipOpenCodeTLSVerify(), false);
|
||||||
|
});
|
||||||
|
|
||||||
it('openai takes priority over gemini when both set', () => {
|
it('openai takes priority over gemini when both set', () => {
|
||||||
process.env.OPENAI_API_KEY = 'sk-test';
|
process.env.OPENAI_API_KEY = 'sk-test';
|
||||||
process.env.GEMINI_API_KEY = 'gemini-key';
|
process.env.GEMINI_API_KEY = 'gemini-key';
|
||||||
|
|||||||
+14
-2
@@ -164,9 +164,8 @@ describe('chat - key rotation', async () => {
|
|||||||
assert.equal(headers[0]['Authorization'], `Basic ${Buffer.from('opencode:secret').toString('base64')}`);
|
assert.equal(headers[0]['Authorization'], `Basic ${Buffer.from('opencode:secret').toString('base64')}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('passes an insecure https agent to OpenCode when TLS verification is disabled', async () => {
|
it('passes an insecure https agent to OpenCode by default', async () => {
|
||||||
process.env.OPENCODE_BASE_URL = 'https://opencode.local:4096';
|
process.env.OPENCODE_BASE_URL = 'https://opencode.local:4096';
|
||||||
process.env.OPENCODE_SKIP_TLS_VERIFY = 'true';
|
|
||||||
const agents = [];
|
const agents = [];
|
||||||
mock.method(axios, 'post', async (url, _payload, opts) => {
|
mock.method(axios, 'post', async (url, _payload, opts) => {
|
||||||
agents.push(opts.httpsAgent);
|
agents.push(opts.httpsAgent);
|
||||||
@@ -179,6 +178,19 @@ describe('chat - key rotation', async () => {
|
|||||||
assert.equal(agents[1].options.rejectUnauthorized, false);
|
assert.equal(agents[1].options.rejectUnauthorized, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('does not pass an insecure https agent to OpenCode when TLS verification is enabled', async () => {
|
||||||
|
process.env.OPENCODE_BASE_URL = 'https://opencode.local:4096';
|
||||||
|
process.env.OPENCODE_SKIP_TLS_VERIFY = 'false';
|
||||||
|
const agents = [];
|
||||||
|
mock.method(axios, 'post', async (url, _payload, opts) => {
|
||||||
|
agents.push(opts.httpsAgent);
|
||||||
|
if (url.endsWith('/session')) return { data: { id: 'ses_test' } };
|
||||||
|
return { data: { parts: [{ type: 'text', text: 'ok' }] } };
|
||||||
|
});
|
||||||
|
await chat('sys', 'user');
|
||||||
|
assert.deepEqual(agents, [undefined, undefined]);
|
||||||
|
});
|
||||||
|
|
||||||
it('uses Responses API for openai GPT-5.5', async () => {
|
it('uses Responses API for openai GPT-5.5', async () => {
|
||||||
process.env.OPENAI_API_KEY = 'sk-test';
|
process.env.OPENAI_API_KEY = 'sk-test';
|
||||||
process.env.OPENAI_MODEL = 'GPT-5.5';
|
process.env.OPENAI_MODEL = 'GPT-5.5';
|
||||||
|
|||||||
+16
-2
@@ -183,10 +183,9 @@ describe('verifyLLM', () => {
|
|||||||
assert.deepEqual(urls, ['http://opencode.local:4096/global/health', 'http://opencode.local:4096/config/providers']);
|
assert.deepEqual(urls, ['http://opencode.local:4096/global/health', 'http://opencode.local:4096/config/providers']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('passes an insecure https agent for opencode when TLS verification is disabled', async () => {
|
it('passes an insecure https agent for opencode by default', async () => {
|
||||||
clearLLMEnv();
|
clearLLMEnv();
|
||||||
process.env.OPENCODE_BASE_URL = 'https://opencode.local:4096';
|
process.env.OPENCODE_BASE_URL = 'https://opencode.local:4096';
|
||||||
process.env.OPENCODE_SKIP_TLS_VERIFY = 'true';
|
|
||||||
const agents = [];
|
const agents = [];
|
||||||
mock.method(axios, 'get', async (url, opts) => {
|
mock.method(axios, 'get', async (url, opts) => {
|
||||||
agents.push(opts.httpsAgent);
|
agents.push(opts.httpsAgent);
|
||||||
@@ -200,6 +199,21 @@ describe('verifyLLM', () => {
|
|||||||
assert.equal(agents[1].options.rejectUnauthorized, false);
|
assert.equal(agents[1].options.rejectUnauthorized, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('does not pass an insecure https agent for opencode when TLS verification is enabled', async () => {
|
||||||
|
clearLLMEnv();
|
||||||
|
process.env.OPENCODE_BASE_URL = 'https://opencode.local:4096';
|
||||||
|
process.env.OPENCODE_SKIP_TLS_VERIFY = 'false';
|
||||||
|
const agents = [];
|
||||||
|
mock.method(axios, 'get', async (url, opts) => {
|
||||||
|
agents.push(opts.httpsAgent);
|
||||||
|
if (url.endsWith('/global/health')) return { data: { healthy: true } };
|
||||||
|
return { data: { providers: [{ id: 'google', models: { 'gemini-2.5-flash': { id: 'gemini-2.5-flash' } } }] } };
|
||||||
|
});
|
||||||
|
const result = await verifyLLM();
|
||||||
|
assert.equal(result.ok, true);
|
||||||
|
assert.deepEqual(agents, [undefined, undefined]);
|
||||||
|
});
|
||||||
|
|
||||||
it('checks openai GPT-5.5 with Responses API', async () => {
|
it('checks openai GPT-5.5 with Responses API', async () => {
|
||||||
clearLLMEnv();
|
clearLLMEnv();
|
||||||
process.env.OPENAI_API_KEY = 'sk-test';
|
process.env.OPENAI_API_KEY = 'sk-test';
|
||||||
|
|||||||
Reference in New Issue
Block a user