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"); 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 () => { it("should ignore invalid fusion.db files in the cwd", async () => {
const projectPath = join(tempDir, "invalid-project"); const projectPath = join(tempDir, "invalid-project");
mkdirSync(join(projectPath, ".fusion"), { recursive: true }); mkdirSync(join(projectPath, ".fusion"), { recursive: true });

View File

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