diff --git a/packages/app/src/projects/workspace-structure.test.ts b/packages/app/src/projects/workspace-structure.test.ts new file mode 100644 index 000000000..3f32c2201 --- /dev/null +++ b/packages/app/src/projects/workspace-structure.test.ts @@ -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", + }), + ]); + }); +}); diff --git a/packages/app/src/projects/workspace-structure.ts b/packages/app/src/projects/workspace-structure.ts index 059385c0c..8d6feba43 100644 --- a/packages/app/src/projects/workspace-structure.ts +++ b/packages/app/src/projects/workspace-structure.ts @@ -123,6 +123,7 @@ export function buildWorkspaceStructureProjects(input: { { projectKey: string; projectName: string; + hasCustomName: boolean; projectKind: WorkspaceDescriptor["projectKind"]; iconWorkingDir: string; hosts: Map; @@ -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,