Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .qwen/e2e-tests/2026-07-31-export-collapsible-tool-output.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Export Collapsible Tool Output

## Scope

Verify that long shell output and long `think` tool content keep their full
text in the shared WebUI while remaining collapsed by default. This covers the
HTML export viewer and the other consumers of `@qwen-code/webui`.

## Baseline

A released global `qwen` executable was not available in this environment, so
the before-change `/export` dry-run could not be performed. Source inspection
on `upstream/main` reproduces the loss: `ShellToolCall` and `ThinkToolCall`
replace content after 500 characters with an ellipsis.

## Manual Scenario

1. Export a session containing a successful Bash or Execute tool call whose
output is longer than 500 characters and ends with a unique marker.
2. Open the exported HTML and find the tool call.
3. Confirm the output is collapsed and has a `Show more` control.
4. Expand it and confirm the unique tail marker is visible, then collapse it
again.
5. Repeat with a `think` tool call longer than 500 characters.

## Regression Checks

- Content of exactly 500 characters has no new toggle.
- Both Bash and Execute variants preserve the full output.
- A long single-line Shell result remains horizontally scrollable after it is
expanded.
- Clicking a shell toggle does not invoke the surrounding OUT-row action.
- Clicking the shell OUT row still opens the complete output.
- Error, empty-output, and short-thinking paths remain unchanged.
- Toggle buttons expose their expanded state to assistive technology.

## Automated Verification

```bash
cd packages/webui
npx vitest run \
src/components/toolcalls/shared/CollapsibleOutput.test.tsx \
src/components/toolcalls/ShellToolCall.test.tsx \
src/components/toolcalls/ThinkToolCall.test.tsx
npm run typecheck
npm run lint
npm run build
```

## Results

- Failure-first run: 3 long-output cases failed because their tail markers
were absent; the 500-character boundary and short-thinking cases passed.
- Focused regression run: 3 files and 7 tests passed.
- A headless Chrome layout probe confirmed that handing overflow from the OUT
`<pre>` to its scroll container changes the container from
`clientWidth/scrollWidth = 200/200` to `200/831` for both Bash and Execute.
- Full WebUI run: 30 files and 398 tests passed with Node.js 24.
- WebUI lint, typecheck, and production build passed.
- A normal local `/export` smoke test was not used as proof because the
generated page loads the published WebUI package from unpkg rather than the
worktree bundle. Component tests and the local WebUI build cover this change
until a release build is available for the manual scenario.
46 changes: 8 additions & 38 deletions packages/webui/src/components/toolcalls/GenericToolCall.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
* Generic tool call component - handles all tool call types as fallback
*/

import { useState, type FC } from 'react';
import type { FC } from 'react';
import {
CollapsibleOutput,
ToolCallContainer,
ToolCallCard,
ToolCallRow,
Expand All @@ -20,44 +21,8 @@ import type { BaseToolCallProps } from './shared/index.js';
import { getToolDisplayLabel } from './labelUtils.js';
import { MarkdownRenderer } from '../messages/MarkdownRenderer/MarkdownRenderer.js';

const COLLAPSED_HEIGHT = 200;
const EXPAND_THRESHOLD = 400;

const CollapsibleOutput: FC<{ content: string }> = ({ content }) => {
const [isExpanded, setIsExpanded] = useState(false);
const isLongContent = content.length > EXPAND_THRESHOLD;

return (
<div className="flex flex-col gap-[3px]">
<div
className="text-[13px] opacity-90 overflow-hidden"
style={
!isExpanded && isLongContent
? {
maxHeight: `${COLLAPSED_HEIGHT}px`,
maskImage: `linear-gradient(to bottom, var(--app-primary-background) 140px, transparent ${COLLAPSED_HEIGHT}px)`,
WebkitMaskImage: `linear-gradient(to bottom, var(--app-primary-background) 140px, transparent ${COLLAPSED_HEIGHT}px)`,
}
: undefined
}
>
<MarkdownRenderer content={content} enableFileLinks={false} />
</div>
{isLongContent && (
<div className="flex justify-center border-t border-[var(--app-input-border)] pt-1">
<button
type="button"
onClick={() => setIsExpanded(!isExpanded)}
className="text-[var(--app-secondary-foreground)] text-[0.8em] hover:text-[var(--app-primary-foreground)] cursor-pointer bg-transparent border-none px-2 py-1 rounded hover:bg-[var(--app-input-background)] transition-colors"
>
{isExpanded ? '▲ Collapse' : '▼ Show more'}
</button>
</div>
)}
</div>
);
};

/**
* Generic tool call component that can display any tool call type
* Used as fallback for unknown tool call kinds
Expand Down Expand Up @@ -101,7 +66,12 @@ export const GenericToolCall: FC<BaseToolCallProps> = ({
<div>{operationText}</div>
</ToolCallRow>
<ToolCallRow label="Output">
<CollapsibleOutput content={output} />
<CollapsibleOutput
isCollapsible={output.length > EXPAND_THRESHOLD}
className="text-[13px] opacity-90"
>
<MarkdownRenderer content={output} enableFileLinks={false} />
</CollapsibleOutput>
</ToolCallRow>
</ToolCallCard>
);
Expand Down
8 changes: 8 additions & 0 deletions packages/webui/src/components/toolcalls/ShellToolCall.css
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@
box-sizing: border-box;
}

.bash-toolcall-output-subtle .bash-toolcall-pre {
overflow: visible;
}

.bash-toolcall-error-content {
color: #c74e39;
}
Expand Down Expand Up @@ -180,6 +184,10 @@
box-sizing: border-box;
}

.execute-toolcall-output-subtle .execute-toolcall-pre {
overflow: visible;
}

.execute-toolcall-error-content {
color: #c74e39;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export const ExecuteWithDescription: Story = {
};

/**
* Execute variant with long output (truncated)
* Execute variant with long, collapsible output
*/
export const ExecuteLongOutput: Story = {
args: {
Expand Down
153 changes: 153 additions & 0 deletions packages/webui/src/components/toolcalls/ShellToolCall.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/**
* @license
* Copyright 2025 Qwen Team
* SPDX-License-Identifier: Apache-2.0
*/

// @vitest-environment jsdom

import { readFileSync } from 'node:fs';
import { resolve } from 'node:path';
import { act } from 'react';
import { createRoot, type Root } from 'react-dom/client';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { PlatformProvider } from '../../context/PlatformContext.js';
import { ShellToolCall } from './ShellToolCall.js';

const shellToolCallStyles = readFileSync(
resolve(process.cwd(), 'src/components/toolcalls/ShellToolCall.css'),
'utf8',
);

describe('ShellToolCall collapsible output', () => {
let container: HTMLDivElement | null = null;
let root: Root | null = null;

beforeEach(() => {
(
globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT?: boolean }
).IS_REACT_ACT_ENVIRONMENT = true;
});

afterEach(() => {
if (root) {
act(() => root?.unmount());
root = null;
}
if (container) {
container.remove();
container = null;
}
});

const renderToolCall = (
kind: 'bash' | 'execute',
output: string,
openTempFile = vi.fn(),
) => {
container = document.createElement('div');
document.body.appendChild(container);
root = createRoot(container);

act(() => {
root?.render(
<PlatformProvider
value={{
platform: 'web',
postMessage: vi.fn(),
onMessage: () => () => {},
openTempFile,
}}
>
<ShellToolCall
toolCall={{
toolCallId: `${kind}-1`,
kind,
title: 'Run command',
status: 'completed',
rawInput: { command: 'run-command' },
content: [
{
type: 'content',
content: { type: 'text', text: output },
},
],
}}
/>
</PlatformProvider>,
);
});

return openTempFile;
};

it.each(['bash', 'execute'] as const)(
'preserves and expands the full %s output without opening a temp file',
(kind) => {
const tailMarker = '__OUTPUT_TAIL__';
const output = `${'x'.repeat(501)}${tailMarker}`;
const openTempFile = renderToolCall(kind, output);

expect(container?.textContent).toContain(tailMarker);

const toggle = container?.querySelector(
'button[aria-label="Expand output"]',
) as HTMLButtonElement;
expect(toggle).not.toBeNull();
expect(toggle.getAttribute('aria-expanded')).toBe('false');
const collapsibleContent = container?.querySelector(
'.toolcall-collapsible-output-content',
) as HTMLDivElement;
expect(collapsibleContent.style.maxHeight).toBe('60px');
expect(collapsibleContent.style.maskImage).toContain('40px');
expect(collapsibleContent.style.maskImage).toContain('60px');
const outputContainer = container?.querySelector(
`.${kind}-toolcall-output-subtle`,
) as HTMLDivElement;
const outputPre = outputContainer.querySelector('pre') as HTMLPreElement;
expect(outputPre).not.toBeNull();
expect(shellToolCallStyles).toContain(
`.${kind}-toolcall-output-subtle .${kind}-toolcall-pre {\n overflow: visible;\n}`,
);

act(() => {
toggle.dispatchEvent(new MouseEvent('click', { bubbles: true }));
});

expect(toggle.getAttribute('aria-expanded')).toBe('true');
expect(toggle.textContent).toContain('Collapse');
expect(collapsibleContent.style.maxHeight).toBe('');
expect(openTempFile).not.toHaveBeenCalled();

act(() => {
toggle.dispatchEvent(new MouseEvent('click', { bubbles: true }));
});

expect(toggle.getAttribute('aria-expanded')).toBe('false');
expect(collapsibleContent.style.maxHeight).toBe('60px');
expect(openTempFile).not.toHaveBeenCalled();

const outRow = Array.from(
container?.querySelectorAll(`.${kind}-toolcall-row`) ?? [],
).find((row) => row.textContent?.includes('OUT'));
expect(outRow).toBeDefined();

act(() => {
outRow?.dispatchEvent(new MouseEvent('click', { bubbles: true }));
});

expect(openTempFile).toHaveBeenCalledWith(
output,
`${kind}-output-${kind}-1`,
);
},
);

it('does not add a toggle at the 500-character boundary', () => {
renderToolCall('bash', 'x'.repeat(500));

expect(
container?.querySelector('button[aria-label="Expand output"]'),
).toBeNull();
});
});
34 changes: 26 additions & 8 deletions packages/webui/src/components/toolcalls/ShellToolCall.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import type { FC } from 'react';
import {
CollapsibleOutput,
ToolCallContainer,
CopyButton,
safeTitle,
Expand Down Expand Up @@ -211,8 +212,7 @@ const ShellToolCallImpl: FC<BaseToolCallProps & { variant: ShellVariant }> = ({
// Success with output
if (textOutputs.length > 0) {
const output = textOutputs.join('\n');
const truncatedOutput =
output.length > 500 ? output.substring(0, 500) + '...' : output;
const isCollapsible = output.length > 500;

return (
<Container
Expand Down Expand Up @@ -250,12 +250,30 @@ const ShellToolCallImpl: FC<BaseToolCallProps & { variant: ShellVariant }> = ({
style={{ cursor: 'pointer' }}
>
<div className={`${classPrefix}-toolcall-label`}>OUT</div>
<div className={`${classPrefix}-toolcall-row-content`}>
<div className={`${classPrefix}-toolcall-output-subtle`}>
<pre className={`${classPrefix}-toolcall-pre`}>
{truncatedOutput}
</pre>
</div>
<div
className={`${classPrefix}-toolcall-row-content ${
isCollapsible ? `${classPrefix}-toolcall-full` : ''
}`}
>
{isCollapsible ? (
<CollapsibleOutput
isCollapsible
collapsedHeight={60}
fadeStart={40}
>
<div className={`${classPrefix}-toolcall-output-subtle`}>
<pre className={`${classPrefix}-toolcall-pre`}>
{output}
</pre>
</div>
</CollapsibleOutput>
) : (
<div className={`${classPrefix}-toolcall-output-subtle`}>
<pre className={`${classPrefix}-toolcall-pre`}>
{output}
</pre>
</div>
)}
</div>
</div>
</div>
Expand Down
Loading
Loading