fix(projects): preserve selected project identity

This commit is contained in:
Mohamed Boudra
2026-07-28 22:57:45 +00:00
parent ec08367d93
commit 6544ca7419
11 changed files with 92 additions and 21 deletions
@@ -75,7 +75,7 @@ test("creates a worktree and registers it in the source workspace project withou
expect(deps.workspaceGitService.getSnapshot).not.toHaveBeenCalled();
expect(deps.projects.get(sourceProject.projectId)).toEqual({
...sourceProject,
projectGroupKey: path.resolve(sourceProject.rootPath),
projectGroupKey: result.repoRoot,
updatedAt: expect.any(String),
});
expect(events).toEqual([`workspace:${result.workspace.workspaceId}`]);
@@ -68,4 +68,18 @@ describe("deriveProjectGroupKey", () => {
}),
).toBe("remote:github.com/getpaseo/paseo");
});
test("preserves the selected path for a checkout without a remote", () => {
const worktreeRoot = path.resolve("worktree");
const mainRepoRoot = path.resolve("main");
expect(
deriveProjectGroupKey({
rootPath: path.join(worktreeRoot, "packages", "app"),
remoteUrl: null,
worktreeRoot,
mainRepoRoot,
}),
).toBe(path.join(mainRepoRoot, "packages", "app"));
});
});
@@ -11,10 +11,14 @@ export function deriveProjectGroupKey(input: {
mainRepoRoot: string | null;
}): string {
const remoteKey = deriveRemoteProjectGroupKey(input.remoteUrl);
if (!remoteKey) return resolve(input.mainRepoRoot ?? input.rootPath);
const selectedPath = deriveSelectedPath(input.rootPath, input.worktreeRoot);
return selectedPath ? `${remoteKey}#subdir:${selectedPath}` : remoteKey;
if (!remoteKey) {
return selectedPath && input.mainRepoRoot
? resolve(input.mainRepoRoot, selectedPath)
: resolve(input.mainRepoRoot ?? input.rootPath);
}
return selectedPath ? `${remoteKey}#subdir:${encodeSelectedPath(selectedPath)}` : remoteKey;
}
function deriveSelectedPath(rootPath: string, worktreeRoot: string | null): string | null {
@@ -29,6 +33,10 @@ function deriveSelectedPath(rootPath: string, worktreeRoot: string | null): stri
) {
return null;
}
return selectedPath;
}
function encodeSelectedPath(selectedPath: string): string {
return selectedPath.split(sep).map(encodeURIComponent).join("/");
}
@@ -1409,7 +1409,7 @@ describe("WorkspaceReconciliationService", () => {
kind: "project_updated",
projectId: "p1",
directory: rootPath,
fields: { projectGroupKey: "/tmp/main-repo" },
fields: { projectGroupKey: path.resolve("/tmp/main-repo") },
},
{
kind: "workspace_updated",