fix(FN-XXXX): avoid inheriting unregistered parent projects
This commit is contained in:
5
.changeset/fix-unregistered-project-detection.md
Normal file
5
.changeset/fix-unregistered-project-detection.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@runfusion/fusion": patch
|
||||
---
|
||||
|
||||
Limit unregistered project detection to the exact current working directory.
|
||||
@@ -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 });
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user