mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-02 02:07:25 +08:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Agent work often ends with a Markdown or plain-text file. > - Task attachments currently open outside the task panel. > - Users need to inspect those files while keeping the task conversation in view. > - This pull request opens text attachments in task tabs and adds rendered, raw, and download controls. > - The same controls work in the mobile task drawer. ## Linked Issues or Issue Description **What happened?** Opening a text attachment did not put its content in a task tab. Markdown files had no in-task rendered/raw toggle. **Expected behavior** Open Markdown and text attachments in one reusable task tab. Show Markdown as rendered content or raw text. Download the original file. **Steps to reproduce** 1. Upload a Markdown file and a plain-text file to a task comment. 2. Open each attachment from the task conversation or artifact list. 3. Switch Markdown between Rendered and Raw. Download both files. 4. Repeat at a mobile viewport width. Related work: #14193 controls artifact tab arrival. This change adds text attachment content tabs. ## What Changed - Route text attachment opens from conversation and artifact cards into task tabs. - Add a text attachment panel with accessible Rendered, Raw, and Download controls. - Preserve ordinary links for other file types. - Support the selected attachment in the mobile drawer. - Keep text-tab actions on the current rich artifact cards, including CSV previews. - Render attachment image references and diagram source without loading media URLs. - Add browser regression tests, component tests, Storybook examples, and usage documentation. ## Verification - Full workspace typecheck, production build, Storybook build, and UI token gates pass locally. - All 6,960 UI tests pass. The additional media regression passes against the real Markdown renderer and fails before the fix. CSV coverage verifies direct downloads and text tabs after preview. - Both desktop and mobile browser cases pass locally. They check rendered/raw Markdown, literal plain text, reusable tabs, review controls, and exact original download bytes. The local fixture used a separate database port because an existing socket occupied the default range. - The full CI test matrix passes on `82be5efbef26927b237a031725bb3d7fa79f637f`. The duplicate local `pnpm test:run` was stopped after this CI result; it did not complete locally. - Greptile is 5/5 on the final commit. All review threads are resolved, and the security scan passes. - All 54 final-head checks pass, including the canary dry run. The two optional Storybook jobs are skipped. ## Risks - Text attachment links now open in the task panel. Other content types keep their existing link behavior. - File display still depends on the existing authenticated attachment route. There are no API or database changes. - Raw text is displayed as text, including strings that look like HTML. Rendered Markdown keeps media references inert. ## Model Used OpenAI Codex, based on GPT-6, with code execution, browser testing, and subagent tool use. The runtime does not expose an exact serving model variant or context-window size. Recovered earlier implementation changes were reviewed and tested; their exact model metadata is unavailable. ## 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 - [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>
86 lines
6.3 KiB
TypeScript
86 lines
6.3 KiB
TypeScript
import { randomUUID } from "node:crypto";
|
|
import fs from "node:fs/promises";
|
|
import { expect, test, type APIRequestContext } from "@playwright/test";
|
|
|
|
async function json(response: Awaited<ReturnType<APIRequestContext["get"]>>) {
|
|
expect(response.ok(), `${response.status()}: ${await response.text()}`).toBe(true);
|
|
return response.json();
|
|
}
|
|
|
|
for (const mobile of [false, true]) {
|
|
test(`opens uploaded text in task tabs and downloads the original (mobile=${mobile})`, async ({ page, request }, testInfo) => {
|
|
await page.setViewportSize(mobile ? { width: 390, height: 844 } : { width: 1440, height: 1000 });
|
|
const company = await json(await request.post("/api/companies", { data: { name: `Text files ${randomUUID()}` } }));
|
|
const issue = await json(await request.post(`/api/companies/${company.id}/issues`, {
|
|
data: { title: "Review uploaded text files", status: "backlog" },
|
|
}));
|
|
const files = [
|
|
{ name: "AGENTS.md", mimeType: "text/markdown", buffer: Buffer.from("# File charter\n\nKeep **original** bytes.\n") },
|
|
{ name: "notes.txt", mimeType: "text/plain", buffer: Buffer.from("Plain text <script>never execute</script>\n") },
|
|
];
|
|
const attachments = [];
|
|
for (const file of files) attachments.push(await json(await request.post(`/api/companies/${company.id}/issues/${issue.id}/attachments`, { multipart: { file } })));
|
|
await json(await request.post(`/api/issues/${issue.id}/comments`, {
|
|
data: { body: "Review the attached files.", attachmentIds: attachments.map((attachment) => attachment.id) },
|
|
}));
|
|
for (const [index, attachment] of attachments.entries()) {
|
|
await json(await request.post(`/api/issues/${issue.id}/work-products`, {
|
|
data: {
|
|
type: "artifact", provider: "paperclip", title: `Delivered ${files[index]!.name}`, status: "ready_for_review",
|
|
metadata: {
|
|
attachmentId: attachment.id, contentType: attachment.contentType, byteSize: attachment.byteSize,
|
|
originalFilename: files[index]!.name, contentPath: attachment.contentPath,
|
|
openPath: attachment.contentPath, downloadPath: `${attachment.contentPath}?download=1`,
|
|
},
|
|
},
|
|
}));
|
|
}
|
|
await page.goto(`/${company.issuePrefix}/issues/${issue.identifier}`);
|
|
await page.getByRole("link", { name: "Open AGENTS.md", exact: true }).click();
|
|
const panel = mobile ? page.getByTestId("mobile-task-side-panel") : page.locator("aside").filter({ has: page.getByRole("tab", { name: "AGENTS.md", exact: true }) });
|
|
await expect(panel.getByRole("tab", { name: "AGENTS.md", exact: true })).toHaveAttribute("aria-selected", "true");
|
|
await expect(panel.getByRole("heading", { name: "File charter", exact: true, level: 1 })).toBeVisible();
|
|
const raw = panel.getByRole("button", { name: "Raw", exact: true });
|
|
await raw.click();
|
|
await expect(raw).toHaveAttribute("aria-pressed", "true");
|
|
await expect(panel.getByLabel("AGENTS.md raw text")).toContainText("# File charter");
|
|
await panel.getByRole("button", { name: "Rendered", exact: true }).click();
|
|
await expect(panel.getByRole("heading", { name: "File charter", exact: true, level: 1 })).toBeVisible();
|
|
await page.screenshot({ path: testInfo.outputPath("markdown-rendered.png"), fullPage: true });
|
|
const markdownDownload = page.waitForEvent("download");
|
|
await panel.getByRole("link", { name: "Download AGENTS.md", exact: true }).click();
|
|
expect(await fs.readFile((await (await markdownDownload).path())!)).toEqual(files[0]!.buffer);
|
|
if (mobile) await panel.getByRole("button", { name: "Toggle side panel", exact: true }).click();
|
|
await page.getByRole("link", { name: "Open notes.txt", exact: true }).click();
|
|
await expect(panel.getByRole("tab", { name: "notes.txt", exact: true })).toHaveAttribute("aria-selected", "true");
|
|
await expect(panel.getByLabel("notes.txt raw text")).toContainText("<script>never execute</script>");
|
|
await expect(panel.getByRole("group", { name: "Markdown view", exact: true })).toHaveCount(0);
|
|
const textDownload = page.waitForEvent("download");
|
|
await panel.getByRole("link", { name: "Download notes.txt", exact: true }).click();
|
|
expect(await fs.readFile((await (await textDownload).path())!)).toEqual(files[1]!.buffer);
|
|
await page.screenshot({ path: testInfo.outputPath("plain-text-download.png"), fullPage: true });
|
|
await panel.getByRole("tab", { name: "AGENTS.md", exact: true }).click();
|
|
await expect(panel.getByRole("heading", { name: "File charter", exact: true, level: 1 })).toBeVisible();
|
|
await expect(panel.getByRole("tab", { name: "AGENTS.md", exact: true })).toHaveCount(1);
|
|
await panel.getByRole("button", { name: "Open a new tab", exact: true }).click();
|
|
await page.getByRole("option", { name: /^Artifacts(?: Already open)?$/ }).click();
|
|
const markdownCard = panel.getByRole("article").filter({ has: page.getByRole("heading", { name: "Delivered AGENTS.md", exact: true }) });
|
|
const review = markdownCard.getByRole("button", { name: /^(Read|Close) document$/ });
|
|
await review.click();
|
|
await expect(review).toHaveAttribute("aria-expanded", "true");
|
|
await expect(panel.getByRole("heading", { name: "File charter", exact: true, level: 1 })).toBeVisible();
|
|
await expect(markdownCard).toContainText("revision 1");
|
|
await expect(panel.getByRole("link", { name: "Download Delivered AGENTS.md", exact: true })).toBeVisible();
|
|
const cardDownload = page.waitForEvent("download");
|
|
const textCard = panel.getByRole("article").filter({ has: page.getByRole("heading", { name: "Delivered notes.txt", exact: true }) });
|
|
await textCard.getByRole("link", { name: "Download file", exact: true }).click();
|
|
expect(await fs.readFile((await (await cardDownload).path())!)).toEqual(files[1]!.buffer);
|
|
await expect(panel.getByRole("tab", { name: "Artifacts", exact: true })).toHaveAttribute("aria-selected", "true");
|
|
await panel.getByRole("button", { name: "Open in tab: Delivered notes.txt", exact: true }).click();
|
|
await expect(panel.getByRole("tab", { name: "notes.txt", exact: true })).toHaveAttribute("aria-selected", "true");
|
|
await panel.getByRole("tab", { name: "Artifacts", exact: true }).click();
|
|
await panel.getByRole("button", { name: "Open in tab: Delivered AGENTS.md", exact: true }).click();
|
|
await expect(panel.getByRole("tab", { name: "AGENTS.md", exact: true })).toHaveAttribute("aria-selected", "true");
|
|
});
|
|
}
|