fix: address triaged review findings
This commit is contained in:
+12
-1
@@ -11,7 +11,18 @@ const api = (path) => `${GITEA_SERVER_URL.replace(/\/$/, '')}/api/v1${path}`;
|
||||
*/
|
||||
export async function getPRDiff() {
|
||||
const resp = await axios.get(api(`/repos/${GITEA_REPOSITORY}/pulls/${PR_NUMBER}.diff`), { headers: headers(), timeout: 60000, httpsAgent });
|
||||
return filterDiff(resp.data, ['.gitea/', '.amazonq/', '.claude/', '.codex/', '.gemini/', '.github/', 'CLAUDE.md', 'GEMINI.md', 'TODO.md', 'README.md']);
|
||||
return filterDiff(resp.data, [
|
||||
'.gitea/',
|
||||
'.amazonq/',
|
||||
'.claude/',
|
||||
'.codex/',
|
||||
'.gemini/',
|
||||
'.github/',
|
||||
'CLAUDE.md',
|
||||
'GEMINI.md',
|
||||
'TODO.md',
|
||||
'README.md',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+3
-6
@@ -1,12 +1,11 @@
|
||||
import { describe, it, afterEach, mock } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import axios from 'axios';
|
||||
import { getPRDiff, filterDiff, postComment } from './gitea.js';
|
||||
|
||||
afterEach(() => mock.restoreAll());
|
||||
|
||||
describe('gitea', async () => {
|
||||
const { getPRDiff, filterDiff, postComment } = await import('./gitea.js');
|
||||
|
||||
describe('gitea', () => {
|
||||
it('getPRDiff calls Gitea diff API with Authorization header', async () => {
|
||||
let capturedUrl, capturedOpts;
|
||||
mock.method(axios, 'get', async (url, opts) => {
|
||||
@@ -59,9 +58,7 @@ describe('gitea', async () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('filterDiff', async () => {
|
||||
const { filterDiff } = await import('./gitea.js');
|
||||
|
||||
describe('filterDiff', () => {
|
||||
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 configured folder blocks', () => {
|
||||
|
||||
@@ -6,6 +6,7 @@ import path from 'path';
|
||||
import { stripCodeFence, repairJSONArrayWithAI, validateJSONArrayFile, ensureJSONArrayFileExists } from './json.js';
|
||||
|
||||
describe('json helpers', () => {
|
||||
const MAX_JSON_BYTES = 1024 * 1024;
|
||||
let workspace;
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -76,6 +77,16 @@ describe('json helpers', () => {
|
||||
assert.equal(fs.readFileSync(fullPath, 'utf8'), '[]\n');
|
||||
});
|
||||
|
||||
it('reads a valid JSON file whose size equals the maximum limit', async () => {
|
||||
const fullPath = path.join(workspace, '.gitea/ai-review/findings.json');
|
||||
fs.mkdirSync(path.dirname(fullPath), { recursive: true });
|
||||
fs.writeFileSync(fullPath, `[]${' '.repeat(MAX_JSON_BYTES - 2)}`, 'utf8');
|
||||
|
||||
const result = await validateJSONArrayFile(fullPath, '.gitea/ai-review/findings.json');
|
||||
|
||||
assert.deepEqual(result, { exists: true, valid: true, repaired: false });
|
||||
});
|
||||
|
||||
it('repairs invalid JSON using AI output and rewrites the file', async () => {
|
||||
const fullPath = path.join(workspace, '.gitea/ai-review/findings.json');
|
||||
fs.mkdirSync(path.dirname(fullPath), { recursive: true });
|
||||
@@ -90,6 +101,20 @@ describe('json helpers', () => {
|
||||
assert.equal(fs.readFileSync(fullPath, 'utf8'), '[{"fixed":true}]\n');
|
||||
});
|
||||
|
||||
it('preserves a trailing newline returned by AI repair', async () => {
|
||||
const fullPath = path.join(workspace, '.gitea/ai-review/findings.json');
|
||||
fs.mkdirSync(path.dirname(fullPath), { recursive: true });
|
||||
fs.writeFileSync(fullPath, '{broken', 'utf8');
|
||||
|
||||
const result = await validateJSONArrayFile(fullPath, '.gitea/ai-review/findings.json', async (_fullPath, _label, original) => {
|
||||
assert.equal(original, '{broken');
|
||||
return '[{"fixed":true}]\n';
|
||||
});
|
||||
|
||||
assert.deepEqual(result, { exists: true, valid: true, repaired: true });
|
||||
assert.equal(fs.readFileSync(fullPath, 'utf8'), '[{"fixed":true}]\n');
|
||||
});
|
||||
|
||||
it('throws when AI repair fails', async () => {
|
||||
const fullPath = path.join(workspace, '.gitea/ai-review/findings.json');
|
||||
fs.mkdirSync(path.dirname(fullPath), { recursive: true });
|
||||
|
||||
Reference in New Issue
Block a user