From 5bbdff7bdfcc6bab7948b338e22ad541cce0e5fe Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 17 Nov 2026 17:56:21 +0000 Subject: [PATCH] fix(ui-kit): a not-posted GitHub draft shows its whole body (#4197) The shared Body cut a draft at the read bodies' 20,000-character bound and said the rest was on GitHub. A draft is what the host posts, up to 65,536 characters, so the draft branch now applies no bound, as the W4 comment preview does after #4154. Read bodies keep the bound and note. A unit test and long-draft stories (W1 issue approval, PR preview, both widths) prove a draft is never cut and a read body still is. Co-Authored-By: Claude Opus 5.5 --- .changeset/github-draft-body-whole.md | 5 ++ packages/ui-kit/src/github/object-parts.tsx | 13 +++- .../github/GitHubPullRequest.stories.tsx | 21 ++++++- .../stories/github/GitHubWrite.stories.tsx | 25 +++++++- .../ui-kit/tests/github-draft-body.test.tsx | 62 +++++++++++++++++++ 5 files changed, 121 insertions(+), 5 deletions(-) create mode 100644 .changeset/github-draft-body-whole.md create mode 100644 packages/ui-kit/tests/github-draft-body.test.tsx diff --git a/.changeset/github-draft-body-whole.md b/.changeset/github-draft-body-whole.md new file mode 100644 index 0000000000..b55d0d209a --- /dev/null +++ b/.changeset/github-draft-body-whole.md @@ -0,0 +1,5 @@ +--- +"@schlessera/brain-ui-kit": patch +--- + +A not-posted GitHub draft now shows its whole body (#4197). `GitHubPullRequest` in `preview` cut a draft longer than 20,000 characters and said "Truncated · the rest is on GitHub", though a draft is not on GitHub yet and the host posts up to 65,536 characters. A draft keeps its 8-line clamp, whose expand control names the whole length. Read bodies keep their 20,000-character bound and their "Truncated" note. The W1 issue approval (`GitHubIssue` with `posting: { status: "preview" }`) already showed the whole body, and a unit test and a long-draft story now hold it to that. diff --git a/packages/ui-kit/src/github/object-parts.tsx b/packages/ui-kit/src/github/object-parts.tsx index bf1c5eea40..fff51a935a 100644 --- a/packages/ui-kit/src/github/object-parts.tsx +++ b/packages/ui-kit/src/github/object-parts.tsx @@ -8,8 +8,8 @@ import { Field, GitHubLink, githubHref, type GitHubState } from "./shared.js"; /** Internal pieces shared by `GitHubPullRequest` and `GitHubIssue`. */ -/** The body's hard bound, from the design's truncation table. */ -const BODY_MAX_CHARS = 20_000; +/** A read or posted body's hard bound, from the design's truncation table. */ +export const BODY_MAX_CHARS = 20_000; /** "1,840": a count in the reader-facing format, the same in every locale the kit renders in. */ export function count(n: number): string { @@ -68,6 +68,13 @@ export function Labels({ labels }: { labels: string[] }) { /** Where a not-posted draft's links say they come from: it is not on GitHub yet. */ export const DRAFT_SOURCE = { source: "this draft", sourcePhrase: "in this draft" } as const; +/** + * An issue or pull request body. A read or posted body keeps the design's + * 20,000-character bound and its "Truncated" note. A draft (`draft`, a + * not-posted preview) shows its whole text behind the same clamp: what is + * approved is what is posted, up to 65,536 characters (#4197, as #4154 did + * for the W4 comment preview). + */ export function Body(p: { body?: string | null; author: string; bodyLength?: number; bodyTruncated?: boolean; htmlUrl?: string | null; draft?: boolean }) { if (!p.body) { return

— No description provided.

; @@ -81,7 +88,7 @@ export function Body(p: { body?: string | null; author: string; bodyLength?: num lines={8} linesNarrow={10} expandLabel={`Show full description · ${count(length)} characters`} - maxChars={BODY_MAX_CHARS} + {...(p.draft ? {} : { maxChars: BODY_MAX_CHARS })} truncated={p.bodyTruncated} truncatedNote={ !p.draft && githubHref(p.htmlUrl) ? ( diff --git a/packages/ui-kit/stories/github/GitHubPullRequest.stories.tsx b/packages/ui-kit/stories/github/GitHubPullRequest.stories.tsx index 0c204a4717..3529b7883c 100644 --- a/packages/ui-kit/stories/github/GitHubPullRequest.stories.tsx +++ b/packages/ui-kit/stories/github/GitHubPullRequest.stories.tsx @@ -1,6 +1,6 @@ import preview from "#.storybook/preview"; import { useState } from "react"; -import { expect, within } from "storybook/test"; +import { expect, userEvent, within } from "storybook/test"; import { argos, commits, eurycleia, penelope, pr, prThread, telemachus } from "../../fixtures/github.js"; import { GitHubCommitRow } from "../../src/github/GitHubCommitRow.js"; @@ -168,3 +168,22 @@ export const Preview = meta.story({ }, }); export const PreviewNarrow = Preview.extend({ ...narrow }); + +/** + * A preview shows its whole draft (#4197): the read bodies' 20,000-character + * bound does not cut what is approved. The 8-line clamp stays, and its + * expand control names the whole length. + */ +const LONG_PR_DRAFT = `${"The key log gains a second signature per opening. ".repeat(500)}The last line of the draft.`; +export const PreviewLongDraft = meta.story({ + args: { preview: true, body: LONG_PR_DRAFT, bodyLength: undefined, bodyTruncated: false }, + ...desktop, + play: async ({ canvas }) => { + await expect(canvas.queryByText(/Truncated/), "a draft is never shown cut").toBeNull(); + const length = Array.from(LONG_PR_DRAFT).length; + await expect(length).toBeGreaterThan(20_000); + await userEvent.click(canvas.getByRole("button", { name: `Show full description · ${length.toLocaleString("en-US")} characters` })); + await expect(canvas.getByText(/The last line of the draft\./)).toBeVisible(); + }, +}); +export const PreviewLongDraftNarrow = PreviewLongDraft.extend({ ...narrow }); diff --git a/packages/ui-kit/stories/github/GitHubWrite.stories.tsx b/packages/ui-kit/stories/github/GitHubWrite.stories.tsx index 23046b61b8..1e33188ce1 100644 --- a/packages/ui-kit/stories/github/GitHubWrite.stories.tsx +++ b/packages/ui-kit/stories/github/GitHubWrite.stories.tsx @@ -1,5 +1,5 @@ import preview from "#.storybook/preview"; -import { expect, fn } from "storybook/test"; +import { expect, fn, userEvent } from "storybook/test"; import { brainBot } from "../../fixtures/github.js"; import { ApprovalCard } from "../../src/decisions/ApprovalCard.js"; @@ -49,6 +49,29 @@ export const W1IssueApproval = meta.story({ }); export const W1IssueApprovalNarrow = W1IssueApproval.extend({ ...narrow }); +/** + * W1 with a draft past the read bodies' 20,000-character bound (#4197): the + * card shows all of what is approved, in both panes, and never says + * "Truncated". The host posts up to 65,536 characters. + */ +const LONG_ISSUE_DRAFT = `${"The tally of the wine store, night by night. ".repeat(560)}The last line of the draft.`; +export const W1LongDraft = meta.story({ + ...desktop, + render: () => ( + + + + ), + play: async ({ canvas }) => { + await expect(Array.from(LONG_ISSUE_DRAFT).length).toBeGreaterThan(20_000); + await expect(canvas.queryByText(/Truncated/), "a draft is never shown cut").toBeNull(); + await expect(canvas.getByText(/The last line of the draft\./), "As shown renders the whole draft").toBeVisible(); + await userEvent.click(canvas.getByRole("tab", { name: "Exact text" })); + await expect(canvas.getByText(/The last line of the draft\.$/), "Exact text is the whole string").toBeVisible(); + }, +}); +export const W1LongDraftNarrow = W1LongDraft.extend({ ...narrow }); + /** W2: the same slot, now the real object, posted. */ export const W2Posted = meta.story({ ...desktop, diff --git a/packages/ui-kit/tests/github-draft-body.test.tsx b/packages/ui-kit/tests/github-draft-body.test.tsx new file mode 100644 index 0000000000..19600e45e1 --- /dev/null +++ b/packages/ui-kit/tests/github-draft-body.test.tsx @@ -0,0 +1,62 @@ +/** + * A not-posted draft's body is never cut (#4197): what the user approves is + * what the host posts, up to 65,536 characters, so the read bodies' + * 20,000-character bound does not apply to it. As markup; the 320px layout, + * both themes and the clamp's expand control in a browser are the W1 long + * draft stories' in `stories/github/GitHubWrite.stories.tsx`. + */ +import { describe, expect, test } from "bun:test"; +import { Window } from "happy-dom"; +import type { ReactElement } from "react"; +import { renderToStaticMarkup } from "react-dom/server"; + +import { telemachus } from "../fixtures/github.js"; +import { GitHubIssue } from "../src/github/GitHubIssue.js"; +import { GitHubPullRequest } from "../src/github/GitHubPullRequest.js"; +import { BODY_MAX_CHARS } from "../src/github/object-parts.js"; + +function draw(element: ReactElement): Document { + const { document } = new Window(); + document.body.innerHTML = renderToStaticMarkup(element); + return document as unknown as Document; +} + +/** Past the read bound, and well inside the write limit. */ +const LONG = `${"The tally of the wine store, night by night. ".repeat(Math.ceil((BODY_MAX_CHARS + 5_000) / 45))}THE-LAST-LINE`; + +const pr = (p: { preview?: boolean }) => ( + +); + +describe("a draft body", () => { + test("is longer than the read bound in this test", () => { + expect(Array.from(LONG).length).toBeGreaterThan(BODY_MAX_CHARS + 1_000); + }); + + test("the W1 issue preview renders all of it, with no Truncated note", () => { + const doc = draw(); + expect(doc.body.textContent, "W1_PREVIEW_WHOLE_BODY").toContain("THE-LAST-LINE"); + expect(doc.body.textContent, "W1_PREVIEW_NO_TRUNCATED_NOTE").not.toContain("Truncated"); + }); + + test("a pull request preview renders all of it, with no Truncated note", () => { + const doc = draw(pr({ preview: true })); + expect(doc.body.textContent, "PR_PREVIEW_WHOLE_BODY").toContain("THE-LAST-LINE"); + expect(doc.body.textContent, "PR_PREVIEW_NO_TRUNCATED_NOTE").not.toContain("Truncated"); + expect(doc.body.textContent, "a draft is not on GitHub").not.toContain("rest is on GitHub"); + }); +}); + +describe("a read body keeps its bound", () => { + test("an issue as read is cut at the bound and says so", () => { + const doc = draw(); + expect(doc.body.textContent, "ISSUE_READ_BOUND").not.toContain("THE-LAST-LINE"); + expect(doc.body.textContent, "ISSUE_READ_TRUNCATED_NOTE").toContain("Truncated"); + }); + + test("a pull request as read is cut at the bound and says so", () => { + const doc = draw(pr({})); + expect(doc.body.textContent, "PR_READ_BOUND").not.toContain("THE-LAST-LINE"); + expect(doc.body.textContent, "PR_READ_TRUNCATED_NOTE").toContain("Truncated"); + }); +});