test(FN-4623): cover backend layout resolution paths
Fusion-Task-Id: FN-4623 Fusion-Task-Lineage: 58122853-cab7-4102-9649-4ceda4c5959e
This commit is contained in:
committed by
gsxdsm
parent
0f372f67c3
commit
a2245e1959
@@ -112,6 +112,13 @@ describe("NativeWorktreeBackend", () => {
|
||||
expect.objectContaining({ cwd: "/repo", timeout: 120000, maxBuffer: 10485760 }),
|
||||
);
|
||||
});
|
||||
|
||||
it("resolves native worktree path via configured worktreesDir", async () => {
|
||||
const backend = new NativeWorktreeBackend({ settings: { worktreesDir: "../{repo}.worktrees" } as any });
|
||||
await expect(
|
||||
backend.resolveWorktreePath({ rootDir: "/repo/project", worktreeName: "fn-1", branch: "fusion/fn-1" }),
|
||||
).resolves.toBe("/repo/project.worktrees/fn-1");
|
||||
});
|
||||
});
|
||||
|
||||
describe("WorktrunkWorktreeBackend", () => {
|
||||
@@ -268,6 +275,29 @@ describe("WorktrunkWorktreeBackend", () => {
|
||||
).rejects.toMatchObject({ code: "worktrunk_sync_conflict", operation: "sync" });
|
||||
});
|
||||
|
||||
it("resolves worktrunk path from wt config show template", async () => {
|
||||
execFileMock.mockResolvedValue({ stdout: '{"config":{"worktree-path":"{{ repo_path }}/../{{ repo }}.{{ branch | sanitize }}"}}', stderr: "" });
|
||||
const backend = new WorktrunkWorktreeBackend({ binaryPath: "worktrunk" });
|
||||
|
||||
await expect(
|
||||
backend.resolveWorktreePath({ rootDir: "/repo/project", worktreeName: "ignored", branch: "fusion/fn-1" }),
|
||||
).resolves.toBe("/repo/project.fusion-fn-1");
|
||||
expect(execFileMock).toHaveBeenCalledWith(
|
||||
"worktrunk",
|
||||
["config", "show", "--format", "json"],
|
||||
expect.objectContaining({ cwd: "/repo/project", timeout: 5000, maxBuffer: 10485760 }),
|
||||
);
|
||||
});
|
||||
|
||||
it("falls back to default layout template when config cannot be read", async () => {
|
||||
execFileMock.mockRejectedValue(new Error("missing config"));
|
||||
const backend = new WorktrunkWorktreeBackend({ binaryPath: "worktrunk" });
|
||||
|
||||
await expect(
|
||||
backend.resolveWorktreePath({ rootDir: "/repo/project", worktreeName: "ignored", branch: "fusion/fn-1" }),
|
||||
).resolves.toBe("/repo/project/.worktrees/fusion-fn-1");
|
||||
});
|
||||
|
||||
it("prunes by listing worktrees and removing worktrunk managed entries", async () => {
|
||||
execMock.mockResolvedValue({
|
||||
stdout:
|
||||
|
||||
@@ -4,6 +4,7 @@ import { join, resolve } from "node:path";
|
||||
import {
|
||||
isInsideConfiguredWorktreesDir,
|
||||
resolveTaskWorktreePath,
|
||||
resolveTaskWorktreePathForBackend,
|
||||
resolveWorktreesDir,
|
||||
} from "../worktree-paths.js";
|
||||
|
||||
@@ -47,4 +48,17 @@ describe("worktree-paths", () => {
|
||||
expect(isInsideConfiguredWorktreesDir(rootDir, undefined, join(rootDir, ".worktrees", "fn-1"))).toBe(true);
|
||||
expect(isInsideConfiguredWorktreesDir(rootDir, undefined, join(rootDir, "fn-1"))).toBe(false);
|
||||
});
|
||||
|
||||
it("delegates to worktrunk backend path resolver", async () => {
|
||||
const resolver = async () => "/tmp/custom/fusion-fn-1";
|
||||
await expect(
|
||||
resolveTaskWorktreePathForBackend(rootDir, "fn-1", undefined, { kind: "worktrunk", resolveWorktreePath: resolver }, "fusion/fn-1"),
|
||||
).resolves.toBe("/tmp/custom/fusion-fn-1");
|
||||
});
|
||||
|
||||
it("falls back to native resolver for non-worktrunk backends", async () => {
|
||||
await expect(
|
||||
resolveTaskWorktreePathForBackend(rootDir, "fn-1", { worktreesDir: "../{repo}.worktrees" } as any, { kind: "native" }, "fusion/fn-1"),
|
||||
).resolves.toBe(resolve(rootDir, "../repo-name.worktrees/fn-1"));
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user