test(comments review): 抽出嚴重等級解析斷言

This commit is contained in:
2026-06-22 16:32:23 +00:00
parent bcd451d13e
commit e3890787ff
+19 -2
View File
@@ -6,6 +6,13 @@ import path from 'node:path';
import { saveFindings, parseLocation, postNewCriticalComments, postFindingsReview } from './comments.js';
import { FINDINGS_PATH } from './config.js';
const REVIEW_SEVERITY_PATTERN = /\*\*嚴重等級\*\*(🔴 嚴重|🟡 警告|🔵 建議)(?:\n|$)/;
const REVIEW_SEVERITY_LABELS = ['🔴 嚴重', '🟡 警告', '🔵 建議'];
function reviewSeverityLabel(comment) {
return comment.body.match(REVIEW_SEVERITY_PATTERN)?.[1];
}
describe('saveFindings', () => {
const tempDirs = [];
const makeTempDir = prefix => {
@@ -187,6 +194,16 @@ describe('postNewCriticalComments', () => {
});
describe('postFindingsReview', () => {
it('extracts review severity labels only when the format is valid', () => {
assert.equal(
reviewSeverityLabel({ body: '**嚴重等級**:🔴 嚴重\n**審查員**Rex' }),
'🔴 嚴重',
);
assert.equal(reviewSeverityLabel({ body: '**審查員**Rex' }), undefined);
assert.equal(reviewSeverityLabel({ body: '**嚴重等級**' }), undefined);
assert.equal(reviewSeverityLabel({ body: '**嚴重等級**:高風險' }), undefined);
});
it('posts one review with statistics and sorted line comments', async () => {
const reviewCalls = [];
const findings = [
@@ -209,8 +226,8 @@ describe('postFindingsReview', () => {
['app/a.js', 'app/b.js', 'app/c.js'],
);
assert.deepEqual(
reviewCalls[0].comments.map(c => c.body.match(/嚴重等級\*\*(.+)/)?.[1]),
['🔴 嚴重', '🟡 警告', '🔵 建議'],
reviewCalls[0].comments.map(reviewSeverityLabel),
REVIEW_SEVERITY_LABELS,
);
assert.deepEqual(
reviewCalls[0].comments.map(c => c.new_position),