refactor: remove legacy workspace UI state

This commit is contained in:
2026-08-10 22:56:00 +02:00
parent fc19b0d67c
commit 90684c3280
12 changed files with 283 additions and 130 deletions
+91 -4
View File
@@ -15,12 +15,12 @@ test("createSession migrates legacy selections and POSTs browser preferences", a
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",
revision: { id: "psd-clinical", commit: "a".repeat(40), blob: "b".repeat(40), snapshotPath: "/snapshot", state: "operational" },
id: "psd-clinical", name: "psd-clinical", file: "psd-clinical.yaml", displayName: "PSD Clinical", language: "en",
revision: { id: "psd-clinical", commit: "a".repeat(40), blob: "b".repeat(40), snapshotPath: "/snapshot" },
}])),
http.get("/api/workspaces/psd-clinical", () => HttpResponse.json({
workspace: canonicalWorkspaceFixture("psd-clinical"),
revision: { id: "psd-clinical", commit: "a".repeat(40), blob: "b".repeat(40), snapshotPath: "/snapshot", state: "operational" },
revision: { id: "psd-clinical", commit: "a".repeat(40), blob: "b".repeat(40), snapshotPath: "/snapshot" },
})),
http.post("/api/sessions", async ({ request }) => {
body = await request.json();
@@ -36,6 +36,93 @@ test("createSession migrates legacy selections and POSTs browser preferences", a
});
});
test("createSession does not POST when a selected summary aliases another workspace name", async () => {
localStorage.setItem("thothii.workspace-registry.v1.preferences", JSON.stringify({
workspaceId: "psd-clinical", provider: "zai", model: "glm-5.2", thinking: "low",
}));
let posted = false;
server.use(
http.get("/api/workspaces", () => HttpResponse.json([{
id: "psd-clinical", name: "other-workspace", file: "psd-clinical.yaml",
displayName: "PSD Clinical", language: "en",
revision: {
id: "psd-clinical", commit: "a".repeat(40), blob: "b".repeat(40), snapshotPath: "/snapshot",
},
}])),
http.get("/api/workspaces/psd-clinical", () => HttpResponse.json({
workspace: canonicalWorkspaceFixture("psd-clinical"),
revision: {
id: "psd-clinical", commit: "a".repeat(40), blob: "b".repeat(40), snapshotPath: "/snapshot",
},
})),
http.post("/api/sessions", () => {
posted = true;
return HttpResponse.json({ id: "s1" });
}),
);
await expect(createSession({ question: "q" })).rejects.toMatchObject({
message: "Could not load workspace registry. Please retry.",
});
expect(posted).toBe(false);
});
test.each([
["historical state", { state: "operational" }],
["an unknown revision field", { generation: 1 }],
["a malformed revision", { commit: "not-a-commit" }],
])("createSession does not POST when the selected summary revision has %s", async (_case, revisionPatch) => {
localStorage.setItem("thothii.workspace-registry.v1.preferences", JSON.stringify({
workspaceId: "psd-clinical", provider: "zai", model: "glm-5.2", thinking: "low",
}));
const revision = {
id: "psd-clinical", commit: "a".repeat(40), blob: "b".repeat(40),
snapshotPath: "/snapshot", ...revisionPatch,
};
let posted = false;
server.use(
http.get("/api/workspaces", () => HttpResponse.json([{
id: "psd-clinical", name: "psd-clinical", file: "psd-clinical.yaml",
displayName: "PSD Clinical", language: "en", revision,
}])),
http.get("/api/workspaces/psd-clinical", () => HttpResponse.json({
workspace: canonicalWorkspaceFixture("psd-clinical"),
revision: {
id: "psd-clinical", commit: "a".repeat(40), blob: "b".repeat(40), snapshotPath: "/snapshot",
},
})),
http.post("/api/sessions", () => {
posted = true;
return HttpResponse.json({ id: "s1" });
}),
);
await expect(createSession({ question: "q" })).rejects.toMatchObject({
message: "Could not load workspace registry. Please retry.",
});
expect(posted).toBe(false);
});
test("createSession preserves allowLegacy for a selected session workspace absent from registry summaries", async () => {
localStorage.setItem("thothii.workspace-registry.v1.preferences", JSON.stringify({
workspaceId: "retained-session-workspace", provider: "zai", model: "glm-5.2", thinking: "low",
}));
let body: unknown;
server.use(
http.get("/api/workspaces", () => HttpResponse.json([])),
http.post("/api/sessions", async ({ request }) => {
body = await request.json();
return HttpResponse.json({ id: "s1" });
}),
);
await expect(createSession({ question: "q" })).resolves.toEqual({ id: "s1" });
expect(body).toEqual({
question: "q", workspaceId: "retained-session-workspace",
provider: "zai", model: "glm-5.2", thinking: "low",
});
});
test("createSession rejects a workspace summary that omits the canonical revision", async () => {
localStorage.clear();
let posted = false;
@@ -44,7 +131,7 @@ test("createSession rejects a workspace summary that omits the canonical revisio
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",
id: "psd-clinical", name: "psd-clinical", file: "psd-clinical.yaml", displayName: "PSD Clinical", language: "en",
}])),
http.post("/api/sessions", async () => {
posted = true;