perf(webui): revalidate prompt summaries and bound navigation work
This commit is contained in:
1 parent
bf1eada575
commit
f9a3e55b64
12 files changed
+235
-42
No files matched your search
@@ -24,6 +24,7 @@ import {
|
||||
fetchMarketplaceSkillTrends,
|
||||
fetchNanobotFeatures,
|
||||
fetchProviderModels,
|
||||
fetchPromptIndex,
|
||||
fetchSessionAutomations,
|
||||
fetchSettingsUsage,
|
||||
fetchSidebarState,
|
||||
@@ -124,6 +125,26 @@ describe("webui API helpers", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("revalidates prompt summaries and replaces only the changed suffix", async () => {
|
||||
const prompt = { id: "u1", preview: "question", answerPreview: "", cursor: "cursor", turnId: "t1", createdAt: 1 };
|
||||
const cached = { revision: "first", prompts: [prompt] };
|
||||
const signal = new AbortController().signal;
|
||||
vi.mocked(fetch).mockResolvedValueOnce({ status: 304 } as Response);
|
||||
await expect(fetchPromptIndex("tok", "websocket:chat-1", signal, cached)).resolves.toBe(cached);
|
||||
expect(fetch).toHaveBeenLastCalledWith("/api/sessions/websocket%3Achat-1/webui-thread/prompts?since=first",
|
||||
expect.objectContaining({ headers: { Authorization: "Bearer tok", "If-None-Match": '"first"' }, cache: "no-store" }));
|
||||
vi.mocked(fetch).mockResolvedValueOnce({ ok: true, json: async () => ({
|
||||
revision: "second", replaceFrom: 1, prompts: [{ ...prompt, id: "u2" }],
|
||||
}) } as Response);
|
||||
const appended = await fetchPromptIndex("tok", "websocket:chat-1", signal, cached);
|
||||
expect(appended.prompts.map((item) => item.id)).toEqual(["u1", "u2"]);
|
||||
expect(appended.prompts[0]).toBe(prompt);
|
||||
vi.mocked(fetch).mockResolvedValueOnce({ ok: true, json: async () => ({ revision: "third", replaceFrom: 1, prompts: [] }) } as Response);
|
||||
expect((await fetchPromptIndex("tok", "websocket:chat-1", signal, appended)).prompts).toEqual([prompt]);
|
||||
vi.mocked(fetch).mockResolvedValueOnce({ ok: true, json: async () => ({ replaceFrom: 2, prompts: [] }) } as Response);
|
||||
await expect(fetchPromptIndex("tok", "websocket:chat-1", signal, cached)).rejects.toThrow("Invalid prompt index revision");
|
||||
});
|
||||
|
||||
it("revalidates a cached WebUI thread and reuses it on 304", async () => {
|
||||
const cached = {
|
||||
schemaVersion: 3,
|
||||
|
||||
Reference in new issue
Block a user