fix(webui): stabilize earlier-history loading and reclaim space (#6349)
* fix(webui): retain smoothly revealed history loading headers * refactor(webui): simplify history loading feedback * fix(webui): keep retained history headers clear of preceding text * fix(webui): reclaim completed history loading space * refactor(webui): group history projection handoff with navigation * test(webui): synchronize history motion observations * fix(webui): collapse history completion geometry handoff
This commit is contained in:
1 parent
73a55e0b2f
commit
743c51e81f
24 files changed
+1658
-356
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { act, fireEvent, render, screen, waitFor, within } from "@testing-library/react";
|
||||
import { StrictMode, type ReactNode } from "react";
|
||||
import { Profiler, StrictMode, type ReactNode } from "react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { preloadMarkdownText } from "@/components/MarkdownText";
|
||||
@@ -4002,6 +4002,89 @@ describe("ThreadShell", () => {
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
{ name: "visible rows after a hidden command prefix", rows: [
|
||||
{ role: "user" as const, content: "/model hidden", turnId: "webui-system:model" },
|
||||
{ role: "assistant" as const, content: "hidden model response", turnId: "webui-system:model" },
|
||||
{ role: "user" as const, content: "older question", turnId: "older-turn" },
|
||||
{ role: "assistant" as const, content: "older answer", turnId: "older-turn" },
|
||||
], expectVisible: true },
|
||||
{ name: "a page containing only hidden command rows", rows: [
|
||||
{ role: "user" as const, content: "/model hidden", turnId: "webui-system:model" },
|
||||
{ role: "assistant" as const, content: "hidden model response", turnId: "webui-system:model" },
|
||||
], expectVisible: false },
|
||||
{ name: "an empty successful page", rows: [], expectVisible: false },
|
||||
{ name: "a failed page", rows: [], expectVisible: false, error: true },
|
||||
])("releases older-page loading after ThreadShell handles $name", async ({ rows, expectVisible, error = false }) => {
|
||||
const client = makeClient();
|
||||
const chatId = `older-projection-${expectVisible ? "visible" : "hidden"}`;
|
||||
let resolveOlder!: (response: Response) => void;
|
||||
let olderReturned = false;
|
||||
const commits: Array<{ loading: boolean; olderVisible: boolean }> = [];
|
||||
vi.stubGlobal("fetch", vi.fn(async (input: RequestInfo | URL) => {
|
||||
const url = String(input);
|
||||
if (!url.includes(`websocket%3A${chatId}/webui-thread`)) {
|
||||
return { ok: false, status: 404, json: async () => ({}) };
|
||||
}
|
||||
if (url.includes("before=")) {
|
||||
return new Promise<Response>((resolve) => { resolveOlder = resolve; });
|
||||
}
|
||||
return httpJson({
|
||||
...transcriptFromSimpleMessages([
|
||||
{ role: "user", content: "current question", turnId: "current-turn" },
|
||||
]),
|
||||
has_pending_tool_calls: expectVisible,
|
||||
active_turn_id: expectVisible ? "current-turn" : null,
|
||||
completed_turn_ids: [],
|
||||
page: { before_cursor: "older-page", has_more_before: true, user_message_offset: 1 },
|
||||
});
|
||||
}));
|
||||
const capture = () => {
|
||||
if (!olderReturned) return;
|
||||
commits.push({
|
||||
loading: document.querySelector('.thread-history-status[data-state="loading"]') !== null,
|
||||
olderVisible: document.body.textContent?.includes("older answer") ?? false,
|
||||
});
|
||||
};
|
||||
const { container } = render(wrap(client, <Profiler id="older-history" onRender={capture}>
|
||||
<ThreadShell session={session(chatId)} title="Older projection" onToggleSidebar={() => {}} />
|
||||
</Profiler>));
|
||||
await screen.findByText("current question");
|
||||
const scroller = container.querySelector(".thread-message-viewport") as HTMLElement;
|
||||
Object.defineProperties(scroller, {
|
||||
scrollHeight: { configurable: true, value: 2400 },
|
||||
clientHeight: { configurable: true, value: 600 },
|
||||
scrollTop: { configurable: true, writable: true, value: 0 },
|
||||
});
|
||||
fireEvent.keyDown(scroller, { key: "Home" });
|
||||
await waitFor(() => expect(resolveOlder).toBeTypeOf("function"));
|
||||
await screen.findByText("Loading earlier messages…");
|
||||
if (expectVisible) {
|
||||
act(() => client._emitChat(chatId, {
|
||||
event: "delta", chat_id: chatId, turn_id: "current-turn", text: "live during pagination",
|
||||
}));
|
||||
await screen.findByText("live during pagination");
|
||||
}
|
||||
const olderPayload = rows.length > 0
|
||||
? transcriptFromSimpleMessages(rows)
|
||||
: { schemaVersion: 3, projection: "events", events: [], page: { before_cursor: null, has_more_before: false } };
|
||||
olderReturned = true;
|
||||
await act(async () => {
|
||||
resolveOlder(error
|
||||
? new Response("History unavailable", { status: 503 })
|
||||
: httpJson({ ...olderPayload, page: { before_cursor: null, has_more_before: false } }));
|
||||
});
|
||||
if (expectVisible) await screen.findByText("older answer");
|
||||
await waitFor(() => expect(container.querySelector('.thread-history-status[data-state="loading"]')).toBeNull());
|
||||
expect(commits.some((commit) => commit.loading && !commit.olderVisible)).toBe(expectVisible);
|
||||
if (error) {
|
||||
expect(container.querySelector('.thread-history-status[data-state="error"]')).toBeInTheDocument();
|
||||
expect(container.querySelector(".thread-history-slot")).toBeInTheDocument();
|
||||
} else {
|
||||
expect(container.querySelector(".thread-history-slot")).not.toBeInTheDocument();
|
||||
}
|
||||
});
|
||||
|
||||
it("prepends earlier history while preserving the active answer cursor", async () => {
|
||||
const client = makeClient();
|
||||
const chatId = "running-paged-history";
|
||||
|
||||
Reference in new issue
Block a user