Files
nanobot/webui/src/tests/thread-message-cache.test.ts
T
chengyongru 1469d4811c perf(webui): reduce repeated work and bound history rendering (#5703)
* perf(webui): reduce repeated work and bound history rendering

* fix(webui): keep continuation reasoning with its answer

* refactor(webui): reuse answer buffers and prepared copy text

* perf(webui): restore conditional replay buffer initialization

* fix(webui): remove code block pagination
2026-09-09 14:02:26 +08:00

25 lines
1019 B
TypeScript

import { expect, it } from "vitest";
import { ThreadMessageCache } from "@/lib/thread-message-cache";
import type { UIMessage } from "@/lib/types";
const rows: UIMessage[] = [{ id: "u", role: "user", content: "hello", createdAt: 1 }];
it("keeps recently visited chats within the entry budget", () => {
const cache = new ThreadMessageCache(() => false, 10000, 2);
cache.set("a", rows); cache.set("b", rows);
expect(cache.get("a")).toBe(rows);
cache.set("c", rows);
expect([cache.get("a"), cache.get("b"), cache.get("c")]).toEqual([rows, undefined, rows]);
});
it("bounds large replay snapshots while retaining temporary chats", () => {
const cache = new ThreadMessageCache((key) => key === "temporary", 1000, 2);
cache.set("temporary", rows);
cache.set("large", [{ ...rows[0], content: "x".repeat(1000) }]);
expect(cache.get("large")).toBeUndefined();
expect(cache.get("temporary")).toBe(rows);
cache.delete("temporary");
cache.set("small", rows);
expect(cache.get("small")).toBe(rows);
});