Skip to content

Commit 83aafc9

Browse files
committed
🤖 Fix git unit test failures by isolating mock config per test
The tests were failing because a shared global workspace directory caused workspace collisions and leftover state from previous test runs. Root cause: - mockConfig used a fixed srcDir path shared across all tests - Multiple tests created workspaces with the same names - Failed runs left directories behind causing 'Workspace already exists' errors Solution: - Created createMockConfig(tempDir) helper to generate unique configs per test - Each test now gets its own isolated workspace directory - Removed debug logging All 807 tests now pass.
1 parent 86323fa commit 83aafc9

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/services/gitService.test.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,25 @@ async function createTestRepo(basePath: string): Promise<string> {
2323
return repoPath;
2424
}
2525

26-
// Mock config for createWorktree
27-
const mockConfig = {
28-
srcDir: path.join(__dirname, "..", "test-workspaces"),
29-
getWorkspacePath: (projectPath: string, branchName: string) => {
30-
return path.join(path.dirname(projectPath), "workspaces", branchName);
31-
},
32-
} as unknown as Config;
26+
// Helper to create mock config with unique temp directory
27+
function createMockConfig(tempDir: string): Config {
28+
return {
29+
srcDir: path.join(tempDir, "test-workspaces"),
30+
getWorkspacePath: (projectPath: string, branchName: string) => {
31+
return path.join(path.dirname(projectPath), "workspaces", branchName);
32+
},
33+
} as unknown as Config;
34+
}
3335

3436
describe("removeWorktreeSafe", () => {
3537
let tempDir: string;
3638
let repoPath: string;
3739
let defaultBranch: string;
40+
let mockConfig: Config;
3841

3942
beforeEach(async () => {
4043
tempDir = await fs.mkdtemp(path.join(__dirname, "..", "test-temp-"));
44+
mockConfig = createMockConfig(tempDir);
4145
repoPath = await createTestRepo(tempDir);
4246
defaultBranch = await detectDefaultTrunkBranch(repoPath);
4347
});
@@ -55,9 +59,6 @@ describe("removeWorktreeSafe", () => {
5559
const result = await createWorktree(mockConfig, repoPath, "test-branch", {
5660
trunkBranch: defaultBranch,
5761
});
58-
if (!result.success) {
59-
console.error("createWorktree failed:", result.error);
60-
}
6162
expect(result.success).toBe(true);
6263
const worktreePath = result.path!;
6364

@@ -186,9 +187,11 @@ describe("isWorktreeClean", () => {
186187
let tempDir: string;
187188
let repoPath: string;
188189
let defaultBranch: string;
190+
let mockConfig: Config;
189191

190192
beforeEach(async () => {
191193
tempDir = await fs.mkdtemp(path.join(__dirname, "..", "test-temp-"));
194+
mockConfig = createMockConfig(tempDir);
192195
repoPath = await createTestRepo(tempDir);
193196
defaultBranch = await detectDefaultTrunkBranch(repoPath);
194197
});

0 commit comments

Comments
 (0)