Compare commits
2 Commits
v0.1.1-beta.1
...
v0.1.1
| Author | SHA1 | Date | |
|---|---|---|---|
| 4a29c4aaa3 | |||
| 78ec8f6d6a |
+59
-6
@@ -1,15 +1,22 @@
|
|||||||
import { describe, it } from 'node:test';
|
import { describe, it, afterEach } from 'node:test';
|
||||||
import assert from 'node:assert/strict';
|
import assert from 'node:assert/strict';
|
||||||
import fs from 'fs';
|
import fs from 'node:fs';
|
||||||
import os from 'os';
|
import os from 'node:os';
|
||||||
import path from 'path';
|
import path from 'node:path';
|
||||||
import { saveFindings } from './comments.js';
|
import { saveFindings } from './comments.js';
|
||||||
import { FINDINGS_PATH } from './config.js';
|
import { FINDINGS_PATH } from './config.js';
|
||||||
|
|
||||||
describe('saveFindings', () => {
|
describe('saveFindings', () => {
|
||||||
|
const tempDirs = [];
|
||||||
|
const makeTempDir = prefix => {
|
||||||
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), prefix));
|
||||||
|
tempDirs.push(dir);
|
||||||
|
return dir;
|
||||||
|
};
|
||||||
|
|
||||||
it('writes findings to workspace and mirror dirs when provided', () => {
|
it('writes findings to workspace and mirror dirs when provided', () => {
|
||||||
const workspace = fs.mkdtempSync(path.join(os.tmpdir(), 'findings-ws-'));
|
const workspace = makeTempDir('findings-ws-');
|
||||||
const mirrorDir = fs.mkdtempSync(path.join(os.tmpdir(), 'findings-mirror-'));
|
const mirrorDir = makeTempDir('findings-mirror-');
|
||||||
const findings = [{ level: 'warning', role: 'Leo', location: 'file.js:1', suggestion: 'test' }];
|
const findings = [{ level: 'warning', role: 'Leo', location: 'file.js:1', suggestion: 'test' }];
|
||||||
|
|
||||||
saveFindings(workspace, findings, mirrorDir);
|
saveFindings(workspace, findings, mirrorDir);
|
||||||
@@ -19,4 +26,50 @@ describe('saveFindings', () => {
|
|||||||
assert.equal(workspaceText, JSON.stringify(findings, null, 2) + '\n');
|
assert.equal(workspaceText, JSON.stringify(findings, null, 2) + '\n');
|
||||||
assert.equal(mirrorText, JSON.stringify(findings, null, 2) + '\n');
|
assert.equal(mirrorText, JSON.stringify(findings, null, 2) + '\n');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('writes only to workspace when mirrorDir is omitted', () => {
|
||||||
|
const workspace = makeTempDir('findings-ws-');
|
||||||
|
const findings = [{ level: 'info', role: 'Maya', location: 'file.js:2', suggestion: 'note' }];
|
||||||
|
|
||||||
|
saveFindings(workspace, findings);
|
||||||
|
|
||||||
|
const workspaceText = fs.readFileSync(path.join(workspace, FINDINGS_PATH), 'utf8');
|
||||||
|
assert.equal(workspaceText, JSON.stringify(findings, null, 2) + '\n');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not duplicate writes when mirrorDir matches workspace', () => {
|
||||||
|
const workspace = makeTempDir('findings-same-');
|
||||||
|
const findings = [];
|
||||||
|
const writeCalls = [];
|
||||||
|
const originalWriteFileSync = fs.writeFileSync;
|
||||||
|
|
||||||
|
fs.writeFileSync = (...args) => {
|
||||||
|
writeCalls.push(args[0]);
|
||||||
|
return originalWriteFileSync(...args);
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
saveFindings(workspace, findings, workspace);
|
||||||
|
} finally {
|
||||||
|
fs.writeFileSync = originalWriteFileSync;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.equal(writeCalls.length, 1);
|
||||||
|
assert.equal(writeCalls[0], path.join(workspace, FINDINGS_PATH));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('writes an empty JSON array when findings is empty', () => {
|
||||||
|
const workspace = makeTempDir('findings-empty-');
|
||||||
|
|
||||||
|
saveFindings(workspace, []);
|
||||||
|
|
||||||
|
const workspaceText = fs.readFileSync(path.join(workspace, FINDINGS_PATH), 'utf8');
|
||||||
|
assert.equal(workspaceText, '[]\n');
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
while (tempDirs.length > 0) {
|
||||||
|
fs.rmSync(tempDirs.pop(), { recursive: true, force: true });
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
+11
-1
@@ -68,6 +68,10 @@ export async function commitAndPush(workspace, repoDir, _spawnSync = spawnSync,
|
|||||||
await withAskpass(workspace, async credEnv => {
|
await withAskpass(workspace, async credEnv => {
|
||||||
run(['config', 'user.email', 'ai-review[bot]@gitea'], repoDir);
|
run(['config', 'user.email', 'ai-review[bot]@gitea'], repoDir);
|
||||||
run(['config', 'user.name', 'AI Review Bot'], repoDir);
|
run(['config', 'user.name', 'AI Review Bot'], repoDir);
|
||||||
|
if (PR_HEAD_BRANCH) {
|
||||||
|
run(['fetch', 'origin', PR_HEAD_BRANCH], repoDir, credEnv);
|
||||||
|
run(['reset', '--hard', `origin/${PR_HEAD_BRANCH}`], repoDir);
|
||||||
|
}
|
||||||
|
|
||||||
const existingSyncPaths = [];
|
const existingSyncPaths = [];
|
||||||
|
|
||||||
@@ -86,8 +90,14 @@ export async function commitAndPush(workspace, repoDir, _spawnSync = spawnSync,
|
|||||||
if (existingSyncPaths.length > 0) {
|
if (existingSyncPaths.length > 0) {
|
||||||
run(['add', ...existingSyncPaths], repoDir);
|
run(['add', ...existingSyncPaths], repoDir);
|
||||||
}
|
}
|
||||||
const generatedSyncPaths = GENERATED_SYNC_PATHS.filter(relPath => fs.existsSync(path.join(repoDir, relPath)));
|
const generatedSyncPaths = GENERATED_SYNC_PATHS.filter(relPath => fs.existsSync(path.join(workspace, relPath)));
|
||||||
if (generatedSyncPaths.length > 0) {
|
if (generatedSyncPaths.length > 0) {
|
||||||
|
for (const relPath of generatedSyncPaths) {
|
||||||
|
const src = path.join(workspace, relPath);
|
||||||
|
const dest = path.join(repoDir, relPath);
|
||||||
|
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
||||||
|
fs.copyFileSync(src, dest);
|
||||||
|
}
|
||||||
run(['add', ...generatedSyncPaths], repoDir);
|
run(['add', ...generatedSyncPaths], repoDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -95,6 +95,9 @@ describe('commitAndPush', () => {
|
|||||||
|
|
||||||
it('adds skill and entry files together with findings', async () => {
|
it('adds skill and entry files together with findings', async () => {
|
||||||
const repoDir = path.join(workspace, 'repo');
|
const repoDir = path.join(workspace, 'repo');
|
||||||
|
fs.mkdirSync(path.join(workspace, '.gitea/ai-review'), { recursive: true });
|
||||||
|
fs.writeFileSync(path.join(workspace, '.gitea/ai-review/findings.json'), '[]\n');
|
||||||
|
fs.writeFileSync(path.join(workspace, '.gitea/ai-review/exclusions.json'), '[]\n');
|
||||||
fs.mkdirSync(path.join(repoDir, '.gitea/ai-review'), { recursive: true });
|
fs.mkdirSync(path.join(repoDir, '.gitea/ai-review'), { recursive: true });
|
||||||
fs.writeFileSync(path.join(repoDir, '.gitea/ai-review/findings.json'), '[]\n');
|
fs.writeFileSync(path.join(repoDir, '.gitea/ai-review/findings.json'), '[]\n');
|
||||||
fs.writeFileSync(path.join(repoDir, '.gitea/ai-review/exclusions.json'), '[]\n');
|
fs.writeFileSync(path.join(repoDir, '.gitea/ai-review/exclusions.json'), '[]\n');
|
||||||
|
|||||||
Reference in New Issue
Block a user