feat: add workspace management editor

This commit is contained in:
2026-08-04 06:27:59 +02:00
parent b686ffe271
commit 48fd316b90
10 changed files with 744 additions and 7 deletions
@@ -0,0 +1,92 @@
import { render, screen, waitFor, within } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { http, HttpResponse } from "msw";
import { beforeEach, expect, test } from "vitest";
import { server } from "../test/msw";
import { WorkspaceManager } from "./WorkspaceManager";
const workspace = {
workspace: { schema_version: 2, id: "psd-clinical", name: "PSD Clinical", language: "en" },
dwh: { engine: "postgres", database: "clinical", schema: "datawarehouse", port: 5432, supported_transports: ["postgres_direct"] },
semantic_index: {
vector_store: { engine: "pgvector", database: "vectors", schema: "public", collection: "clinical", dimensions: 768, distance: "cosine", supported_transports: ["pgvector_direct"] },
embedding: { provider: "ollama_compatible", model: "nomic-embed-text", dimensions: 768 },
},
llm_policy: { default: "zai/glm-5.2", allowed: ["zai/glm-5.2"] },
} as const;
function renderManager() {
const client = new QueryClient({ defaultOptions: { queries: { retry: false } } });
return render(<QueryClientProvider client={client}><WorkspaceManager open onClose={() => undefined} /></QueryClientProvider>);
}
beforeEach(() => {
localStorage.clear();
server.use(
http.get("http://localhost:8787/workspace-registry/status", () =>
HttpResponse.json({ branch: "main", head: "a".repeat(40), ahead: 0, behind: 0, degraded: false })),
http.get("http://localhost:8787/workspaces", () => HttpResponse.json([{
id: "psd-clinical", name: "PSD Clinical", displayName: "PSD Clinical", description: "Clinical data",
language: "en", file: "workspaces/psd-clinical.yaml",
revision: { id: "psd-clinical", commit: "a".repeat(40), blob: "b".repeat(40), snapshotPath: "/tmp/psd", state: "operational" },
}])),
http.get("http://localhost:8787/workspaces/psd-clinical", () => HttpResponse.json({
workspace,
revision: { id: "psd-clinical", commit: "a".repeat(40), blob: "b".repeat(40), snapshotPath: "/tmp/psd", state: "operational" },
})),
);
});
test("lists registry workspaces and saves a new workspace only as a browser draft", async () => {
const user = userEvent.setup();
renderManager();
expect(await screen.findByRole("heading", { name: "Workspace management" })).toBeVisible();
expect(await screen.findByRole("button", { name: "PSD Clinical" })).toBeVisible();
await user.click(screen.getByRole("button", { name: "New workspace" }));
await user.clear(screen.getByLabelText("Workspace ID"));
await user.type(screen.getByLabelText("Workspace ID"), "trial-registry");
await user.click(screen.getByRole("button", { name: "Save draft" }));
await waitFor(() => expect(screen.getByText("Draft saved in this browser.")).toBeVisible());
expect(localStorage.getItem("thothii.workspace-registry.v1.draft.trial-registry")).not.toBeNull();
});
test("stages duplicate and delete operations without publishing", async () => {
const user = userEvent.setup();
let published = false;
server.use(http.post("http://localhost:8787/workspaces/publish", () => {
published = true;
return HttpResponse.json({});
}));
renderManager();
await user.click(await screen.findByRole("button", { name: "PSD Clinical" }));
await user.click(screen.getByRole("button", { name: "Duplicate workspace" }));
expect(screen.getByLabelText("Workspace ID")).not.toBeDisabled();
await user.click(screen.getByRole("button", { name: "PSD Clinical" }));
await user.click(screen.getByRole("button", { name: "Delete workspace" }));
expect(screen.getByText("Deletion draft staged locally.")).toBeVisible();
expect(published).toBe(false);
});
test("runs validation and installation test with only sanitized messages", async () => {
const user = userEvent.setup();
server.use(
http.post("http://localhost:8787/workspaces/validate", () => HttpResponse.json({ workspace, contract: {} })),
http.post("http://localhost:8787/workspaces/psd-clinical/test", () => HttpResponse.json({
activatable: false,
diagnostics: [{ level: "warning", code: "binding_missing", field: "dwh", message: "DWH binding is not configured" }],
})),
);
renderManager();
await user.click(await screen.findByRole("button", { name: "PSD Clinical" }));
await user.click(screen.getByRole("button", { name: "Validate workspace" }));
expect(await screen.findByText("Workspace definition is valid.")).toBeVisible();
await user.click(screen.getByRole("button", { name: "Test on this installation" }));
expect(await screen.findByText("binding_missing: DWH binding is not configured")).toBeVisible();
expect(within(screen.getByTestId("workspace-diagnostics")).queryByText(/password|token|secret/i)).not.toBeInTheDocument();
});