Support PowerShell and resolve workspaces by directory path
This commit is contained in:
@@ -3,6 +3,7 @@ import type { WorkspaceDescriptor } from "@/stores/session-store";
|
||||
import {
|
||||
getWorkspaceExecutionAuthority,
|
||||
requireWorkspaceExecutionAuthority,
|
||||
resolveWorkspaceMapKeyByIdentity,
|
||||
resolveWorkspaceIdByExecutionDirectory,
|
||||
resolveWorkspaceRouteId,
|
||||
} from "./workspace-execution";
|
||||
@@ -72,6 +73,46 @@ describe("resolveWorkspaceIdByExecutionDirectory", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveWorkspaceMapKeyByIdentity", () => {
|
||||
it("returns the existing map key when the identity already matches a key", () => {
|
||||
const workspaces = new Map<string, WorkspaceDescriptor>([
|
||||
[
|
||||
"workspace-1",
|
||||
createWorkspace({
|
||||
id: "workspace-1",
|
||||
workspaceDirectory: "/repo/.paseo/worktrees/feature",
|
||||
}),
|
||||
],
|
||||
]);
|
||||
|
||||
expect(
|
||||
resolveWorkspaceMapKeyByIdentity({
|
||||
workspaces,
|
||||
workspaceIdentity: "workspace-1",
|
||||
}),
|
||||
).toBe("workspace-1");
|
||||
});
|
||||
|
||||
it("resolves a workspace directory identity to the canonical map key", () => {
|
||||
const workspaces = new Map<string, WorkspaceDescriptor>([
|
||||
[
|
||||
"workspace-1",
|
||||
createWorkspace({
|
||||
id: "workspace-1",
|
||||
workspaceDirectory: "C:\\repo\\feature\\",
|
||||
}),
|
||||
],
|
||||
]);
|
||||
|
||||
expect(
|
||||
resolveWorkspaceMapKeyByIdentity({
|
||||
workspaces,
|
||||
workspaceIdentity: "C:/repo/feature",
|
||||
}),
|
||||
).toBe("workspace-1");
|
||||
});
|
||||
});
|
||||
|
||||
describe("workspace execution authority", () => {
|
||||
it("returns an explicit failure when workspace id is missing", () => {
|
||||
expect(
|
||||
|
||||
@@ -44,6 +44,36 @@ export function resolveWorkspaceIdByExecutionDirectory(input: {
|
||||
return null;
|
||||
}
|
||||
|
||||
export function resolveWorkspaceMapKeyByIdentity(input: {
|
||||
workspaces: Map<string, WorkspaceDescriptor> | null | undefined;
|
||||
workspaceIdentity: string | null | undefined;
|
||||
}): string | null {
|
||||
const normalizedWorkspaceIdentity = normalizeWorkspaceIdentity(input.workspaceIdentity);
|
||||
if (!normalizedWorkspaceIdentity) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const workspaces = input.workspaces;
|
||||
if (!workspaces) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (workspaces.has(normalizedWorkspaceIdentity)) {
|
||||
return normalizedWorkspaceIdentity;
|
||||
}
|
||||
|
||||
for (const [workspaceKey, workspace] of workspaces) {
|
||||
if (
|
||||
normalizeWorkspaceIdentity(workspace.id) === normalizedWorkspaceIdentity ||
|
||||
normalizeWorkspaceIdentity(workspace.workspaceDirectory) === normalizedWorkspaceIdentity
|
||||
) {
|
||||
return workspaceKey;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export function getWorkspaceExecutionAuthority(
|
||||
input:
|
||||
| {
|
||||
@@ -58,11 +88,14 @@ export function getWorkspaceExecutionAuthority(
|
||||
"workspace" in input
|
||||
? input.workspace
|
||||
: (() => {
|
||||
const normalizedWorkspaceId = normalizeWorkspaceIdentity(input.workspaceId);
|
||||
if (!normalizedWorkspaceId) {
|
||||
const workspaceKey = resolveWorkspaceMapKeyByIdentity({
|
||||
workspaces: input.workspaces,
|
||||
workspaceIdentity: input.workspaceId,
|
||||
});
|
||||
if (!workspaceKey) {
|
||||
return null;
|
||||
}
|
||||
return input.workspaces?.get(normalizedWorkspaceId) ?? null;
|
||||
return input.workspaces?.get(workspaceKey) ?? null;
|
||||
})();
|
||||
|
||||
if ("workspaces" in input) {
|
||||
|
||||
Reference in New Issue
Block a user