fix(comments review): 送出前排序 Review comments #37
@@ -1 +1,18 @@
|
|||||||
[]
|
[
|
||||||
|
{
|
||||||
|
"level": "critical",
|
||||||
|
"role": "Maya",
|
||||||
|
"location": "app/comments.test.js:240",
|
||||||
|
"problem": "新增的測試案例 `sorts the final review comment payload after filtering non-commentable findings`,其預期結果 `['🟡 警告', '🔵 建議']` 似乎有誤。輸入的 `critical` 等級的 finding 帶有 `suggestion` 欄位,照理來說應該會被轉換成評論,並依嚴重性排在最前面。目前測試結果卻將其排除,這可能代表 `toReviewComment` 函數有未預期的行為,或是測試的預期結果不正確,導致未能完整驗證排序邏輯。",
|
||||||
|
"suggestion": "請確認 `toReviewComment` 函數對於 `critical` 等級且帶有 `suggestion` 的 finding 是否會回傳 `null`。\n1. 如果不會,則測試的預期結果應修正為 `['🔴 嚴重', '🟡 警告', '🔵 建議']`,以確保所有應轉換的評論都被包含且排序正確。\n2. 如果 `toReviewComment` 確實會過濾掉某些 `critical` finding,則應新增一個獨立的測試案例,明確驗證 `critical` finding 在何種情況下會被過濾,並解釋其原因。\n3. 同時,這個測試案例也應該明確斷言最終評論的數量,以確保過濾行為符合預期。",
|
||||||
|
"is_new": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"level": "info",
|
||||||
|
"role": "Bard",
|
||||||
|
"location": "app/comments.test.js:252",
|
||||||
|
"problem": "測試中用於提取評論嚴重等級的正規表達式 `c.body.match(/嚴重等級\\*\\*:(.+)/)?.[1]` 雖然有效,但其寫法較為冗長且直接依賴於評論內文的特定格式。這使得測試在評論格式微調時可能變得脆弱,且降低了可讀性,如同樂章中突兀的音符。",
|
||||||
|
"suggestion": "若評論內文的格式是固定的,可考慮將此正規表達式提取為一個具名常數或輔助函式,以提升可讀性與維護性。若 `toReviewComment` 函式能回傳一個包含結構化資訊(如 `level`)的物件,則測試可直接斷言該物件屬性,避免解析字串,讓測試更為優雅。",
|
||||||
|
"is_new": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|||||||
+7
-3
@@ -94,11 +94,15 @@ export async function postFindingsReview(findings, deps = {}) {
|
|||||||
summaryFindings = findings,
|
summaryFindings = findings,
|
||||||
commentFindings = findings,
|
commentFindings = findings,
|
||||||
} = deps;
|
} = deps;
|
||||||
const sortedComments = [...commentFindings].sort(bySeverity);
|
const commentItems = commentFindings
|
||||||
const comments = sortedComments.map(toReviewComment).filter(Boolean);
|
.map(finding => ({ finding, comment: toReviewComment(finding) }))
|
||||||
|
.filter(item => item.comment);
|
||||||
|
const comments = commentItems
|
||||||
|
.sort((a, b) => bySeverity(a.finding, b.finding))
|
||||||
|
.map(item => item.comment);
|
||||||
const body = buildReviewSummary(summaryFindings);
|
const body = buildReviewSummary(summaryFindings);
|
||||||
await postReview({ body, comments });
|
await postReview({ body, comments });
|
||||||
ok(`review 發布: summary=${summaryFindings.length} total=${sortedComments.length} commentable=${comments.length}`);
|
ok(`review 發布: summary=${summaryFindings.length} total=${commentFindings.length} commentable=${comments.length}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -238,6 +238,22 @@ describe('postFindingsReview', () => {
|
|||||||
assert.equal(reviewCalls[0].comments[0].path, 'app/b.js');
|
assert.equal(reviewCalls[0].comments[0].path, 'app/b.js');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|||||||
|
it('sorts the final review comment payload after filtering non-commentable findings', async () => {
|
||||||
|
const reviewCalls = [];
|
||||||
|
await postFindingsReview([
|
||||||
|
{ level: 'info', role: 'Maya', location: 'app/c.js:30', suggestion: 'I' },
|
||||||
|
{ level: 'critical', role: 'Rex', location: 'app/a.js', suggestion: 'missing line' },
|
||||||
|
{ level: 'warning', role: 'Leo', location: 'app/b.js:20', suggestion: 'W' },
|
||||||
|
], {
|
||||||
|
postReview: async (args) => { reviewCalls.push(args); },
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.deepEqual(
|
||||||
|
reviewCalls[0].comments.map(c => c.body.match(/嚴重等級\*\*:(.+)/)?.[1]),
|
||||||
|
admin
commented
嚴重等級:🔵 建議 **嚴重等級**:🔵 建議
**審查員**:Bard
**問題**:測試中用於提取評論嚴重等級的正規表達式 `c.body.match(/嚴重等級\*\*:(.+)/)?.[1]` 雖然有效,但其寫法較為冗長且直接依賴於評論內文的特定格式。這使得測試在評論格式微調時可能變得脆弱,且降低了可讀性,如同樂章中突兀的音符。
**建議**:若評論內文的格式是固定的,可考慮將此正規表達式提取為一個具名常數或輔助函式,以提升可讀性與維護性。若 `toReviewComment` 函式能回傳一個包含結構化資訊(如 `level`)的物件,則測試可直接斷言該物件屬性,避免解析字串,讓測試更為優雅。
|
|||||||
|
['🟡 警告', '🔵 建議'],
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it('uses an explicit problem field when present', async () => {
|
it('uses an explicit problem field when present', async () => {
|
||||||
const reviewCalls = [];
|
const reviewCalls = [];
|
||||||
await postFindingsReview([
|
await postFindingsReview([
|
||||||
|
|||||||
Reference in New Issue
Block a user
嚴重等級:🔴 嚴重
審查員:Maya
問題:新增的測試案例
sorts the final review comment payload after filtering non-commentable findings,其預期結果['🟡 警告', '🔵 建議']似乎有誤。輸入的critical等級的 finding 帶有suggestion欄位,照理來說應該會被轉換成評論,並依嚴重性排在最前面。目前測試結果卻將其排除,這可能代表toReviewComment函數有未預期的行為,或是測試的預期結果不正確,導致未能完整驗證排序邏輯。建議:請確認
toReviewComment函數對於critical等級且帶有suggestion的 finding 是否會回傳null。['🔴 嚴重', '🟡 警告', '🔵 建議'],以確保所有應轉換的評論都被包含且排序正確。toReviewComment確實會過濾掉某些criticalfinding,則應新增一個獨立的測試案例,明確驗證criticalfinding 在何種情況下會被過濾,並解釋其原因。