fix(projects): reconcile grouped custom names

This commit is contained in:
Mohamed Boudra
2026-07-28 23:33:50 +00:00
parent 34500f30cf
commit 26452a4f01
2 changed files with 64 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
import { describe, expect, it } from "vitest";
import type { WorkspaceDescriptor } from "@/stores/session-store";
import { buildWorkspaceStructureProjects } from "./workspace-structure";
function workspace(input: {
id: string;
projectName: string;
projectCustomName: string | null;
}): WorkspaceDescriptor {
return {
id: input.id,
projectId: `project-${input.id}`,
projectGroupKey: "remote:github.com/acme/app",
projectDisplayName: input.projectName,
projectCustomName: input.projectCustomName,
projectRootPath: `/repo/${input.id}`,
workspaceDirectory: `/repo/${input.id}`,
projectKind: "git",
workspaceKind: "local_checkout",
name: "main",
status: "done",
statusEnteredAt: null,
archivingAt: null,
diffStat: null,
scripts: [],
};
}
describe("buildWorkspaceStructureProjects", () => {
it("promotes a later grouped host's custom project name", () => {
const projects = buildWorkspaceStructureProjects({
sessions: [
{
serverId: "host-a",
workspaces: [workspace({ id: "a", projectName: "acme/app", projectCustomName: null })],
},
{
serverId: "host-b",
workspaces: [
workspace({ id: "b", projectName: "acme/app", projectCustomName: "My App" }),
],
},
],
});
expect(projects).toEqual([
expect.objectContaining({
projectKey: "remote:github.com/acme/app",
projectName: "My App",
}),
]);
});
});

View File

@@ -123,6 +123,7 @@ export function buildWorkspaceStructureProjects(input: {
{
projectKey: string;
projectName: string;
hasCustomName: boolean;
projectKind: WorkspaceDescriptor["projectKind"];
iconWorkingDir: string;
hosts: Map<string, WorkspaceStructureHostPlacement>;
@@ -153,6 +154,7 @@ export function buildWorkspaceStructureProjects(input: {
emptyProject.projectCustomName ??
emptyProject.projectDisplayName ??
projectDisplayNameFromProjectId(projectKey),
hasCustomName: Boolean(emptyProject.projectCustomName),
projectKind: emptyProject.projectKind,
iconWorkingDir: emptyProject.projectRootPath,
hosts: new Map([[session.serverId, placement]]),
@@ -161,6 +163,10 @@ export function buildWorkspaceStructureProjects(input: {
continue;
}
if (emptyProject.projectCustomName && !existing.hasCustomName) {
existing.projectName = emptyProject.projectCustomName;
existing.hasCustomName = true;
}
existing.hosts.set(session.serverId, placement);
}
@@ -180,6 +186,7 @@ export function buildWorkspaceStructureProjects(input: {
workspace.projectCustomName ??
workspace.projectDisplayName ??
projectDisplayNameFromProjectId(projectKey),
hasCustomName: Boolean(workspace.projectCustomName),
projectKind: workspace.projectKind,
iconWorkingDir: workspace.projectRootPath,
hosts: new Map([
@@ -204,6 +211,10 @@ export function buildWorkspaceStructureProjects(input: {
continue;
}
if (workspace.projectCustomName && !existing.hasCustomName) {
existing.projectName = workspace.projectCustomName;
existing.hasCustomName = true;
}
existing.hosts.set(session.serverId, {
serverId: session.serverId,
projectId: workspace.projectId,