Files
PaperClipAI/ui/src/lib/issue-output.test.ts
T
DottaandPaperclip b2a33d0184 [codex] Filter document artifacts from issue outputs (#7608)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - Issue detail pages promote certain artifact work products into the
dedicated Output surface while also listing raw attachments below
> - Document-like artifacts such as plan markdown can currently be
promoted like binary outputs, which makes the same work product story
look like both an output and a document/attachment
> - The output surface should stay focused on inspectable generated
media, archives, PDFs, WebAssembly, SVG/images, and true binary
deliverables while document-like artifacts remain in the document or
attachment flow
> - This pull request filters document-like artifact metadata out of the
Output section and avoids duplicating the attachments that back promoted
outputs
> - The benefit is a cleaner issue detail page where plans and markdown
reports do not appear as binary outputs, while real output files still
get highlighted

## Linked Issues or Issue Description

Fixes #7609
Refs PAP-10354
Refs PAP-10369

## What Changed

- Added output MIME-type normalization and eligibility checks for issue
artifact work products.
- Filtered markdown, text, JSON, XML, CSV, YAML, source-like files, and
generic binary artifacts with document-like filenames out of promoted
issue outputs.
- Kept video, image including SVG, PDF, ZIP, WebAssembly, and true
binary artifacts eligible for the Output section.
- Hid attachments that back promoted outputs while leaving filtered
document-like artifact attachments visible.
- Preserved the full image attachment set for chat image gallery lookup
even when promoted image outputs are hidden from the attachment list.
- Added focused tests for output eligibility, glyph labeling, output
promotion, attachment filtering, gallery image preservation, and the
output section render behavior.

## Verification

- `pnpm vitest run ui/src/lib/issue-output.test.ts
ui/src/pages/IssueDetail.test.tsx
ui/src/components/issue-output/IssueOutputSection.test.tsx`
- GitHub PR checks are green on
`7d1b80f9702f20ab86cc502bffce599b13f1b088`.
- Greptile confidence score is 5/5 and both Greptile review threads are
resolved.

## Risks

- Low risk. The change only affects UI classification of Paperclip
artifact work products. The main behavioral risk is an uncommon
text-like generated artifact no longer appearing in the Output section;
it remains available through the normal attachment/document surfaces.

> 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 GPT-5 Codex via Paperclip CodexCoder, with repository tool use
and local command execution.

## 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 run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] If this change affects the UI, I have included before/after
screenshots
- [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: Paperclip <noreply@paperclip.ing>
2026-06-05 14:40:20 -05:00

238 lines
9.6 KiB
TypeScript

import { describe, expect, it } from "vitest";
import type { IssueWorkProduct } from "@paperclipai/shared";
import {
formatBytes,
formatDuration,
getIssueOutputs,
getOutputFileGlyph,
getPromotedOutputAttachmentIds,
isOutputEligibleContentType,
} from "./issue-output";
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: overrides.title ?? "output.mp4",
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;
}
let uuidCounter = 0;
function uuid() {
uuidCounter += 1;
return `00000000-0000-4000-8000-${String(uuidCounter).padStart(12, "0")}`;
}
function videoMetadata(attachmentId = uuid()) {
return {
attachmentId,
contentType: "video/mp4",
byteSize: 19_293_798,
contentPath: `/api/attachments/${attachmentId}/content`,
openPath: `/api/attachments/${attachmentId}/content`,
downloadPath: `/api/attachments/${attachmentId}/content?download=1`,
originalFilename: "demo.mp4",
};
}
function artifactMetadata(contentType: string, originalFilename: string, attachmentId = uuid()) {
return {
...videoMetadata(attachmentId),
contentType,
originalFilename,
};
}
describe("formatBytes", () => {
it("renders bytes below 1KB as whole bytes", () => {
expect(formatBytes(0)).toBe("0 B");
expect(formatBytes(512)).toBe("512 B");
});
it("uses one trimmed decimal place from KB upward", () => {
expect(formatBytes(1024)).toBe("1 KB");
expect(formatBytes(412 * 1024)).toBe("412 KB");
expect(formatBytes(19_293_798)).toBe("18.4 MB");
expect(formatBytes(1.2 * 1024 * 1024 * 1024)).toBe("1.2 GB");
});
it("handles invalid input defensively", () => {
expect(formatBytes(Number.NaN)).toBe("0 B");
expect(formatBytes(-10)).toBe("0 B");
});
});
describe("formatDuration", () => {
it("formats sub-hour durations as m:ss", () => {
expect(formatDuration(58)).toBe("0:58");
expect(formatDuration(102)).toBe("1:42");
});
it("formats durations over an hour as h:mm:ss", () => {
expect(formatDuration(3600 + 42 * 60 + 9)).toBe("1:42:09");
});
});
describe("getOutputFileGlyph", () => {
it("maps known mime types to tone + label", () => {
expect(getOutputFileGlyph("video/mp4")).toEqual({ label: "MP4", tone: "video" });
expect(getOutputFileGlyph("video/mp4; charset=binary")).toEqual({ label: "MP4", tone: "video" });
expect(getOutputFileGlyph("video/quicktime")).toEqual({ label: "MOV", tone: "video" });
expect(getOutputFileGlyph("application/pdf")).toEqual({ label: "PDF", tone: "pdf" });
expect(getOutputFileGlyph("application/zip")).toEqual({ label: "ZIP", tone: "zip" });
expect(getOutputFileGlyph("image/png")).toEqual({ label: "IMG", tone: "image" });
});
it("falls back to BIN for unknown types", () => {
expect(getOutputFileGlyph("application/octet-stream")).toEqual({ label: "BIN", tone: "bin" });
expect(getOutputFileGlyph(undefined)).toEqual({ label: "BIN", tone: "bin" });
});
it("labels document-like fallbacks defensively", () => {
expect(getOutputFileGlyph("text/plain")).toEqual({ label: "TXT", tone: "bin" });
expect(getOutputFileGlyph("text/markdown")).toEqual({ label: "MD", tone: "bin" });
expect(getOutputFileGlyph("application/json; charset=utf-8")).toEqual({ label: "JSON", tone: "bin" });
expect(getOutputFileGlyph("application/wasm")).toEqual({ label: "WASM", tone: "bin" });
});
});
describe("isOutputEligibleContentType", () => {
it("keeps media, pdf, zip, and true generic binary outputs eligible", () => {
expect(isOutputEligibleContentType("video/mp4; charset=binary")).toBe(true);
expect(isOutputEligibleContentType("image/png")).toBe(true);
expect(isOutputEligibleContentType("image/svg+xml")).toBe(true);
expect(isOutputEligibleContentType("application/pdf")).toBe(true);
expect(isOutputEligibleContentType("application/vnd.example.bundle+zip")).toBe(true);
expect(isOutputEligibleContentType("application/wasm")).toBe(true);
expect(isOutputEligibleContentType("application/octet-stream")).toBe(true);
expect(isOutputEligibleContentType("application/octet-stream", "build.bin")).toBe(true);
});
it("filters document-like and source formats out of outputs", () => {
expect(isOutputEligibleContentType("text/markdown")).toBe(false);
expect(isOutputEligibleContentType("text/plain")).toBe(false);
expect(isOutputEligibleContentType("application/json")).toBe(false);
expect(isOutputEligibleContentType("application/vnd.api+json")).toBe(false);
expect(isOutputEligibleContentType("text/html")).toBe(false);
expect(isOutputEligibleContentType("application/xml")).toBe(false);
expect(isOutputEligibleContentType("text/csv")).toBe(false);
expect(isOutputEligibleContentType("application/x-yaml")).toBe(false);
expect(isOutputEligibleContentType("application/octet-stream", "report.md")).toBe(false);
expect(isOutputEligibleContentType("application/octet-stream", "notes.txt")).toBe(false);
});
});
describe("getIssueOutputs", () => {
it("ignores non-artifact work products and returns empty for no outputs", () => {
const result = getIssueOutputs([
makeWorkProduct({ id: "pr-1", type: "pull_request" }),
makeWorkProduct({ id: "doc-1", type: "document" }),
makeWorkProduct({ id: "artifact-1", type: "artifact", provider: "custom", metadata: videoMetadata() }),
]);
expect(result.count).toBe(0);
expect(result.primary).toBeNull();
expect(result.rest).toEqual([]);
});
it("parses a single video artifact into a primary output", () => {
const result = getIssueOutputs([
makeWorkProduct({ id: "wp-1", metadata: videoMetadata(), isPrimary: true }),
]);
expect(result.count).toBe(1);
expect(result.primary?.id).toBe("wp-1");
expect(result.primary?.degraded).toBe(false);
expect(result.primary?.metadata?.contentType).toBe("video/mp4");
expect(result.rest).toEqual([]);
});
it("ignores markdown and text artifact metadata instead of promoting them to outputs", () => {
const result = getIssueOutputs([
makeWorkProduct({ id: "markdown", metadata: artifactMetadata("text/markdown", "report.md") }),
makeWorkProduct({ id: "text", metadata: artifactMetadata("text/plain", "notes.txt") }),
makeWorkProduct({ id: "json", metadata: artifactMetadata("application/json", "summary.json") }),
makeWorkProduct({ id: "generic-markdown", metadata: artifactMetadata("application/octet-stream", "legacy-report.md") }),
]);
expect(result.count).toBe(0);
expect(result.primary).toBeNull();
});
it("keeps video, image, pdf, zip, and binary artifact metadata as outputs", () => {
const result = getIssueOutputs([
makeWorkProduct({ id: "video", metadata: artifactMetadata("video/mp4", "demo.mp4") }),
makeWorkProduct({ id: "image", metadata: artifactMetadata("image/png", "screenshot.png") }),
makeWorkProduct({ id: "svg", metadata: artifactMetadata("image/svg+xml", "diagram.svg") }),
makeWorkProduct({ id: "pdf", metadata: artifactMetadata("application/pdf", "brief.pdf") }),
makeWorkProduct({ id: "zip", metadata: artifactMetadata("application/zip; charset=binary", "bundle.zip") }),
makeWorkProduct({ id: "wasm", metadata: artifactMetadata("application/wasm", "module.wasm") }),
makeWorkProduct({ id: "binary", metadata: artifactMetadata("application/octet-stream", "build.bin") }),
]);
expect(result.items.map((item) => item.id)).toEqual(["video", "image", "svg", "pdf", "zip", "wasm", "binary"]);
});
it("orders the explicit primary first, then most recent", () => {
const result = getIssueOutputs([
makeWorkProduct({
id: "old",
createdAt: new Date("2026-05-29T10:00:00Z"),
metadata: videoMetadata(),
}),
makeWorkProduct({
id: "primary",
isPrimary: true,
createdAt: new Date("2026-05-28T10:00:00Z"),
metadata: videoMetadata(),
}),
makeWorkProduct({
id: "recent",
createdAt: new Date("2026-05-30T10:00:00Z"),
metadata: videoMetadata(),
}),
]);
expect(result.primary?.id).toBe("primary");
expect(result.rest.map((r) => r.id)).toEqual(["recent", "old"]);
});
it("marks artifacts with invalid metadata as degraded without throwing", () => {
const result = getIssueOutputs([
makeWorkProduct({
id: "broken",
metadata: { attachmentId: "att-x", contentType: "video/mp4" } as Record<string, unknown>,
}),
]);
expect(result.count).toBe(1);
expect(result.primary?.degraded).toBe(true);
expect(result.primary?.metadata).toBeNull();
});
});
describe("getPromotedOutputAttachmentIds", () => {
it("returns backing attachment ids only for work products promoted to outputs", () => {
const videoAttachmentId = uuid();
const markdownAttachmentId = uuid();
const ids = getPromotedOutputAttachmentIds([
makeWorkProduct({ id: "video", metadata: videoMetadata(videoAttachmentId) }),
makeWorkProduct({ id: "markdown", metadata: artifactMetadata("text/markdown", "report.md", markdownAttachmentId) }),
makeWorkProduct({ id: "broken", metadata: { attachmentId: "bad" } as Record<string, unknown> }),
]);
expect(Array.from(ids)).toEqual([videoAttachmentId]);
});
});