File size: 3,610 Bytes
52efc7b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | /**
* @license
* Copyright 2026 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import { waitFor } from '../../../test-utils/async.js';
import { renderWithProviders } from '../../../test-utils/render.js';
import { SubagentGroupDisplay } from './SubagentGroupDisplay.js';
import {
Kind,
CoreToolCallStatus,
SubagentState,
} from '@google/gemini-cli-core';
import type { IndividualToolCallDisplay } from '../../types.js';
import { describe, it, expect, vi } from 'vitest';
import { Text } from 'ink';
vi.mock('../../utils/MarkdownDisplay.js', () => ({
MarkdownDisplay: ({ text }: { text: string }) => <Text>{text}</Text>,
}));
describe('<SubagentGroupDisplay />', () => {
const mockToolCalls: IndividualToolCallDisplay[] = [
{
callId: 'call-1',
name: 'agent_1',
description: 'Test agent 1',
confirmationDetails: undefined,
status: CoreToolCallStatus.Executing,
kind: Kind.Agent,
resultDisplay: {
isSubagentProgress: true,
agentName: 'api-monitor',
state: SubagentState.RUNNING,
recentActivity: [
{
id: 'act-1',
type: 'tool_call',
status: SubagentState.RUNNING,
content: '',
displayName: 'Action Required',
description: 'Verify server is running',
},
],
},
},
{
callId: 'call-2',
name: 'agent_2',
description: 'Test agent 2',
confirmationDetails: undefined,
status: CoreToolCallStatus.Success,
kind: Kind.Agent,
resultDisplay: {
isSubagentProgress: true,
agentName: 'db-manager',
state: SubagentState.COMPLETED,
result: 'Database schema validated',
recentActivity: [
{
id: 'act-2',
type: 'thought',
status: SubagentState.COMPLETED,
content: 'Database schema validated',
},
],
},
},
];
const renderSubagentGroup = async (
toolCallsToRender: IndividualToolCallDisplay[],
height?: number,
) =>
renderWithProviders(
<SubagentGroupDisplay
toolCalls={toolCallsToRender}
terminalWidth={80}
availableTerminalHeight={height}
isExpandable={true}
/>,
);
it('renders nothing if there are no agent tool calls', async () => {
const { lastFrame } = await renderSubagentGroup([], 40);
expect(lastFrame({ allowEmpty: true })).toBe('');
});
it('renders collapsed view by default with correct agent counts and states', async () => {
const { lastFrame } = await renderSubagentGroup(mockToolCalls, 40);
expect(lastFrame()).toMatchSnapshot();
});
it('expands when availableTerminalHeight is undefined', async () => {
const { lastFrame, rerender } = await renderSubagentGroup(
mockToolCalls,
40,
);
// Default collapsed view
await waitFor(() => {
expect(lastFrame()).toContain('(ctrl+o to expand)');
});
// Expand view
rerender(
<SubagentGroupDisplay
toolCalls={mockToolCalls}
terminalWidth={80}
availableTerminalHeight={undefined}
isExpandable={true}
/>,
);
await waitFor(() => {
expect(lastFrame()).toContain('(ctrl+o to collapse)');
});
// Collapse view
rerender(
<SubagentGroupDisplay
toolCalls={mockToolCalls}
terminalWidth={80}
availableTerminalHeight={40}
isExpandable={true}
/>,
);
await waitFor(() => {
expect(lastFrame()).toContain('(ctrl+o to expand)');
});
});
});
|