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
+27
View File
@@ -15,7 +15,12 @@ test("createSession migrates legacy selections and POSTs browser preferences", a
})),
http.get("/api/workspaces", () => HttpResponse.json([{
id: "psd-clinical", name: "psd-clinical", file: "psd-clinical.yaml", displayName: "PSD Clinical",
revision: { id: "psd-clinical", commit: "a".repeat(40), blob: "b".repeat(40), snapshotPath: "/snapshot", state: "operational" },
}])),
http.get("/api/workspaces/psd-clinical", () => HttpResponse.json({
workspace: { llm_policy: { allowed: ["zai/glm-5.2"] } },
revision: { id: "psd-clinical", commit: "a".repeat(40), blob: "b".repeat(40), snapshotPath: "/snapshot", state: "operational" },
})),
http.post("/api/sessions", async ({ request }) => {
body = await request.json();
return HttpResponse.json({ id: "s1" });
@@ -30,6 +35,28 @@ test("createSession migrates legacy selections and POSTs browser preferences", a
});
});
test("createSession rejects a workspace summary that omits the canonical revision", async () => {
localStorage.clear();
let posted = false;
server.use(
http.get("/api/settings", () => HttpResponse.json({
workspace: "psd-clinical", provider: "zai", model: "glm-5.2", thinking: "low",
})),
http.get("/api/workspaces", () => HttpResponse.json([{
id: "psd-clinical", name: "psd-clinical", file: "psd-clinical.yaml", displayName: "PSD Clinical",
}])),
http.post("/api/sessions", async () => {
posted = true;
return HttpResponse.json({ id: "s1" });
}),
);
await expect(createSession({ question: "q" })).rejects.toMatchObject({
message: "Could not load selected workspace policy. Please retry.",
});
expect(posted).toBe(false);
});
test.each([202, 204])("prewarmRuntime accepts a body-less %s response", async (status) => {
let called = false;
server.use(
+5 -1
View File
@@ -59,7 +59,11 @@ async function ensureWorkspaceSelectionPolicy(): Promise<WorkspacePreference> {
throw new WorkspaceSelectionError(WORKSPACE_SUMMARY_ERROR);
}
if (workspacePreferences.load().workspaceId !== workspaceId) continue;
if (workspace?.revision.state === "migration_required") {
if (workspace && !workspace.revision) {
workspacePolicyGate.reject(workspaceId);
throw new WorkspaceSelectionError(WORKSPACE_POLICY_ERROR);
}
if (workspace?.revision?.state === "migration_required") {
workspacePolicyGate.rejectSummary(workspaceId);
throw new WorkspaceSelectionError(WORKSPACE_POLICY_ERROR);
}