FN-6817: root reliability fixtures under worker temp
Reliability interaction fixtures now stay inside the Vitest worker temp root to avoid merge-reuse worktree collisions. - Add a helper that prefers FUSION_TEST_WORKER_ROOT for reliability fixture roots. - Verify fixture git initialization before tests use generated repositories. - Clean up the paired worktree root during fixture teardown. - Cover the worker-root placement and worktree-root cleanup behavior in the merge runner preflight test. Files changed: .../__tests__/reliability-interactions/_helpers.ts | 21 ++++++++++++- .../merge-runner-spawn-enoent-prevention.test.ts | 35 ++++++++++++++++++++-- 2 files changed, 53 insertions(+), 3 deletions(-) Fusion-Task-Id: FN-6817 Fusion-Task-Lineage: dd5c5e7b-c7cd-42be-971d-7527c2334f36
This commit is contained in:
@@ -12,6 +12,22 @@ export function git(cwd: string, command: string): string {
|
||||
return execSync(command, { cwd, encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] }).trim();
|
||||
}
|
||||
|
||||
export function reliabilityTestTempParent(): string {
|
||||
/*
|
||||
FNXC:ReliabilityFixtures 2026-06-20-21:24:
|
||||
FN-6817 traced merge-reuse-task-worktree flakes to reliability fixtures escaping the per-invocation Vitest worker root.
|
||||
Keep project roots and their `-worktrees` siblings under FUSION_TEST_WORKER_ROOT so concurrent package lanes and teardown cannot collide through the shared OS temp root.
|
||||
*/
|
||||
return process.env.FUSION_TEST_WORKER_ROOT ?? tmpdir();
|
||||
}
|
||||
|
||||
function assertInitializedGitRepository(rootDir: string): void {
|
||||
const insideWorkTree = git(rootDir, "git rev-parse --is-inside-work-tree");
|
||||
if (insideWorkTree !== "true") {
|
||||
throw new Error(`Reliability fixture git init did not create a usable repository at ${rootDir}`);
|
||||
}
|
||||
}
|
||||
|
||||
export type ReliabilityFixture = {
|
||||
rootDir: string;
|
||||
store: TaskStore;
|
||||
@@ -40,8 +56,10 @@ export async function makeReliabilityFixture(input: {
|
||||
task?: Partial<Task>;
|
||||
settings?: Partial<Settings>;
|
||||
} = {}): Promise<ReliabilityFixture> {
|
||||
const rootDir = await mkdtemp(join(tmpdir(), "fusion-reliability-"));
|
||||
const rootDir = await mkdtemp(join(reliabilityTestTempParent(), "fusion-reliability-"));
|
||||
const worktreeRoot = `${rootDir}-worktrees`;
|
||||
git(rootDir, "git init -b main");
|
||||
assertInitializedGitRepository(rootDir);
|
||||
git(rootDir, 'git config user.email "test@example.com"');
|
||||
git(rootDir, 'git config user.name "Test User"');
|
||||
await writeFile(join(rootDir, "README.md"), "# fixture\n", "utf-8");
|
||||
@@ -87,6 +105,7 @@ export async function makeReliabilityFixture(input: {
|
||||
manager.stop();
|
||||
store.close();
|
||||
await rm(rootDir, { recursive: true, force: true });
|
||||
await rm(worktreeRoot, { recursive: true, force: true });
|
||||
},
|
||||
writeAndCommit: async (file, content, message) => {
|
||||
const absolute = join(rootDir, file);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { mkdir, rm, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { existsSync } from "node:fs";
|
||||
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join, sep } from "node:path";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
vi.mock("../../pi.js", () => ({
|
||||
@@ -82,6 +84,35 @@ describe("FN-6278 reliability interactions: merge runner cwd preflight", () => {
|
||||
executingTaskLock._clearForTest();
|
||||
});
|
||||
|
||||
it.skipIf(!hasGit)("FN-6817: roots the shared reliability fixture under the Vitest worker root", async () => {
|
||||
const previousWorkerRoot = process.env.FUSION_TEST_WORKER_ROOT;
|
||||
const workerRoot = await mkdtemp(join(tmpdir(), "fn-6817-worker-root-"));
|
||||
process.env.FUSION_TEST_WORKER_ROOT = workerRoot;
|
||||
let fixture: Awaited<ReturnType<typeof makeReliabilityFixture>> | undefined;
|
||||
|
||||
try {
|
||||
fixture = await makeReliabilityFixture({ taskId: "FN-6817-RI-WORKER-ROOT" });
|
||||
const worktreeRoot = `${fixture.rootDir}-worktrees`;
|
||||
await mkdir(worktreeRoot, { recursive: true });
|
||||
|
||||
expect(fixture.rootDir.startsWith(`${workerRoot}${sep}`)).toBe(true);
|
||||
expect(worktreeRoot.startsWith(`${workerRoot}${sep}`)).toBe(true);
|
||||
expect(git(fixture.rootDir, "git rev-parse --is-inside-work-tree")).toBe("true");
|
||||
|
||||
await fixture.cleanup();
|
||||
fixture = undefined;
|
||||
expect(existsSync(worktreeRoot)).toBe(false);
|
||||
} finally {
|
||||
if (fixture) await fixture.cleanup();
|
||||
if (previousWorkerRoot === undefined) {
|
||||
delete process.env.FUSION_TEST_WORKER_ROOT;
|
||||
} else {
|
||||
process.env.FUSION_TEST_WORKER_ROOT = previousWorkerRoot;
|
||||
}
|
||||
await rm(workerRoot, RM);
|
||||
}
|
||||
});
|
||||
|
||||
it.skipIf(!hasGit)("reacquires before spawning git when the reuse worktree cwd vanished", async () => {
|
||||
const { fixture, rootDir, store, taskId, branch, worktreeRoot, worktreePath } = await setupReuseMergeFixture({
|
||||
taskId: "FN-6278-RI-VANISHED",
|
||||
|
||||
Reference in New Issue
Block a user