2026-03-17 23:11:20 -04:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2026 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
import { waitFor } from '../../../test-utils/async.js';
|
2026-03-18 16:38:56 +00:00
|
|
|
import { renderWithProviders } from '../../../test-utils/render.js';
|
2026-03-17 23:11:20 -04:00
|
|
|
import { SubagentGroupDisplay } from './SubagentGroupDisplay.js';
|
|
|
|
|
import { Kind, CoreToolCallStatus } from '@google/gemini-cli-core';
|
|
|
|
|
import type { IndividualToolCallDisplay } from '../../types.js';
|
2026-03-31 17:54:22 -04:00
|
|
|
import { describe, it, expect, vi } from 'vitest';
|
2026-03-17 23:11:20 -04:00
|
|
|
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: 'running',
|
|
|
|
|
recentActivity: [
|
|
|
|
|
{
|
|
|
|
|
id: 'act-1',
|
|
|
|
|
type: 'tool_call',
|
|
|
|
|
status: '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: 'completed',
|
|
|
|
|
result: 'Database schema validated',
|
|
|
|
|
recentActivity: [
|
|
|
|
|
{
|
|
|
|
|
id: 'act-2',
|
|
|
|
|
type: 'thought',
|
|
|
|
|
status: 'completed',
|
|
|
|
|
content: 'Database schema validated',
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
2026-03-19 17:05:33 +00:00
|
|
|
const renderSubagentGroup = async (
|
2026-03-17 23:11:20 -04:00
|
|
|
toolCallsToRender: IndividualToolCallDisplay[],
|
|
|
|
|
height?: number,
|
2026-03-18 16:38:56 +00:00
|
|
|
) =>
|
|
|
|
|
renderWithProviders(
|
|
|
|
|
<SubagentGroupDisplay
|
|
|
|
|
toolCalls={toolCallsToRender}
|
|
|
|
|
terminalWidth={80}
|
|
|
|
|
availableTerminalHeight={height}
|
|
|
|
|
isExpandable={true}
|
|
|
|
|
/>,
|
|
|
|
|
);
|
2026-03-17 23:11:20 -04:00
|
|
|
|
|
|
|
|
it('renders nothing if there are no agent tool calls', async () => {
|
2026-03-19 17:05:33 +00:00
|
|
|
const { lastFrame } = await renderSubagentGroup([], 40);
|
2026-03-17 23:11:20 -04:00
|
|
|
expect(lastFrame({ allowEmpty: true })).toBe('');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('renders collapsed view by default with correct agent counts and states', async () => {
|
2026-03-20 20:08:29 +00:00
|
|
|
const { lastFrame } = await renderSubagentGroup(mockToolCalls, 40);
|
2026-03-17 23:11:20 -04:00
|
|
|
expect(lastFrame()).toMatchSnapshot();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('expands when availableTerminalHeight is undefined', async () => {
|
2026-03-19 17:05:33 +00:00
|
|
|
const { lastFrame, rerender } = await renderSubagentGroup(
|
|
|
|
|
mockToolCalls,
|
|
|
|
|
40,
|
|
|
|
|
);
|
2026-03-17 23:11:20 -04:00
|
|
|
|
|
|
|
|
// Default collapsed view
|
|
|
|
|
await waitFor(() => {
|
|
|
|
|
expect(lastFrame()).toContain('(ctrl+o to expand)');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Expand view
|
2026-03-18 16:38:56 +00:00
|
|
|
rerender(
|
|
|
|
|
<SubagentGroupDisplay
|
|
|
|
|
toolCalls={mockToolCalls}
|
|
|
|
|
terminalWidth={80}
|
|
|
|
|
availableTerminalHeight={undefined}
|
|
|
|
|
isExpandable={true}
|
|
|
|
|
/>,
|
|
|
|
|
);
|
2026-03-17 23:11:20 -04:00
|
|
|
await waitFor(() => {
|
|
|
|
|
expect(lastFrame()).toContain('(ctrl+o to collapse)');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Collapse view
|
2026-03-18 16:38:56 +00:00
|
|
|
rerender(
|
|
|
|
|
<SubagentGroupDisplay
|
|
|
|
|
toolCalls={mockToolCalls}
|
|
|
|
|
terminalWidth={80}
|
|
|
|
|
availableTerminalHeight={40}
|
|
|
|
|
isExpandable={true}
|
|
|
|
|
/>,
|
|
|
|
|
);
|
2026-03-17 23:11:20 -04:00
|
|
|
await waitFor(() => {
|
|
|
|
|
expect(lastFrame()).toContain('(ctrl+o to expand)');
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|