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",
+19 -2
View File
@@ -1,8 +1,13 @@
import { describe, expect, it } from "vitest";
import { afterEach, describe, expect, it, vi } from "vitest";
import { deriveWsUrl } from "@/lib/bootstrap";
import { deriveWsUrl, fetchBootstrap } from "@/lib/bootstrap";
describe("bootstrap helpers", () => {
afterEach(() => {
vi.useRealTimers();
vi.unstubAllGlobals();
});
it("prefers the server-provided websocket URL over the current dev host", () => {
expect(deriveWsUrl("/", "tok en", "ws://127.0.0.1:8765/")).toBe(
"ws://127.0.0.1:8765/?token=tok%20en",
@@ -20,4 +25,16 @@ describe("bootstrap helpers", () => {
"ws://localhost:3000/?token=tok",
);
});
it("times out when the bootstrap endpoint never responds", async () => {
vi.useFakeTimers();
vi.stubGlobal("fetch", vi.fn(() => new Promise<Response>(() => {})));
const pending = expect(fetchBootstrap("", "", 25)).rejects.toThrow(
"Request timed out after 25ms",
);
await vi.advanceTimersByTimeAsync(25);
await pending;
});
});