diff --git a/ui/src/components/IssueMonitorBanner.test.tsx b/ui/src/components/IssueMonitorBanner.test.tsx index 3074c002537..825724a797b 100644 --- a/ui/src/components/IssueMonitorBanner.test.tsx +++ b/ui/src/components/IssueMonitorBanner.test.tsx @@ -1,8 +1,39 @@ -// @vitest-environment node -import { renderToStaticMarkup } from "react-dom/server"; -import { expect, it } from "vitest"; -import type { Issue } from "@paperclipai/shared"; -import { IssueMonitorComposerStrip } from "./IssueMonitorBanner"; +// @vitest-environment jsdom +import type { ReactElement } from "react"; +import { flushSync } from "react-dom"; +import { createRoot, type Root } from "react-dom/client"; +import { afterEach, expect, it } from "vitest"; +import type { Issue, IssueWorkProduct } from "@paperclipai/shared"; +import { IssueMonitorBanner, IssueMonitorComposerStrip } from "./IssueMonitorBanner"; + +const mounted: Array<{ root: Root; container: HTMLDivElement }> = []; + +afterEach(() => { + while (mounted.length > 0) { + const entry = mounted.pop()!; + flushSync(() => entry.root.unmount()); + entry.container.remove(); + } +}); + +function render(element: ReactElement): HTMLDivElement { + const container = document.createElement("div"); + document.body.appendChild(container); + const root = createRoot(container); + flushSync(() => root.render(element)); + mounted.push({ root, container }); + return container; +} + +function findButton(container: HTMLElement, label: string): HTMLButtonElement | undefined { + return Array.from(container.querySelectorAll("button")).find( + (button) => button.textContent?.trim() === label, + ); +} + +function findCheckNowButton(container: HTMLElement): HTMLButtonElement | undefined { + return findButton(container, "Check now"); +} function waitingIssue(scheduledRetryReason: string) { return { @@ -17,14 +48,150 @@ function waitingIssue(scheduledRetryReason: string) { } as unknown as Issue; } -it("tells a user that a reply rechecks usage, not that it starts work outright", () => { - const markup = renderToStaticMarkup(); - expect(markup).toContain("Pool exhausted"); - expect(markup).toContain("Sending a reply checks usage again now."); - expect(markup).not.toContain("wakes the agent now"); +function monitoredIssue(serviceName = "github_pr_checks") { + return { + id: "issue-2", + status: "in_progress", + executionState: { + monitor: { + status: "scheduled", + nextCheckAt: new Date(Date.now() + 3 * 60_000).toISOString(), + attemptCount: 1, + serviceName, + }, + }, + } as unknown as Issue; +} + +function pendingPullRequestWorkProduct(): IssueWorkProduct { + return { + id: "wp-pr-1", + type: "pull_request", + title: "PR #23763", + status: "open", + reviewState: "needs_board_review", + url: "https://github.com/paperclipai/paperclip/pull/23763", + isPrimary: true, + updatedAt: new Date().toISOString(), + } as unknown as IssueWorkProduct; +} + +it("tells a user that a reply rechecks usage and keeps Check now vertically centered alongside the hint", () => { + const container = render( + {}} />, + ); + const strip = container.querySelector('[data-testid="issue-monitor-composer-strip"]'); + expect(strip?.textContent).toContain("Pool exhausted"); + expect(strip?.textContent).not.toContain("wakes the agent now"); + + const hint = Array.from(container.querySelectorAll("p")).find((node) => + node.textContent?.includes("Sending a reply checks usage again now."), + ); + const button = findCheckNowButton(container); + expect(hint).toBeDefined(); + expect(button).toBeDefined(); + + const row = button!.parentElement; + const leftColumn = hint!.parentElement; + expect(row).not.toBeNull(); + expect(row!.classList.contains("sm:flex-row")).toBe(true); + expect(row!.classList.contains("sm:items-center")).toBe(true); + expect(leftColumn).not.toBeNull(); + expect(leftColumn).not.toBe(row); + expect(leftColumn!.parentElement).toBe(row); + expect(leftColumn!.textContent).toContain("Pool exhausted"); + expect(leftColumn!.contains(hint!)).toBe(true); + expect(leftColumn!.contains(button!)).toBe(false); + expect(row!.contains(hint!)).toBe(true); + expect(row!.contains(button!)).toBe(true); }); -it("keeps the wake-now promise for an ordinary scheduled retry", () => { - const markup = renderToStaticMarkup(); - expect(markup).toContain("Sending a reply wakes the agent now"); +it("omits the reply wake copy for an ordinary scheduled retry", () => { + const container = render( + {}} />, + ); + expect(container.textContent).not.toContain("wakes the agent now"); + expect(container.textContent).not.toContain("before the scheduled check"); + expect(container.querySelector("p")).toBeNull(); + + const button = findCheckNowButton(container); + expect(button).toBeDefined(); + expect(button!.parentElement?.classList.contains("sm:flex-row")).toBe(true); + expect(button!.parentElement?.classList.contains("sm:items-center")).toBe(true); +}); + +it("omits the reply wake copy and centers Check now for a scheduled monitor", () => { + const stripContainer = render( + {}} />, + ); + expect(stripContainer.textContent).toContain("Watching: github_pr_checks"); + expect(stripContainer.textContent).not.toContain("wakes the agent now"); + expect(stripContainer.textContent).not.toContain("before the scheduled check"); + expect(stripContainer.querySelector("p")).toBeNull(); + + const stripButton = findCheckNowButton(stripContainer); + expect(stripButton).toBeDefined(); + expect(stripButton!.parentElement?.classList.contains("sm:flex-row")).toBe(true); + expect(stripButton!.parentElement?.classList.contains("sm:items-center")).toBe(true); + + const bannerContainer = render( + {}} />, + ); + const banner = bannerContainer.querySelector('[role="note"]'); + const bannerButton = findCheckNowButton(bannerContainer); + expect(banner).not.toBeNull(); + expect(banner!.classList.contains("sm:flex-row")).toBe(true); + expect(banner!.classList.contains("sm:items-center")).toBe(true); + expect(banner!.classList.contains("sm:items-start")).toBe(false); + expect(bannerButton).toBeDefined(); + expect(bannerButton!.parentElement?.parentElement).toBe(banner); +}); + +it("renders the relocated pullRequestReview and active-run strip hints inside the centered row", () => { + const workProducts = [pendingPullRequestWorkProduct()]; + + const reviewContainer = render( + {}} + />, + ); + const reviewHint = Array.from(reviewContainer.querySelectorAll("p")).find((node) => + node.textContent?.includes("Review on GitHub, then check status to have the agent verify the result."), + ); + const checkStatusButton = findButton(reviewContainer, "Check status"); + expect(reviewHint).toBeDefined(); + expect(checkStatusButton).toBeDefined(); + const reviewRow = checkStatusButton!.parentElement; + const reviewLeftColumn = reviewHint!.parentElement; + expect(reviewRow?.classList.contains("sm:flex-row")).toBe(true); + expect(reviewRow?.classList.contains("sm:items-center")).toBe(true); + expect(reviewLeftColumn?.parentElement).toBe(reviewRow); + expect(reviewLeftColumn?.contains(checkStatusButton!)).toBe(false); + + const activeReviewContainer = render( + {}} + />, + ); + expect(activeReviewContainer.textContent).toContain( + "Review on GitHub while the current run finishes saving its work.", + ); + expect(findButton(activeReviewContainer, "Check status")).toBeUndefined(); + + const activeRunContainer = render( + {}} + />, + ); + expect(activeRunContainer.textContent).toContain( + "You can keep sending instructions while the agent waits.", + ); + expect(findCheckNowButton(activeRunContainer)).toBeUndefined(); }); diff --git a/ui/src/components/IssueMonitorBanner.tsx b/ui/src/components/IssueMonitorBanner.tsx index ba30072750a..7eca5d53b46 100644 --- a/ui/src/components/IssueMonitorBanner.tsx +++ b/ui/src/components/IssueMonitorBanner.tsx @@ -61,15 +61,13 @@ export interface MonitorSurfaceCopy { bannerMeta: string[]; /** Muted detail line for the composer strip. */ stripMeta: string[]; + /** Optional state-specific hint rendered beneath the strip metadata inside the left column. */ + stripHint?: string; /** `warning` (amber) once overdue, `info` (blue) while still on schedule. */ tone: "info" | "warning"; workspaceWait?: boolean; pullRequestReview?: boolean; - automaticChecksPaused?: boolean; checkUnavailable?: boolean; - executionWait?: boolean; - /** Waiting for AI account usage; a reply rechecks usage instead of starting work outright. */ - usageWait?: boolean; } function capitalize(value: string): string { @@ -102,7 +100,6 @@ export function buildMonitorSurfaceCopy( bannerMeta: [hint], stripMeta: [hint], tone: "info", - automaticChecksPaused: true, checkUnavailable: !canCheckNow, }; } @@ -113,6 +110,7 @@ export function buildMonitorSurfaceCopy( stripTitle: "Waiting for the sandbox provider", bannerMeta: ["The sandbox provider is unavailable. Work continues automatically when it is back."], stripMeta: ["Work continues automatically when the sandbox provider is back."], + stripHint: "You can keep sending instructions while the agent waits.", tone: "info", workspaceWait: true, }; @@ -124,6 +122,7 @@ export function buildMonitorSurfaceCopy( stripTitle: "Waiting for workspace", bannerMeta: ["Another task is using this workspace. Work starts automatically when it is available."], stripMeta: ["Work starts automatically when the workspace is available."], + stripHint: "You can keep sending instructions while the agent waits.", tone: "info", workspaceWait: true, }; @@ -139,8 +138,10 @@ export function buildMonitorSurfaceCopy( stripTitle: "Monitor waits for current run", bannerMeta: [hint, `Scheduled for ${absolute} (your time)`], stripMeta: [hint, `Scheduled for ${absolute}`], + stripHint: awaitingPullRequestReview + ? "Review on GitHub while the current run finishes saving its work." + : "You can keep sending instructions while the agent waits.", tone: "info", - executionWait: true, checkUnavailable: true, pullRequestReview: awaitingPullRequestReview, }; @@ -151,6 +152,7 @@ export function buildMonitorSurfaceCopy( stripTitle: "Pull request review requested", bannerMeta: [`Next check ${eta} · ${absolute} (your time)`], stripMeta: [`Next check ${eta} · ${absolute}`], + stripHint: "Review on GitHub, then check status to have the agent verify the result.", tone: derived.state === "overdue" ? "warning" : "info", pullRequestReview: true, }; @@ -161,8 +163,8 @@ export function buildMonitorSurfaceCopy( stripTitle: "Pool exhausted", bannerMeta: [`Usage recheck ${eta} · ${absolute} (your time)`, "Tasks with a selected account keep it while waiting. Work resumes when usage permits or the agent uses a different account."], stripMeta: [`Usage recheck ${eta} · ${absolute}`, "Tasks with a selected account keep it while waiting."], + stripHint: "Sending a reply checks usage again now. The agent starts as soon as usage is available.", tone: "info", - usageWait: true, }; } @@ -321,7 +323,7 @@ export function IssueMonitorBanner({ tone={copy.tone} icon={Clock} title={copy.bannerTitle} - className={cn("relative my-3", canCancel && "pr-12")} + className={cn("relative my-3 sm:items-center", canCancel && "pr-12")} actions={onCheckNow && !copy.workspaceWait && !copy.checkUnavailable ? : null} > {canCancel ? : null} @@ -336,8 +338,7 @@ export function IssueMonitorBanner({ /** * Slim, inline (not sticky) strip anchored directly above the reply composer. - * Mirrors the banner's monitor state and reminds the reader that replying wakes - * the agent early (PAP-14557 decisions 2 + wireframe 02). + * Mirrors the banner's monitor state. */ export function IssueMonitorComposerStrip({ issue, @@ -356,32 +357,22 @@ export function IssueMonitorComposerStrip({
-
-
);