fix(core): resolve build and lint failures in worktreeService

- Fix incorrect 'fs.promises' usage
- Provide missing 'projectRoot' to 'isGeminiWorktree'
- Replace 'any' with specific types and type guards to satisfy ESLint
- Update tests to match implementation changes
This commit is contained in:
A.K.M. Adib
2026-05-04 16:00:41 -04:00
parent 7f19202892
commit 3369da59b3
2 changed files with 16 additions and 7 deletions
@@ -86,7 +86,7 @@ describe('worktree utilities', () => {
describe('createWorktree', () => {
it('should execute git worktree add with correct branch and path if it does not exist', async () => {
vi.mocked(fs.promises.stat).mockRejectedValue({ code: 'ENOENT' } as any);
vi.mocked(fs.stat).mockRejectedValue({ code: 'ENOENT' });
vi.mocked(execa).mockResolvedValue({ stdout: '' } as never);
const resultPath = await createWorktree(projectRoot, worktreeName);
@@ -100,7 +100,9 @@ describe('worktree utilities', () => {
});
it('should return existing path and not call git if it already exists', async () => {
vi.mocked(fs.promises.stat).mockResolvedValue({ isDirectory: () => true } as any);
vi.mocked(fs.stat).mockResolvedValue({
isDirectory: () => true,
} as never);
const resultPath = await createWorktree(projectRoot, worktreeName);
@@ -109,7 +111,7 @@ describe('worktree utilities', () => {
});
it('should throw an error if git worktree add fails', async () => {
vi.mocked(fs.promises.stat).mockRejectedValue({ code: 'ENOENT' } as any);
vi.mocked(fs.stat).mockRejectedValue({ code: 'ENOENT' });
vi.mocked(execa).mockRejectedValue(new Error('git failed'));
await expect(createWorktree(projectRoot, worktreeName)).rejects.toThrow(
+11 -4
View File
@@ -128,12 +128,19 @@ export async function createWorktree(
}
try {
const stats = await fs.promises.stat(worktreePath);
if (stats.isDirectory() && await isGeminiWorktree(worktreePath)) {
const stats = await fs.stat(worktreePath);
if (stats.isDirectory() && isGeminiWorktree(worktreePath, projectRoot)) {
return worktreePath;
}
} catch (err) {
if (err.code !== 'ENOENT') throw err;
} catch (err: unknown) {
if (
err &&
typeof err === 'object' &&
'code' in err &&
err.code !== 'ENOENT'
) {
throw err;
}
}
const branchName = `worktree-${name}`;