fix(FN-XXXX): avoid inheriting unregistered parent projects

This commit is contained in:
gsxdsm
2026-05-01 23:35:44 -07:00
parent 9e52028102
commit 9fc5fd99c4
3 changed files with 28 additions and 9 deletions

View File

@@ -0,0 +1,5 @@
---
"@runfusion/fusion": patch
---
Limit unregistered project detection to the exact current working directory.

View File

@@ -118,6 +118,16 @@ describe("project-context", () => {
expect(found?.name).toBe("legacy-project");
});
it("should not inherit an unregistered parent project from a nested cwd", async () => {
const projectPath = createMockProject("legacy-project");
const nestedDir = join(projectPath, "src", "components");
mkdirSync(nestedDir, { recursive: true });
const found = await detectProjectFromCwd(nestedDir, central);
expect(found).toBeUndefined();
});
it("should ignore invalid fusion.db files in the cwd", async () => {
const projectPath = join(tempDir, "invalid-project");
mkdirSync(join(projectPath, ".fusion"), { recursive: true });

View File

@@ -180,7 +180,8 @@ export async function detectProjectFromCwd(
cwd: string,
central: CentralCore
): Promise<RegisteredProject | { id: string; name: string; path: string } | undefined> {
let currentDir = resolve(cwd);
const startDir = resolve(cwd);
let currentDir = startDir;
// Walk up the directory tree
while (true) {
@@ -192,14 +193,17 @@ export async function detectProjectFromCwd(
if (project) {
return project;
}
// Not registered, but has .fusion/fusion.db - still use it as a valid project
// This preserves legacy single-project CLI behavior.
// Use empty string for id to indicate unregistered status.
return {
id: "",
name: basename(currentDir) || "current-project",
path: currentDir,
};
// For unregistered projects, only accept an exact CWD match.
// This preserves legacy single-project behavior without accidentally
// resolving unrelated parent directories higher in the filesystem.
if (currentDir === startDir) {
return {
id: "",
name: basename(currentDir) || "current-project",
path: currentDir,
};
}
}
// Move up to parent