diff --git a/.gitea/ai-review/exclusions.json b/.gitea/ai-review/exclusions.json index ac80e9f..6986a6e 100644 --- a/.gitea/ai-review/exclusions.json +++ b/.gitea/ai-review/exclusions.json @@ -208,5 +208,10 @@ "role": "Zara", "location": "app/main.js", "suggestion": "deduplicateWithAI 和 filterFalsePositivesWithAI 為循序依賴流程(去重後才能過濾),無法平行化" + }, + { + "role": "Leo", + "location": "app/comments.js", + "suggestion": "buildTable 函式已在 comments.js 第 13 行定義,非未定義或未匯入,不會導致執行時錯誤" } ] diff --git a/app/gitea.test.js b/app/gitea.test.js index bd19a83..26e916a 100644 --- a/app/gitea.test.js +++ b/app/gitea.test.js @@ -2,13 +2,10 @@ import { describe, it, afterEach, mock } from 'node:test'; import assert from 'node:assert/strict'; import axios from 'axios'; -// gitea.js reads env vars at module load time (ESM cache), so we test -// the actual values baked in at import time and verify behavior via axios mocks. - afterEach(() => mock.restoreAll()); describe('gitea', async () => { - const { getPRDiff, postComment } = await import('./gitea.js'); + const { getPRDiff, filterDiff, postComment } = await import('./gitea.js'); it('getPRDiff calls Gitea diff API with Authorization header', async () => { let capturedUrl, capturedOpts; @@ -48,7 +45,6 @@ describe('gitea', async () => { return { data: '' }; }); await getPRDiff(); - // httpsAgent is undefined when GITEA_SKIP_TLS_VERIFY !== 'true' assert.equal(capturedOpts.httpsAgent, undefined); }); @@ -62,3 +58,32 @@ describe('gitea', async () => { await assert.rejects(() => postComment('test'), /api error/); }); }); + +describe('filterDiff', async () => { + const { filterDiff } = await import('./gitea.js'); + + const block = (file) => `diff --git a/${file} b/${file}\n--- a/${file}\n+++ b/${file}\n@@ -1 +1 @@\n-old\n+new\n`; + + it('filters out .gitea/ blocks', () => { + const diff = block('.gitea/workflows/review.yaml') + block('src/index.js'); + const result = filterDiff(diff, ['.gitea/']); + assert.ok(!result.includes('.gitea/')); + assert.ok(result.includes('src/index.js')); + }); + + it('does not filter non-.gitea/ blocks', () => { + const diff = block('src/index.js') + block('README.md'); + const result = filterDiff(diff, ['.gitea/']); + assert.equal(result, diff); + }); + + it('returns empty string when all blocks are excluded', () => { + const diff = block('.gitea/workflows/review.yaml') + block('.gitea/ai-review/findings.json'); + const result = filterDiff(diff, ['.gitea/']); + assert.equal(result, ''); + }); + + it('returns empty string for empty diff', () => { + assert.equal(filterDiff('', ['.gitea/']), ''); + }); +});