refactor: make browser workspace writes bootstrap-only
This commit is contained in:
@@ -2,150 +2,65 @@ import { render, screen, waitFor } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { http, HttpResponse } from "msw";
|
||||
import { beforeEach, expect, test, vi } from "vitest";
|
||||
import type { CanonicalWorkspace, PublishWorkspaceRequest, WorkspaceConflict } from "../api/workspaces";
|
||||
import { canonicalWorkspaceFixture, workspaceRevisionFixture } from "../test/workspace-fixtures";
|
||||
import { server } from "../test/msw";
|
||||
import { WorkspacePublishDialog } from "./WorkspacePublishDialog";
|
||||
|
||||
const workspace: CanonicalWorkspace = {
|
||||
workspace: { schema_version: 3, id: "psd-clinical", name: "PSD Clinical", language: "en" },
|
||||
dwh: { engine: "postgres", database: "clinical", schema: "datawarehouse", supported_transports: ["postgres_direct"] },
|
||||
semantic_index: {
|
||||
vector_store: { engine: "qdrant", collection: "clinical", dimensions: 1024, distance: "cosine" },
|
||||
embedding: { provider: "ollama_internal", model: "qwen3-embedding:0.6b", dimensions: 1024 },
|
||||
const workspace = {
|
||||
...canonicalWorkspaceFixture("bootstrap-slot"),
|
||||
workspace: {
|
||||
...canonicalWorkspaceFixture("bootstrap-slot").workspace,
|
||||
name: "Bootstrap slot",
|
||||
description: "Needs configuration",
|
||||
},
|
||||
llm_policy: { allowed: ["zai/glm-5.2"] },
|
||||
};
|
||||
|
||||
const request: PublishWorkspaceRequest = {
|
||||
action: "update", workspace, baseCommit: "a".repeat(40), baseBlob: "b".repeat(40),
|
||||
};
|
||||
|
||||
const conflict: WorkspaceConflict = {
|
||||
code: "workspace_conflict",
|
||||
fields: ["semantic_index.vector_store.collection"],
|
||||
expected: { commit: "a".repeat(40), blob: "b".repeat(40) },
|
||||
actual: { commit: "c".repeat(40), blob: "d".repeat(40) },
|
||||
base: workspace,
|
||||
local: { ...workspace, semantic_index: { ...workspace.semantic_index, vector_store: { ...workspace.semantic_index.vector_store, collection: "local_collection" } } },
|
||||
remote: { ...workspace, semantic_index: { ...workspace.semantic_index, vector_store: { ...workspace.semantic_index.vector_store, collection: "remote_collection" } } },
|
||||
};
|
||||
|
||||
const diagnosticsBranchConflict: WorkspaceConflict = {
|
||||
...conflict,
|
||||
fields: ["diagnostics.dwh_rest"],
|
||||
base: workspace,
|
||||
remote: workspace,
|
||||
local: {
|
||||
...workspace,
|
||||
dwh: { ...workspace.dwh, supported_transports: ["postgres_direct", "rest_api"] },
|
||||
diagnostics: { dwh_rest: { method: "GET", path: "/health", auth: "none", response: { database: "database", schema: "schema" } } },
|
||||
},
|
||||
const request = {
|
||||
action: "create" as const,
|
||||
workspace,
|
||||
baseCommit: "a".repeat(40),
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
server.use(http.post("/api/workspaces/validate", () => HttpResponse.json({ workspace, contract: {} })));
|
||||
});
|
||||
|
||||
test("validates a draft and requires a separate confirmation before publishing", async () => {
|
||||
test("validates a bootstrap draft and requires a separate confirmation before creating it", async () => {
|
||||
const user = userEvent.setup();
|
||||
const published = vi.fn();
|
||||
let publishCalls = 0;
|
||||
server.use(http.post("/api/workspaces/publish", () => {
|
||||
publishCalls += 1;
|
||||
return HttpResponse.json({ revision: { id: "psd-clinical", commit: "c".repeat(40), blob: "d".repeat(40), snapshotPath: "/safe" } });
|
||||
return HttpResponse.json({ revision: workspaceRevisionFixture("bootstrap-slot") });
|
||||
}));
|
||||
render(<WorkspacePublishDialog open request={request} onOpenChange={vi.fn()} onPublished={published} onResolved={vi.fn()} onPull={vi.fn()} onReload={vi.fn()} />);
|
||||
|
||||
expect(screen.getByRole("button", { name: "Publish" })).toBeDisabled();
|
||||
render(<WorkspacePublishDialog open request={request} onOpenChange={vi.fn()} onPublished={published} />);
|
||||
|
||||
expect(screen.getByRole("button", { name: "Create workspace" })).toBeDisabled();
|
||||
await user.click(screen.getByRole("button", { name: "Validate draft" }));
|
||||
expect(await screen.findByText("Workspace definition is valid." )).toBeVisible();
|
||||
await user.click(screen.getByRole("button", { name: "Publish" }));
|
||||
expect(screen.getByRole("heading", { name: "Confirm publication" })).toBeVisible();
|
||||
expect(await screen.findByText("Workspace definition is valid.")).toBeVisible();
|
||||
await user.click(screen.getByRole("button", { name: "Create workspace" }));
|
||||
expect(screen.getByRole("heading", { name: "Confirm workspace creation" })).toBeVisible();
|
||||
expect(publishCalls).toBe(0);
|
||||
await user.click(screen.getByRole("button", { name: "Confirm publish" }));
|
||||
await user.click(screen.getByRole("button", { name: "Confirm create" }));
|
||||
|
||||
await waitFor(() => expect(published).toHaveBeenCalledTimes(1));
|
||||
await waitFor(() => expect(published).toHaveBeenCalledWith(workspaceRevisionFixture("bootstrap-slot")));
|
||||
expect(publishCalls).toBe(1);
|
||||
});
|
||||
|
||||
test("shows a field-level conflict and never overwrites the remote workspace", async () => {
|
||||
const user = userEvent.setup();
|
||||
let published = false;
|
||||
server.use(http.post("/api/workspaces/publish", () => {
|
||||
published = true;
|
||||
return HttpResponse.json({ ...conflict, message: "Workspace changed in the registry." }, { status: 409 });
|
||||
}));
|
||||
render(<WorkspacePublishDialog open request={request} onOpenChange={vi.fn()} onPublished={vi.fn()} onResolved={vi.fn()} onPull={vi.fn()} onReload={vi.fn()} />);
|
||||
|
||||
await user.click(screen.getByRole("button", { name: "Validate draft" }));
|
||||
await user.click(await screen.findByRole("button", { name: "Publish" }));
|
||||
await user.click(screen.getByRole("button", { name: "Confirm publish" }));
|
||||
|
||||
expect(await screen.findByText("semantic_index.vector_store.collection")).toBeVisible();
|
||||
expect(screen.getByText("local_collection")).toBeVisible();
|
||||
expect(screen.getByText("remote_collection")).toBeVisible();
|
||||
expect(screen.getByRole("radio", { name: "Use your draft for semantic_index.vector_store.collection" })).toBeVisible();
|
||||
expect(screen.getByRole("radio", { name: "Use registry value for semantic_index.vector_store.collection" })).toBeVisible();
|
||||
expect(screen.getByRole("button", { name: "Save revised draft" })).toBeDisabled();
|
||||
expect(published).toBe(true);
|
||||
});
|
||||
|
||||
test("saves explicit local choices as a rebased draft and does not republish it", async () => {
|
||||
const user = userEvent.setup();
|
||||
const saved = vi.fn();
|
||||
let publishCalls = 0;
|
||||
server.use(http.post("/api/workspaces/publish", () => {
|
||||
publishCalls += 1;
|
||||
return HttpResponse.json({ ...conflict, message: "Workspace changed in the registry." }, { status: 409 });
|
||||
}));
|
||||
render(<WorkspacePublishDialog open request={request} onOpenChange={vi.fn()} onPublished={vi.fn()} onResolved={saved} onPull={vi.fn()} onReload={vi.fn()} />);
|
||||
|
||||
await user.click(screen.getByRole("button", { name: "Validate draft" }));
|
||||
await user.click(await screen.findByRole("button", { name: "Publish" }));
|
||||
await user.click(screen.getByRole("button", { name: "Confirm publish" }));
|
||||
await user.click(await screen.findByRole("radio", { name: "Use your draft for semantic_index.vector_store.collection" }));
|
||||
await user.click(screen.getByRole("button", { name: "Save revised draft" }));
|
||||
|
||||
expect(saved).toHaveBeenCalledWith(expect.objectContaining({
|
||||
baseCommit: "c".repeat(40), baseBlob: "d".repeat(40),
|
||||
workspace: expect.objectContaining({ semantic_index: expect.objectContaining({ vector_store: expect.objectContaining({ collection: "local_collection" }) }) }),
|
||||
}));
|
||||
expect(publishCalls).toBe(1);
|
||||
});
|
||||
|
||||
test("rebases a selected optional diagnostics branch into the revised draft", async () => {
|
||||
const user = userEvent.setup();
|
||||
const saved = vi.fn();
|
||||
server.use(http.post("/api/workspaces/publish", () => HttpResponse.json({
|
||||
...diagnosticsBranchConflict, message: "Workspace changed in the registry.",
|
||||
}, { status: 409 })));
|
||||
render(<WorkspacePublishDialog open request={request} onOpenChange={vi.fn()} onPublished={vi.fn()} onResolved={saved} onPull={vi.fn()} onReload={vi.fn()} />);
|
||||
|
||||
await user.click(screen.getByRole("button", { name: "Validate draft" }));
|
||||
await user.click(await screen.findByRole("button", { name: "Publish" }));
|
||||
await user.click(screen.getByRole("button", { name: "Confirm publish" }));
|
||||
await user.click(await screen.findByRole("radio", { name: "Use your draft for diagnostics.dwh_rest" }));
|
||||
await user.click(screen.getByRole("button", { name: "Save revised draft" }));
|
||||
|
||||
expect(saved).toHaveBeenCalledWith(expect.objectContaining({
|
||||
baseCommit: "c".repeat(40), baseBlob: "d".repeat(40),
|
||||
workspace: expect.objectContaining({ diagnostics: diagnosticsBranchConflict.local.diagnostics }),
|
||||
}));
|
||||
});
|
||||
|
||||
test("keeps a conflict open and redacts a failed registry pull", async () => {
|
||||
test("surfaces a safe curator-owned refusal without showing conflict resolution UI", async () => {
|
||||
const user = userEvent.setup();
|
||||
server.use(http.post("/api/workspaces/publish", () => HttpResponse.json({
|
||||
...conflict, message: "Workspace changed in the registry.",
|
||||
code: "workspace_curator_owned",
|
||||
message: "Existing descriptors are curator-owned.",
|
||||
}, { status: 409 })));
|
||||
render(<WorkspacePublishDialog open request={request} onOpenChange={vi.fn()} onPublished={vi.fn()} onResolved={vi.fn()} onPull={vi.fn().mockRejectedValue(new Error("token=secret"))} onReload={vi.fn()} />);
|
||||
|
||||
render(<WorkspacePublishDialog open request={request} onOpenChange={vi.fn()} onPublished={vi.fn()} />);
|
||||
|
||||
await user.click(screen.getByRole("button", { name: "Validate draft" }));
|
||||
await user.click(await screen.findByRole("button", { name: "Publish" }));
|
||||
await user.click(screen.getByRole("button", { name: "Confirm publish" }));
|
||||
await user.click(await screen.findByRole("button", { name: "Pull latest registry" }));
|
||||
await user.click(await screen.findByRole("button", { name: "Create workspace" }));
|
||||
await user.click(screen.getByRole("button", { name: "Confirm create" }));
|
||||
|
||||
expect(await screen.findByText("Registry pull could not be completed. Try again or reload the workspace.")).toBeVisible();
|
||||
expect(screen.queryByText(/token=secret/)).not.toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: "Reload workspace" })).toBeVisible();
|
||||
expect(await screen.findByText("workspace_curator_owned: Existing descriptors are curator-owned.")).toBeVisible();
|
||||
expect(screen.queryByText(/save revised draft|use your draft|use registry value/i)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user