-
Notifications
You must be signed in to change notification settings - Fork 3k
feat(web-shell): show sub-agents as a chronological transcript with a parallel-agent timeline #6772
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
185 changes: 185 additions & 0 deletions
185
packages/web-shell/client/components/messages/tools/ParallelAgentsGroup.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,185 @@ | ||
| // @vitest-environment jsdom | ||
| import { afterEach, describe, expect, it, vi } from 'vitest'; | ||
| import { act } from 'react'; | ||
| import { createRoot, type Root } from 'react-dom/client'; | ||
| import { I18nProvider } from '../../../i18n'; | ||
| import type { ACPToolCall } from '../../../adapters/types'; | ||
|
|
||
| // ParallelAgentsGroup renders SubAgentPanel, which pulls in ToolGroup; | ||
| // ToolGroup imports App only for CompactModeContext — loading the real | ||
| // App module would drag the whole application graph into this unit test. | ||
| vi.mock('../../../App', async () => { | ||
| const { createContext } = await import('react'); | ||
| return { CompactModeContext: createContext(false) }; | ||
| }); | ||
|
|
||
| const { computeAgentsTimeline, ParallelAgentsGroup } = await import( | ||
| './ParallelAgentsGroup' | ||
| ); | ||
|
|
||
| ( | ||
| globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean } | ||
| ).IS_REACT_ACT_ENVIRONMENT = true; | ||
|
|
||
| function agent(partial: Partial<ACPToolCall>): ACPToolCall { | ||
| return { | ||
| callId: 'a1', | ||
| toolName: 'Task', | ||
| status: 'completed', | ||
| ...partial, | ||
| } as ACPToolCall; | ||
| } | ||
|
|
||
| const mounted: Array<{ root: Root; container: HTMLElement }> = []; | ||
|
|
||
| afterEach(() => { | ||
| for (const { root, container } of mounted.splice(0)) { | ||
| act(() => root.unmount()); | ||
| container.remove(); | ||
| } | ||
| }); | ||
|
|
||
| // Render the group and expand it (it starts collapsed) so the per-agent | ||
| // timeline is in the DOM. | ||
| function renderExpandedGroup(agents: ACPToolCall[]): HTMLElement { | ||
| const container = document.createElement('div'); | ||
| document.body.appendChild(container); | ||
| const root = createRoot(container); | ||
| act(() => { | ||
| root.render( | ||
| <I18nProvider language="en"> | ||
| <ParallelAgentsGroup agents={agents} /> | ||
| </I18nProvider>, | ||
| ); | ||
| }); | ||
| mounted.push({ root, container }); | ||
| const summary = container.querySelector('[aria-expanded]') as HTMLElement; | ||
| act(() => summary.click()); | ||
| return container; | ||
| } | ||
|
|
||
| describe('computeAgentsTimeline', () => { | ||
| it('returns null for a single agent or missing start times', () => { | ||
| expect( | ||
| computeAgentsTimeline([agent({ startTime: 0, endTime: 5_000 })], 10_000), | ||
| ).toBeNull(); | ||
| expect( | ||
| computeAgentsTimeline( | ||
| [ | ||
| agent({ callId: 'a1', startTime: 0, endTime: 5_000 }), | ||
| agent({ callId: 'a2' }), | ||
| ], | ||
| 10_000, | ||
| ), | ||
| ).toBeNull(); | ||
| }); | ||
|
|
||
| it('returns null for a sub-second span (nothing to compare)', () => { | ||
| expect( | ||
| computeAgentsTimeline( | ||
| [ | ||
| agent({ callId: 'a1', startTime: 0, endTime: 400 }), | ||
| agent({ callId: 'a2', startTime: 100, endTime: 600 }), | ||
| ], | ||
| 1_000, | ||
| ), | ||
| ).toBeNull(); | ||
| }); | ||
|
|
||
| it('lays out bars against the combined span, running bars ending at now', () => { | ||
| const timeline = computeAgentsTimeline( | ||
| [ | ||
| agent({ callId: 'a1', startTime: 0, endTime: 24_000 }), | ||
| agent({ callId: 'a2', startTime: 3_000, status: 'in_progress' }), | ||
| ], | ||
| 15_000, | ||
| )!; | ||
| expect(timeline).not.toBeNull(); | ||
|
|
||
| const done = timeline.rows.get('a1')!; | ||
| expect(done.leftPct).toBe(0); | ||
| expect(done.widthPct).toBe(100); | ||
| expect(done.running).toBe(false); | ||
|
|
||
| const running = timeline.rows.get('a2')!; | ||
| expect(running.leftPct).toBeCloseTo(12.5); | ||
| expect(running.widthPct).toBeCloseTo(50); | ||
| expect(running.running).toBe(true); | ||
| }); | ||
|
|
||
| it('keeps a visible sliver for near-instant agents, clamped to the edge', () => { | ||
| const timeline = computeAgentsTimeline( | ||
| [ | ||
| agent({ callId: 'a1', startTime: 0, endTime: 10_000 }), | ||
| agent({ callId: 'a2', startTime: 10_000, endTime: 10_000 }), | ||
| ], | ||
| 10_000, | ||
| )!; | ||
| const sliver = timeline.rows.get('a2')!; | ||
| expect(sliver.widthPct).toBe(2); | ||
| expect(sliver.leftPct + sliver.widthPct).toBeLessThanOrEqual(100); | ||
| }); | ||
|
|
||
| it('picks nice ruler ticks that stop short of the right edge', () => { | ||
| const timeline = computeAgentsTimeline( | ||
| [ | ||
| agent({ callId: 'a1', startTime: 0, endTime: 24_000 }), | ||
| agent({ callId: 'a2', startTime: 3_000, endTime: 20_000 }), | ||
| ], | ||
| 24_000, | ||
| )!; | ||
| expect(timeline.ticks.map((tick) => tick.label)).toEqual([ | ||
| '0s', | ||
| '10s', | ||
| '20s', | ||
| ]); | ||
| expect(timeline.ticks[2].leftPct).toBeCloseTo((20_000 / 24_000) * 100); | ||
| }); | ||
|
|
||
| it('emits a single tick for a span barely over 1s, so the ruler is dropped', () => { | ||
| // Only 0s fits before the 92% cutoff; the component gates the ruler on | ||
| // ticks.length >= 2, so this span renders bars without a ruler. | ||
| const timeline = computeAgentsTimeline( | ||
| [ | ||
| agent({ callId: 'a1', startTime: 0, endTime: 1_050 }), | ||
| agent({ callId: 'a2', startTime: 0, endTime: 1_050 }), | ||
| ], | ||
| 1_050, | ||
| )!; | ||
| expect(timeline).not.toBeNull(); | ||
| expect(timeline.ticks.length).toBe(1); | ||
| }); | ||
| }); | ||
|
|
||
| describe('ParallelAgentsGroup timeline rendering', () => { | ||
| it('renders one bar per agent and a ruler when the span is comparable', () => { | ||
| const container = renderExpandedGroup([ | ||
| agent({ callId: 'a1', startTime: 0, endTime: 24_000 }), | ||
| agent({ callId: 'a2', startTime: 3_000, endTime: 20_000 }), | ||
| ]); | ||
| // The computed geometry actually reaches the DOM: a bar per agent... | ||
| expect(container.querySelectorAll('[class*="bar"]').length).toBe(2); | ||
| // ...and the ruler with its nice ticks. | ||
| expect(container.querySelector('[class*="ruler"]')).not.toBeNull(); | ||
| expect(container.textContent).toContain('0s'); | ||
| expect(container.textContent).toContain('10s'); | ||
| }); | ||
|
|
||
| it('renders the bars but no ruler when the span yields a single tick', () => { | ||
| const container = renderExpandedGroup([ | ||
| agent({ callId: 'a1', startTime: 0, endTime: 1_050 }), | ||
| agent({ callId: 'a2', startTime: 0, endTime: 1_050 }), | ||
| ]); | ||
| expect(container.querySelectorAll('[class*="bar"]').length).toBe(2); | ||
| expect(container.querySelector('[class*="ruler"]')).toBeNull(); | ||
| }); | ||
|
|
||
| it('renders no timeline at all when bars would not be comparable', () => { | ||
| // A single agent → computeAgentsTimeline returns null → plain list. | ||
| const container = renderExpandedGroup([ | ||
| agent({ callId: 'a1', startTime: 0, endTime: 24_000 }), | ||
| ]); | ||
| expect(container.querySelector('[class*="track"]')).toBeNull(); | ||
| expect(container.querySelector('[class*="ruler"]')).toBeNull(); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Suggestion] Several specific code paths introduced in this PR lack test coverage:
barRunningCSS class is never exercised in a DOM rendering test — all timeline render tests use only completed agentsdata-statusattribute on step elements is never asserted, even though the CSS rail coloring depends entirely on itendTimeundefined (the?? starts[i]fallback incomputeAgentsTimeline) is not testedfailedagent with both result and tools to exercise theshowSectionCapspathtaskToolCallsrendering path (fromrawOutput.toolCalls) through the step wrapper is never tested — all SubAgentPanel tests usesubToolsEach is a narrow gap, but together they leave the new chronological layout's status-dependent styling and edge cases unverified.
— qwen3.7-max via Qwen Code /review