mirror of
https://github.com/getpaseo/paseo.git
synced 2026-07-29 12:01:31 +00:00
test(server): cover home directory prefix match in workspace resolution
Locks down the fix from e92f0847 so prefix matching never swallows a
child path under the user's home workspace.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { execSync } from "node:child_process";
|
||||
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 { expect, test, vi } from "vitest";
|
||||
import { Session } from "./session.js";
|
||||
@@ -47,6 +47,10 @@ interface SessionTestAccess {
|
||||
getAgentPayloadById(agentId: string): Promise<unknown>;
|
||||
buildProjectPlacementForCwd(cwd: string): Promise<unknown>;
|
||||
buildProjectPlacement(cwd: string): Promise<unknown>;
|
||||
resolveRegisteredWorkspaceIdForCwd(
|
||||
cwd: string,
|
||||
workspaces: ReturnType<typeof createPersistedWorkspaceRecord>[],
|
||||
): string;
|
||||
buildWorkspaceDescriptorMap(...args: unknown[]): Promise<Map<string, unknown>>;
|
||||
describeWorkspaceRecord(...args: unknown[]): Promise<unknown>;
|
||||
describeWorkspaceRecordWithGitData(...args: unknown[]): Promise<unknown>;
|
||||
@@ -3042,3 +3046,21 @@ test("subscribed fetch_workspaces includes git enrichment in the initial snapsho
|
||||
expect(workspaceUpdates).toEqual([]);
|
||||
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