FN-5952: delete obsolete cwd-fallback-removed test

Remove obsolete cwd-fallback reliability coverage and keep the remaining worktree recovery test portable.

- delete the skipped reliability-interactions cwd fallback removal test that no longer covers a distinct path
- update executor worktree recovery to use os.tmpdir() and clean up its temporary root in finally

Files changed:
 .../engine/src/__tests__/executor-worktree.test.ts | 57 ++++++++++++----------
 .../cwd-integration-fallback-removed.test.ts       | 56 ---------------------
 2 files changed, 31 insertions(+), 82 deletions(-)

Fusion-Task-Id: FN-5952

Fusion-Task-Lineage: 8a621b9c-ec24-4400-93c7-e9d946e15283
This commit is contained in:
gsxdsm
2026-06-07 14:24:28 -07:00
parent 645f3c22fe
commit 23eb7e25c5
2 changed files with 31 additions and 82 deletions

View File

@@ -1695,37 +1695,42 @@ describe("TaskExecutor worktree recovery", () => {
it("removes existing directory that is not a registered worktree", async () => {
const store = createMockStore();
const fs = await import("node:fs/promises");
const tempRoot = await fs.mkdtemp("/tmp/executor-worktree-");
const staleWorktreePath = `${tempRoot}/.worktrees/swift-falcon`;
const { tmpdir } = await import("node:os");
const rootDir = await fs.mkdtemp(`${tmpdir()}/executor-worktree-`);
const staleWorktreePath = `${rootDir}/.worktrees/swift-falcon`;
// Directory exists but is not registered
mockedExistsSync.mockReturnValue(true);
try {
// Directory exists but is not registered
mockedExistsSync.mockImplementation((path) => String(path) === staleWorktreePath);
await fs.mkdir(staleWorktreePath, { recursive: true });
await fs.writeFile(`${staleWorktreePath}/marker.txt`, "stale");
await fs.mkdir(staleWorktreePath, { recursive: true });
await fs.writeFile(`${staleWorktreePath}/marker.txt`, "stale");
// Mock git worktree list to not include our path
mockedExecSync.mockImplementation((cmd: string | string[]) => {
const command = typeof cmd === "string" ? cmd : cmd[0];
if (command.includes("git worktree list")) {
return Buffer.from("/other/path/.git/worktrees/other\n");
}
return Buffer.from("");
});
// Mock git worktree list to not include our path
mockedExecSync.mockImplementation((cmd: string | string[]) => {
const command = typeof cmd === "string" ? cmd : cmd[0];
if (command.includes("git worktree list")) {
return Buffer.from("/other/path/.git/worktrees/other\n");
}
return Buffer.from("");
});
const executor = new TaskExecutor(store, tempRoot);
await executor.execute(makeTask());
const executor = new TaskExecutor(store, rootDir);
await executor.execute(makeTask());
expect(
mockedExecSync.mock.calls.some((call) =>
typeof call[0] === "string" && call[0].includes("rm -rf"),
),
).toBe(false);
await expect(fs.access(staleWorktreePath)).rejects.toThrow();
expect(store.logEntry).toHaveBeenCalledWith(
"FN-050",
expect.stringContaining("Removing existing directory (not a registered worktree)"),
);
expect(
mockedExecSync.mock.calls.some((call) =>
typeof call[0] === "string" && call[0].includes("rm -rf"),
),
).toBe(false);
await expect(fs.access(staleWorktreePath)).rejects.toThrow();
expect(store.logEntry).toHaveBeenCalledWith(
"FN-050",
expect.stringContaining("Removing existing directory (not a registered worktree)"),
);
} finally {
await fs.rm(rootDir, { recursive: true, force: true });
}
});
it("handles locked worktree by unlocking before removal", async () => {

View File

@@ -1,56 +0,0 @@
import { mkdir } from "node:fs/promises";
import { join } from "node:path";
import { describe, expect, it } from "vitest";
import { aiMergeTask } from "../../merger.js";
import { git, makeReliabilityFixture } from "./_helpers.js";
describe("FN-5348 reliability interactions: cwd fallback removal", () => {
// FN-5348 dirty-refusal path replaced by autostash. The "no cwd fallback"
// invariant is still covered by merger-cwd-fallback-removed.test.ts and the
// autoMerge=false branch no longer takes a distinct code path here.
it.skip("autoMerge=false + dirty reused worktree autostashes and proceeds without any cwd fallback events", async () => {
const fixture = await makeReliabilityFixture({
taskId: "FN-5348-RI-AUTO-OFF-AUTOSTASH",
settings: {
autoMerge: false,
baseBranch: "master",
mergeIntegrationWorktree: "reuse-task-worktree",
} as any,
});
try {
const { rootDir, store, task } = fixture;
const actualTask = await store.getTask(task.id);
const branch = `fusion/${actualTask!.id.toLowerCase()}`;
const worktreeRoot = `${rootDir}-worktrees`;
const worktreePath = join(worktreeRoot, actualTask!.id.toLowerCase());
git(rootDir, "git branch -m main master");
const completedSteps = (actualTask?.steps ?? []).map((step) => ({ ...step, status: "done" as const }));
await store.updateTask(task.id, {
baseBranch: "master",
branch,
steps: completedSteps,
currentStep: completedSteps.length,
} as any);
await fixture.createBranch(branch);
await fixture.writeAndCommit("packages/engine/src/fn-5348-ri-refusal.ts", "export const refusal = true;\n", "feat: add refusal merge content");
await fixture.checkout("master");
await mkdir(worktreeRoot, { recursive: true });
git(rootDir, `git worktree add ${JSON.stringify(worktreePath)} ${JSON.stringify(branch)}`);
await store.updateTask(task.id, { worktree: worktreePath, branch } as any);
store.enqueueMergeQueue(task.id);
git(worktreePath, "sh -c 'printf dirty > DIRTY.txt'");
await aiMergeTask(store, rootDir, task.id).catch(() => undefined);
const auditTypes = store.getRunAuditEvents({ taskId: task.id }).map((event) => event.mutationType);
expect(auditTypes).toContain("merge:reuse-handoff-autostash");
expect(auditTypes).not.toContain("merge:cwd-integration-fallback-removed");
expect(auditTypes).not.toContain("merge:cwd-integration-fallback-refused");
} finally {
await fixture.cleanup();
}
}, 30_000);
});