fix(llm): 強化 OpenCode JSON 回應解析
This commit is contained in:
@@ -208,6 +208,20 @@ describe('chatJSON', async () => {
|
||||
assert.deepEqual(result, [{ level: 'info' }]);
|
||||
});
|
||||
|
||||
it('extracts JSON array from surrounding prose', async () => {
|
||||
process.env.OPENAI_API_KEY = 'sk-test';
|
||||
mockAxiosPost([makeOkResponse('**Reviewing findings**\n\n[{"level":"warning","suggestion":"x"}]\n\nDone.')]);
|
||||
const result = await chatJSON('sys', 'user');
|
||||
assert.deepEqual(result, [{ level: 'warning', suggestion: 'x' }]);
|
||||
});
|
||||
|
||||
it('extracts JSON object from surrounding prose', async () => {
|
||||
process.env.OPENAI_API_KEY = 'sk-test';
|
||||
mockAxiosPost([makeOkResponse('**Begin Combine**\n{"merged_text":"repo block\\n\\nsource block"}')]);
|
||||
const result = await chatJSON('sys', 'user');
|
||||
assert.deepEqual(result, { merged_text: 'repo block\n\nsource block' });
|
||||
});
|
||||
|
||||
it('returns [] when JSON is invalid', async () => {
|
||||
process.env.OPENAI_API_KEY = 'sk-test';
|
||||
mockAxiosPost([makeOkResponse('not json')]);
|
||||
|
||||
Reference in New Issue
Block a user