Repository navigation
fix(cli): bound SubAgent display by visual height to prevent flicker #3721
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 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5201f55
fix(cli): bound SubAgent display by visual height to prevent flicker
6eabab1
test(tui): add SubAgent flicker regression script and ANSI counter
b91d5cd
fix(cli): address inline review on SubAgent flicker fix
f1ef2da
fix(cli): address round-2 inline review on SubAgent flicker
ad72112
fix(cli): gate SubAgent useKeypress on isFocused for parallel runs
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
640 changes: 640 additions & 0 deletions
640
integration-tests/terminal-capture/subagent-flicker-regression.ts
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
159 changes: 159 additions & 0 deletions
159
packages/cli/src/ui/components/subagents/runtime/AgentExecutionDisplay.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,159 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2025 Qwen | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import { act } from 'react'; | ||
| import { render } from 'ink-testing-library'; | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest'; | ||
| import type { AgentResultDisplay } from '@qwen-code/qwen-code-core'; | ||
| import { makeFakeConfig } from '@qwen-code/qwen-code-core'; | ||
| import { AgentExecutionDisplay } from './AgentExecutionDisplay.js'; | ||
|
|
||
| let keypressHandler: | ||
| | ((key: { ctrl?: boolean; name?: string }) => void) | ||
| | undefined; | ||
|
|
||
| vi.mock('../../../hooks/useKeypress.js', () => ({ | ||
| // The mock honours { isActive } so historical/completed displays don't | ||
| // capture the keypress handler — same scoping the production hook does. | ||
| useKeypress: vi.fn( | ||
| ( | ||
| handler: (key: { ctrl?: boolean; name?: string }) => void, | ||
| options?: { isActive?: boolean }, | ||
| ) => { | ||
| keypressHandler = options?.isActive === false ? undefined : handler; | ||
| }, | ||
| ), | ||
| })); | ||
|
|
||
| function makeRunningData(toolCount: number): AgentResultDisplay { | ||
| return { | ||
| type: 'task_execution', | ||
| subagentName: 'reviewer', | ||
| subagentColor: 'blue', | ||
| status: 'running', | ||
| taskDescription: 'Review large output stability', | ||
| taskPrompt: `${'very-long-task-prompt '.repeat(20)}\nsecond\nthird`, | ||
| toolCalls: Array.from({ length: toolCount }, (_, index) => ({ | ||
| callId: `call-${index}`, | ||
| name: `tool-${index}`, | ||
| status: 'success', | ||
| description: `description-${index} ${'wide '.repeat(20)}`, | ||
| resultDisplay: `result-${index} ${'payload '.repeat(20)}`, | ||
| })), | ||
| }; | ||
| } | ||
|
|
||
| function makeCompletedData(toolCount: number): AgentResultDisplay { | ||
| return { | ||
| ...makeRunningData(toolCount), | ||
| status: 'completed', | ||
| executionSummary: { | ||
| rounds: 3, | ||
| totalDurationMs: 12_345, | ||
| totalToolCalls: toolCount, | ||
| successfulToolCalls: toolCount, | ||
| failedToolCalls: 0, | ||
| successRate: 100, | ||
| inputTokens: 100, | ||
| outputTokens: 200, | ||
| thoughtTokens: 0, | ||
| cachedTokens: 0, | ||
| totalTokens: 4_321, | ||
| toolUsage: [], | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| function visualRowCount(frame: string): number { | ||
| if (!frame) return 0; | ||
| return frame.split('\n').length; | ||
| } | ||
|
|
||
| describe('<AgentExecutionDisplay />', () => { | ||
| beforeEach(() => { | ||
| keypressHandler = undefined; | ||
| }); | ||
|
|
||
| it('bounds expanded detail by the assigned visual height', () => { | ||
| const { lastFrame } = render( | ||
| <AgentExecutionDisplay | ||
| data={makeRunningData(8)} | ||
| availableHeight={8} | ||
| childWidth={40} | ||
| config={makeFakeConfig()} | ||
| />, | ||
| ); | ||
|
|
||
| act(() => { | ||
| keypressHandler?.({ ctrl: true, name: 'e' }); | ||
| }); | ||
|
|
||
| const frame = lastFrame() ?? ''; | ||
| expect(frame).toContain('Showing the first 1 visual lines'); | ||
| expect(frame).toContain('Showing the last 1 of 8 tools'); | ||
| expect(frame).toContain('tool-7'); | ||
| expect(frame).not.toContain('tool-0'); | ||
| }); | ||
|
|
||
| it('keeps the rendered running frame within availableHeight', () => { | ||
| const availableHeight = 26; | ||
| const { lastFrame } = render( | ||
| <AgentExecutionDisplay | ||
| data={makeRunningData(8)} | ||
| availableHeight={availableHeight} | ||
| childWidth={80} | ||
| config={makeFakeConfig()} | ||
| />, | ||
| ); | ||
|
|
||
| act(() => { | ||
| keypressHandler?.({ ctrl: true, name: 'e' }); | ||
| }); | ||
|
|
||
| expect(visualRowCount(lastFrame() ?? '')).toBeLessThanOrEqual( | ||
| availableHeight, | ||
| ); | ||
| }); | ||
|
|
||
| it('keeps the rendered completed frame within availableHeight', () => { | ||
| const availableHeight = 30; | ||
| const { lastFrame } = render( | ||
| <AgentExecutionDisplay | ||
| data={makeCompletedData(8)} | ||
| availableHeight={availableHeight} | ||
| childWidth={80} | ||
| config={makeFakeConfig()} | ||
| />, | ||
| ); | ||
|
|
||
| act(() => { | ||
| keypressHandler?.({ ctrl: true, name: 'e' }); | ||
| }); | ||
|
|
||
| expect(visualRowCount(lastFrame() ?? '')).toBeLessThanOrEqual( | ||
| availableHeight, | ||
| ); | ||
| }); | ||
|
|
||
| it('does not respond to ctrl+e once the subagent has completed', () => { | ||
| const { lastFrame } = render( | ||
| <AgentExecutionDisplay | ||
| data={makeCompletedData(2)} | ||
| availableHeight={20} | ||
| childWidth={80} | ||
| config={makeFakeConfig()} | ||
| />, | ||
| ); | ||
|
|
||
| const before = lastFrame() ?? ''; | ||
| act(() => { | ||
| keypressHandler?.({ ctrl: true, name: 'e' }); | ||
| }); | ||
| const after = lastFrame() ?? ''; | ||
|
|
||
| expect(after).toBe(before); | ||
| }); | ||
| }); | ||
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.
Uh oh!
There was an error while loading. Please reload this page.