summaryrefslogtreecommitdiff
path: root/packages/core/src/services/gitService.test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/core/src/services/gitService.test.ts')
-rw-r--r--packages/core/src/services/gitService.test.ts31
1 files changed, 17 insertions, 14 deletions
diff --git a/packages/core/src/services/gitService.test.ts b/packages/core/src/services/gitService.test.ts
index 9820ba5f..732b2652 100644
--- a/packages/core/src/services/gitService.test.ts
+++ b/packages/core/src/services/gitService.test.ts
@@ -6,6 +6,7 @@
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { GitService } from './gitService.js';
+import { Storage } from '../config/storage.js';
import * as path from 'path';
import * as fs from 'fs/promises';
import * as os from 'os';
@@ -55,6 +56,7 @@ describe('GitService', () => {
let projectRoot: string;
let homedir: string;
let hash: string;
+ let storage: Storage;
beforeEach(async () => {
testRootDir = await fs.mkdtemp(path.join(os.tmpdir(), 'git-service-test-'));
@@ -100,6 +102,7 @@ describe('GitService', () => {
hoistedMockCommit.mockResolvedValue({
commit: 'initial',
});
+ storage = new Storage(projectRoot);
});
afterEach(async () => {
@@ -109,13 +112,13 @@ describe('GitService', () => {
describe('constructor', () => {
it('should successfully create an instance', () => {
- expect(() => new GitService(projectRoot)).not.toThrow();
+ expect(() => new GitService(projectRoot, storage)).not.toThrow();
});
});
describe('verifyGitAvailability', () => {
it('should resolve true if git --version command succeeds', async () => {
- const service = new GitService(projectRoot);
+ const service = new GitService(projectRoot, storage);
await expect(service.verifyGitAvailability()).resolves.toBe(true);
});
@@ -124,7 +127,7 @@ describe('GitService', () => {
callback(new Error('git not found'));
return {} as ChildProcess;
});
- const service = new GitService(projectRoot);
+ const service = new GitService(projectRoot, storage);
await expect(service.verifyGitAvailability()).resolves.toBe(false);
});
});
@@ -135,14 +138,14 @@ describe('GitService', () => {
callback(new Error('git not found'));
return {} as ChildProcess;
});
- const service = new GitService(projectRoot);
+ const service = new GitService(projectRoot, storage);
await expect(service.initialize()).rejects.toThrow(
'Checkpointing is enabled, but Git is not installed. Please install Git or disable checkpointing to continue.',
);
});
it('should call setupShadowGitRepository if Git is available', async () => {
- const service = new GitService(projectRoot);
+ const service = new GitService(projectRoot, storage);
const setupSpy = vi
.spyOn(service, 'setupShadowGitRepository')
.mockResolvedValue(undefined);
@@ -162,14 +165,14 @@ describe('GitService', () => {
});
it('should create history and repository directories', async () => {
- const service = new GitService(projectRoot);
+ const service = new GitService(projectRoot, storage);
await service.setupShadowGitRepository();
const stats = await fs.stat(repoDir);
expect(stats.isDirectory()).toBe(true);
});
it('should create a .gitconfig file with the correct content', async () => {
- const service = new GitService(projectRoot);
+ const service = new GitService(projectRoot, storage);
await service.setupShadowGitRepository();
const expectedConfigContent =
@@ -180,7 +183,7 @@ describe('GitService', () => {
it('should initialize git repo in historyDir if not already initialized', async () => {
hoistedMockCheckIsRepo.mockResolvedValue(false);
- const service = new GitService(projectRoot);
+ const service = new GitService(projectRoot, storage);
await service.setupShadowGitRepository();
expect(hoistedMockSimpleGit).toHaveBeenCalledWith(repoDir);
expect(hoistedMockInit).toHaveBeenCalled();
@@ -188,7 +191,7 @@ describe('GitService', () => {
it('should not initialize git repo if already initialized', async () => {
hoistedMockCheckIsRepo.mockResolvedValue(true);
- const service = new GitService(projectRoot);
+ const service = new GitService(projectRoot, storage);
await service.setupShadowGitRepository();
expect(hoistedMockInit).not.toHaveBeenCalled();
});
@@ -198,7 +201,7 @@ describe('GitService', () => {
const visibleGitIgnorePath = path.join(projectRoot, '.gitignore');
await fs.writeFile(visibleGitIgnorePath, gitignoreContent);
- const service = new GitService(projectRoot);
+ const service = new GitService(projectRoot, storage);
await service.setupShadowGitRepository();
const hiddenGitIgnorePath = path.join(repoDir, '.gitignore');
@@ -207,7 +210,7 @@ describe('GitService', () => {
});
it('should not create a .gitignore in shadow repo if project .gitignore does not exist', async () => {
- const service = new GitService(projectRoot);
+ const service = new GitService(projectRoot, storage);
await service.setupShadowGitRepository();
const hiddenGitIgnorePath = path.join(repoDir, '.gitignore');
@@ -221,7 +224,7 @@ describe('GitService', () => {
// Create a directory instead of a file to cause a read error
await fs.mkdir(visibleGitIgnorePath);
- const service = new GitService(projectRoot);
+ const service = new GitService(projectRoot, storage);
// EISDIR is the expected error code on Unix-like systems
await expect(service.setupShadowGitRepository()).rejects.toThrow(
/EISDIR: illegal operation on a directory, read|EBUSY: resource busy or locked, read/,
@@ -230,7 +233,7 @@ describe('GitService', () => {
it('should make an initial commit if no commits exist in history repo', async () => {
hoistedMockCheckIsRepo.mockResolvedValue(false);
- const service = new GitService(projectRoot);
+ const service = new GitService(projectRoot, storage);
await service.setupShadowGitRepository();
expect(hoistedMockCommit).toHaveBeenCalledWith('Initial commit', {
'--allow-empty': null,
@@ -239,7 +242,7 @@ describe('GitService', () => {
it('should not make an initial commit if commits already exist', async () => {
hoistedMockCheckIsRepo.mockResolvedValue(true);
- const service = new GitService(projectRoot);
+ const service = new GitService(projectRoot, storage);
await service.setupShadowGitRepository();
expect(hoistedMockCommit).not.toHaveBeenCalled();
});