fix(webui): preserve previews during credential renewal
This commit is contained in:
1 parent
b555164a17
commit
c2edd5632e
8 files changed
+89
-11
No files matched your search
@@ -165,4 +165,23 @@ describe("FilePreviewPanel", () => {
|
||||
|
||||
expect(fetchFilePreview).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("preserves the open image and zoom on token renewal, using the current token for the next file", async () => {
|
||||
vi.mocked(fetchFilePreview).mockResolvedValue({
|
||||
kind: "image", path: "/workspace/chart.png", display_path: "chart.png",
|
||||
size: 42, mime_type: "image/png", data_url: "data:image/png;base64,example",
|
||||
});
|
||||
const view = (token: string, path = "chart.png") =>
|
||||
<FilePreviewPanel sessionKey="websocket:a" path={path} token={token} />;
|
||||
const { rerender } = render(view("old"));
|
||||
fireEvent.click(await screen.findByRole("button", { name: "View image: chart.png" }));
|
||||
const dialog = screen.getByRole("dialog");
|
||||
fireEvent.click(within(dialog).getByRole("button", { name: "Zoom in" }));
|
||||
rerender(view("renewed"));
|
||||
expect(fetchFilePreview).toHaveBeenCalledTimes(1);
|
||||
expect(screen.getByRole("dialog")).toBe(dialog);
|
||||
expect(within(dialog).getByRole("button", { name: "Fit image" })).toHaveTextContent("150%");
|
||||
rerender(view("renewed", "second.png"));
|
||||
await waitFor(() => expect(fetchFilePreview).toHaveBeenLastCalledWith("renewed", "websocket:a", "second.png"));
|
||||
});
|
||||
});
|
||||
@@ -5,6 +5,7 @@ import App from "@/App";
|
||||
import { ThreadMessageCache } from "@/lib/thread-message-cache";
|
||||
import { FilePreviewStore } from "@/hooks/useFilePreviewState";
|
||||
import type { InboundEvent, Outbound } from "@/lib/types";
|
||||
import { fetchBootstrap } from "@/lib/bootstrap";
|
||||
import { canonicalThreadPayload } from "./thread-test-payload";
|
||||
|
||||
let groupedTopics = false;
|
||||
@@ -16,7 +17,7 @@ const previewFile = (path: string) => ({
|
||||
|
||||
vi.mock("@/lib/bootstrap", async (importOriginal) => ({
|
||||
...await importOriginal<typeof import("@/lib/bootstrap")>(),
|
||||
fetchBootstrap: async () => ({ token: "test", api_token: "test", ws_path: "/" }),
|
||||
fetchBootstrap: vi.fn(async () => ({ token: "test", api_token: "test", ws_path: "/" })),
|
||||
deriveWsUrl: () => "ws://test",
|
||||
}));
|
||||
|
||||
@@ -95,6 +96,7 @@ async function selectTopic(name: string) {
|
||||
|
||||
describe("temporary chat navigation", () => {
|
||||
beforeEach(() => {
|
||||
vi.mocked(fetchBootstrap).mockReset().mockResolvedValue({ token: "test", api_token: "test", ws_path: "/" });
|
||||
groupedTopics = false;
|
||||
withFiles = false;
|
||||
localStorage.clear();
|
||||
@@ -145,6 +147,30 @@ describe("temporary chat navigation", () => {
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
it("keeps the preview resource stable across bootstrap token refresh", async () => {
|
||||
withFiles = true;
|
||||
vi.useFakeTimers({ shouldAdvanceTime: true });
|
||||
vi.mocked(fetchBootstrap)
|
||||
.mockResolvedValueOnce({ token: "old", api_token: "old", ws_path: "/", expires_in: 30 })
|
||||
.mockResolvedValue({ token: "renewed", api_token: "renewed", ws_path: "/", expires_in: 300 });
|
||||
render(<App />);
|
||||
await screen.findByRole("button", { name: "Temporary chat" });
|
||||
act(() => TestSocket.current.open());
|
||||
await selectTopic("Regular topic");
|
||||
fireEvent.click(await screen.findByRole("button", { name: "notes.txt" }));
|
||||
const content = await screen.findByText("Preview of notes.txt");
|
||||
const fullPreviewRequests = () => vi.mocked(fetch).mock.calls.filter(([url]) =>
|
||||
String(url).includes("/file-preview?path=") && !String(url).includes("probe=") && !String(url).includes("metadata="));
|
||||
expect(fullPreviewRequests()).toHaveLength(1);
|
||||
await act(async () => { await vi.advanceTimersByTimeAsync(15_000); });
|
||||
expect(fetchBootstrap).toHaveBeenCalledTimes(2);
|
||||
expect(screen.getByText("Preview of notes.txt")).toBe(content);
|
||||
expect(fullPreviewRequests()).toHaveLength(1);
|
||||
fireEvent.click(screen.getByRole("button", { name: "second.txt" }));
|
||||
await screen.findByText("Preview of second.txt");
|
||||
expect(new Headers(fullPreviewRequests().at(-1)?.[1]?.headers).get("Authorization")).toBe("Bearer renewed");
|
||||
});
|
||||
|
||||
it.each([false, true])("restores file previews after pane navigation (temporary=%s)", async (temporary) => {
|
||||
withFiles = true;
|
||||
groupedTopics = true;
|
||||
|
||||
@@ -76,6 +76,16 @@ describe("web preview boundaries", () => {
|
||||
});
|
||||
|
||||
describe("web link actions", () => {
|
||||
it("reserves room for actions beside a full-width link row without changing inline links", () => {
|
||||
const { rerender } = render(<WebLink layout="row" href="https://example.com/">Long website title</WebLink>);
|
||||
const link = screen.getByRole("link", { name: "Long website title" });
|
||||
expect(link.parentElement).toHaveClass("inline-flex", "w-full");
|
||||
expect(link).toHaveClass("min-w-0", "flex-1");
|
||||
expect(screen.getByRole("button", { name: "Link actions" })).toHaveClass("shrink-0");
|
||||
rerender(<WebLink href="https://example.com/">Long website title</WebLink>);
|
||||
expect(link.parentElement).toHaveClass("inline");
|
||||
expect(link).not.toHaveClass("flex-1");
|
||||
});
|
||||
it("opens a shared right-click menu without loading any website beforehand", async () => {
|
||||
const open = vi.fn();
|
||||
const { container } = render(<WebPreviewContext.Provider value={open}><WebLink href="https://example.com/?a=b#c">Example</WebLink></WebPreviewContext.Provider>);
|
||||
|
||||
Reference in new issue
Block a user