Files
PaperClipAI/ui/src/lib/issue-artifacts.test.ts
T
scotttongandClaude Fable 5 5bb2490b86 feat(ui): surface all issue documents and agent artifacts in chat-style sidebar (#11226)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - The task detail page uses a chat-style thread with a right sidebar;
the sidebar has a Plan tab and an Artifacts tab (#11101 made this UI the
default)
> - The Plan tab only showed the one issue document named `plan`, and
the Artifacts tab only listed formal work products; other agent-authored
documents (for example a `synthesis` doc) and agent-attached files were
invisible in the sidebar
> - Users could see an agent mention a document in the thread but had no
way to find that document in the sidebar, which breaks trust in the task
view as the record of the work
> - This pull request surfaces every non-system issue document in the
Plan tab, composes the Artifacts tab from work products, documents, and
agent-created attachments, and gives thread images a full-screen
lightbox with download
> - The benefit is that anything an agent produces on a task is now
reachable from the sidebar, while user uploads stay with their comments
in the thread

## Linked Issues or Issue Description

Refs #11101 (chat-style task UI default — this PR extends its sidebar).

**Subsystem affected**

Task detail UI (chat-style thread sidebar): Plan tab, Artifacts tab, and
thread attachment rendering in `ui/src`.

**Current behavior**

The Plan tab renders only the issue document literally named `plan`. The
Artifacts tab renders only formal work products. Agent-authored
documents with any other name, and files agents attach to comments, do
not appear anywhere in the sidebar. Thread images open as bare links.

**Proposed behavior**

The Plan tab lists every non-system issue document, with the `plan`
document first and the others rendered inline below it. The Artifacts
tab composes three sources — work products, issue documents, and
agent-created comment attachments — deduplicated against
attachment-backed work products via `metadata.attachmentId`, and shows
whenever any source is non-empty. Work-product rows without a resolvable
attachment or document fall back to links found in their metadata so
they stay clickable. Images in the thread open a shared full-screen
lightbox with a download action. Files uploaded by users stay
thread-only and are not mixed into the Artifacts tab.

**Reason and benefit**

Agents routinely produce documents that are not named `plan` and attach
files to their comments. Users reading the thread must be able to find
every one of those outputs from the sidebar. Redundant surfacing is
acceptable; an unfindable document is not.

**Breaking changes**

None. This is additive rendering; no schema or API changes.

## What Changed

- `IssuePropertiesPlansTab.tsx`: renders all non-system issue documents,
`plan` primary, others inline below via `MarkdownBody`
- `IssuePropertiesArtifactsTab.tsx`: composes work products + documents
+ agent-created attachments with dedupe; rows without an
attachment/document target fall back to `metadata` links
- `IssueProperties.tsx`: Artifacts tab visibility now derives from the
composed source set
- New `ui/src/lib/issue-artifacts.ts`: pure composition/dedupe logic,
unit-tested
- New `ui/src/components/task-chat/task-chat-attachments.ts`: splits
agent vs user comment attachments, unit-tested
- `TaskChatBubble.tsx`: thread images open the shared full-screen
lightbox with download
- `useIssueDocuments.ts`: hook now exposes the full issue-document list

## Verification

- `pnpm typecheck` — passes across the workspace
- `pnpm check:token-gates` — 3/3 CLEAN
- `cd ui && pnpm vitest run src/lib/issue-artifacts.test.ts
src/components/task-chat/task-chat-attachments.test.ts
src/pages/IssueDetail.test.tsx` — 74 tests pass
- Manual: open a task whose agent created a document not named `plan`
(for example `synthesis`); confirm it appears in the Plan tab below the
plan and in the Artifacts tab; confirm an image the agent attached
appears under Artifacts; confirm a user-uploaded image stays only in the
thread and opens full screen with a download button

Snapshot baselines are intentionally not updated for this visual change,
per the `doc/design/DECISION-SHEET.md` entry "Per-change snapshot
verification demoted to dormant (Jul 13 2026)".

## Risks

- Low risk: rendering-only change scoped to the task sidebar and thread
bubbles; composition logic is pure and unit-tested
- Dedupe relies on `metadata.attachmentId` linkage; a work product with
malformed metadata would render as a duplicate row (cosmetic only)

## Model Used

- Claude (Anthropic), model id `claude-fable-5`, extended thinking
enabled, agentic tool use via Claude Agent SDK (Claude Code harness)

## 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 either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run 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
- [ ] All Paperclip CI gates are green
- [ ] 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: Claude Fable 5 <noreply@anthropic.com>
2026-08-11 12:09:58 -07:00

161 lines
5.4 KiB
TypeScript

import { describe, expect, it } from "vitest";
import type { IssueAttachment, IssueWorkProduct } from "@paperclipai/shared";
import {
documentDisplayTitle,
isAgentAttachment,
selectAgentArtifactAttachments,
workProductHref,
} from "./issue-artifacts";
function makeAttachment(overrides: Partial<IssueAttachment> & { id: string }): IssueAttachment {
return {
companyId: "company-1",
issueId: "issue-1",
issueCommentId: null,
assetId: "asset-1",
provider: "local",
objectKey: `objects/${overrides.id}`,
contentType: "image/png",
byteSize: 1024,
sha256: "0".repeat(64),
originalFilename: "shot.png",
createdByAgentId: null,
createdByUserId: null,
createdAt: new Date("2026-08-01T12:00:00Z"),
updatedAt: new Date("2026-08-01T12:00:00Z"),
contentPath: `/api/attachments/${overrides.id}/content`,
...overrides,
} as IssueAttachment;
}
function makePromotingWorkProduct(attachmentId: string): IssueWorkProduct {
return {
id: `wp-${attachmentId}`,
companyId: "company-1",
projectId: null,
issueId: "issue-1",
executionWorkspaceId: null,
runtimeServiceId: null,
type: "artifact",
provider: "paperclip",
externalId: null,
title: "output.png",
url: null,
status: "active",
reviewState: "none",
isPrimary: false,
healthStatus: "unknown",
summary: null,
metadata: {
attachmentId,
contentType: "image/png",
byteSize: 1024,
contentPath: `/api/attachments/${attachmentId}/content`,
openPath: `/api/attachments/${attachmentId}/content`,
downloadPath: `/api/attachments/${attachmentId}/content?download=1`,
originalFilename: "output.png",
},
createdByRunId: null,
createdAt: new Date("2026-08-01T12:00:00Z"),
updatedAt: new Date("2026-08-01T12:00:00Z"),
} as IssueWorkProduct;
}
describe("isAgentAttachment", () => {
it("accepts agent-authored rows regardless of comment binding", () => {
expect(isAgentAttachment(makeAttachment({ id: "a", createdByAgentId: "agent-1" }))).toBe(true);
expect(
isAgentAttachment(
makeAttachment({ id: "b", createdByAgentId: "agent-1", issueCommentId: "comment-1" }),
),
).toBe(true);
});
it("rejects user uploads", () => {
expect(isAgentAttachment(makeAttachment({ id: "c", createdByUserId: "user-1" }))).toBe(false);
expect(
isAgentAttachment(
makeAttachment({ id: "d", createdByUserId: "user-1", issueCommentId: "comment-1" }),
),
).toBe(false);
});
it("treats authorless rows as agent output only when not comment-bound", () => {
expect(isAgentAttachment(makeAttachment({ id: "e" }))).toBe(true);
expect(isAgentAttachment(makeAttachment({ id: "f", issueCommentId: "comment-1" }))).toBe(false);
});
});
describe("selectAgentArtifactAttachments", () => {
it("keeps agent attachments and drops user uploads", () => {
const agent = makeAttachment({ id: "agent-file", createdByAgentId: "agent-1" });
const user = makeAttachment({
id: "user-file",
createdByUserId: "user-1",
issueCommentId: "comment-1",
});
expect(selectAgentArtifactAttachments([agent, user], [])).toEqual([agent]);
});
it("dedupes attachments already promoted to work products", () => {
// The promotion metadata schema requires a UUID attachmentId.
const promotedId = "00000000-0000-4000-8000-000000000001";
const promoted = makeAttachment({ id: promotedId, createdByAgentId: "agent-1" });
const loose = makeAttachment({ id: "loose", createdByAgentId: "agent-1" });
const result = selectAgentArtifactAttachments(
[promoted, loose],
[makePromotingWorkProduct(promotedId)],
);
expect(result.map((a) => a.id)).toEqual(["loose"]);
});
it("tolerates missing inputs", () => {
expect(selectAgentArtifactAttachments(null, null)).toEqual([]);
});
});
describe("workProductHref", () => {
it("prefers the top-level url", () => {
expect(
workProductHref({ url: "https://example.com/pr/1", metadata: { openPath: "/api/x" } }),
).toBe("https://example.com/pr/1");
});
it("falls back to metadata.openPath, then metadata.url", () => {
expect(
workProductHref({ url: null, metadata: { openPath: "/api/attachments/a/content" } }),
).toBe("/api/attachments/a/content");
expect(
workProductHref({ url: null, metadata: { url: "https://tunnel.here.now/x" } }),
).toBe("https://tunnel.here.now/x");
expect(
workProductHref({
url: null,
metadata: { openPath: "/api/attachments/a/content", url: "https://tunnel.here.now/x" },
}),
).toBe("/api/attachments/a/content");
});
it("ignores non-string and blank metadata values", () => {
expect(workProductHref({ url: null, metadata: { openPath: 42, url: " " } })).toBeNull();
});
it("returns null without url or metadata links", () => {
expect(workProductHref({ url: null, metadata: null })).toBeNull();
expect(workProductHref({ url: null, metadata: { attachmentId: "a" } })).toBeNull();
});
});
describe("documentDisplayTitle", () => {
it("prefers the stored title", () => {
expect(documentDisplayTitle({ key: "synthesis", title: "Findings Synthesis" })).toBe(
"Findings Synthesis",
);
});
it("humanizes the key when no title is set", () => {
expect(documentDisplayTitle({ key: "synthesis", title: null })).toBe("Synthesis");
expect(documentDisplayTitle({ key: "design_notes-v2", title: " " })).toBe("Design notes v2");
});
});