feat: enhance exclusions.json with additional suggestions and add chatJSON tests for JSON response handling
This commit is contained in:
@@ -126,3 +126,28 @@ describe('chat - key rotation', async () => {
|
||||
assert.equal(capturedHeaders['anthropic-version'], '2023-06-01');
|
||||
});
|
||||
});
|
||||
|
||||
describe('chatJSON', async () => {
|
||||
const { chatJSON } = await import('./llm.js');
|
||||
|
||||
it('parses plain JSON response', async () => {
|
||||
process.env.OPENAI_API_KEY = 'sk-test';
|
||||
mockAxiosPost([makeOkResponse('[{"level":"critical"}]')]);
|
||||
const result = await chatJSON('sys', 'user');
|
||||
assert.deepEqual(result, [{ level: 'critical' }]);
|
||||
});
|
||||
|
||||
it('strips markdown code block before parsing', async () => {
|
||||
process.env.OPENAI_API_KEY = 'sk-test';
|
||||
mockAxiosPost([makeOkResponse('```json\n[{"level":"info"}]\n```')]);
|
||||
const result = await chatJSON('sys', 'user');
|
||||
assert.deepEqual(result, [{ level: 'info' }]);
|
||||
});
|
||||
|
||||
it('returns [] when JSON is invalid', async () => {
|
||||
process.env.OPENAI_API_KEY = 'sk-test';
|
||||
mockAxiosPost([makeOkResponse('not json')]);
|
||||
const result = await chatJSON('sys', 'user');
|
||||
assert.deepEqual(result, []);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user