fix(webui): open the preset for blocked image input (#6724)

This commit is contained in:
chengyongru authored and GitHub committed 2026-11-19 18:39:00 +08:00
1 parent 607de63fb4
commit ce12bfdd0d
38 files changed
+430 -78

No files matched your search

+14
View File
@@ -137,6 +137,20 @@ describe("RecoveryNotice", () => {
expect(screen.getByRole("button", { name: "Dismiss" })).toBeInTheDocument();
});
it("keeps image recovery available without offering the same blocked retry", () => {
const onInspectImagePreset = vi.fn();
const state = { ...INTERRUPTED, reason: "model_request_failed", failure_error_kind: "unsupported_image" };
const actions = { onContinue: vi.fn(), onDismiss: vi.fn(), onInspectImagePreset };
const { rerender } = render(<RecoveryNotice state={state} {...actions} imageInputBlocked />);
expect(screen.getByRole("alert")).toHaveTextContent("This request includes images");
expect(screen.queryByRole("button", { name: "Continue" })).not.toBeInTheDocument();
fireEvent.click(screen.getByRole("button", { name: "View preset" }));
expect(onInspectImagePreset).toHaveBeenCalledOnce();
rerender(<RecoveryNotice state={state} {...actions} imageInputBlocked={false} />);
expect(screen.getByRole("button", { name: "Continue" })).toBeEnabled();
});
it("shows model authorization recovery after loading saved state", () => {
const onOpenSettings = vi.fn();
render(
+13
View File
@@ -83,6 +83,19 @@ function autoDynamicProviderPayload(
};
}
it("opens the targeted backup preset and focuses its Image input switch", async () => {
const { payload, backupPreset } = settingsPayloadWithBackup();
payload.model_presets[1] = { ...backupPreset, supports_images: false };
requestMutationMock.mockResolvedValue(payload);
renderSettingsView({ initialSection: "models", initialSettings: payload, focusTarget: "image-input:backup" });
const editor = await screen.findByRole("dialog", { name: "backup" });
const toggle = within(editor).getByRole("switch", { name: "Image input" });
expect(toggle).not.toBeChecked();
await waitFor(() => expect(toggle).toHaveFocus());
expect(requestMutationMock).not.toHaveBeenCalledWith("settings.model_configuration.update", expect.anything(), expect.anything());
});
async function togglePresetEditor(name = "primary") {
const row = await screen.findByTestId(`model-call-order-row-${name}`);
fireEvent.click(within(row).getAllByRole("button")[0]);
@@ -88,6 +88,56 @@ beforeEach(() => {
});
describe("ThreadComposer — attachments", () => {
it.each([false, true])("keeps a blocked image draft and opens the preset (active turn: %s)", async (isStreaming) => {
const file = pngFile("screenshot.png");
encodeImage.mockResolvedValueOnce(resolveReady(file));
const onSend = vi.fn();
const onInspectImagePreset = vi.fn();
const renderComposer = (imageInputBlocked: boolean, active = false) => (
<ThreadComposer isStreaming={active} {...{ onSend, imageInputBlocked, onInspectImagePreset }} />
);
const { rerender } = render(renderComposer(true, isStreaming), { wrapper: ToastProvider });
const textarea = screen.getByLabelText(/message input/i);
const input = textarea.closest("form")!.querySelector('input[type="file"]')!;
await act(async () => fireEvent.change(input, { target: { files: [file] } }));
fireEvent.change(textarea, { target: { value: "Please describe this" } });
fireEvent.keyDown(textarea, { key: "Enter" });
expect(screen.getByRole("alert")).toHaveTextContent("Image input is off for this preset");
expect(onSend).not.toHaveBeenCalled();
expect(textarea).toHaveValue("Please describe this");
expect(screen.getByTestId("composer-chip")).toBeVisible();
fireEvent.click(screen.getByRole("button", { name: "View preset" }));
expect(onInspectImagePreset).toHaveBeenCalledOnce();
rerender(renderComposer(false));
fireEvent.keyDown(textarea, { key: "Enter" });
expect(onSend).toHaveBeenCalledWith("Please describe this", [expect.objectContaining({
preview: expect.objectContaining({ name: file.name, kind: "image" }),
})], undefined);
});
it("pauses an already queued image when the next preset cannot process it", async () => {
const file = pngFile("queued.png");
encodeImage.mockResolvedValueOnce(resolveReady(file));
const onSend = vi.fn();
const { rerender } = render(<ThreadComposer isStreaming onSend={onSend} />, { wrapper: ToastProvider });
const textarea = screen.getByLabelText(/message input/i);
const input = textarea.closest("form")!.querySelector('input[type="file"]')!;
await act(async () => fireEvent.change(input, { target: { files: [file] } }));
fireEvent.change(textarea, { target: { value: "Queued with image" } });
fireEvent.keyDown(textarea, { key: "Enter" });
const queue = screen.getByRole("group", { name: "Waiting to send" });
expect(queue).toHaveTextContent("Queued with image");
rerender(<ThreadComposer imageInputBlocked onSend={onSend} />);
expect(await screen.findByRole("alert")).toHaveTextContent("Image input is off for this preset");
expect(onSend).not.toHaveBeenCalled();
fireEvent.click(within(queue).getByRole("button", { name: "Edit message" }));
expect(textarea).toHaveValue("Queued with image");
expect(screen.getByTestId("composer-chip")).toBeVisible();
});
it("previews a picked image with size details on hover and includes its data url on send", async () => {
const user = userEvent.setup();
const file = pngFile("a.png", 100);
@@ -150,11 +200,11 @@ describe("ThreadComposer — attachments", () => {
expect(onSend.mock.calls[0][1].map((attachment: { media: { name: string } }) => attachment.media.name)).toEqual([first.name]);
});
it("attaches a picked PDF and includes its data url on send", async () => {
it("attaches and sends a PDF even when the preset does not accept images", async () => {
const file = pdfFile();
const onSend = vi.fn();
render(<ThreadComposer onSend={onSend} />);
render(<ThreadComposer onSend={onSend} imageInputBlocked />);
const input = screen
.getByLabelText(/message input/i)
+36
View File
@@ -5746,6 +5746,42 @@ describe("ThreadShell", () => {
});
});
it.each([
["unsupported_image", "Image input is off for this preset"],
["image_request_rejected", "The model rejected the image request"],
])("shows %s as a preset action toast when there is no work to recover", async (errorKind, toastTitle) => {
const chatId = "chat-image-failure";
const client = makeClient();
const inspectPreset = vi.fn();
render(wrap(client, <ToastProvider>
<ThreadShell
session={{ ...session(chatId), modelPreset: "test-vision" }}
title="Chat image failure"
onToggleSidebar={() => {}}
onInspectImagePreset={inspectPreset}
/>
</ToastProvider>));
await act(async () => {});
act(() => client._emitChat(chatId, {
event: "turn_end", chat_id: chatId, turn_id: "image-turn",
outcome: "failed", failure_kind: "model", failure_error_kind: errorKind,
}));
expect(screen.queryByRole("alert")).not.toBeInTheDocument();
act(() => client._emitChat(chatId, {
event: "recovery_state", chat_id: chatId, recovery_id: "image-attempt",
status: "recovered", reason: "input_rejected", failure_error_kind: errorKind,
}));
const toast = await screen.findByRole("alert");
expect(toast.closest('[data-toast-tone="error"]')).not.toBeNull();
expect(toast).toHaveTextContent(toastTitle);
expect(screen.queryByRole("button", { name: "Continue" })).not.toBeInTheDocument();
fireEvent.click(screen.getByRole("button", { name: "View preset" }));
expect(inspectPreset).toHaveBeenCalledOnce();
expect(inspectPreset).toHaveBeenCalledWith("test-vision");
});
it.each([false, true])("keeps one terminal model failure visible until the next user action (recovery: %s)", async (recoverable) => {
const client = makeClient();
await act(async () => {