From e3890787ff1914216469fec2a7c98bc2eb6feb06 Mon Sep 17 00:00:00 2001 From: Jeffery Date: Mon, 22 Jun 2026 16:32:23 +0000 Subject: [PATCH] =?UTF-8?q?test(comments=20review):=20=E6=8A=BD=E5=87=BA?= =?UTF-8?q?=E5=9A=B4=E9=87=8D=E7=AD=89=E7=B4=9A=E8=A7=A3=E6=9E=90=E6=96=B7?= =?UTF-8?q?=E8=A8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/comments.test.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/app/comments.test.js b/app/comments.test.js index f413765..ddcc817 100644 --- a/app/comments.test.js +++ b/app/comments.test.js @@ -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),