fix(ai-review): 避免建問題模式嚴重結果 fail-open

This commit is contained in:
Jeffery
2026-07-21 14:24:04 +08:00
parent 24b248884f
commit 555611db07
3 changed files with 110 additions and 84 deletions
+15 -10
View File
@@ -210,7 +210,7 @@ async function main() {
};
/**
* 建問題模式:建立追蹤 issue(標題=PR 標題、本文=PR 描述+回溯 PR 的引言,連同挑好的標籤一次建立),
* 並把 `issueBuffer` 內暫存的情境留言批次寫入 issue;設定閉包變數 `issue` 供後續留言直接發到 issue。
* 並把 `issueBuffer` 內暫存的情境留言依流程順序寫入 issue;設定閉包變數 `issue` 供後續留言直接發到 issue。
* 僅於「確定有保留問題」時呼叫一次。標籤於建立時一次帶入,省去「先建空標籤 issue 再補掛」的多餘 API 往返。
*
* @param {number[]} [labelIds] - 建立 issue 時要一併掛上的標籤 id 陣列(由 `review.selectLabels` 事先挑選);
@@ -224,9 +224,9 @@ async function main() {
labels: labelIds,
});
log('建問題', 'INF', `已建立追蹤 issue #${issue.number},寫入 ${issueBuffer.length} 則情境留言。`);
await Promise.all(
issueBuffer.map((body) => gitea.createCommentOnIssue(ctx, issue.number, body)),
);
for (const body of issueBuffer) {
await gitea.createCommentOnIssue(ctx, issue.number, body);
}
issueBuffer.length = 0;
};
@@ -302,7 +302,9 @@ async function main() {
await queueOrPostComment(templates.rolesComment({ title: '🛡️ 防守方登場', roles: defenders }));
// ── 步驟 8:防守方裁決 → 排除 → 排序 → 保存 findings ──────────────────
const { kept, excluded } = await review.runDefenders({ tool, model: ctx.model, cwd, defenders, findings });
const { kept, excluded } = findings.length === 0
? { kept: [], excluded: [] }
: await review.runDefenders({ tool, model: ctx.model, cwd, defenders, findings });
review.sortFindings(kept);
const relativePath = saveFindings({ cwd, ctx, tool, kept, excluded });
@@ -398,12 +400,15 @@ async function main() {
}
// ── 收尾:commit 並 pushsuccess=無嚴重問題、failure=有嚴重問題)───────
// 一般模式:findingsexclusions.json;建問題模式:問題明細已在 issue 留言,只 commit exclusions.json。
// 一般模式:findingsexclusions.json;建問題模式通常只 commit exclusions.json。
// 若有嚴重問題,仍 commit findings 檔產生 [failure] 結果 commit,避免相依 API 不支援時 fail-open。
const result = severe.length === 0 ? 'success' : 'failure';
const filesToCommit = ctx.createIssue ? [] : [relativePath];
if (exclusionsChanged) {
filesToCommit.push(path.join('.gitea', 'ai-review', 'exclusions.json'));
}
const filesToCommit = review.resultFilesToCommit({
createIssue: ctx.createIssue,
severeCount: severe.length,
relativePath,
exclusionsChanged,
});
if (filesToCommit.length > 0) {
commitFindings({ cwd, ctx, files: filesToCommit, result });
} else {