Revert "test: cover review edge cases and repair paths"

This reverts commit 61942eeebbba95c81431896c7fd8f43ff0e7c0d5.
This commit is contained in:
2026-05-13 06:25:28 +00:00
parent 3f3ead0f08
commit 0c9748049c
8 changed files with 41 additions and 243 deletions
+5 -5
View File
@@ -77,20 +77,20 @@ function fallback(label, findings, e) {
}
/** 只保留 AI 需要的欄位,減少 token 用量 */
export function toAIPayload(findings) {
function toAIPayload(findings) {
return findings.map(({ level, role, location, suggestion }) => ({ level, role, location, suggestion }));
}
/**
* 呼叫 LLM 進行語意去重,失敗時降級回傳原始 findings
*/
export async function deduplicateWithAI(findings, chatFn = chatJSON) {
export async function deduplicateWithAI(findings) {
if (findings.length === 0) return findings;
const systemPrompt = `移除語意重複的程式碼審查問題(JSON 陣列)。保留等級較高者(critical > warning > info)。只回傳去重後的 JSON 陣列。`;
try {
const result = await chatFn(systemPrompt, JSON.stringify(toAIPayload(findings)));
const result = await chatJSON(systemPrompt, JSON.stringify(toAIPayload(findings)));
if (Array.isArray(result) && result.length > 0) {
console.log(` AI 去重: ${findings.length} -> ${result.length}`);
// 以 location+suggestion 為 key,將原始 findings 的完整欄位(含 is_new)補回
@@ -131,7 +131,7 @@ export function applyExclusions(findings, exclusions) {
/**
* 呼叫 AI 判斷哪些問題是誤報或不需處理,失敗時降級回傳原始 findings
*/
export async function filterFalsePositivesWithAI(findings, exclusions = [], chatFn = chatJSON) {
export async function filterFalsePositivesWithAI(findings, exclusions = []) {
if (findings.length === 0) return findings;
const exclusionHint = exclusions.length > 0
@@ -141,7 +141,7 @@ export async function filterFalsePositivesWithAI(findings, exclusions = [], chat
const systemPrompt = `判斷以下程式碼審查問題是否為誤報或不適用(如已正確使用 secrets、CI/CD 必要權限等),移除後只回傳需保留的 JSON 陣列。${exclusionHint}`;
try {
const result = await chatFn(systemPrompt, JSON.stringify(toAIPayload(findings)));
const result = await chatJSON(systemPrompt, JSON.stringify(toAIPayload(findings)));
if (Array.isArray(result) && result.length > 0) {
console.log(` AI 誤報過濾: ${findings.length} -> ${result.length}`);
const origMap = new Map(findings.map(f => [`${f.location}|${String(f.suggestion).slice(0, 50)}`, f]));