fix: fail safe on missing workspace revisions

This commit is contained in:
2026-08-08 20:03:41 +02:00
parent c3a5621737
commit 1b1213317b
10 changed files with 205 additions and 98 deletions
+29
View File
@@ -389,6 +389,35 @@ test("initial submit rejects a migration-required workspace after summaries load
expect(body).toBeUndefined();
});
test("initial submit rejects a workspace summary that omits the canonical revision", async () => {
let body: unknown;
let failure: string | undefined;
localStorage.setItem("thothii.workspace-registry.v1.preferences", JSON.stringify({
workspaceId: "broken-workspace", provider: "zai", model: "glm-5.2", thinking: "medium",
}));
server.use(
http.get("/api/settings", () => HttpResponse.json({ workspace: "broken-workspace" })),
http.get("/api/workspaces", () => HttpResponse.json([{
id: "broken-workspace", name: "broken-workspace", file: "broken-workspace.yaml", displayName: "Broken workspace",
}])),
http.get("/api/models", () => HttpResponse.json({ models: [
{ provider: "zai", id: "glm-5.2", name: "GLM-5.2", reasoning: true },
] })),
http.post("/api/sessions", async ({ request }) => {
body = await request.json();
return HttpResponse.json({ id: "s1" });
}),
);
const client = new QueryClient({ defaultOptions: { queries: { retry: false } } });
render(<QueryClientProvider client={client}><ComposerFooter /><SteerInput sessionId={null} onSessionCreateFailed={(message) => { failure = message; }} /></QueryClientProvider>);
await userEvent.type(screen.getByRole("textbox", { name: /new question/i }), "q");
await userEvent.click(screen.getByRole("button", { name: /send/i }));
await waitFor(() => expect(failure).toBe("Could not load selected workspace policy. Please retry."));
expect(body).toBeUndefined();
});
test("failed workspace summaries block creation and report a safe error", async () => {
let body: unknown;
let failure: string | undefined;
+7 -5
View File
@@ -180,12 +180,11 @@ export function ComposerFooter() {
const workspace = preferences.workspaceId ?? settings?.workspace ?? "";
const selectedWorkspace = workspaces.find((candidate) => candidate.id === workspace);
const selectedWorkspaceHasRevision = Boolean(selectedWorkspace?.revision);
const { data: workspaceRecord, isError: workspacePolicyError } = useQuery({
queryKey: ["workspace", workspace],
queryFn: () => getWorkspace(workspace),
// Legacy metadata responses do not carry a registry revision, so retain the
// existing selector behavior without issuing an incompatible detail request.
enabled: Boolean(selectedWorkspace?.revision),
enabled: selectedWorkspaceHasRevision,
});
const model = preferences.model ?? settings?.model ?? "";
const thinking = preferences.thinking ?? settings?.thinking ?? "medium";
@@ -202,6 +201,8 @@ export function ComposerFooter() {
workspacePolicyGate.beginSummary(workspace);
} else if (workspaceSummariesError) {
workspacePolicyGate.rejectSummary(workspace);
} else if (selectedWorkspace && !selectedWorkspaceHasRevision) {
workspacePolicyGate.rejectSummary(workspace);
} else if (selectedWorkspace?.revision?.state === "migration_required") {
workspacePolicyGate.rejectSummary(workspace);
} else if (selectedWorkspace?.revision) {
@@ -241,7 +242,8 @@ export function ComposerFooter() {
function update(patch: WorkspacePreference) {
if (patch.workspaceId && patch.workspaceId !== workspace) {
const selected = workspaces.find((candidate) => candidate.id === patch.workspaceId);
if (selected?.revision?.state === "migration_required") workspacePolicyGate.rejectSummary(patch.workspaceId);
if (selected && !selected.revision) workspacePolicyGate.rejectSummary(patch.workspaceId);
else if (selected?.revision?.state === "migration_required") workspacePolicyGate.rejectSummary(patch.workspaceId);
else if (selected?.revision) workspacePolicyGate.select(patch.workspaceId);
else workspacePolicyGate.allowLegacy(patch.workspaceId);
}
@@ -267,7 +269,7 @@ export function ComposerFooter() {
{workspaces.length === 0 ? (
<option value="">— workspace —</option>
) : (
workspaces.filter((w) => w.revision?.state !== "migration_required").map((w) => (
workspaces.filter((w) => w.revision && w.revision.state !== "migration_required").map((w) => (
<option key={w.name} value={w.name}>
{w.name}
</option>
@@ -232,6 +232,24 @@ test("shows a migration banner for legacy descriptors and does not load editor d
expect(screen.queryByLabelText("Vector collection")).not.toBeInTheDocument();
});
test("shows an actionable unavailable message when a workspace summary omits its canonical revision", async () => {
const user = userEvent.setup();
server.use(
http.get("/api/workspaces", () => HttpResponse.json([
{
id: "broken-workspace", name: "Broken workspace", displayName: "Broken workspace", description: "Broken data",
language: "en", file: "workspaces/broken-workspace.yaml",
},
])),
);
renderManager();
await user.click(await screen.findByRole("button", { name: "Broken workspace" }));
expect(await screen.findByText("This workspace summary is incomplete. Refresh the registry or choose another workspace before creating sessions or editing drafts.")).toBeVisible();
expect(screen.queryByLabelText("Vector collection")).not.toBeInTheDocument();
});
test("shows an accessible retry instead of a loading status when the registry status query fails", async () => {
const user = userEvent.setup();
let calls = 0;
+10 -4
View File
@@ -63,11 +63,12 @@ export function WorkspaceManager({ open, onClose }: { open: boolean; onClose: ()
const workspacesQuery = useQuery({ queryKey: ["workspaces"], queryFn: listWorkspaces, enabled: open });
const workspaces = workspacesQuery.data ?? [];
const selectedSummary = useMemo(() => workspaces.find((workspace) => workspace.id === selectedId), [selectedId, workspaces]);
const selectedIsLegacy = selectedSummary?.revision.state === "migration_required";
const selectedSummaryIncomplete = Boolean(selectedSummary && !selectedSummary.revision);
const selectedIsLegacy = selectedSummary?.revision?.state === "migration_required";
const detailQuery = useQuery({
queryKey: ["workspace", selectedId],
queryFn: () => getWorkspace(selectedId!),
enabled: Boolean(open && selectedId && !localDraft && !selectedIsLegacy),
enabled: Boolean(open && selectedId && !localDraft && !selectedSummaryIncomplete && !selectedIsLegacy),
});
const status = statusQuery.data;
const record = detailQuery.data;
@@ -311,13 +312,18 @@ export function WorkspaceManager({ open, onClose }: { open: boolean; onClose: ()
</nav>
<div className="min-w-0 overflow-y-auto px-5 py-5">
{selectedIsLegacy ? (
{selectedSummaryIncomplete ? (
<div className="rounded-md border border-amber-500/30 bg-amber-500/10 px-4 py-3 text-sm">
<p className="font-semibold">Workspace summary unavailable</p>
<p className="mt-1">This workspace summary is incomplete. Refresh the registry or choose another workspace before creating sessions or editing drafts.</p>
</div>
) : selectedIsLegacy ? (
<div className="rounded-md border border-amber-500/30 bg-amber-500/10 px-4 py-3 text-sm">
<p className="font-semibold">Migration required</p>
<p className="mt-1">This workspace uses a legacy descriptor and must be migrated to schema v3 before new sessions or publication.</p>
</div>
) : detailQuery.isError && selectedId && !localDraft ? <QueryError name="Workspace details failed" message="Could not load workspace details." retryLabel="Retry workspace details" onRetry={() => { void detailQuery.refetch(); }} /> : !currentDraft && !detailQuery.isLoading && <div className="grid min-h-64 place-items-center text-center"><div><h3 className="font-heading font-semibold">Select a workspace</h3><p className="mt-1 text-sm text-muted-foreground">Review an existing definition or start a browser-only draft.</p></div></div>}
{!selectedIsLegacy && !detailQuery.isError && (currentDraft || detailQuery.isLoading) && (
{!selectedSummaryIncomplete && !selectedIsLegacy && !detailQuery.isError && (currentDraft || detailQuery.isLoading) && (
<>
{detailQuery.isLoading && !currentDraft ? <p className="text-sm text-muted-foreground">Loading workspace definition…</p> : currentDraft && <>
<div className="mb-5 flex flex-wrap items-start justify-between gap-3 border-b border-border/70 pb-4">