fix: add Leo/Zara false positive exclusion; add cloneRepo unit tests
This commit is contained in:
+57
-1
@@ -3,7 +3,7 @@ import assert from 'node:assert/strict';
|
||||
import fs from 'fs';
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
import { commitAndPush } from './git.js';
|
||||
import { commitAndPush, cloneRepo } from './git.js';
|
||||
|
||||
// --- helpers ---
|
||||
function makeTmpWorkspace() {
|
||||
@@ -91,3 +91,59 @@ describe('commitAndPush', () => {
|
||||
await assert.doesNotReject(() => commitAndPush(workspace, failSpawn));
|
||||
});
|
||||
});
|
||||
|
||||
describe('cloneRepo', () => {
|
||||
let workspace;
|
||||
|
||||
before(() => { workspace = fs.mkdtempSync(path.join(os.tmpdir(), 'clone-test-')); });
|
||||
after(() => { fs.rmSync(workspace, { recursive: true, force: true }); });
|
||||
|
||||
it('clones repo when repoDir does not exist', () => {
|
||||
const spawn = makeSpawn();
|
||||
cloneRepo(workspace, spawn);
|
||||
const cloneCalled = spawn.calls.some(c => c.args[0] === 'clone');
|
||||
assert.ok(cloneCalled, 'expected git clone to be called');
|
||||
});
|
||||
|
||||
it('fetches and checks out when repoDir already exists', () => {
|
||||
const repoDir = path.join(workspace, 'repo');
|
||||
fs.mkdirSync(repoDir, { recursive: true });
|
||||
const spawn = makeSpawn();
|
||||
cloneRepo(workspace, spawn);
|
||||
const cloneCalled = spawn.calls.some(c => c.args[0] === 'clone');
|
||||
const fetchCalled = spawn.calls.some(c => c.args[0] === 'fetch');
|
||||
assert.ok(!cloneCalled, 'clone should not run when repoDir exists');
|
||||
assert.ok(fetchCalled, 'fetch should run when repoDir exists');
|
||||
});
|
||||
|
||||
it('does not embed token in any git command argument', () => {
|
||||
const spawn = makeSpawn();
|
||||
cloneRepo(workspace, spawn);
|
||||
for (const { args } of spawn.calls) {
|
||||
assert.ok(!args.join(' ').includes('test-token'), `Token leaked in git args: ${args.join(' ')}`);
|
||||
}
|
||||
});
|
||||
|
||||
it('uses GIT_ASKPASS for network operations', () => {
|
||||
const spawn = makeSpawn();
|
||||
cloneRepo(workspace, spawn);
|
||||
const networkCalls = spawn.calls.filter(c => ['clone', 'fetch'].includes(c.args[0]));
|
||||
assert.ok(networkCalls.length > 0, 'expected at least one network git call');
|
||||
for (const { args, opts } of networkCalls) {
|
||||
assert.ok(opts?.env?.GIT_ASKPASS, `GIT_ASKPASS missing for git ${args[0]}`);
|
||||
}
|
||||
});
|
||||
|
||||
it('cleans up askpass script after run', () => {
|
||||
const spawn = makeSpawn();
|
||||
cloneRepo(workspace, spawn);
|
||||
const leftover = fs.readdirSync(workspace).filter(f => f.endsWith('.git-askpass.sh'));
|
||||
assert.equal(leftover.length, 0, 'askpass script was not cleaned up');
|
||||
});
|
||||
|
||||
it('returns repoDir path', () => {
|
||||
const spawn = makeSpawn();
|
||||
const result = cloneRepo(workspace, spawn);
|
||||
assert.equal(result, path.join(workspace, 'repo'));
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user