import { fireEvent, render, screen, waitFor } from "@testing-library/react"; import { describe, expect, it, vi } from "vitest"; import { RecoveryNotice } from "@/components/thread/RecoveryNotice"; const INTERRUPTED = { status: "awaiting_user" as const, recovery_id: "recovery-1", reason: "tool_state_uncertain", }; describe("RecoveryNotice", () => { it("hides the internal resuming state after Continue is accepted", async () => { const onContinue = vi.fn().mockResolvedValue(undefined); render( , ); fireEvent.click(screen.getByRole("button", { name: "Continue" })); await waitFor(() => expect(screen.queryByRole("alert")).not.toBeInTheDocument()); expect(onContinue).toHaveBeenCalledOnce(); }); it("keeps an active continuation hidden after remounting", async () => { const onContinue = vi.fn().mockResolvedValue(undefined); const onDismiss = vi.fn().mockResolvedValue(undefined); const { unmount } = render( , ); fireEvent.click(screen.getByRole("button", { name: "Continue" })); await waitFor(() => expect(screen.queryByRole("alert")).not.toBeInTheDocument()); unmount(); const { container } = render( , ); expect(container).toBeEmptyDOMElement(); }); it("uses the shared alert surface and motion treatment", () => { render( , ); const notice = screen.getByRole("alert"); expect(notice).toHaveAttribute("data-recovery-status", "awaiting_user"); expect(notice).toHaveAttribute("aria-live", "assertive"); expect(notice).toHaveClass( "thread-composer-notice", "rounded-control", "animate-in", "fade-in-0", "slide-in-from-bottom-1", "duration-200", "motion-reduce:animate-none", ); }); it("keeps the notice visible when Continue fails", async () => { const onContinue = vi.fn().mockRejectedValue(new Error("offline")); render( , ); fireEvent.click(screen.getByRole("button", { name: "Continue" })); await waitFor(() => { expect(screen.getByRole("alert")).toHaveTextContent("Recovery action failed"); }); }); it.each(["awaiting_user", "failed"] as const)( "shows the decision surface again when a continuation returns to %s", async (status) => { const onContinue = vi.fn().mockResolvedValue(undefined); const { rerender } = render( , ); fireEvent.click(screen.getByRole("button", { name: "Continue" })); await waitFor(() => expect(screen.queryByRole("alert")).not.toBeInTheDocument()); rerender( , ); rerender( , ); await waitFor(() => expect(screen.getByRole("alert")).toBeInTheDocument()); }, ); it("does not offer Continue when saved conversation context is unavailable", () => { render( , ); 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( , ); 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(); }); });