fix(webui): recover model failures and align chat controls
This commit is contained in:
1 parent
688976bcb9
commit
28f6c26946
42 files changed
+646
-82
No files matched your search
@@ -209,12 +209,12 @@ describe("MessageBubble", () => {
|
||||
const pill = screen.getByText("hello");
|
||||
|
||||
expect(row).toHaveClass("ml-auto", "flex");
|
||||
expect(row).toHaveAttribute("data-user-text-bubble", "true");
|
||||
expect(pill.parentElement).toHaveAttribute("data-user-text-bubble", "true");
|
||||
expect(pill).toHaveClass("ml-auto", "w-fit", "rounded-floating");
|
||||
expect(pill).toHaveTextContent("hello");
|
||||
});
|
||||
|
||||
it("aligns the context trigger to the first text line only when text leads the user block", () => {
|
||||
it("anchors the context trigger to the text even below an image or quote", () => {
|
||||
const message: UIMessage = {
|
||||
id: "u-alignment", role: "user", content: "first line\nsecond line", createdAt: 0,
|
||||
};
|
||||
@@ -222,15 +222,17 @@ describe("MessageBubble", () => {
|
||||
const { container, rerender } = render(
|
||||
<MessageBubble message={message} contextMenu={contextMenu} />,
|
||||
);
|
||||
const row = container.firstElementChild!;
|
||||
expect(row).toHaveAttribute("data-user-text-bubble", "true");
|
||||
expect(screen.getByRole("button", { name: "Message actions" }).parentElement).toBe(row);
|
||||
const anchor = container.querySelector("[data-user-text-bubble]")!;
|
||||
expect(anchor).toHaveClass("relative");
|
||||
expect(screen.getByRole("button", { name: "Message actions" }).parentElement).toBe(anchor);
|
||||
|
||||
rerender(<MessageBubble message={{ ...message, images: [{ name: "image.png" }] }} contextMenu={contextMenu} />);
|
||||
expect(row).not.toHaveAttribute("data-user-text-bubble");
|
||||
expect(screen.getByRole("button", { name: "Message actions" }).parentElement)
|
||||
.toBe(container.querySelector("[data-user-text-bubble]"));
|
||||
|
||||
rerender(<MessageBubble message={{ ...message, content: "> [!QUOTE]\n> excerpt\n\nreply" }} contextMenu={contextMenu} />);
|
||||
expect(row).not.toHaveAttribute("data-user-text-bubble");
|
||||
expect(screen.getByRole("button", { name: "Message actions" }).parentElement)
|
||||
.toBe(screen.getByText("reply").parentElement);
|
||||
});
|
||||
|
||||
it("renders cross-session input with its public handle", () => {
|
||||
|
||||
@@ -5,11 +5,12 @@ import { resolveModelRequestFailureCopy } from "@/lib/model-request-failure";
|
||||
|
||||
describe("model request failure copy", () => {
|
||||
it("maps every sanitized provider error category to a specific cause", () => {
|
||||
const titles = ["billing", "connection", "timeout", "rate_limit", "server", "unknown"].map(
|
||||
const titles = ["authentication", "billing", "connection", "timeout", "rate_limit", "server", "unknown"].map(
|
||||
(errorKind) => resolveModelRequestFailureCopy({ errorKind }, i18n.t).title,
|
||||
);
|
||||
|
||||
expect(titles).toEqual([
|
||||
"Model provider authorization failed",
|
||||
"Model provider quota is unavailable",
|
||||
"Could not connect to the model provider",
|
||||
"Model provider request timed out",
|
||||
@@ -24,8 +25,7 @@ describe("model request failure copy", () => {
|
||||
{ errorKind: "connection", attempts: 4 },
|
||||
i18n.t,
|
||||
).body).toBe(
|
||||
"The request still failed on attempt 4, so retries stopped. "
|
||||
+ "Check the provider configuration or service status, then try again.",
|
||||
"Stopped after 4 attempts. Try again later or choose another model.",
|
||||
);
|
||||
});
|
||||
|
||||
@@ -42,7 +42,7 @@ describe("model request failure copy", () => {
|
||||
const body = resolveModelRequestFailureCopy({ errorKind: "unknown" }, i18n.t).body;
|
||||
|
||||
expect(body).toBe(
|
||||
"Check the provider configuration or service status, then try again.",
|
||||
"Try again later or choose another model.",
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -62,7 +62,7 @@ describe("RecoveryNotice", () => {
|
||||
expect(notice).toHaveAttribute("data-recovery-status", "awaiting_user");
|
||||
expect(notice).toHaveAttribute("aria-live", "assertive");
|
||||
expect(notice).toHaveClass(
|
||||
"max-w-[49.5rem]",
|
||||
"thread-composer-notice",
|
||||
"rounded-control",
|
||||
"animate-in",
|
||||
"fade-in-0",
|
||||
@@ -136,4 +136,21 @@ describe("RecoveryNotice", () => {
|
||||
expect(screen.queryByRole("button", { name: "Continue" })).not.toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: "Dismiss" })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("shows model authorization recovery after loading saved state", () => {
|
||||
const onOpenSettings = vi.fn();
|
||||
render(
|
||||
<RecoveryNotice
|
||||
state={{ ...INTERRUPTED, reason: "model_request_failed", failure_error_kind: "authentication" }}
|
||||
onContinue={vi.fn().mockResolvedValue(undefined)}
|
||||
onDismiss={vi.fn().mockResolvedValue(undefined)}
|
||||
onOpenSettings={onOpenSettings}
|
||||
/>,
|
||||
);
|
||||
expect(screen.getByRole("alert")).toHaveTextContent("Model provider authorization failed");
|
||||
expect(screen.getByRole("alert")).not.toHaveTextContent("Task interrupted");
|
||||
fireEvent.click(screen.getByRole("button", { name: "Open model settings" }));
|
||||
expect(onOpenSettings).toHaveBeenCalledOnce();
|
||||
expect(screen.getByRole("button", { name: "Continue" })).toBeEnabled();
|
||||
});
|
||||
});
|
||||
@@ -589,7 +589,7 @@ describe("ThreadComposer", () => {
|
||||
expect(input.className).toContain("pt-[27px]");
|
||||
fireEvent.change(input, { target: { value: "1" } });
|
||||
expect(input.className).toContain("pt-[27px]");
|
||||
expect(input.parentElement?.parentElement?.className).toContain("max-w-[58rem]");
|
||||
expect(input.parentElement?.parentElement?.className).toContain("max-w-[var(--composer-content-width,58rem)]");
|
||||
});
|
||||
|
||||
it("defers textarea autosizing until IME composition commits", () => {
|
||||
@@ -821,7 +821,7 @@ describe("ThreadComposer", () => {
|
||||
const input = screen.getByPlaceholderText("Type your message...");
|
||||
expect(input.className).toContain("min-h-[50px]");
|
||||
expect(input.className).toContain("text-composer");
|
||||
expect(input.parentElement?.parentElement?.className).toContain("max-w-[49.5rem]");
|
||||
expect(input.parentElement?.parentElement?.className).toContain("max-w-[var(--composer-content-width,49.5rem)]");
|
||||
expect(input.parentElement?.parentElement?.className).toContain("rounded-panel");
|
||||
expect(input.parentElement?.parentElement?.className).not.toContain("shadow-");
|
||||
expect(screen.getByRole("button", { name: "Send message" }).className).toContain("bg-foreground");
|
||||
|
||||
@@ -5030,7 +5030,7 @@ describe("ThreadShell", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps a terminal model failure visible until the next user action", async () => {
|
||||
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 () => {
|
||||
await i18n.changeLanguage("zh-CN");
|
||||
@@ -5066,14 +5066,40 @@ describe("ThreadShell", () => {
|
||||
const banner = await screen.findByRole("alert");
|
||||
expect(banner).toHaveTextContent("无法连接模型提供商");
|
||||
expect(banner).toHaveTextContent(
|
||||
"模型提供商请求在第 4 次尝试后仍然失败,已停止重试。请检查提供商配置或服务状态后重试。",
|
||||
"已尝试 4 次,仍未成功。可稍后继续或切换模型。",
|
||||
);
|
||||
expect(banner).not.toHaveTextContent("Unlocalized server failure");
|
||||
if (recoverable) {
|
||||
act(() => {
|
||||
client._emitChat("chat-model-failure", {
|
||||
event: "recovery_state",
|
||||
chat_id: "chat-model-failure",
|
||||
recovery_id: "model-recovery",
|
||||
status: "awaiting_user",
|
||||
reason: "model_request_failed",
|
||||
failure_error_kind: "connection",
|
||||
});
|
||||
});
|
||||
expect(screen.getAllByRole("alert")).toHaveLength(1);
|
||||
expect(screen.getByRole("alert")).toHaveTextContent("无法连接模型提供商");
|
||||
expect(screen.getByRole("button", { name: "继续" })).toBeEnabled();
|
||||
}
|
||||
|
||||
fireEvent.change(screen.getByLabelText("消息输入框"), {
|
||||
target: { value: "try again" },
|
||||
});
|
||||
fireEvent.click(screen.getByRole("button", { name: "发送消息" }));
|
||||
if (recoverable) {
|
||||
act(() => {
|
||||
client._emitChat("chat-model-failure", {
|
||||
event: "recovery_state",
|
||||
chat_id: "chat-model-failure",
|
||||
recovery_id: "model-recovery",
|
||||
status: "recovered",
|
||||
reason: "superseded",
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.queryByRole("alert")).not.toBeInTheDocument();
|
||||
|
||||
@@ -726,6 +726,36 @@ describe("useNanobotStream", () => {
|
||||
expect(fake.client.finishRunLocally).toHaveBeenCalledWith("chat-recovery");
|
||||
});
|
||||
|
||||
it.each(["awaiting_user", "resuming"] as const)(
|
||||
"reconciles a missed model recovery event after reconnecting to %s",
|
||||
(status) => {
|
||||
const fake = fakeClient();
|
||||
const { result } = renderHook(() => useNanobotStream("chat-recovery", EMPTY_MESSAGES), {
|
||||
wrapper: wrap(fake.client),
|
||||
});
|
||||
act(() => {
|
||||
fake.emit("chat-recovery", {
|
||||
event: "turn_end", chat_id: "chat-recovery",
|
||||
outcome: "failed", failure_kind: "model", failure_error_kind: "connection",
|
||||
});
|
||||
});
|
||||
expect(result.current.streamError?.kind).toBe("model_request_failed");
|
||||
act(() => {
|
||||
fake.emit("chat-recovery", {
|
||||
event: "attached", chat_id: "chat-recovery",
|
||||
recovery_state: {
|
||||
recovery_id: "recovery-1", status,
|
||||
reason: status === "resuming" ? "user_confirmed" : "model_request_failed",
|
||||
failure_error_kind: "connection",
|
||||
},
|
||||
});
|
||||
});
|
||||
expect(result.current.streamError).toBeNull();
|
||||
expect(result.current.recoveryState?.status).toBe(status);
|
||||
expect(result.current.isStreaming).toBe(status === "resuming");
|
||||
},
|
||||
);
|
||||
|
||||
it("does not let historical recovered state clear a later active turn", () => {
|
||||
const fake = fakeClient();
|
||||
const { result } = renderHook(
|
||||
|
||||
Reference in new issue
Block a user