fix: support wrapped exclusions schema

This commit is contained in:
2026-05-15 06:39:17 +00:00
parent 4a29c4aaa3
commit f43ba63f0f
2 changed files with 71 additions and 1 deletions
+21 -1
View File
@@ -34,6 +34,12 @@ function readJSONArray(fullPath, label) {
}
}
function normalizeExclusions(data) {
if (Array.isArray(data)) return data;
if (data && Array.isArray(data.excluded_findings)) return data.excluded_findings;
return [];
}
/**
* 讀取舊 findings(從 workspace 的 FINDINGS_PATH
*/
@@ -107,7 +113,21 @@ export async function deduplicateWithAI(findings) {
* 讀取排除問題檔案(從 workspace 的 EXCLUSIONS_PATH
*/
export function loadExclusions(workspace) {
const exclusions = readJSONArray(path.join(workspace, EXCLUSIONS_PATH), '排除問題');
const fullPath = path.join(workspace, EXCLUSIONS_PATH);
if (!fs.existsSync(fullPath)) {
console.log(' 排除問題檔案不存在,視為空');
console.log(' 讀取排除問題: 0 筆');
return [];
}
let exclusions = [];
try {
const data = JSON.parse(fs.readFileSync(fullPath, 'utf8'));
exclusions = normalizeExclusions(data);
} catch (e) {
console.log(` ⚠️ 讀取排除問題失敗: ${e.message},視為空`);
exclusions = [];
}
console.log(` 讀取排除問題: ${exclusions.length}`);
return exclusions;
}