Update engine tests so child_process mocks cover execFile alongside exec. - add execFile mock implementations and promisify support in branch/worktree tests that rely on child_process behavior - extend simpler child_process mocks in integration, sandbox, and worktree tests to export execFile stubs - keep existing exec and execSync mock behavior unchanged while restoring compatibility with code that now imports execFile Files changed: packages/engine/src/__tests__/branch-autocorrect.test.ts | 9 ++++++++- .../engine/src/__tests__/branch-conflicts-self-owned.test.ts | 9 ++++++++- packages/engine/src/__tests__/branch-conflicts.test.ts | 9 ++++++++- packages/engine/src/__tests__/integration-branch.test.ts | 1 + .../engine/src/__tests__/sandbox/bubblewrap-detect.test.ts | 1 + .../engine/src/__tests__/sandbox/sandbox-exec-backend.test.ts | 1 + .../engine/src/__tests__/sandbox/sandbox-exec-detect.test.ts | 1 + .../engine/src/__tests__/worktree-acquisition-backend.test.ts | 2 +- .../src/__tests__/worktree-acquisition-worktrunk.test.ts | 2 +- packages/engine/src/__tests__/worktree-backend.test.ts | 2 +- .../engine/src/__tests__/worktree-hooks-cross-platform.test.ts | 2 +- packages/engine/src/__tests__/worktree-pool.test.ts | 10 ++++++++-- packages/engine/src/__tests__/worktree-stale-lock.test.ts | 2 +- .../engine/src/__tests__/worktree-stale-registration.test.ts | 2 +- 14 files changed, 42 insertions(+), 11 deletions(-) Fusion-Task-Id: FN-6004 Fusion-Task-Lineage: f87fb103-fe5d-4fc9-a640-9991c06e6448
34 lines
1.3 KiB
TypeScript
34 lines
1.3 KiB
TypeScript
import { mkdtempSync } from "node:fs";
|
|
import { access, mkdir, readFile } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
|
|
const { execMock } = vi.hoisted(() => ({ execMock: vi.fn() }));
|
|
vi.mock("node:child_process", () => ({ exec: execMock, execFile: vi.fn() }));
|
|
|
|
import { writeFileAtomic } from "../worktree-hooks.js";
|
|
|
|
describe("worktree-hooks cross-platform", () => {
|
|
it("creates missing parent directories without shell mkdir", async () => {
|
|
const root = mkdtempSync(join(tmpdir(), "wt-hooks-xplat-"));
|
|
const target = join(root, "nested", "hooks", "pre-commit");
|
|
await writeFileAtomic(target, "#!/bin/sh\n");
|
|
|
|
await expect(access(target)).resolves.toBeUndefined();
|
|
expect(execMock.mock.calls.some((c) => typeof c[0] === "string" && c[0].startsWith("mkdir"))).toBe(false);
|
|
});
|
|
|
|
it("is idempotent when parent directory already exists", async () => {
|
|
const root = mkdtempSync(join(tmpdir(), "wt-hooks-xplat-existing-"));
|
|
const parent = join(root, "hooks");
|
|
const target = join(parent, "commit-msg");
|
|
|
|
await mkdir(parent, { recursive: true });
|
|
await writeFileAtomic(target, "first\n");
|
|
await writeFileAtomic(target, "first\n");
|
|
|
|
expect(await readFile(target, "utf-8")).toBe("first\n");
|
|
});
|
|
});
|