Files
PaperClipAI/ui/src/components/issue-output/IssueOutputSection.test.tsx
T
Dotta b4fccaa8c4 [codex] Unify issue media attachment gallery (#8785)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - Issue detail pages and run output cards both render user-facing
attachment previews
> - Media attachments were handled through separate gallery entry
points, so attachments from issue comments and issue output did not
share one consistent viewing path
> - A shared gallery path makes image browsing more predictable across
the issue surface
> - This pull request unifies the issue media attachment gallery
behavior across attachments, output cards, and issue detail rendering
> - The benefit is a more consistent image preview experience with
focused regression coverage around the affected UI paths

## Linked Issues or Issue Description

Refs #8788

This PR fixes inconsistent issue media preview behavior across
attachment and output surfaces.

## What Changed

- Unified issue media attachment gallery behavior across issue
attachments, issue output, output primary cards, and issue detail
rendering.
- Added image gallery modal coverage and regression tests for
attachments, output image handling, keyboard navigation, and issue
detail interactions.
- Preserved the primary video output Open action while still allowing
gallery browsing when a gallery handler is available.
- Updated issue attachment and issue output helper logic to preserve
shared image gallery metadata.

## Verification

- `pnpm --filter @paperclipai/ui exec vitest run
src/components/ImageGalleryModal.test.tsx
src/components/issue-output/IssueOutputSection.test.tsx
src/components/IssueAttachmentsSection.test.tsx
src/pages/IssueDetail.test.tsx`
- Result: 4 files passed, 47 tests passed.

## Risks

Low to medium risk. The change is UI-scoped but touches shared issue
attachment/output rendering paths, so regressions would most likely
appear as image/video preview ordering, missing gallery entries, or
incorrect non-image attachment behavior.

> For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and
discuss it in `#dev` before opening the PR. Feature PRs that overlap
with planned core work may need to be redirected — check the roadmap
first. See `CONTRIBUTING.md`.

## Model Used

OpenAI Codex, GPT-5 coding agent session with shell and git/GitHub CLI
tool use. Exact serving revision and context window were not exposed by
the runtime.

## 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
2026-06-30 07:53:40 -07:00

210 lines
6.7 KiB
TypeScript

import { renderToStaticMarkup } from "react-dom/server";
import { describe, expect, it } from "vitest";
import type { IssueWorkProduct } from "@paperclipai/shared";
import { IssueOutputSection } from "./IssueOutputSection";
function makeWorkProduct(overrides: Partial<IssueWorkProduct> & { id: string }): IssueWorkProduct {
return {
companyId: "company-1",
projectId: null,
issueId: "issue-1",
executionWorkspaceId: null,
runtimeServiceId: null,
type: "artifact",
provider: "paperclip",
externalId: null,
title: "output",
url: null,
status: "active",
reviewState: "none",
isPrimary: false,
healthStatus: "unknown",
summary: null,
metadata: null,
createdByRunId: null,
createdAt: new Date("2026-05-30T12:00:00Z"),
updatedAt: new Date("2026-05-30T12:00:00Z"),
...overrides,
} as IssueWorkProduct;
}
const UUIDS: Record<string, string> = {
"att-1": "11111111-1111-4111-8111-111111111111",
"att-vid": "22222222-2222-4222-8222-222222222222",
"att-pdf": "33333333-3333-4333-8333-333333333333",
"att-img": "44444444-4444-4444-8444-444444444444",
"att-webm": "55555555-5555-4555-8555-555555555555",
};
function metadata(key: string, contentType: string, filename: string) {
const attachmentId = UUIDS[key] ?? key;
return {
attachmentId,
contentType,
byteSize: 19_293_798,
contentPath: `/api/attachments/${attachmentId}/content`,
openPath: `/api/attachments/${attachmentId}/content`,
downloadPath: `/api/attachments/${attachmentId}/content?download=1`,
originalFilename: filename,
};
}
describe("IssueOutputSection", () => {
it("renders a playable, downloadable video as the primary output", () => {
const markup = renderToStaticMarkup(
<IssueOutputSection
workProducts={[
makeWorkProduct({
id: "wp-1",
title: "Demo walkthrough",
isPrimary: true,
metadata: metadata("att-1", "video/mp4", "demo.mp4"),
}),
]}
/>,
);
// Native video player present
expect(markup).toContain("<video");
expect(markup).toContain("controls");
expect(markup).toContain(`/api/attachments/${UUIDS["att-1"]}/content`);
// Filename surfaced and download/open wired
expect(markup).toContain("demo.mp4");
expect(markup).toContain(`/api/attachments/${UUIDS["att-1"]}/content?download=1`);
expect(markup).toContain("Download");
expect(markup).toContain("Open");
// Section header + size formatting
expect(markup).toContain("Output");
expect(markup).toContain("18.4 MB");
});
it("keeps the open action for primary videos when gallery browsing is enabled", () => {
const markup = renderToStaticMarkup(
<IssueOutputSection
workProducts={[
makeWorkProduct({
id: "wp-video",
title: "Demo walkthrough",
isPrimary: true,
metadata: metadata("att-1", "video/mp4", "demo.mp4"),
}),
]}
onMediaClick={() => undefined}
/>,
);
expect(markup).toContain("Browse");
expect(markup).toContain("Open");
expect(markup).toContain(`href="/api/attachments/${UUIDS["att-1"]}/content"`);
expect(markup).toContain("Download");
});
it("renders nothing when the issue has no artifact outputs (empty state)", () => {
const markup = renderToStaticMarkup(
<IssueOutputSection
workProducts={[
makeWorkProduct({ id: "pr-1", type: "pull_request" }),
]}
/>,
);
expect(markup).toBe("");
});
it("renders nothing for markdown-only artifact work products", () => {
const markup = renderToStaticMarkup(
<IssueOutputSection
workProducts={[
makeWorkProduct({
id: "wp-markdown",
title: "plan.md",
isPrimary: true,
metadata: metadata("att-1", "text/markdown", "plan.md"),
}),
]}
/>,
);
expect(markup).toBe("");
});
it("renders the primary card plus an Also produced list for multiple outputs", () => {
const markup = renderToStaticMarkup(
<IssueOutputSection
workProducts={[
makeWorkProduct({
id: "wp-primary",
isPrimary: true,
createdAt: new Date("2026-05-30T12:00:00Z"),
metadata: metadata("att-vid", "video/mp4", "summary.mp4"),
}),
makeWorkProduct({
id: "wp-pdf",
createdAt: new Date("2026-05-30T11:00:00Z"),
metadata: metadata("att-pdf", "application/pdf", "talking-points.pdf"),
}),
]}
/>,
);
expect(markup).toContain("Also produced");
expect(markup).toContain("summary.mp4");
expect(markup).toContain("talking-points.pdf");
// PDF glyph tile label appears for the secondary row
expect(markup).toContain("PDF");
});
it("renders secondary image and video outputs as preview tiles", () => {
const markup = renderToStaticMarkup(
<IssueOutputSection
workProducts={[
makeWorkProduct({
id: "wp-primary",
isPrimary: true,
metadata: metadata("att-pdf", "application/pdf", "brief.pdf"),
}),
makeWorkProduct({
id: "wp-image",
createdAt: new Date("2026-05-30T11:00:00Z"),
metadata: metadata("att-img", "image/png", "screenshot.png"),
}),
makeWorkProduct({
id: "wp-video",
createdAt: new Date("2026-05-30T10:00:00Z"),
metadata: metadata("att-webm", "video/webm", "clip.webm"),
}),
]}
/>,
);
expect(markup).toContain("Also produced");
expect(markup).toContain("screenshot.png");
expect(markup).toContain("clip.webm");
expect(markup).toContain("<img");
expect(markup).toContain("<video");
expect(markup).toContain("Open screenshot.png");
expect(markup).toContain("Open clip.webm");
});
it("surfaces an output with failed/invalid attachment metadata without crashing", () => {
const markup = renderToStaticMarkup(
<IssueOutputSection
workProducts={[
makeWorkProduct({
id: "wp-broken",
title: "broken-output.mp4",
isPrimary: true,
// Missing required path fields → fails the shared metadata schema
metadata: { attachmentId: "att-x", contentType: "video/mp4" } as Record<string, unknown>,
}),
]}
/>,
);
expect(markup).toContain("broken-output.mp4");
expect(markup).toContain("metadata is unavailable");
// No video element and no download link can be built from invalid metadata
expect(markup).not.toContain("<video");
expect(markup).not.toContain("download=1");
});
});