refactor: add new suggestion for comments.js and enhance filterDiff tests for better coverage
This commit is contained in:
@@ -208,5 +208,10 @@
|
|||||||
"role": "Zara",
|
"role": "Zara",
|
||||||
"location": "app/main.js",
|
"location": "app/main.js",
|
||||||
"suggestion": "deduplicateWithAI 和 filterFalsePositivesWithAI 為循序依賴流程(去重後才能過濾),無法平行化"
|
"suggestion": "deduplicateWithAI 和 filterFalsePositivesWithAI 為循序依賴流程(去重後才能過濾),無法平行化"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"role": "Leo",
|
||||||
|
"location": "app/comments.js",
|
||||||
|
"suggestion": "buildTable 函式已在 comments.js 第 13 行定義,非未定義或未匯入,不會導致執行時錯誤"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
+30
-5
@@ -2,13 +2,10 @@ import { describe, it, afterEach, mock } from 'node:test';
|
|||||||
import assert from 'node:assert/strict';
|
import assert from 'node:assert/strict';
|
||||||
import axios from 'axios';
|
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());
|
afterEach(() => mock.restoreAll());
|
||||||
|
|
||||||
describe('gitea', async () => {
|
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 () => {
|
it('getPRDiff calls Gitea diff API with Authorization header', async () => {
|
||||||
let capturedUrl, capturedOpts;
|
let capturedUrl, capturedOpts;
|
||||||
@@ -48,7 +45,6 @@ describe('gitea', async () => {
|
|||||||
return { data: '' };
|
return { data: '' };
|
||||||
});
|
});
|
||||||
await getPRDiff();
|
await getPRDiff();
|
||||||
// httpsAgent is undefined when GITEA_SKIP_TLS_VERIFY !== 'true'
|
|
||||||
assert.equal(capturedOpts.httpsAgent, undefined);
|
assert.equal(capturedOpts.httpsAgent, undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -62,3 +58,32 @@ describe('gitea', async () => {
|
|||||||
await assert.rejects(() => postComment('test'), /api error/);
|
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/']), '');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user