fix(projects): preserve selected host identity

This commit is contained in:
Mohamed Boudra
2026-07-28 22:18:48 +00:00
parent 8f89aee756
commit d3d59749b0
4 changed files with 107 additions and 2 deletions

View File

@@ -66,6 +66,17 @@ async function expectOneProjectContainsBothWorkspaces(
await expect(page.locator('[data-testid^="sidebar-project-row-"]')).toHaveCount(1);
}
async function openGroupedProjectSettings(page: Page): Promise<void> {
const projectRow = page.locator('[data-testid^="sidebar-project-row-"]').first();
const testId = await projectRow.getAttribute("data-testid");
if (!testId) throw new Error("Grouped project row has no test ID");
const projectKey = testId.slice("sidebar-project-row-".length);
await projectRow.hover();
await page.getByTestId(`sidebar-project-kebab-${projectKey}`).click();
await page.getByTestId(`sidebar-project-menu-open-settings-${projectKey}`).click();
await expect(page.getByTestId("host-picker")).toBeVisible({ timeout: 30_000 });
}
async function readPersistedProjectGroupKey(host: IsolatedHostDaemon): Promise<unknown> {
const projectsPath = path.join(host.paseoHome, "projects", "projects.json");
const projects = JSON.parse(await readFile(projectsPath, "utf8")) as Array<
@@ -231,4 +242,33 @@ test.describe("Sidebar project grouping", () => {
.poll(() => readPersistedProjectGroupKey(reconciledCrossHostProject.secondaryHost))
.toBe("remote:github.com/paseo-e2e/grouped-project");
});
test("resets a rename draft when switching grouped-project hosts", async ({
page,
crossHostProject,
}) => {
await gotoAppShell(page);
await addConnectedHostAndReload(page, {
serverId: crossHostProject.secondaryHost.serverId,
label: SECONDARY_HOST_LABEL,
port: crossHostProject.secondaryHost.port,
});
await waitForConnectedHost(page, {
serverId: crossHostProject.secondaryHost.serverId,
endpoint: `localhost:${crossHostProject.secondaryHost.port}`,
});
await expectOneProjectContainsBothWorkspaces(page, crossHostProject);
await openGroupedProjectSettings(page);
await page.getByTestId("project-name-edit-button").click();
const nameInput = page.getByTestId("project-name-input");
await nameInput.fill("Draft from the first host");
await page.getByTestId("host-picker").click();
await page.getByTestId(`host-picker-item-${crossHostProject.secondary.serverId}`).click();
await expect(nameInput).not.toBeVisible();
await page.getByTestId("project-name-edit-button").click();
await expect(page.getByTestId("project-name-input")).toHaveValue("");
});
});

View File

@@ -242,6 +242,7 @@ function ProjectSettingsBody({
projectKey={project.projectKey}
/>
<ProjectNameEditor
key={selectedHost.projectId ?? project.projectKey}
projectName={selectedHost.projectName}
projectCustomName={selectedHost.projectCustomName}
projectId={selectedHost.projectId ?? project.projectKey}

View File

@@ -33,7 +33,7 @@ export function classifyDirectoryForProjectMembership(input: {
const cwd = resolve(input.cwd);
const checkout: ProjectCheckoutLitePayload = { ...input.checkout, cwd };
const projectKey = deriveProjectGroupKey({
rootPath: checkout.worktreeRoot ?? cwd,
rootPath: cwd,
remoteUrl: checkout.remoteUrl,
worktreeRoot: checkout.worktreeRoot,
mainRepoRoot: checkout.mainRepoRoot,
@@ -54,7 +54,8 @@ export function classifyDirectoryForProjectMembership(input: {
function deriveWorkspaceDirectoryKey(cwd: string, checkout: ProjectCheckoutLitePayload): string {
const worktreeRoot = checkout.worktreeRoot ? parseGitRevParsePath(checkout.worktreeRoot) : null;
return worktreeRoot ?? resolve(cwd);
const selectedRoot = resolve(cwd);
return worktreeRoot && resolve(worktreeRoot) === selectedRoot ? worktreeRoot : selectedRoot;
}
function deriveProjectGroupingName(projectKey: string): string {

View File

@@ -377,6 +377,69 @@ describe("bootstrapWorkspaceRegistries", () => {
]);
});
test("keeps legacy agents in different monorepo subprojects separate", async () => {
const appProject = path.join(GIT_PROJECT, "packages", "app");
const serverProject = path.join(GIT_PROJECT, "packages", "server");
mkdirSync(appProject, { recursive: true });
mkdirSync(serverProject, { recursive: true });
workspaceGitService = createNoopWorkspaceGitService({
getCheckout: async (cwd) => ({
cwd,
isGit: true,
currentBranch: "main",
remoteUrl: "git@github.com:acme/legacy-project.git",
worktreeRoot: GIT_PROJECT,
isPaseoOwnedWorktree: false,
mainRepoRoot: null,
}),
});
await agentStorage.initialize();
for (const [id, cwd] of [
["app-agent", appProject],
["server-agent", serverProject],
]) {
await agentStorage.upsert({
id,
provider: "codex",
cwd,
createdAt: "2026-03-01T00:00:00.000Z",
updatedAt: "2026-03-02T00:00:00.000Z",
lastActivityAt: "2026-03-02T00:00:00.000Z",
lastUserMessageAt: null,
title: null,
labels: {},
lastStatus: "idle",
lastModeId: null,
config: null,
runtimeInfo: { provider: "codex", sessionId: null },
persistence: null,
archivedAt: null,
});
}
await bootstrapWorkspaceRegistries({
paseoHome,
agentStorage,
projectRegistry,
workspaceRegistry,
workspaceGitService,
logger,
});
expect((await projectRegistry.list()).map((project) => project.projectId).sort()).toEqual([
"remote:github.com/acme/legacy-project#subdir:packages/app",
"remote:github.com/acme/legacy-project#subdir:packages/server",
]);
expect(
new Set((await workspaceRegistry.list()).map((workspace) => workspace.projectId)),
).toEqual(
new Set([
"remote:github.com/acme/legacy-project#subdir:packages/app",
"remote:github.com/acme/legacy-project#subdir:packages/server",
]),
);
});
test("migrates cwd-only agents to the oldest existing same-cwd workspace", async () => {
await projectRegistry.initialize();
await workspaceRegistry.initialize();