test(FN-4904): add core resolver integration coverage
Fusion-Task-Id: FN-4904 Fusion-Task-Lineage: 5da52c8c-0ed6-4e3a-920e-aa1b56d0b719
This commit is contained in:
committed by
gsxdsm
parent
87d259b366
commit
b40a58d693
@@ -1,5 +1,8 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { getProjectRootFromWorktree } from "../pi-extensions.js";
|
||||
import { mkdtempSync, mkdirSync, rmSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { tmpdir } from "node:os";
|
||||
import { getProjectRootFromWorktree, resolvePiExtensionProjectRoot } from "../pi-extensions.js";
|
||||
|
||||
describe("getProjectRootFromWorktree", () => {
|
||||
it("detects POSIX worktree paths", () => {
|
||||
@@ -26,3 +29,46 @@ describe("getProjectRootFromWorktree", () => {
|
||||
).toBe("/tmp");
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolvePiExtensionProjectRoot", () => {
|
||||
it("prefers parent repo root for worktree paths when parent .fusion exists", () => {
|
||||
const root = mkdtempSync(join(tmpdir(), "fn-4904-root-"));
|
||||
try {
|
||||
mkdirSync(join(root, ".fusion"), { recursive: true });
|
||||
mkdirSync(join(root, ".worktrees", "feature", ".fusion"), { recursive: true });
|
||||
const cwd = join(root, ".worktrees", "feature", "sub");
|
||||
mkdirSync(cwd, { recursive: true });
|
||||
|
||||
expect(resolvePiExtensionProjectRoot(cwd)).toBe(root);
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it("falls back to legacy walk when parent repo root does not have .fusion", () => {
|
||||
const root = mkdtempSync(join(tmpdir(), "fn-4904-root-"));
|
||||
try {
|
||||
const worktreeRoot = join(root, ".worktrees", "feature");
|
||||
mkdirSync(join(worktreeRoot, ".fusion"), { recursive: true });
|
||||
const cwd = join(worktreeRoot, "sub");
|
||||
mkdirSync(cwd, { recursive: true });
|
||||
|
||||
expect(resolvePiExtensionProjectRoot(cwd)).toBe(worktreeRoot);
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it("preserves non-worktree behavior", () => {
|
||||
const root = mkdtempSync(join(tmpdir(), "fn-4904-root-"));
|
||||
try {
|
||||
mkdirSync(join(root, ".fusion"), { recursive: true });
|
||||
const cwd = join(root, "sub", "dir");
|
||||
mkdirSync(cwd, { recursive: true });
|
||||
|
||||
expect(resolvePiExtensionProjectRoot(cwd)).toBe(root);
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user