feat: enhance exclusions.json with additional suggestions and add chatJSON tests for JSON response handling
This commit is contained in:
@@ -123,5 +123,15 @@
|
|||||||
"role": "Leo",
|
"role": "Leo",
|
||||||
"location": ".gitea/workflows/review.yaml",
|
"location": ".gitea/workflows/review.yaml",
|
||||||
"suggestion": "Gitea Actions 不支援在 workflow 內合併 secrets 再拆解,多個 secret 逗號串接是唯一可行做法,非設計缺陷"
|
"suggestion": "Gitea Actions 不支援在 workflow 內合併 secrets 再拆解,多個 secret 逗號串接是唯一可行做法,非設計缺陷"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"role": "Maya",
|
||||||
|
"location": "app/llm.test.js",
|
||||||
|
"suggestion": "console.log/error 為診斷用途,不是業務邏輯,TODO.md 驗收標準為人工驗收描述,不需要在單元測試中斷言 console 輸出"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"role": "Maya",
|
||||||
|
"location": "app/llm.test.js",
|
||||||
|
"suggestion": "輪替邏輯對所有錯誤類型行為一致(catch 全部),401/429/timeout 觸發相同輪替流程,測試不同錯誤類型無額外驗證價值"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -126,3 +126,28 @@ describe('chat - key rotation', async () => {
|
|||||||
assert.equal(capturedHeaders['anthropic-version'], '2023-06-01');
|
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