Support PowerShell and resolve workspaces by directory path
This commit is contained in:
@@ -49,6 +49,31 @@ describe("patchWorkspaceServices", () => {
|
||||
expect(next.get("/repo/other")).toBe(other);
|
||||
});
|
||||
|
||||
it("patches the matching workspace when the update uses workspace directory identity", () => {
|
||||
const current = new Map<string, WorkspaceDescriptor>([
|
||||
[
|
||||
"42",
|
||||
workspace({
|
||||
id: "42",
|
||||
services: [],
|
||||
}),
|
||||
],
|
||||
]);
|
||||
|
||||
current.set("42", {
|
||||
...current.get("42")!,
|
||||
workspaceDirectory: "C:\\repo\\main\\",
|
||||
});
|
||||
|
||||
const next = patchWorkspaceServices(current, {
|
||||
workspaceId: "C:/repo/main",
|
||||
services: [runningService],
|
||||
});
|
||||
|
||||
expect(next).not.toBe(current);
|
||||
expect(next.get("42")?.services).toEqual([runningService]);
|
||||
});
|
||||
|
||||
it("ignores updates for unknown workspaces", () => {
|
||||
const current = new Map<string, WorkspaceDescriptor>([
|
||||
["/repo/main", workspace({ id: "/repo/main", services: [] })],
|
||||
|
||||
@@ -1,17 +1,26 @@
|
||||
import type { ServiceStatusUpdateMessage } from "@server/shared/messages";
|
||||
import type { WorkspaceDescriptor } from "@/stores/session-store";
|
||||
import { resolveWorkspaceMapKeyByIdentity } from "@/utils/workspace-execution";
|
||||
|
||||
export function patchWorkspaceServices(
|
||||
workspaces: Map<string, WorkspaceDescriptor>,
|
||||
update: ServiceStatusUpdateMessage["payload"],
|
||||
): Map<string, WorkspaceDescriptor> {
|
||||
const existing = workspaces.get(update.workspaceId);
|
||||
const workspaceKey = resolveWorkspaceMapKeyByIdentity({
|
||||
workspaces,
|
||||
workspaceIdentity: update.workspaceId,
|
||||
});
|
||||
if (!workspaceKey) {
|
||||
return workspaces;
|
||||
}
|
||||
|
||||
const existing = workspaces.get(workspaceKey);
|
||||
if (!existing) {
|
||||
return workspaces;
|
||||
}
|
||||
|
||||
const next = new Map(workspaces);
|
||||
next.set(update.workspaceId, {
|
||||
next.set(workspaceKey, {
|
||||
...existing,
|
||||
services: update.services.map((s) => ({ ...s })),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user