Files
PaperClipAI/ui/src/components/AttentionQueueRow.test.tsx
T
cf1def0ca6 feat(inbox): rebuild compact cards and share task review controls (#20961)
## Thinking Path

> - Paperclip helps people manage AI agents and their work.
> - The inbox collects decisions, requests, and updates for the people
in a company.
> - People need a clear personal queue and a consistent way to answer
each request.
> - Repeated headings, inconsistent card actions, and separate review
flows make that work harder.
> - This pull request connects the inbox UI to the routing foundation in
#20959.
> - Compact cards use shared task controls and open supporting work in a
side panel.
> - People can answer, claim, transfer, archive, and inspect outcomes
from one place.

## Linked Issues or Issue Description

**What existing behavior does this improve?**

The inbox cards, personal views, shared task controls, and decision
history.

**Subsystem affected**

UI. This PR targets master and uses the routing foundation merged in
#20959.

**Current behavior**

The inbox repeats headings and counts. Cards have different layouts and
action placement. The requester can repeat the signed-in person's name.
Review and question controls differ between the inbox and task thread.

**Proposed behavior**

Open Assigned to you by default. Show one count line above the cards.
Use a compact card layout with consistent actions and supporting
details. Show the requester's avatar and name only when they differ from
the signed-in person. Share question controls, including a radio option
for Other that reveals a text field when selected.

**Reason and benefit**

People can scan their queue and complete requests without losing the
surrounding task or creating separate drafts for the same review.

**Breaking changes**

The default inbox view becomes personal. The all-assignee and shared
views remain available. Card close menus distinguish personal archive
and snooze from shared withdrawal.

**Additional context**

Refs #20959, #19363, and #19520. Refs #20268 for related
actionable-request work. This stack adds personal routing and shared
controls. ROADMAP.md includes Multiple Human Users and Agent Reviews and
Approvals.

## What Changed

- Add personal, unassigned, company, all-assignee, and archived inbox
views. Add claim, transfer, personal close actions, receipts, and
history controls.
- Use compact decision cards with a single count line, one-pixel
borders, and equal space above, below, and to the right of each primary
action.
- Open artifacts and synchronized confirmation/approval controls in a
shared side panel. Share their revision drafts and action state with the
task thread. Other requests keep one editable form on the inbox card
while reviewing an artifact.
- Make Other match the question options and reveal its field only when
selected. Apply this to inbox and task question cards.
- Hide self-requester labels, space agent avatars, and use the standard
canceled status icon for withdrawn requests.
- Use connector logos in connector cards. Keep the connector promotion
background and sidebar border continuous.
- Add company and project decision-owner controls and document the
updated inbox behavior.

## Verification

- The complete [GitHub Actions CI
matrix](https://github.com/paperclipai/paperclip/actions/runs/43141559641)
passes on `8d81a75e49b518fff6b6ff4c23dd67979b0b97ee` (Linux/Node 24:
typecheck, build, general and serialized tests, Runner support, browser
shards, and aggregate gates). Greptile is 5/5 on that exact head with
zero open findings, and the security scan passes.
- Local UI typechecking passes. Eight focused suites pass 382 tests: 236
inbox/review/question/connector tests plus all 146 composer tests.
Regressions passed red to green for attachment links, prompt rendering,
single-form artifact review, connector scope copy, accessible headings,
and the composer test harness's missing theme provider. The final commit
changes only that test harness; production code is unchanged from
`59d015833f`.
- Browser acceptance on the production implementation confirms preserved
selected answers with one editable question form, accessible Markdown
prompts, inert image references, accurate connector scope copy, native
PDF downloads, image sidebar previews, and Open file requesting the
attachment endpoint while preserving the inbox URL. Request reads and
file responses were intercepted; no question answers were written. The
preview is healthy on the final head.
- Visual and interaction checks cover Other radio behavior in both
themes and on mobile, the loaded Google Calendar logo, and 20px above,
below, and to the right of the primary action across all 23 visible
cards. The affected desktop/mobile navigation and sidebar specs pass
locally and in the final CI browser matrix.
- Real-editor browser checks confirm Ctrl/Cmd+Enter cannot bypass
another person's confirmation. Cancel preserves the draft and unlocks
silently; Continue submits once. Approval write failures remain visible.
- `pnpm verify` returns exit 2 because DESIGN.md requires broader
coverage; the final full CI matrix supplies every requested gate. Maps
and Storybook catalog structural checks pass. The routing foundation
#20959 merged after passing 249 database tests, server typechecking,
full CI, Greptile 5/5, and security scanning. Its backend and SDK
registry are preserved.
- Demo data is retained for testing; database suites and browser specs
use separate disposable databases.

## Risks

- The inbox uses the routing contracts merged in #20959. Personal
filters and history affect shared task entry points; the affected
controls are included in local regression coverage and full CI.
- Personal defaults and close-menu wording change inbox behavior.
Existing resolver permissions still control shared actions.
- Shared revision state and live invalidation affect two surfaces.
Focused tests cover draft synchronization, action locks, and incoming
updates.
- Visual changes use the existing design tokens and component
primitives.

## Model Used

OpenAI GPT-6 through Codex. Used repository tools, code execution, and
browser checks. This session does not expose a more specific runtime
model ID or its context-window size.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have described the issue in-PR following the relevant issue
template
- [x] I have not referenced internal/instance-local Paperclip issues or
links
- [x] My branch name describes the change and contains no internal
Paperclip ticket id
- [x] I have run focused tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

---------

Co-authored-by: Scott Tong <scott@scottsmbpm5max.lan>
Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-11-11 21:05:00 -08:00

1086 lines
39 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// @vitest-environment jsdom
import { createRoot } from "react-dom/client";
import { flushSync } from "react-dom";
import { useState, type AnchorHTMLAttributes, type ReactElement } from "react";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { afterEach, describe, expect, it, vi } from "vitest";
import type { AttentionItem, AttentionSourceKind } from "@paperclipai/shared";
import { accessApi } from "../api/access";
import { approvalsApi } from "../api/approvals";
import { ApiError } from "../api/client";
import { issuesApi } from "../api/issues";
import { ToastViewport } from "./ToastViewport";
import { ToastProvider } from "../context/ToastContext";
import { ApprovalResolver, JoinRequestResolver, AttentionQueueRow } from "./AttentionQueueRow";
vi.mock("@/lib/router", () => ({
Link: ({ children, to, ...props }: AnchorHTMLAttributes<HTMLAnchorElement> & { to: string }) => (
<a href={to} {...props}>{children}</a>
),
}));
vi.mock("../api/access", () => ({ accessApi: { approveJoinRequest: vi.fn(), rejectJoinRequest: vi.fn() } }));
vi.mock("../api/approvals", () => ({
approvalsApi: {
approve: vi.fn(),
reject: vi.fn(),
requestRevision: vi.fn(),
},
}));
vi.mock("../api/issues", () => ({
issuesApi: {
acceptInteraction: vi.fn(),
rejectInteraction: vi.fn(),
decideStalledReview: vi.fn(() => Promise.resolve({})),
},
}));
// Spy on `relativeTime` (called exactly once per active-row render) so the
// memoization test below can count row renders without a profiling build.
vi.mock("../lib/utils", async (importOriginal) => {
const original = await importOriginal<typeof import("../lib/utils")>();
return { ...original, relativeTime: vi.fn(original.relativeTime) };
});
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(globalThis as any).IS_REACT_ACT_ENVIRONMENT = true;
function act<T>(cb: () => T): T {
let result: T | undefined;
flushSync(() => {
result = cb();
});
return result as T;
}
let root: ReturnType<typeof createRoot> | null = null;
let container: HTMLDivElement | null = null;
let queryClient: QueryClient | null = null;
afterEach(() => {
if (root) act(() => root?.unmount());
root = null;
container?.remove();
container = null;
vi.clearAllMocks();
});
function render(element: ReactElement) {
container = document.createElement("div");
document.body.appendChild(container);
root = createRoot(container);
const client = new QueryClient({ defaultOptions: { queries: { retry: false } } });
queryClient = client;
act(() =>
root?.render(
<ToastProvider>
<QueryClientProvider client={client}>
{element}
<ToastViewport />
</QueryClientProvider>
</ToastProvider>,
),
);
return container;
}
function buildItem(overrides: Partial<AttentionItem> = {}): AttentionItem {
return {
id: "a1",
companyId: "c1",
sourceKind: "approval",
subject: {
kind: "approval",
id: "approval-1",
companyId: "c1",
title: "Hire agent: Research Analyst",
identifier: null,
status: "pending",
href: "/PAP/approvals/approval-1",
metadata: {},
},
whyNow: "Approval is pending a board decision.",
decisionVerbs: [],
inlineResolvable: true,
entryRule: "",
exitRule: "",
dedupKey: "approval:approval-1",
dismissalKey: "attention:approval:approval-1",
severity: "high",
rank: 0,
activityAt: "2026-07-09T12:00:00Z",
createdAt: "2026-07-09T12:00:00Z",
updatedAt: "2026-07-09T12:00:00Z",
relatedIssue: null,
project: null,
workspace: null,
detail: null,
dismissal: null,
...overrides,
audience: overrides.audience ?? { kind: "pool", userId: null, reason: "none" },
stale: overrides.stale ?? null,
changeFingerprint: overrides.changeFingerprint ?? "fixture.other",
closeModes: overrides.closeModes ?? ["archive", "snooze"],
obligationKey: overrides.obligationKey ?? null,
obligationLeadId: overrides.obligationLeadId ?? null,
required: overrides.required ?? false,
expiresAt: overrides.expiresAt ?? null,
ruleKey: overrides.ruleKey ?? null,
originAgentName: overrides.originAgentName ?? null,
queues: overrides.queues ?? [],
shelf: overrides.shelf ?? false,
retentionDays: overrides.retentionDays ?? 30,
keep: overrides.keep ?? false,
archivedAt: overrides.archivedAt ?? null,
retentionVersion: overrides.retentionVersion ?? 1,
decideBy: overrides.decideBy ?? null,
decideByAttribution: overrides.decideByAttribution ?? null,
snoozedUntil: overrides.snoozedUntil ?? null,
trainingExampleId: overrides.trainingExampleId ?? null,
};
}
const noop = () => {};
describe("AttentionQueueRow", () => {
it("renders an inline approval resolver when expanded", () => {
const el = render(
<AttentionQueueRow
item={buildItem()}
companyId="c1"
expanded
onToggleExpand={noop}
onDismiss={noop}
/>,
);
expect(el.textContent).toContain("Approve");
expect(el.textContent).toContain("Request revision");
expect(el.textContent).toContain("Reject");
// Inline rows show an expand chevron, not an "Open" deep-link.
expect(el.textContent).not.toContain("Open");
});
it("inlines a stalled review with the three review verbs (PAP-16080 §4.4)", () => {
const el = render(
<AttentionQueueRow
item={buildItem({
sourceKind: "review" as AttentionSourceKind,
inlineResolvable: true,
subject: {
kind: "issue",
id: "issue-1",
companyId: "c1",
title: "PR ready for review",
identifier: null,
status: "in_review",
href: "/PAP/issues/PAP-1",
metadata: { reviewAttentionState: "stalled" },
},
})}
companyId="c1"
expanded
onToggleExpand={noop}
onDismiss={noop}
/>,
);
// Inline rows resolve in place, not via an "Open" deep-link.
expect(el.textContent).not.toContain("Open");
expect(el.textContent).toContain("Approve");
expect(el.textContent).toContain("Request changes");
expect(el.textContent).toContain("Send back to work");
});
// PAP-16506 P4: an opt-in policy warns before the card offers Approve, because
// the server refuses the verdict. The default earns no pixels.
const reviewItemWithPolicy = (reviewPolicy?: unknown) =>
buildItem({
sourceKind: "review" as AttentionSourceKind,
inlineResolvable: true,
subject: {
kind: "issue",
id: "issue-1",
companyId: "c1",
title: "PR ready for review",
identifier: null,
status: "in_review",
href: "/PAP/issues/PAP-1",
metadata: {
reviewAttentionState: "stalled",
...(reviewPolicy === undefined ? {} : { reviewPolicy }),
},
},
});
it("says nothing about who can approve on a review with no policy set", () => {
const el = render(
<AttentionQueueRow
item={reviewItemWithPolicy()}
companyId="c1"
expanded
onToggleExpand={noop}
onDismiss={noop}
/>,
);
expect(el.querySelector('[data-testid="review-policy-badge"]')).toBeNull();
expect(el.textContent).not.toContain("Anyone else");
expect(el.textContent).not.toContain("Human only");
// The verbs still render — suppressing the badge must not suppress the card.
expect(el.textContent).toContain("Send back to work");
});
it("badges the opt-in constraint when the issue carries one", () => {
const el = render(
<AttentionQueueRow
item={reviewItemWithPolicy("human_only")}
companyId="c1"
expanded
onToggleExpand={noop}
onDismiss={noop}
/>,
);
const badge = el.querySelector('[data-testid="review-policy-badge"]');
expect(badge?.getAttribute("data-review-policy")).toBe("human_only");
expect(badge?.textContent).toContain("Human only");
expect(badge?.getAttribute("title")).toContain("Agents cannot");
});
it("badges a not_creator policy as 'Anyone else'", () => {
const el = render(
<AttentionQueueRow
item={reviewItemWithPolicy("not_creator")}
companyId="c1"
expanded
onToggleExpand={noop}
onDismiss={noop}
/>,
);
const badge = el.querySelector('[data-testid="review-policy-badge"]');
expect(badge?.getAttribute("data-review-policy")).toBe("not_creator");
expect(badge?.textContent).toContain("Anyone else");
});
it("shows no badge for an explicit default or an unrecognised policy", () => {
for (const policy of ["anyone", "board_only"]) {
const el = render(
<AttentionQueueRow
item={reviewItemWithPolicy(policy)}
companyId="c1"
expanded
onToggleExpand={noop}
onDismiss={noop}
/>,
);
expect(el.querySelector('[data-testid="review-policy-badge"]')).toBeNull();
}
});
it("deep-links a covered review instead of inlining", () => {
const el = render(
<AttentionQueueRow
item={buildItem({
sourceKind: "review" as AttentionSourceKind,
inlineResolvable: false,
subject: {
kind: "issue",
id: "issue-1",
companyId: "c1",
title: "PR ready for review",
identifier: null,
status: "in_review",
href: "/PAP/issues/PAP-1",
metadata: {},
},
})}
companyId="c1"
expanded
onToggleExpand={noop}
onDismiss={noop}
/>,
);
expect(el.textContent).toContain("Open");
expect(el.textContent).not.toContain("Send back to work");
});
it("folds the rest of its obligation into the row as evidence (PAP-749 task 2d)", () => {
const lead = buildItem({ obligationKey: "approval:approval-1", obligationLeadId: "a1" });
const review = buildItem({
id: "review:t1",
sourceKind: "review",
subject: { kind: "issue", id: "t1", companyId: "c1", title: "Launch page", identifier: "PAP-8", status: "in_review", href: "/PAP/issues/PAP-8" },
whyNow: "Issue is in review with a linked pending approval.",
obligationKey: "approval:approval-1",
obligationLeadId: "a1",
});
const el = render(
<AttentionQueueRow item={lead} companyId="c1" expanded={false} onToggleExpand={noop} onDismiss={noop} evidence={[review]} />,
);
const list = el.querySelector('[data-attention-obligation="approval:approval-1"]');
expect(list?.getAttribute("aria-label")).toBe("Part of this request");
expect(list?.querySelector('[data-attention-evidence="review:t1"]')?.textContent)
.toBe("Task waiting on this approval: PAP-8 Launch page — Issue is in review with a linked pending approval.");
});
it("puts Archive for me in the Close… menu", () => {
const onDismiss = vi.fn();
const item = buildItem();
render(
<AttentionQueueRow
item={item}
companyId="c1"
expanded={false}
onToggleExpand={noop}
onDismiss={onDismiss}
/>,
);
// The Close… menu replaces the old row menu (PAP-749 Rule 6). Its items
// live in a portal and opening is environment-flaky in jsdom, so assert the
// wiring by locating the trigger; AttentionCloseMenu.test covers the verbs.
const trigger = container?.querySelector("[data-attention-close-menu]");
expect(trigger?.getAttribute("aria-label")).toBe("Close…");
});
it("toggles expand when the collapsed header of an inline row is clicked", () => {
const onToggleExpand = vi.fn();
render(
<AttentionQueueRow
item={buildItem()}
companyId="c1"
expanded={false}
onToggleExpand={onToggleExpand}
onDismiss={noop}
/>,
);
const header = container?.querySelector('[role="button"][aria-expanded]');
expect(header).toBeTruthy();
expect(header?.getAttribute("aria-expanded")).toBe("false");
act(() => {
header?.dispatchEvent(new MouseEvent("click", { bubbles: true }));
});
expect(onToggleExpand).toHaveBeenCalledTimes(1);
});
it("exposes the visible expand chevron as an accessible button", () => {
const onToggleExpand = vi.fn();
render(
<AttentionQueueRow
item={buildItem()}
companyId="c1"
expanded={false}
onToggleExpand={onToggleExpand}
onDismiss={noop}
/>,
);
const chevronButton = container?.querySelector('button[aria-label="Expand decision"]');
expect(chevronButton).toBeTruthy();
expect(chevronButton?.getAttribute("aria-expanded")).toBe("false");
act(() => chevronButton?.dispatchEvent(new MouseEvent("click", { bubbles: true })));
expect(onToggleExpand).toHaveBeenCalledWith(expect.objectContaining({ id: "a1" }));
});
it("does not navigate on title click — the title is plain text, not a link", () => {
render(
<AttentionQueueRow
item={buildItem()}
companyId="c1"
expanded={false}
onToggleExpand={noop}
onDismiss={noop}
/>,
);
const links = Array.from(container?.querySelectorAll("a") ?? []);
// No anchor should carry the subject title (only the identifier link, absent here).
expect(links.some((a) => a.textContent?.includes("Hire agent: Research Analyst"))).toBe(false);
});
// The eyebrow carries the decision kind and the task key only. Project
// identity was removed from the card: the queue is filtered and grouped by
// project from the toolbar, so repeating it on every row spent the eyebrow's
// width on a fact the operator had usually just chosen.
it("keeps project identity off the card", () => {
render(
<AttentionQueueRow
item={buildItem({
project: { id: "project-1", name: "Alpha", urlKey: "alpha", color: null, icon: "rocket" },
})}
companyId="c1"
expanded={false}
onToggleExpand={noop}
onDismiss={noop}
/>,
);
expect(container?.querySelector('[data-testid="attention-project-meta"]')).toBeNull();
expect(container?.textContent).not.toContain("Alpha");
});
it("separates eyebrow facts with a middle dot, not a slash", () => {
render(
<AttentionQueueRow
item={buildItem({
sourceKind: "blocker_attention",
subject: {
kind: "issue",
id: "i1",
companyId: "c1",
title: "Update primary paperclip instance",
identifier: "PAP-23",
status: "blocked",
href: "/PAP/issues/PAP-23",
},
relatedIssue: null,
})}
companyId="c1"
expanded={false}
onToggleExpand={noop}
onDismiss={noop}
/>,
);
const eyebrow = container?.querySelector('[data-attention-row] > div');
expect(eyebrow?.textContent).toContain("·");
expect(eyebrow?.textContent).not.toContain("/");
});
// Regression: the meta breadcrumb used to read only `relatedIssue`, so rows
// whose subject IS the task (reviews, blocked dependencies) showed no key at
// all — the rows most obviously about a task were the ones missing it.
it("shows the task key when the subject is the task itself", () => {
render(
<AttentionQueueRow
item={buildItem({
sourceKind: "blocker_attention",
subject: {
kind: "issue",
id: "i1",
companyId: "c1",
title: "Update primary paperclip instance",
identifier: "PAP-23",
status: "blocked",
href: "/PAP/issues/PAP-23",
},
relatedIssue: null,
})}
companyId="c1"
expanded={false}
onToggleExpand={noop}
onDismiss={noop}
/>,
);
const link = Array.from(container?.querySelectorAll("a") ?? []).find((a) => a.textContent === "PAP-23");
expect(link).toBeTruthy();
expect(link?.getAttribute("href")).toBe("/PAP/issues/PAP-23");
});
it("shows no task key on a row that is not attached to a task", () => {
render(
<AttentionQueueRow
item={buildItem({ relatedIssue: null })}
companyId="c1"
expanded={false}
onToggleExpand={noop}
onDismiss={noop}
/>,
);
expect(container?.textContent).not.toMatch(/PAP-\d+/);
});
it("places the timestamp beside the row menu without a clock icon", () => {
render(
<AttentionQueueRow
item={buildItem()}
companyId="c1"
expanded={false}
onToggleExpand={noop}
onDismiss={noop}
/>,
);
const menu = container?.querySelector('[aria-label="Row actions"]');
const menuArea = menu?.closest('[data-attention-menu="true"]');
expect(menuArea?.textContent).not.toBe("");
expect(container?.querySelector("svg.lucide-clock")).toBeNull();
});
// Rows became rounded cards when the decision types were flattened: with the
// left accent rail gone, the card's own shape carries the separation that the
// rail used to, so square edges no longer read as deliberate.
it("uses rounded card edges and can show a keyboard selection ring", () => {
render(
<AttentionQueueRow
item={buildItem()}
companyId="c1"
expanded={false}
onToggleExpand={noop}
onDismiss={noop}
selected
/>,
);
const row = container?.querySelector("[data-attention-row]");
expect(row?.getAttribute("class")).toContain("rounded-xl");
expect(row?.getAttribute("class")).toContain("ring-ring");
});
it("renders collapsed inline decision verbs in a dedicated action bar with semantic variants", () => {
render(
<AttentionQueueRow
item={buildItem({
decisionVerbs: [
{ id: "approve", label: "Approve", description: null },
{ id: "reject", label: "Reject", description: null },
],
})}
companyId="c1"
expanded={false}
onToggleExpand={noop}
onDismiss={noop}
/>,
);
const header = container?.querySelector('[role="button"][aria-expanded]');
expect(header?.textContent).not.toContain("Approve");
expect(header?.textContent).not.toContain("Reject");
const decisionActions = container?.querySelector('[aria-label="Decision actions"]');
expect(decisionActions?.textContent).toContain("Approve");
expect(decisionActions?.textContent).toContain("Reject");
// The footer splits the row's last line: disclosure on the left, decision
// verbs on the right, so the affirmative verb sits in the same place in
// every row whether it is collapsed or expanded.
const actionArea = decisionActions?.closest('[data-attention-actions="true"]');
expect(actionArea?.getAttribute("class")).toContain("justify-between");
expect(decisionActions?.parentElement?.getAttribute("class")).toContain("@xl:justify-end");
const rowMenu = container?.querySelector("[data-attention-close-menu]");
expect(rowMenu?.closest('[data-attention-menu="true"]')).toBeTruthy();
expect(rowMenu?.closest('[data-attention-actions="true"]')).toBeNull();
const buttons = Array.from(decisionActions?.querySelectorAll("button") ?? []);
expect(buttons.find((button) => button.textContent === "Approve")?.getAttribute("data-variant")).toBe(
"default",
);
expect(buttons.find((button) => button.textContent === "Reject")?.getAttribute("data-variant")).toBe(
"destructive",
);
});
it("submits a compact approval without expanding the card and confirms it", async () => {
const onToggleExpand = vi.fn();
vi.mocked(approvalsApi.approve).mockResolvedValue({} as never);
render(
<AttentionQueueRow
item={buildItem({
decisionVerbs: [{ id: "approve", label: "Approve", description: null }],
})}
companyId="c1"
expanded={false}
onToggleExpand={onToggleExpand}
onDismiss={noop}
/>,
);
const approve = Array.from(container?.querySelectorAll("button") ?? []).find(
(button) => button.textContent === "Approve",
);
const invalidate = vi.spyOn(queryClient!, "invalidateQueries");
act(() => approve?.dispatchEvent(new MouseEvent("click", { bubbles: true })));
await new Promise((resolve) => setTimeout(resolve, 0));
expect(approvalsApi.approve).toHaveBeenCalledWith("approval-1");
expect(onToggleExpand).not.toHaveBeenCalled();
expect(container?.textContent).toContain("Approval approved");
// An open approval page refreshes too (PAP-771).
expect(invalidate).toHaveBeenCalledWith({ queryKey: ["approvals", "detail", "approval-1"] });
expect(invalidate).toHaveBeenCalledWith({ queryKey: ["approvals", "c1"] });
});
it("renders configured confirmation labels and accepts from the compact action area", async () => {
const onToggleExpand = vi.fn();
vi.mocked(issuesApi.acceptInteraction).mockResolvedValue({} as never);
render(
<AttentionQueueRow
item={buildItem({
sourceKind: "issue_thread_interaction",
subject: {
kind: "interaction",
id: "interaction-1",
companyId: "c1",
title: "Plan approval",
identifier: null,
status: "pending",
href: "/PAP/issues/issue-1#interaction-interaction-1",
metadata: { kind: "request_confirmation", issueId: "issue-1" },
},
decisionVerbs: [
{ id: "accept", label: "Approve plan", description: null },
{ id: "reject", label: "Request changes", description: null },
],
})}
companyId="c1"
expanded={false}
onToggleExpand={onToggleExpand}
onDismiss={noop}
/>,
);
const decisionActions = container?.querySelector('[aria-label="Decision actions"]');
expect(decisionActions?.textContent).toContain("Approve plan");
expect(decisionActions?.textContent).toContain("Request changes");
expect(Array.from(decisionActions?.querySelectorAll("button") ?? []).find((button) => button.textContent === "Approve plan")?.getAttribute("data-variant")).toBe("default");
expect(Array.from(decisionActions?.querySelectorAll("button") ?? []).find((button) => button.textContent === "Request changes")?.getAttribute("data-variant")).toBe("outline");
const approve = Array.from(decisionActions?.querySelectorAll("button") ?? []).find(
(button) => button.textContent === "Approve plan",
);
const invalidate = vi.spyOn(queryClient!, "invalidateQueries");
act(() => approve?.dispatchEvent(new MouseEvent("click", { bubbles: true })));
await new Promise((resolve) => setTimeout(resolve, 0));
expect(issuesApi.acceptInteraction).toHaveBeenCalledWith("issue-1", "interaction-1");
expect(onToggleExpand).not.toHaveBeenCalled();
// One record, many views (PAP-771): task detail and chat refresh too.
for (const queryKey of [["attention", "c1"], ["issues", "interactions", "issue-1"], ["issues", "pending-questions"], ["issues", "decision-receipts"]]) {
expect(invalidate).toHaveBeenCalledWith({ queryKey });
}
expect(invalidate).not.toHaveBeenCalledWith({ queryKey: ["access", "join-requests", "c1", "pending_approval"] });
});
it("opens the matching confirmation form when requesting changes from a compact action", () => {
const onToggleExpand = vi.fn();
render(
<AttentionQueueRow
item={buildItem({
sourceKind: "issue_thread_interaction",
subject: {
kind: "interaction",
id: "interaction-1",
companyId: "c1",
title: "Plan approval",
identifier: null,
status: "pending",
href: "/PAP/issues/issue-1#interaction-interaction-1",
metadata: { kind: "request_confirmation", issueId: "issue-1" },
},
decisionVerbs: [{ id: "reject", label: "Request changes", description: null }],
})}
companyId="c1"
expanded={false}
onToggleExpand={onToggleExpand}
onDismiss={noop}
/>,
);
const requestChanges = Array.from(container?.querySelectorAll("button") ?? []).find(
(button) => button.textContent === "Request changes",
);
act(() => requestChanges?.dispatchEvent(new MouseEvent("click", { bubbles: true })));
expect(onToggleExpand).toHaveBeenCalledOnce();
expect(issuesApi.rejectInteraction).not.toHaveBeenCalled();
});
// The old context row bundled project identity + thumbnails together; project
// identity has since moved up into the meta breadcrumb, so evidence is now a
// block of the row's own column rather than a shared strip.
it("renders evidence thumbnails as their own block below the text stack", () => {
render(
<AttentionQueueRow
item={buildItem({
detail: {
kind: "generic",
summaryExcerpt: "Visual evidence attached.",
images: [{ assetId: "asset-1", alt: "Screenshot" }],
},
})}
companyId="c1"
expanded={false}
onToggleExpand={noop}
onDismiss={noop}
/>,
);
const image = container?.querySelector('img[alt="Screenshot"]');
expect(image?.getAttribute("src")).toBe("/api/assets/asset-1/content");
const thumbnailStack = image?.parentElement?.parentElement;
expect(thumbnailStack?.getAttribute("class")).toContain("items-center");
// The strip is collapsed-only content: it rides the inverse disclosure so
// it can fade out as the expanded gallery fades in, rather than popping.
const cluster = thumbnailStack?.closest("[data-decision-disclosure]");
expect(cluster).toBeTruthy();
expect(cluster?.getAttribute("data-state")).toBe("open");
expect(cluster?.closest("[data-attention-row]")).toBeTruthy();
});
it("is memoized — a parent re-render with identical props does not re-render the row", async () => {
const { relativeTime } = await import("../lib/utils");
const item = buildItem();
let bump: () => void = () => {};
function Harness() {
const [, setTick] = useState(0);
bump = () => setTick((n) => n + 1);
return (
<AttentionQueueRow
item={item}
companyId="c1"
expanded={false}
onToggleExpand={noop}
onDismiss={noop}
/>
);
}
render(<Harness />);
const rendersAfterMount = vi.mocked(relativeTime).mock.calls.length;
expect(rendersAfterMount).toBeGreaterThan(0);
act(() => bump());
expect(vi.mocked(relativeTime).mock.calls.length).toBe(rendersAfterMount);
});
it("does not expose a toggle button for non-inline rows", () => {
render(
<AttentionQueueRow
item={buildItem({ sourceKind: "failed_run" as AttentionSourceKind, inlineResolvable: false })}
companyId="c1"
expanded={false}
onToggleExpand={noop}
onDismiss={noop}
/>,
);
expect(container?.querySelector('[role="button"][aria-expanded]')).toBeNull();
});
it("makes a non-inline row with images expandable", () => {
const onToggleExpand = vi.fn();
render(
<AttentionQueueRow
item={buildItem({
sourceKind: "review" as AttentionSourceKind,
inlineResolvable: false,
detail: {
kind: "generic",
summaryExcerpt: "3 files changed",
images: [
{ assetId: "img-1", alt: "one" },
{ assetId: "img-2", alt: "two" },
],
},
})}
companyId="c1"
expanded={false}
onToggleExpand={onToggleExpand}
onDismiss={noop}
/>,
);
const header = container?.querySelector('[role="button"][aria-expanded]');
expect(header).not.toBeNull();
act(() => (header as HTMLElement).click());
expect(onToggleExpand).toHaveBeenCalledTimes(1);
});
it("shows a larger gallery with an n-more link to the issue when expanded", () => {
render(
<AttentionQueueRow
item={buildItem({
sourceKind: "review" as AttentionSourceKind,
inlineResolvable: false,
relatedIssue: {
kind: "issue",
id: "issue-1",
companyId: "c1",
title: "Ship it",
identifier: "PAP-42",
status: "in_progress",
href: "/PAP/issues/PAP-42",
metadata: {},
},
detail: {
kind: "generic",
summaryExcerpt: "5 screenshots",
images: [
{ assetId: "img-1", alt: "one" },
{ assetId: "img-2", alt: "two" },
{ assetId: "img-3", alt: "three" },
{ assetId: "img-4", alt: "four" },
{ assetId: "img-5", alt: "five" },
],
},
})}
companyId="c1"
expanded
onToggleExpand={noop}
onDismiss={noop}
/>,
);
const gallery = container?.querySelector('[data-attention-expanded-images="true"]');
expect(gallery).not.toBeNull();
// First three images render at the larger size.
expect(gallery?.querySelectorAll("img")).toHaveLength(3);
// "n more" link points at the related issue (5 images − 3 shown = 2 more).
const moreLink = Array.from(gallery?.querySelectorAll("a") ?? []).find((a) =>
a.textContent?.includes("2 more"),
);
expect(moreLink).toBeDefined();
expect(moreLink?.getAttribute("href")).toBe("/PAP/issues/PAP-42");
});
it("shows the remaining image count when no issue link is available", () => {
render(
<AttentionQueueRow
item={buildItem({
sourceKind: "review" as AttentionSourceKind,
inlineResolvable: false,
subject: {
kind: "issue",
id: "issue-1",
companyId: "c1",
title: "Unlinked review",
identifier: null,
status: "in_review",
href: null,
metadata: {},
},
detail: {
kind: "generic",
summaryExcerpt: "4 screenshots",
images: [
{ assetId: "img-1", alt: "one" },
{ assetId: "img-2", alt: "two" },
{ assetId: "img-3", alt: "three" },
{ assetId: "img-4", alt: "four" },
],
},
})}
companyId="c1"
expanded
onToggleExpand={noop}
onDismiss={noop}
/>,
);
const gallery = container?.querySelector('[data-attention-expanded-images="true"]');
expect(gallery?.textContent).toContain("1 more");
expect(gallery?.querySelectorAll("a")).toHaveLength(0);
});
// PAP-17287: the collapsed row must say who may resolve an interaction before
// its compact verbs are used, and a denial must keep the server's reason.
function interactionItem(
audience: AttentionItem["resolverAudience"],
verbs: AttentionItem["decisionVerbs"] = [
{ id: "accept", label: "Accept", description: null },
{ id: "reject", label: "Reject", description: null },
],
) {
return buildItem({
sourceKind: "issue_thread_interaction",
subject: {
kind: "interaction",
id: "interaction-1",
companyId: "c1",
title: "Close this confirmation?",
identifier: null,
status: "pending",
href: "/PAP/issues/issue-1#interaction-interaction-1",
metadata: { kind: "request_confirmation", issueId: "issue-1" },
},
decisionVerbs: verbs,
resolverAudience: audience,
});
}
const openAudience: AttentionItem["resolverAudience"] = {
requestedResolverPolicy: "anyone",
effectiveResolverPolicy: "anyone",
effectiveResolverPolicySource: "requested",
resolverPolicyProvenance: "inherited",
addresseeAgentId: null,
addresseeName: null,
createdByAgentId: "agent-watchdog",
createdByAgentName: "Watchdog",
};
it("states the server-derived audience before the compact decision verbs", () => {
render(
<AttentionQueueRow
item={interactionItem(openAudience)}
companyId="c1"
expanded={false}
onToggleExpand={noop}
onDismiss={noop}
/>,
);
const audience = container?.querySelector('[data-testid="interaction-audience"]');
expect(audience?.getAttribute("data-audience-policy")).toBe("anyone");
expect(audience?.getAttribute("data-audience-open")).toBe("true");
expect(audience?.textContent).toContain("Anyone");
expect(audience?.textContent).toContain("Anyone can respond");
// Reading order is the point: the audience qualifies the buttons, so it has
// to precede them in the DOM as well as on screen.
const actions = container?.querySelector('[aria-label="Decision actions"]');
expect(audience && actions && audience.compareDocumentPosition(actions))
.toBe(Node.DOCUMENT_POSITION_FOLLOWING);
});
it("names the addressed responder on a restricted collapsed row", () => {
render(
<AttentionQueueRow
item={interactionItem({
...openAudience,
addresseeAgentId: "agent-codex",
addresseeName: "CodexCoder",
})}
companyId="c1"
expanded={false}
onToggleExpand={noop}
onDismiss={noop}
/>,
);
const audience = container?.querySelector('[data-testid="interaction-audience"]');
expect(audience?.getAttribute("data-audience-open")).toBe("false");
expect(audience?.textContent).toContain("Only CodexCoder or the board can respond");
// A collapsed row spends its line on the responder, not on a badge that
// repeats the clause beside it.
expect(audience?.textContent).not.toContain("Addressed —");
});
// PAP-17289: the row's shell is `overflow-hidden`, so a clause that cannot
// wrap is cut mid-word with no ellipsis and names a responder that does not
// exist. jsdom does no layout, so this asserts the wrapping rule itself.
it("lets a long addressee name wrap instead of being cut mid-word", () => {
const addresseeName = "ReleaseEngineeringPlatformCoordinationServiceBot";
render(
<AttentionQueueRow
item={interactionItem({
...openAudience,
addresseeAgentId: "agent-release",
addresseeName,
})}
companyId="c1"
expanded={false}
onToggleExpand={noop}
onDismiss={noop}
/>,
);
const audience = container?.querySelector('[data-testid="interaction-audience"]');
const summary = audience?.querySelector('[data-testid="interaction-audience-summary"]');
expect(summary?.textContent).toBe(`Only ${addresseeName} or the board can respond`);
expect(summary?.parentElement?.className).toContain("break-words");
});
it("says who may answer once, in the audience line, when it knows the viewer (PAP-767)", () => {
render(
<AttentionQueueRow
item={{
...interactionItem({ ...openAudience, addresseeAgentId: "agent-nap", addresseeName: "Napping Agent" }),
audience: { kind: "pool", userId: null, reason: "none" },
}}
companyId="c1"
currentUserId="scott"
expanded={false}
onToggleExpand={noop}
onDismiss={noop}
/>,
);
const line = container?.querySelector('[data-attention-audience="pool"]');
expect(line?.textContent).toContain("No owner yet. Napping Agent or any board member can answer it.");
expect(container?.textContent).not.toContain("Any board member can answer it.");
// No second, contradicting clause beside the buttons.
expect(container?.querySelector('[data-testid="interaction-audience"]')).toBeNull();
});
it("renders no audience line when the feed carries no resolver metadata", () => {
render(
<AttentionQueueRow
item={interactionItem(null)}
companyId="c1"
expanded={false}
onToggleExpand={noop}
onDismiss={noop}
/>,
);
// Never guess a policy client-side: silence beats a wrong audience.
expect(container?.querySelector('[data-testid="interaction-audience"]')).toBeNull();
});
it("keeps the server denial reason and names the responder when a compact accept is refused", async () => {
vi.mocked(issuesApi.acceptInteraction).mockRejectedValue(
new ApiError("This issue-thread interaction is human-only", 403, {
error: "This issue-thread interaction is human-only",
code: "interaction_human_only",
}),
);
render(
<AttentionQueueRow
item={interactionItem({
...openAudience,
requestedResolverPolicy: "human_only",
effectiveResolverPolicy: "human_only",
})}
companyId="c1"
expanded={false}
onToggleExpand={noop}
onDismiss={noop}
/>,
);
const accept = Array.from(container?.querySelectorAll("button") ?? []).find(
(button) => button.textContent === "Accept",
);
act(() => accept?.dispatchEvent(new MouseEvent("click", { bubbles: true })));
await act(async () => {
await new Promise((resolve) => setTimeout(resolve, 0));
});
const feedback = document.body.textContent ?? "";
expect(feedback).toContain("This issue-thread interaction is human-only.");
expect(feedback).toContain("Only the board can respond.");
expect(feedback).not.toMatch(/try again/i);
});
it("does not surface training state or actions for decisions", () => {
render(
<AttentionQueueRow
item={buildItem({ trainingExampleId: "example-1" })}
companyId="c1"
expanded={false}
onToggleExpand={noop}
onDismiss={noop}
/>,
);
expect(container?.textContent).not.toContain("Train");
expect(container?.querySelector('[data-testid="attention-trained-badge"]')).toBeNull();
expect(container?.querySelector('[data-testid="attention-train-inline"]')).toBeNull();
expect(container?.querySelector('[data-testid="attention-train-button"]')).toBeNull();
});
});
describe("decision write failures", () => {
it.each(["approve", "reject", "requestRevision"] as const)("shows a failed approval %s beside its controls", async (method) => {
vi.mocked(approvalsApi[method]).mockRejectedValueOnce(new Error("Decision could not be saved"));
const host = render(<ApprovalResolver item={buildItem()} companyId="c1" toggle={null} presentation={method === "requestRevision" ? "panel" : "card"} />);
const label = method === "approve" ? "Approve" : method === "reject" ? "Reject" : "Request revision";
act(() => [...host.querySelectorAll<HTMLButtonElement>("button")].find(button => button.textContent === label)!.click());
await vi.waitFor(() => expect(host.querySelector('[role="alert"]')?.textContent).toContain("Decision could not be saved"));
});
it.each(["approve", "reject"] as const)("shows a failed join-request %s beside its controls", async (action) => {
const method = action === "approve" ? "approveJoinRequest" : "rejectJoinRequest";
vi.mocked(accessApi[method]).mockRejectedValueOnce(new Error("Join request could not be saved"));
const host = render(<JoinRequestResolver item={buildItem({ sourceKind: "join_request" })} companyId="c1" toggle={null} presentation="card" />);
const label = action === "approve" ? "Approve access" : "Decline";
act(() => [...host.querySelectorAll<HTMLButtonElement>("button")].find(button => button.textContent === label)!.click());
await vi.waitFor(() => expect(host.querySelector('[role="alert"]')?.textContent).toContain("Join request could not be saved"));
});
});