test(FN-4753): complete Step 4 — update unit tests for removeWorktree
Fusion-Task-Id: FN-4753 Fusion-Task-Lineage: 8229b56a-8997-4faf-8872-18e49b9386ff
This commit is contained in:
committed by
gsxdsm
parent
0fc2b9e6b2
commit
d808d8f979
@@ -10,6 +10,7 @@ import { reviewStep as mockedReviewStepFn } from "../reviewer.js";
|
||||
import { execSync } from "node:child_process";
|
||||
import { findWorktreeUser, aiMergeTask } from "../merger.js";
|
||||
import { WorktreePool } from "../worktree-pool.js";
|
||||
import * as worktreePoolModule from "../worktree-pool.js";
|
||||
import { BranchConflictError } from "../branch-conflicts.js";
|
||||
import * as branchConflictModule from "../branch-conflicts.js";
|
||||
import { generateWorktreeName, slugify } from "../worktree-names.js";
|
||||
@@ -1129,7 +1130,7 @@ describe("TaskExecutor worktree recovery", () => {
|
||||
|
||||
// Should have cleaned up the conflicting worktree
|
||||
expect(mockedExecSync).toHaveBeenCalledWith(
|
||||
expect.stringContaining('git worktree remove "/tmp/test/.worktrees/green-sage" --force'),
|
||||
expect.stringContaining('git worktree remove --force "/tmp/test/.worktrees/green-sage"'),
|
||||
expect.any(Object),
|
||||
);
|
||||
|
||||
@@ -1720,6 +1721,7 @@ describe("TaskExecutor dependency-based worktree creation", () => {
|
||||
const store = createMockStore();
|
||||
const executor = new TaskExecutor(store, "/tmp/test");
|
||||
const conflictingPath = "/tmp/test/.worktrees/sharp-stone";
|
||||
const removeWorktreeSpy = vi.spyOn(worktreePoolModule, "removeWorktree");
|
||||
|
||||
let firstAttempt = true;
|
||||
mockedExecSync.mockImplementation((cmd: any) => {
|
||||
@@ -1738,9 +1740,13 @@ describe("TaskExecutor dependency-based worktree creation", () => {
|
||||
|
||||
await executor.execute(makeTask({ id: "FN-064" }));
|
||||
|
||||
expect(mockedExecSync).toHaveBeenCalledWith(
|
||||
`git worktree remove "${conflictingPath}" --force`,
|
||||
expect.objectContaining({ cwd: "/tmp/test" }),
|
||||
expect(removeWorktreeSpy).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
worktreePath: conflictingPath,
|
||||
rootDir: "/tmp/test",
|
||||
taskId: "FN-064",
|
||||
settings: expect.any(Object),
|
||||
}),
|
||||
);
|
||||
expect(mockedExecSync).toHaveBeenCalledWith(
|
||||
'git branch -D "fusion/fn-064"',
|
||||
@@ -1775,7 +1781,7 @@ describe("TaskExecutor dependency-based worktree creation", () => {
|
||||
);
|
||||
throw err;
|
||||
}
|
||||
if (cmd === `git worktree remove "${conflictingPath}" --force`) {
|
||||
if (cmd === `git worktree remove --force "${conflictingPath}"`) {
|
||||
throw new Error("remove failed");
|
||||
}
|
||||
return Buffer.from("");
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
StepSessionExecutor,
|
||||
} from "../step-session-executor.js";
|
||||
import { AgentLogger } from "../agent-logger.js";
|
||||
import * as worktreeBackendModule from "../worktree-backend.js";
|
||||
import type { TaskDetail, Settings, TaskStore } from "@fusion/core";
|
||||
|
||||
// ── Shared test fixtures ──────────────────────────────────────────────
|
||||
@@ -1889,6 +1890,8 @@ describe("StepSessionExecutor", () => {
|
||||
mockedCreateFnAgent.mockResolvedValue({ session } as any);
|
||||
mockedExecSync.mockReturnValue("");
|
||||
|
||||
const removeWorktreeSpy = vi.spyOn(worktreeBackendModule, "removeWorktree");
|
||||
|
||||
const executor = new StepSessionExecutor({
|
||||
taskDetail: task,
|
||||
worktreePath: "/project/.worktrees/main",
|
||||
@@ -1899,10 +1902,13 @@ describe("StepSessionExecutor", () => {
|
||||
await executor.executeAll();
|
||||
await executor.cleanup();
|
||||
|
||||
// Verify cleanup was called with git worktree remove
|
||||
expect(mockedExecSync).toHaveBeenCalledWith(
|
||||
expect.stringContaining("git worktree remove"),
|
||||
expect.objectContaining({ cwd: "/project" }),
|
||||
expect(removeWorktreeSpy).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
rootDir: "/project",
|
||||
taskId: "FN-001",
|
||||
settings,
|
||||
worktreePath: expect.stringContaining("/project/.worktrees/"),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user