test(ai-review): 補 comment 只標註新問題與對話收斂 duplicate 分支測試

This commit is contained in:
Jeffery
2026-06-23 13:51:36 +08:00
parent fb2624a215
commit cadfaff31d
2 changed files with 28 additions and 9 deletions
+11 -9
View File
@@ -244,7 +244,7 @@ describe('postFindingsReview', () => {
assert.equal(reviewSeverityLabel({ body: '**嚴重等級**:高風險' }), undefined);
});
it('posts one review with statistics and sorted line comments', async () => {
it('posts inline comments only for new findings, not old ones', async () => {
const reviewCalls = [];
const findings = [
{ level: 'info', role: 'Maya', location: 'app/c.js:30', suggestion: 'I', is_new: true },
@@ -262,23 +262,23 @@ describe('postFindingsReview', () => {
assert.match(reviewCalls[0].body, /\| 類型 \| 🔴 嚴重 \| 🟡 警告 \| 🔵 建議 \|/);
assert.match(reviewCalls[0].body, /\| 舊問題 \| 1 筆 \| 0 筆 \| 0 筆 \|/);
assert.match(reviewCalls[0].body, /\| 新問題 \| 0 筆 \| 1 筆 \| 1 筆 \|/);
// 舊問題 app/a.jsis_new:false)不應被行內標註,僅新問題依嚴重等級排序後標註
assert.ok(!reviewCalls[0].comments.some(c => c.path === 'app/a.js'));
assert.deepEqual(
reviewCalls[0].comments.map(c => c.path),
['app/a.js', 'app/b.js', 'app/c.js'],
['app/b.js', 'app/c.js'],
);
assert.deepEqual(
reviewCalls[0].comments.map(reviewSeverityLabel),
REVIEW_SEVERITY_LABELS,
['🟡 警告', '🔵 建議'],
);
assert.deepEqual(
reviewCalls[0].comments.map(c => c.new_position),
[10, 20, 30],
[20, 30],
);
assert.match(reviewCalls[0].comments[0].body, /嚴重等級/);
assert.match(reviewCalls[0].comments[0].body, /.*Rex/s);
assert.match(reviewCalls[0].comments[0].body, /.*/s);
assert.doesNotMatch(reviewCalls[0].comments[0].body, /.*app\/a\.js:10/s);
assert.match(reviewCalls[0].comments[0].body, /.*C/s);
assert.match(reviewCalls[0].comments[0].body, /.*Leo/s);
assert.match(reviewCalls[0].comments[0].body, /.*W/s);
});
it('appends the usage section to the review body when provided', async () => {
@@ -318,7 +318,9 @@ describe('postFindingsReview', () => {
assert.equal(reviewCalls.length, 1);
assert.match(reviewCalls[0].body, /\| 舊問題 \| 1 筆 \| 0 筆 \| 0 筆 \|/);
assert.match(reviewCalls[0].body, /\| 新問題 \| 0 筆 \| 1 筆 \| 1 筆 \|/);
assert.equal(reviewCalls[0].comments.length, 3);
// 統計含新舊(舊問題仍計入本文),但行內 comment 只給新問題(舊 critical 不標註)
assert.equal(reviewCalls[0].comments.length, 2);
assert.ok(!reviewCalls[0].comments.some(c => c.path === 'app/a.js'));
});
it('only adds comments for findings with parseable file and line', async () => {