fix(webui): bound startup fetch waits

This commit is contained in:
chengyongru
2026-06-02 18:47:34 +08:00
committed by Xubin Ren
parent 2a98360105
commit 456ed77e79
5 changed files with 130 additions and 19 deletions
+18 -1
View File
@@ -1,4 +1,4 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import {
createModelConfiguration,
@@ -38,6 +38,11 @@ describe("webui API helpers", () => {
);
});
afterEach(() => {
vi.useRealTimers();
vi.unstubAllGlobals();
});
it("percent-encodes websocket keys when fetching webui-thread snapshot", async () => {
await fetchWebuiThread("tok", "websocket:chat-1");
@@ -151,6 +156,18 @@ describe("webui API helpers", () => {
});
});
it("times out when an API request never responds", async () => {
vi.useFakeTimers();
vi.stubGlobal("fetch", vi.fn(() => new Promise<Response>(() => {})));
const pending = expect(listSessions("tok")).rejects.toThrow(
"Request timed out after 20000ms",
);
await vi.advanceTimersByTimeAsync(20_000);
await pending;
});
it("serializes provider settings updates without returning secrets", async () => {
await updateProviderSettings("tok", {
provider: "openrouter",