File size: 9,097 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 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | /**
* @license
* Copyright 2026 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import { describe, it, expect, vi, afterEach } from 'vitest';
import { renderWithProviders } from '../../../test-utils/render.js';
import { createMockSettings } from '../../../test-utils/settings.js';
import { ToolGroupDisplay } from './ToolGroupDisplay.js';
import {
CoreToolCallStatus,
UPDATE_TOPIC_DISPLAY_NAME,
} from '@google/gemini-cli-core';
import type {
HistoryItemToolDisplayGroup,
ToolDisplayItem,
} from '../../types.js';
describe('<ToolGroupDisplay />', () => {
afterEach(() => {
vi.restoreAllMocks();
});
const createToolItem = (
overrides: Partial<ToolDisplayItem> = {},
): ToolDisplayItem => ({
status: CoreToolCallStatus.Success,
name: 'test-tool',
description: 'Test description',
...overrides,
});
const createHistoryItem = (
tools: ToolDisplayItem[],
overrides: Partial<HistoryItemToolDisplayGroup> = {},
): HistoryItemToolDisplayGroup => ({
type: 'tool_display_group',
tools,
borderColor: 'gray',
borderDimColor: true,
borderTop: true,
borderBottom: true,
...overrides,
});
const fullVerbositySettings = createMockSettings({
ui: { errorVerbosity: 'full', compactToolOutput: false },
});
const compactSettings = createMockSettings({
ui: { compactToolOutput: true },
});
describe('Golden Snapshots', () => {
it('renders notices at the top (hoisting)', async () => {
const tools = [
createToolItem({ name: 'Tool A', format: 'box' }),
createToolItem({
name: UPDATE_TOPIC_DISPLAY_NAME,
description: 'New Topic',
format: 'notice',
}),
];
const item = createHistoryItem(tools);
const { lastFrame } = await renderWithProviders(
<ToolGroupDisplay item={item} />,
{ settings: fullVerbositySettings },
);
const output = lastFrame();
// Notice should be before Tool A
expect(output.indexOf(UPDATE_TOPIC_DISPLAY_NAME)).toBeLessThan(
output.indexOf('Tool A'),
);
expect(output).toMatchSnapshot();
});
it('renders in compact mode (no box borders)', async () => {
const tools = [
createToolItem({ name: 'Tool A' }),
createToolItem({ name: 'Tool B' }),
];
const item = createHistoryItem(tools);
const { lastFrame } = await renderWithProviders(
<ToolGroupDisplay item={item} />,
{ settings: compactSettings },
);
const output = lastFrame();
// Should not contain box drawing characters for the outer box
expect(output).not.toContain('╭');
expect(output).not.toContain('╰');
expect(output).toMatchSnapshot();
});
it('renders in boxed mode (full verbosity)', async () => {
const tools = [createToolItem({ name: 'Tool A' })];
const item = createHistoryItem(tools);
const { lastFrame } = await renderWithProviders(
<ToolGroupDisplay item={item} />,
{ settings: fullVerbositySettings },
);
const output = lastFrame();
expect(output).toContain('╭');
expect(output).toContain('╰');
expect(output).toMatchSnapshot();
});
it('renders standalone notices without a box', async () => {
const tools = [
createToolItem({
name: 'Notice Only',
format: 'notice',
}),
];
const item = createHistoryItem(tools);
const { lastFrame } = await renderWithProviders(
<ToolGroupDisplay item={item} />,
{ settings: fullVerbositySettings },
);
const output = lastFrame();
expect(output).not.toContain('╭');
expect(output).toMatchSnapshot();
});
it('renders error message when display info is missing', async () => {
// Create an item that effectively has no display properties
const tools = [
{
status: CoreToolCallStatus.Executing,
originalRequestName: 'missing-tool',
} as ToolDisplayItem,
];
const item = createHistoryItem(tools);
const { lastFrame } = await renderWithProviders(
<ToolGroupDisplay item={item} />,
);
const output = lastFrame();
expect(output).toContain('Error: Tool display missing');
expect(output).toMatchSnapshot();
});
it('hides tools awaiting approval (confirming)', async () => {
const tools = [
createToolItem({
name: 'Confirming Tool',
status: CoreToolCallStatus.AwaitingApproval,
}),
];
const item = createHistoryItem(tools);
const { lastFrame } = await renderWithProviders(
<ToolGroupDisplay item={item} />,
);
// Should render nothing (null)
expect(lastFrame({ allowEmpty: true })).toBe('');
});
});
describe('Result Formatting', () => {
it('renders text results with summary below', async () => {
const tools = [
createToolItem({
result: { type: 'text', text: 'Detailed output' },
resultSummary: 'Short summary',
format: 'box',
}),
];
const item = createHistoryItem(tools);
const { lastFrame } = await renderWithProviders(
<ToolGroupDisplay item={item} />,
{ settings: fullVerbositySettings },
);
const output = lastFrame();
expect(output).toContain('Detailed output');
expect(output).toContain('Short summary');
// Summary should be below detailed output
expect(output.indexOf('Detailed output')).toBeLessThan(
output.indexOf('Short summary'),
);
expect(output).toMatchSnapshot();
});
it('renders compact tools with summary on same line', async () => {
const tools = [
createToolItem({
resultSummary: 'Success summary',
format: 'compact',
}),
];
const item = createHistoryItem(tools);
const { lastFrame } = await renderWithProviders(
<ToolGroupDisplay item={item} />,
);
const output = lastFrame();
expect(output).toContain('→ Success summary');
expect(output).toMatchSnapshot();
});
it('renders placeholder for diff results', async () => {
const tools = [
createToolItem({
result: {
type: 'diff',
beforeText: 'old',
afterText: 'new',
path: 'file.ts',
},
}),
];
const item = createHistoryItem(tools);
const { lastFrame } = await renderWithProviders(
<ToolGroupDisplay item={item} />,
{ settings: fullVerbositySettings },
);
const output = lastFrame();
expect(output).toContain('[Diff Display: 3 -> 3 chars]');
expect(output).toMatchSnapshot();
});
it('renders placeholder for terminal results', async () => {
const tools = [
createToolItem({
result: { type: 'terminal' },
}),
];
const item = createHistoryItem(tools);
const { lastFrame } = await renderWithProviders(
<ToolGroupDisplay item={item} />,
{ settings: fullVerbositySettings },
);
expect(lastFrame()).toContain('[Terminal Output]');
});
it('renders placeholder for agent results', async () => {
const tools = [
createToolItem({
result: { type: 'agent', threadId: 'thread-123' },
}),
];
const item = createHistoryItem(tools);
const { lastFrame } = await renderWithProviders(
<ToolGroupDisplay item={item} />,
{ settings: fullVerbositySettings },
);
expect(lastFrame()).toContain('[Subagent: thread-123]');
});
});
describe('Border & Margin Logic', () => {
it('forces top border on box when it follows a notice', async () => {
const tools = [
createToolItem({ name: 'Notice', format: 'notice' }),
createToolItem({ name: 'Tool in Box', format: 'box' }),
];
// Even if item.borderTop is false (continuing a group),
// the box should have a top border because it follows a notice.
const item = createHistoryItem(tools, { borderTop: false });
const { lastFrame } = await renderWithProviders(
<ToolGroupDisplay item={item} />,
{ settings: fullVerbositySettings },
);
const output = lastFrame();
expect(output).toContain('Notice');
expect(output).toContain('╭'); // Top border for the box
expect(output).toMatchSnapshot();
});
it('applies bottom margin in compact mode when group is at boundary', async () => {
const tools = [createToolItem({ name: 'Compact Tool' })];
const item = createHistoryItem(tools, { borderBottom: true });
const { lastFrame } = await renderWithProviders(
<ToolGroupDisplay item={item} />,
{ settings: compactSettings },
);
// This is hard to assert via string check, but ensure match snapshot
// captures the vertical spacing.
expect(lastFrame()).toMatchSnapshot();
});
});
});
|