test(roles 與 comments): 新增腳色載入器測試與嚴重問題 comment 的邊界/多筆案例

This commit is contained in:
Jeffery
2026-06-16 16:41:40 +08:00
parent 1602853c99
commit d8b681e63b
2 changed files with 116 additions and 0 deletions
+33
View File
@@ -150,4 +150,37 @@ describe('postNewCriticalComments', () => {
assert.equal(inlineCalls.length, 0);
assert.equal(issueCalls.length, 0);
});
it('posts nothing when given an empty findings array', async () => {
const inlineCalls = [];
const issueCalls = [];
await postNewCriticalComments([], {
postInline: async (args) => { inlineCalls.push(args); },
postIssue: async (body) => { issueCalls.push(body); },
});
assert.equal(inlineCalls.length, 0);
assert.equal(issueCalls.length, 0);
});
it('handles multiple criticals, posting inline where possible and degrading the rest', async () => {
const inlineCalls = [];
const issueCalls = [];
const findings = [
{ ...critical, location: 'app/a.js:10', suggestion: 'A' }, // 有行號、inline 成功
{ ...critical, location: 'app/b.js', suggestion: 'B' }, // 無行號 → 降級為一般 comment
{ ...critical, location: 'app/c.js:20', suggestion: 'C' }, // inline 拋錯 → 降級為一般 comment
];
await postNewCriticalComments(findings, {
postInline: async (args) => {
if (args.path === 'app/c.js') throw new Error('line not in diff');
inlineCalls.push(args);
},
postIssue: async (body) => { issueCalls.push(body); },
});
assert.equal(inlineCalls.length, 1);
assert.equal(inlineCalls[0].path, 'app/a.js');
assert.equal(inlineCalls[0].line, 10);
assert.equal(issueCalls.length, 2);
assert.ok(issueCalls.every(b => /嚴重問題/.test(b)));
});
});