test(review 與 OpenCode TLS): 補齊 Pull Review 與 TLS 設定覆蓋
This commit is contained in:
+50
-1
@@ -3,7 +3,7 @@ import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
import { saveFindings, parseLocation, postNewCriticalComments } from './comments.js';
|
||||
import { saveFindings, parseLocation, buildReviewPayload, postFindingsReview, postNewCriticalComments } from './comments.js';
|
||||
import { FINDINGS_PATH } from './config.js';
|
||||
|
||||
describe('saveFindings', () => {
|
||||
@@ -185,3 +185,52 @@ describe('postNewCriticalComments', () => {
|
||||
assert.ok(issueCalls.every(b => criticalCommentPattern.test(b)));
|
||||
});
|
||||
});
|
||||
|
||||
describe('review payload', () => {
|
||||
const intro = '## Reviewers\n\nLeo / Maya';
|
||||
const findings = [
|
||||
{ level: 'warning', role: 'Leo', location: 'app/a.js:1', suggestion: '改善命名', is_new: true },
|
||||
{ level: 'critical', role: 'Rex', location: 'app/b.js:5', suggestion: '修正權限檢查', is_new: true },
|
||||
{ level: 'critical', role: 'Maya', location: 'app/c.js', suggestion: '補上交易保護', is_new: true },
|
||||
{ level: 'info', role: 'Bard', location: 'app/d.js:9', suggestion: '補註解', is_new: false },
|
||||
];
|
||||
|
||||
it('builds one review body with role intro and inline comments for every located finding', () => {
|
||||
const payload = buildReviewPayload(intro, findings);
|
||||
assert.match(payload.body, /Reviewers/);
|
||||
assert.doesNotMatch(payload.body, /改善命名/);
|
||||
assert.match(payload.body, /無法行內標註的新嚴重問題/);
|
||||
assert.equal(payload.comments.length, 3);
|
||||
assert.deepEqual(payload.comments.map(c => c.path), ['app/a.js', 'app/b.js', 'app/d.js']);
|
||||
assert.deepEqual(payload.comments.map(c => c.new_position), [1, 5, 9]);
|
||||
assert.match(payload.comments[0].body, /新發現問題/);
|
||||
assert.match(payload.comments[1].body, /新嚴重問題/);
|
||||
assert.match(payload.comments[2].body, /舊有未解決問題/);
|
||||
});
|
||||
|
||||
it('posts findings as a single pull review', async () => {
|
||||
const calls = [];
|
||||
await postFindingsReview(intro, findings, {
|
||||
postReview: async (payload) => { calls.push(payload); },
|
||||
});
|
||||
assert.equal(calls.length, 1);
|
||||
assert.match(calls[0].body, /Reviewers/);
|
||||
assert.equal(calls[0].comments.length, 3);
|
||||
});
|
||||
|
||||
it('falls back to one review body when inline comments are rejected', async () => {
|
||||
const calls = [];
|
||||
await postFindingsReview(intro, findings, {
|
||||
postReview: async (payload) => {
|
||||
calls.push(payload);
|
||||
if (calls.length === 1) throw new Error('line not in diff');
|
||||
},
|
||||
});
|
||||
assert.equal(calls.length, 2);
|
||||
assert.equal(calls[1].comments.length, 0);
|
||||
assert.match(calls[1].body, /改善命名/);
|
||||
assert.match(calls[1].body, /修正權限檢查/);
|
||||
assert.match(calls[1].body, /補上交易保護/);
|
||||
assert.match(calls[1].body, /補註解/);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user