feat: refactor commitAndPush to use GIT_ASKPASS for authentication and add tests

This commit is contained in:
2026-05-12 01:01:19 +00:00
parent 66d93abe24
commit 9279050ca9
2 changed files with 50 additions and 5 deletions
+30
View File
@@ -0,0 +1,30 @@
import { commitAndPush } from './git.js';
import fs from 'fs';
import path from 'path';
// Mock dependencies and environment
jest.mock('fs');
jest.mock('child_process', () => ({
spawnSync: jest.fn(() => ({ status: 0, stdout: '', stderr: '' }))
}));
describe('commitAndPush', () => {
const workspace = '/tmp/workspace';
const repoDir = path.join(workspace, 'repo');
beforeEach(() => {
jest.clearAllMocks();
fs.existsSync.mockReturnValue(false);
fs.writeFileSync.mockImplementation(() => {});
fs.unlinkSync.mockImplementation(() => {});
});
it('should clone repo and configure git', async () => {
await expect(commitAndPush(workspace)).resolves.not.toThrow();
});
it('should not clone if repo exists', async () => {
fs.existsSync.mockReturnValue(true);
await expect(commitAndPush(workspace)).resolves.not.toThrow();
});
});