fix(server): skip home directory in workspace prefix matching (#563)
Skip the home directory in workspace prefix matching so child paths under the home workspace get their own workspace records. Closes #562
This commit is contained in:
@@ -6257,8 +6257,10 @@ export class Session {
|
|||||||
return exact.workspaceId;
|
return exact.workspaceId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const userHome = homedir();
|
||||||
let bestMatch: PersistedWorkspaceRecord | null = null;
|
let bestMatch: PersistedWorkspaceRecord | null = null;
|
||||||
for (const workspace of workspaces) {
|
for (const workspace of workspaces) {
|
||||||
|
if (workspace.cwd === userHome) continue;
|
||||||
const prefix = workspace.cwd.endsWith(sep) ? workspace.cwd : `${workspace.cwd}${sep}`;
|
const prefix = workspace.cwd.endsWith(sep) ? workspace.cwd : `${workspace.cwd}${sep}`;
|
||||||
if (!normalizedCwd.startsWith(prefix)) {
|
if (!normalizedCwd.startsWith(prefix)) {
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { execSync } from "node:child_process";
|
import { execSync } from "node:child_process";
|
||||||
import { mkdtempSync, realpathSync, rmSync, writeFileSync } from "node:fs";
|
import { mkdtempSync, realpathSync, rmSync, writeFileSync } from "node:fs";
|
||||||
import { tmpdir } from "node:os";
|
import { homedir, tmpdir } from "node:os";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { expect, test, vi } from "vitest";
|
import { expect, test, vi } from "vitest";
|
||||||
import { Session } from "./session.js";
|
import { Session } from "./session.js";
|
||||||
@@ -51,6 +51,10 @@ interface SessionTestAccess {
|
|||||||
getAgentPayloadById(agentId: string): Promise<unknown>;
|
getAgentPayloadById(agentId: string): Promise<unknown>;
|
||||||
buildProjectPlacementForCwd(cwd: string): Promise<unknown>;
|
buildProjectPlacementForCwd(cwd: string): Promise<unknown>;
|
||||||
buildProjectPlacement(cwd: string): Promise<unknown>;
|
buildProjectPlacement(cwd: string): Promise<unknown>;
|
||||||
|
resolveRegisteredWorkspaceIdForCwd(
|
||||||
|
cwd: string,
|
||||||
|
workspaces: ReturnType<typeof createPersistedWorkspaceRecord>[],
|
||||||
|
): string;
|
||||||
buildWorkspaceDescriptorMap(...args: unknown[]): Promise<Map<string, unknown>>;
|
buildWorkspaceDescriptorMap(...args: unknown[]): Promise<Map<string, unknown>>;
|
||||||
describeWorkspaceRecord(...args: unknown[]): Promise<unknown>;
|
describeWorkspaceRecord(...args: unknown[]): Promise<unknown>;
|
||||||
describeWorkspaceRecordWithGitData(...args: unknown[]): Promise<unknown>;
|
describeWorkspaceRecordWithGitData(...args: unknown[]): Promise<unknown>;
|
||||||
@@ -3747,3 +3751,21 @@ test("subscribed fetch_workspaces includes git enrichment in the initial snapsho
|
|||||||
expect(workspaceUpdates).toEqual([]);
|
expect(workspaceUpdates).toEqual([]);
|
||||||
expect(session.describeWorkspaceRecordWithGitData).toHaveBeenCalledWith(gitWorkspace, gitProject);
|
expect(session.describeWorkspaceRecordWithGitData).toHaveBeenCalledWith(gitWorkspace, gitProject);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("resolveRegisteredWorkspaceIdForCwd does not match home directory as a prefix", () => {
|
||||||
|
const session = createSessionForWorkspaceTests();
|
||||||
|
const home = homedir();
|
||||||
|
const childCwd = path.join(home, "projects/new-app");
|
||||||
|
const homeWorkspace = createPersistedWorkspaceRecord({
|
||||||
|
workspaceId: home,
|
||||||
|
projectId: "proj-home",
|
||||||
|
cwd: home,
|
||||||
|
kind: "directory",
|
||||||
|
displayName: "home",
|
||||||
|
createdAt: "2026-03-01T12:00:00.000Z",
|
||||||
|
updatedAt: "2026-03-01T12:00:00.000Z",
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(session.resolveRegisteredWorkspaceIdForCwd(childCwd, [homeWorkspace])).toBe(childCwd);
|
||||||
|
expect(session.resolveRegisteredWorkspaceIdForCwd(home, [homeWorkspace])).toBe(home);
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user