Skip to content

Commit e22d450

Browse files
fix(web): keep short multiline user messages expanded (#128085)
* fix(web): keep short user prompts expanded * test(ui): drop non-regressing disclosure cases
1 parent 2a87667 commit e22d450

4 files changed

Lines changed: 159 additions & 89 deletions

File tree

‎ui/src/e2e/chat-user-bubble-disclosure.e2e.test.ts‎

Lines changed: 97 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -10,73 +10,106 @@ import {
1010
const suite = createChatFlowE2eSuite();
1111

1212
suite.define(() => {
13-
it.each([
14-
{
15-
name: "explicit lines",
16-
text: Array.from({ length: 8 }, (_, index) => `Prompt line ${index + 1}`).join("\n"),
13+
it("keeps seven short lines fully visible", async () => {
14+
const text = [
15+
"please re-review these:",
16+
"#127818",
17+
"#127826",
18+
"#127844",
19+
"#127881",
20+
"",
21+
"rerun the same session we had for these",
22+
].join("\n");
23+
const context = await suite.newBrowserContext({
24+
locale: "en-US",
25+
serviceWorkers: "block",
1726
viewport: { height: 900, width: 1280 },
18-
},
19-
{
20-
name: "soft-wrapped text",
21-
text: `${"This prompt remains mounted while its narrow visual preview is clamped. ".repeat(7)}Final prompt tail.`,
22-
viewport: { height: 844, width: 390 },
23-
},
24-
] as const)(
25-
"clamps $name to five lines and toggles the complete prompt",
26-
async ({ name, text, viewport }) => {
27-
const context = await suite.newBrowserContext({
28-
locale: "en-US",
29-
serviceWorkers: "block",
30-
viewport,
31-
});
32-
const page = await context.newPage();
33-
await installMockGateway(page, {
34-
historyMessages: [{ role: "user", content: [{ type: "text", text }], timestamp: 1 }],
35-
});
27+
});
28+
const page = await context.newPage();
29+
await installMockGateway(page, {
30+
historyMessages: [{ role: "user", content: [{ type: "text", text }], timestamp: 1 }],
31+
});
3632

37-
try {
38-
await page.goto(`${suite.server.baseUrl}chat`);
39-
const bubble = page.locator(".chat-group.user .chat-bubble");
40-
await bubble.waitFor({ state: "visible", timeout: 10_000 });
41-
const content = bubble.locator(".chat-message-disclosure__content");
42-
const toggle = bubble.getByRole("button", { name: "Show more" });
33+
try {
34+
await page.goto(`${suite.server.baseUrl}chat`);
35+
const bubble = page.locator(".chat-group.user .chat-bubble");
36+
await bubble.waitFor({ state: "visible", timeout: 10_000 });
37+
const proofDir = path.join(
38+
process.cwd(),
39+
".artifacts",
40+
"control-ui-e2e",
41+
"user-bubble-clamp",
42+
);
43+
if (captureUiProofEnabled) {
44+
await mkdir(proofDir, { recursive: true });
45+
await bubble.screenshot({ path: path.join(proofDir, "short-message.png") });
46+
}
4347

44-
expect(await toggle.getAttribute("aria-expanded")).toBe("false");
45-
expect(await content.evaluate((element) => getComputedStyle(element).webkitLineClamp)).toBe(
46-
"5",
47-
);
48-
expect(await content.textContent()).toContain(text.slice(-18));
49-
const collapsedHeight = await content.evaluate((element) => element.clientHeight);
50-
expect(
51-
await content.evaluate((element) => element.scrollHeight > element.clientHeight),
52-
).toBe(true);
53-
const proofDir = path.join(
54-
process.cwd(),
55-
".artifacts",
56-
"control-ui-e2e",
57-
"user-bubble-disclosure",
58-
);
59-
const proofName = name.replaceAll(" ", "-");
60-
if (captureUiProofEnabled) {
61-
await mkdir(proofDir, { recursive: true });
62-
await bubble.screenshot({ path: path.join(proofDir, `${proofName}-collapsed.png`) });
63-
}
48+
expect(await bubble.getByRole("button", { name: "Show more" }).count()).toBe(0);
49+
expect(await bubble.locator(".chat-message-disclosure").count()).toBe(0);
50+
const bubbleText = await bubble.textContent();
51+
for (const line of text.split("\n").filter(Boolean)) {
52+
expect(bubbleText).toContain(line);
53+
}
54+
} finally {
55+
await suite.closeBrowserContext(context);
56+
}
57+
});
6458

65-
await toggle.click();
66-
const collapse = bubble.getByRole("button", { name: "Show less" });
67-
expect(await collapse.getAttribute("aria-expanded")).toBe("true");
68-
expect(await content.evaluate((element) => getComputedStyle(element).webkitLineClamp)).toBe(
69-
"none",
70-
);
71-
expect(await content.evaluate((element) => element.clientHeight)).toBeGreaterThan(
72-
collapsedHeight,
73-
);
74-
if (captureUiProofEnabled) {
75-
await bubble.screenshot({ path: path.join(proofDir, `${proofName}-expanded.png`) });
76-
}
77-
} finally {
78-
await suite.closeBrowserContext(context);
59+
it("clamps a 1300-character prompt to five lines and toggles the complete prompt", async () => {
60+
const text =
61+
`${"This long prompt stays mounted while its preview is clamped. ".repeat(22)}Final prompt tail.`.slice(
62+
0,
63+
1_300,
64+
);
65+
const context = await suite.newBrowserContext({
66+
locale: "en-US",
67+
serviceWorkers: "block",
68+
viewport: { height: 844, width: 390 },
69+
});
70+
const page = await context.newPage();
71+
await installMockGateway(page, {
72+
historyMessages: [{ role: "user", content: [{ type: "text", text }], timestamp: 1 }],
73+
});
74+
75+
try {
76+
await page.goto(`${suite.server.baseUrl}chat`);
77+
const bubble = page.locator(".chat-group.user .chat-bubble");
78+
await bubble.waitFor({ state: "visible", timeout: 10_000 });
79+
const content = bubble.locator(".chat-message-disclosure__content");
80+
const toggle = bubble.getByRole("button", { name: "Show more" });
81+
82+
expect(await toggle.getAttribute("aria-expanded")).toBe("false");
83+
expect(await content.evaluate((element) => getComputedStyle(element).webkitLineClamp)).toBe(
84+
"5",
85+
);
86+
expect(await content.textContent()).toContain(text.slice(-18));
87+
const collapsedHeight = await content.evaluate((element) => element.clientHeight);
88+
expect(await content.evaluate((element) => element.scrollHeight > element.clientHeight)).toBe(
89+
true,
90+
);
91+
const proofDir = path.join(
92+
process.cwd(),
93+
".artifacts",
94+
"control-ui-e2e",
95+
"user-bubble-clamp",
96+
);
97+
if (captureUiProofEnabled) {
98+
await mkdir(proofDir, { recursive: true });
99+
await bubble.screenshot({ path: path.join(proofDir, "long-message-collapsed.png") });
79100
}
80-
},
81-
);
101+
102+
await toggle.click();
103+
const collapse = bubble.getByRole("button", { name: "Show less" });
104+
expect(await collapse.getAttribute("aria-expanded")).toBe("true");
105+
expect(await content.evaluate((element) => getComputedStyle(element).webkitLineClamp)).toBe(
106+
"none",
107+
);
108+
expect(await content.evaluate((element) => element.clientHeight)).toBeGreaterThan(
109+
collapsedHeight,
110+
);
111+
} finally {
112+
await suite.closeBrowserContext(context);
113+
}
114+
});
82115
});

‎ui/src/pages/chat/components/chat-message-markdown.test.ts‎

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
// Contract for the full-message fetch flag: the Gateway marks every display-
33
// capped projection (user rows included), but the expander that consumes this
44
// flag renders loaded content for assistant rows alone.
5-
import { describe, expect, it } from "vitest";
6-
import { resolveMessageActionDetails } from "./chat-message-markdown.ts";
5+
import { render } from "lit";
6+
import { describe, expect, it, vi } from "vitest";
7+
import { renderUserMessageMarkdown, resolveMessageActionDetails } from "./chat-message-markdown.ts";
78

89
const cappedMeta = { id: "msg-1", truncated: true, reason: "display-cap" };
910

@@ -51,3 +52,39 @@ describe("resolveMessageActionDetails full-message fetch flag", () => {
5152
expect(details?.shouldFetchFullMessage).toBe(false);
5253
});
5354
});
55+
56+
describe("user message disclosure", () => {
57+
it.each([
58+
{
59+
name: "seven short lines",
60+
markdown: [
61+
"please re-review these:",
62+
"#127818",
63+
"#127826",
64+
"#127844",
65+
"#127881",
66+
"",
67+
"rerun the same session we had for these",
68+
].join("\n"),
69+
},
70+
{ name: "exactly 1200 UTF-16 code units", markdown: "a".repeat(1_200) },
71+
{ name: "forty short lines", markdown: Array(40).fill("a").join("\n") },
72+
])("keeps $name fully visible", ({ markdown }) => {
73+
const container = document.createElement("div");
74+
75+
render(
76+
renderUserMessageMarkdown(
77+
markdown,
78+
"message",
79+
{ isStreaming: false, onToggleUserMessageExpanded: vi.fn() },
80+
{},
81+
),
82+
container,
83+
);
84+
85+
expect(container.querySelector(".chat-message-disclosure")).toBeNull();
86+
for (const line of markdown.split("\n").filter(Boolean)) {
87+
expect(container.textContent).toContain(line);
88+
}
89+
});
90+
});

‎ui/src/pages/chat/components/chat-message-markdown.ts‎

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,9 @@ export function renderReplyButton(
201201
`;
202202
}
203203

204-
const USER_MESSAGE_COLLAPSED_LINE_LIMIT = 5;
205-
const USER_MESSAGE_COLLAPSED_CHAR_LIMIT = 700;
204+
// Character length owns normal disclosure; this high line cap only bounds newline-heavy prompts.
205+
const USER_MESSAGE_COLLAPSED_CHAR_LIMIT = 1_200;
206+
const USER_MESSAGE_COLLAPSED_LINE_LIMIT = 40;
206207

207208
function shouldCollapseUserMessage(markdown: string): boolean {
208209
return (
@@ -253,28 +254,21 @@ export function renderUserMessageMarkdown(
253254
markdownRenderOptions: MarkdownRenderOptions,
254255
duplicateSuffix?: DuplicateSuffix,
255256
) {
256-
if (!opts.onToggleUserMessageExpanded) {
257+
if (!opts.onToggleUserMessageExpanded || !shouldCollapseUserMessage(markdown)) {
257258
return renderMarkdownText(markdown, opts.isStreaming, markdownRenderOptions, duplicateSuffix);
258259
}
259260

260261
const disclosureId = `user-message:${messageKey}`;
261262
const expanded = opts.isUserMessageExpanded?.(disclosureId) ?? false;
262-
const likelyOverflow = shouldCollapseUserMessage(markdown);
263263
return html`
264-
<div
265-
class="chat-message-disclosure ${expanded
266-
? "is-expanded has-overflow"
267-
: likelyOverflow
268-
? "has-overflow"
269-
: ""}"
270-
>
264+
<div class="chat-message-disclosure ${expanded ? "is-expanded has-overflow" : ""}">
271265
<div class="chat-message-disclosure__content" ${ref(userMessageOverflowRef(expanded))}>
272266
${renderMarkdownText(markdown, opts.isStreaming, markdownRenderOptions, duplicateSuffix)}
273267
</div>
274268
<button
275269
class="chat-message-disclosure__toggle"
276270
type="button"
277-
?hidden=${!expanded && !likelyOverflow}
271+
?hidden=${!expanded}
278272
aria-label=${t(expanded ? "chat.messages.showLess" : "chat.messages.showMore")}
279273
aria-expanded=${String(expanded)}
280274
@click=${() => opts.onToggleUserMessageExpanded?.(disclosureId)}

‎ui/src/pages/chat/components/chat-message.test.ts‎

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,10 +1007,7 @@ describe("grouped chat rendering", () => {
10071007

10081008
it("collapses long user messages and toggles their disclosure state", () => {
10091009
const container = document.createElement("div");
1010-
const collapsedLines = [
1011-
"Inspect AGENTS.md:188 first.",
1012-
...Array.from({ length: 11 }, (_, index) => `Prompt line ${index}`),
1013-
];
1010+
const collapsedLines = ["Inspect AGENTS.md:188 first.", "a".repeat(1_201)];
10141011
const expandedTail = "Full prompt tail after the disclosure boundary.";
10151012
const markdownContent = [...collapsedLines, expandedTail].join("\n");
10161013
const onToggleUserMessageExpanded = vi.fn();
@@ -1074,7 +1071,7 @@ describe("grouped chat rendering", () => {
10741071

10751072
it("collapses a long single-line user message without truncating its DOM", () => {
10761073
const container = document.createElement("div");
1077-
const markdownContent = `${"a".repeat(699)}😀`;
1074+
const markdownContent = `${"a".repeat(1_199)}😀`;
10781075

10791076
renderGroupedMessage(
10801077
container,
@@ -1088,20 +1085,29 @@ describe("grouped chat rendering", () => {
10881085
expect(expectElement(disclosure, ".chat-text", HTMLDivElement).textContent).toContain("😀");
10891086
});
10901087

1091-
it("does not add prompt disclosure controls to short user or assistant messages", () => {
1088+
it("does not add prompt disclosure controls to short multiline user or assistant messages", () => {
10921089
const container = document.createElement("div");
10931090
const onToggleUserMessageExpanded = vi.fn();
1091+
const shortMultilinePrompt = [
1092+
"please re-review these:",
1093+
"#127818",
1094+
"#127826",
1095+
"#127844",
1096+
"#127881",
1097+
"",
1098+
"rerun the same session we had for these",
1099+
].join("\n");
10941100

10951101
renderGroupedMessage(
10961102
container,
1097-
{ role: "user", content: "Short prompt", timestamp: 1001 },
1103+
{ role: "user", content: shortMultilinePrompt, timestamp: 1001 },
10981104
"user",
10991105
{ onToggleUserMessageExpanded },
11001106
);
1101-
expect(container.querySelector(".chat-message-disclosure")).not.toBeNull();
1102-
expect(
1103-
container.querySelector<HTMLButtonElement>(".chat-message-disclosure__toggle")?.hidden,
1104-
).toBe(true);
1107+
expect(container.querySelector(".chat-message-disclosure")).toBeNull();
1108+
for (const line of shortMultilinePrompt.split("\n").filter(Boolean)) {
1109+
expect(container.textContent).toContain(line);
1110+
}
11051111

11061112
renderAssistantMessage(
11071113
container,

0 commit comments

Comments
 (0)