This commit is contained in:
+23
-1
@@ -4,7 +4,7 @@ import axios from 'axios';
|
||||
import { extractBalancedJSON, extractJSONText } from '../llm.js';
|
||||
|
||||
const ENV_KEYS = [
|
||||
'OPENCODE_BASE_URL', 'OPENCODE_MODEL', 'OPENCODE_PROVIDER',
|
||||
'OPENCODE_BASE_URL', 'OPENCODE_MODEL', 'OPENCODE_PROVIDER', 'OPENCODE_RETRY_ATTEMPTS',
|
||||
];
|
||||
|
||||
let saved = {};
|
||||
@@ -87,6 +87,7 @@ describe('chat - OpenCode', async () => {
|
||||
|
||||
it('throws an error when OpenCode fails instead of exiting the process', async () => {
|
||||
process.env.OPENCODE_BASE_URL = 'http://opencode.local:4096';
|
||||
process.env.OPENCODE_RETRY_ATTEMPTS = '1';
|
||||
mock.method(axios, 'post', async () => {
|
||||
const err = new Error('Request failed with status code 500');
|
||||
err.response = { status: 500, data: { error: 'provider overloaded' } };
|
||||
@@ -98,6 +99,27 @@ describe('chat - OpenCode', async () => {
|
||||
|
||||
assert.equal(exitMock.mock.calls.length, 0);
|
||||
});
|
||||
|
||||
it('retries transient OpenCode failures before returning content', async () => {
|
||||
process.env.OPENCODE_BASE_URL = 'http://opencode.local:4096';
|
||||
process.env.OPENCODE_RETRY_ATTEMPTS = '2';
|
||||
let messageAttempts = 0;
|
||||
mock.method(axios, 'post', async (url) => {
|
||||
if (url.endsWith('/session')) return { data: { id: 'ses_test' } };
|
||||
messageAttempts += 1;
|
||||
if (messageAttempts === 1) {
|
||||
const err = new Error('Request failed with status code 500');
|
||||
err.response = { status: 500, data: { error: 'temporary failure' } };
|
||||
throw err;
|
||||
}
|
||||
return { data: { parts: [{ type: 'text', text: 'ok after retry' }] } };
|
||||
});
|
||||
|
||||
const result = await chat('sys', 'user');
|
||||
|
||||
assert.equal(result, 'ok after retry');
|
||||
assert.equal(messageAttempts, 2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('chatJSON', async () => {
|
||||
|
||||
Reference in New Issue
Block a user