Compare commits
5 Commits
v0.2.7
...
v0.2.9-beta.1
| Author | SHA1 | Date | |
|---|---|---|---|
| 6036ce45c4 | |||
| 648334d153 | |||
| 9d759464c2 | |||
| 12d7403a0e | |||
| babe599977 |
@@ -1,9 +1 @@
|
|||||||
[
|
[]
|
||||||
{
|
|
||||||
"level": "warning",
|
|
||||||
"role": "Mage",
|
|
||||||
"location": "app/preflight.js:23",
|
|
||||||
"suggestion": "在 `app/llm.js` 與 `app/preflight.js` 中,`opencodeAxiosOptions` 函數的邏輯存在重複。雖然 `timeout` 參數在兩處有所不同,但處理 `httpsAgent` 的核心邏輯是相同的。建議將 `httpsAgent` 的建立邏輯抽象為一個共用函數或在 `config.js` 中定義,以避免未來修改時造成不一致,並提高程式碼的可維護性。\n\n例如,可以將 `httpsAgent` 的邏輯移至 `config.js`:\n```javascript\n// app/config.js\nexport function getOpenCodeHttpsAgent() {\n return shouldSkipOpenCodeTLSVerify() ? new https.Agent({ rejectUnauthorized: false }) : undefined;\n}\n\n// app/llm.js\nimport { getOpenCodeHttpsAgent } from './config.js';\nfunction opencodeAxiosOptions(headers) {\n return {\n headers,\n httpsAgent: getOpenCodeHttpsAgent(),\n };\n}\n\n// app/preflight.js\nimport { getOpenCodeHttpsAgent } from './config.js';\nconst opencodeAxiosOptions = (headers) => ({\n headers,\n timeout: 30000,\n httpsAgent: getOpenCodeHttpsAgent(),\n});\n```",
|
|
||||||
"is_new": true
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|||||||
@@ -224,8 +224,8 @@ jobs:
|
|||||||
OPENCODE_BASE_URL: http://192.168.3.124:4096
|
OPENCODE_BASE_URL: http://192.168.3.124:4096
|
||||||
OPENCODE_PROVIDER: google
|
OPENCODE_PROVIDER: google
|
||||||
OPENCODE_MODEL: gemini-2.5-flash
|
OPENCODE_MODEL: gemini-2.5-flash
|
||||||
# 若 OpenCode server 使用自簽憑證,才需要提供:
|
# 預設會跳過 OpenCode TLS 驗證;若要強制驗證憑證才需要設定:
|
||||||
# OPENCODE_SKIP_TLS_VERIFY: true
|
# OPENCODE_SKIP_TLS_VERIFY: false
|
||||||
# 若 OpenCode server 有設定 OPENCODE_SERVER_PASSWORD,才需要提供:
|
# 若 OpenCode server 有設定 OPENCODE_SERVER_PASSWORD,才需要提供:
|
||||||
# OPENCODE_SERVER_USERNAME: opencode
|
# OPENCODE_SERVER_USERNAME: opencode
|
||||||
# OPENCODE_SERVER_PASSWORD: ${{ secrets.OPENCODE_SERVER_PASSWORD }}
|
# OPENCODE_SERVER_PASSWORD: ${{ secrets.OPENCODE_SERVER_PASSWORD }}
|
||||||
|
|||||||
+2
-2
@@ -96,9 +96,9 @@ inputs:
|
|||||||
description: 'OpenCode server Basic Auth password'
|
description: 'OpenCode server Basic Auth password'
|
||||||
required: false
|
required: false
|
||||||
OPENCODE_SKIP_TLS_VERIFY:
|
OPENCODE_SKIP_TLS_VERIFY:
|
||||||
description: '跳過 OpenCode server SSL/TLS 憑證驗證(自簽憑證時使用)'
|
description: '跳過 OpenCode server SSL/TLS 憑證驗證'
|
||||||
required: false
|
required: false
|
||||||
default: 'false'
|
default: 'true'
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: 'docker'
|
using: 'docker'
|
||||||
|
|||||||
+7
-1
@@ -1,3 +1,5 @@
|
|||||||
|
import https from 'https';
|
||||||
|
|
||||||
export const GITEA_TOKEN = process.env.GITEA_TOKEN || '';
|
export const GITEA_TOKEN = process.env.GITEA_TOKEN || '';
|
||||||
export const GITEA_COMMENT_TOKEN = process.env.GITEA_COMMENT_TOKEN || '';
|
export const GITEA_COMMENT_TOKEN = process.env.GITEA_COMMENT_TOKEN || '';
|
||||||
export const GITEA_SERVER_URL = process.env.GITEA_SERVER_URL || 'https://gitea.com';
|
export const GITEA_SERVER_URL = process.env.GITEA_SERVER_URL || 'https://gitea.com';
|
||||||
@@ -12,7 +14,11 @@ export const FINDINGS_PATH = '.gitea/ai-review/findings.json';
|
|||||||
export const EXCLUSIONS_PATH = '.gitea/ai-review/exclusions.json';
|
export const EXCLUSIONS_PATH = '.gitea/ai-review/exclusions.json';
|
||||||
|
|
||||||
export function shouldSkipOpenCodeTLSVerify() {
|
export function shouldSkipOpenCodeTLSVerify() {
|
||||||
return process.env.OPENCODE_SKIP_TLS_VERIFY === 'true';
|
return process.env.OPENCODE_SKIP_TLS_VERIFY !== 'false';
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getOpenCodeHttpsAgent() {
|
||||||
|
return shouldSkipOpenCodeTLSVerify() ? new https.Agent({ rejectUnauthorized: false }) : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 將逗號分隔的 API key 字串拆成陣列 */
|
/** 將逗號分隔的 API key 字串拆成陣列 */
|
||||||
|
|||||||
+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';
|
||||||
|
|||||||
+2
-3
@@ -1,6 +1,5 @@
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import https from 'https';
|
import { getLLMConfig, getOpenCodeHttpsAgent } from './config.js';
|
||||||
import { getLLMConfig, shouldSkipOpenCodeTLSVerify } from './config.js';
|
|
||||||
import { line, error } from './log.js';
|
import { line, error } from './log.js';
|
||||||
|
|
||||||
function isOpenAIGpt55(provider, model) {
|
function isOpenAIGpt55(provider, model) {
|
||||||
@@ -50,7 +49,7 @@ function applyOpenCodeAuth(headers) {
|
|||||||
function opencodeAxiosOptions(headers) {
|
function opencodeAxiosOptions(headers) {
|
||||||
return {
|
return {
|
||||||
headers,
|
headers,
|
||||||
httpsAgent: shouldSkipOpenCodeTLSVerify() ? new https.Agent({ rejectUnauthorized: false }) : undefined,
|
httpsAgent: getOpenCodeHttpsAgent(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+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';
|
||||||
|
|||||||
+2
-2
@@ -7,8 +7,8 @@ import {
|
|||||||
GITEA_REPOSITORY,
|
GITEA_REPOSITORY,
|
||||||
GITEA_SKIP_TLS_VERIFY,
|
GITEA_SKIP_TLS_VERIFY,
|
||||||
PR_NUMBER,
|
PR_NUMBER,
|
||||||
|
getOpenCodeHttpsAgent,
|
||||||
getLLMConfig,
|
getLLMConfig,
|
||||||
shouldSkipOpenCodeTLSVerify,
|
|
||||||
} from './config.js';
|
} from './config.js';
|
||||||
import { verifyRemoteAccess } from './git.js';
|
import { verifyRemoteAccess } from './git.js';
|
||||||
import { step, line, ok, error } from './log.js';
|
import { step, line, ok, error } from './log.js';
|
||||||
@@ -30,7 +30,7 @@ const applyOpenCodeAuth = (headers) => {
|
|||||||
const opencodeAxiosOptions = (headers) => ({
|
const opencodeAxiosOptions = (headers) => ({
|
||||||
headers,
|
headers,
|
||||||
timeout: 30000,
|
timeout: 30000,
|
||||||
httpsAgent: shouldSkipOpenCodeTLSVerify() ? new https.Agent({ rejectUnauthorized: false }) : undefined,
|
httpsAgent: getOpenCodeHttpsAgent(),
|
||||||
});
|
});
|
||||||
|
|
||||||
function giteaErr(e) {
|
function giteaErr(e) {
|
||||||
|
|||||||
+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