Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(sidebar): bound each department-order save at 10 s

Bugfixer 24eb7a30daa94
diff --git a/src/components/bot-sections.test.ts b/src/components/bot-sections.test.ts
index 19026ec304..48cf002b78 100644
--- a/src/components/bot-sections.test.ts
+++ b/src/components/bot-sections.test.ts
@@ -1,9 +1,10 @@
import { afterEach, describe, expect, it, vi } from "vitest";
-const sent: { body: string; finish: () => void }[] = [];
+const sent: { body: string; timeoutMs?: number; finish: () => void }[] = [];
vi.mock("@/state/store", async (importOriginal) => ({
...(await importOriginal<typeof import("@/state/store")>()),
- api: vi.fn((_path: string, init: { body: string }) => new Promise<void>((resolve) => sent.push({ body: init.body, finish: resolve }))),
+ api: vi.fn((_path: string, init: { body: string; timeoutMs?: number }) =>
+ new Promise<void>((resolve) => sent.push({ body: init.body, timeoutMs: init.timeoutMs, finish: resolve }))),
}));
const { saveDepartmentOrder } = await import("./bot-sections");
@@ -23,4 +24,13 @@ describe("saving the department order", () => {
sent[1].finish();
expect(await Promise.all([first, second])).toEqual([true, true]);
});
+
+ it("bounds each save, so a save the server never answers cannot hold back the moves after it", async () => {
+ const saving = saveDepartmentOrder(vi.fn(), ["Sales", "Ops"], ["Ops", "Sales"]);
+ await settle();
+ expect(sent).toHaveLength(1);
+ expect(sent[0].timeoutMs).toBeGreaterThan(0);
+ sent[0].finish();
+ expect(await saving).toBe(true);
+ });
});
diff --git a/src/components/bot-sections.ts b/src/components/bot-sections.ts
index 1e33f4bbc9..ac1468e1d8 100644
--- a/src/components/bot-sections.ts
+++ b/src/components/bot-sections.ts
@@ -76,7 +76,7 @@ export async function saveDepartmentOrder(dispatch: Dispatch<Action>, sections:
const request = ++departmentOrderRequest;
dispatch({ type: "sectionsOrdered", sections: names });
try {
- const saved = departmentOrderSaves.then(() => api("/api/sidebar-sections/order", { method: "PUT", body: JSON.stringify({ sections: names }) }));
+ const saved = departmentOrderSaves.then(() => api("/api/sidebar-sections/order", { method: "PUT", body: JSON.stringify({ sections: names }), timeoutMs: 10_000 }));
departmentOrderSaves = saved.catch(() => undefined);
await saved;
return true;