File size: 2,704 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
/**
 * @license
 * Copyright 2026 Google LLC
 * SPDX-License-Identifier: Apache-2.0
 */

import { describe, it, expect } from 'vitest';
import { renderWithProviders } from '../../../test-utils/render.js';
import { SubagentHistoryMessage } from './SubagentHistoryMessage.js';
import type { HistoryItemSubagent } from '../../types.js';
import { SubagentState } from '@google/gemini-cli-core';

describe('SubagentHistoryMessage', () => {
  const mockItem: HistoryItemSubagent = {
    type: 'subagent',
    agentName: 'research',
    history: [
      {
        id: '1',
        type: 'thought',
        content: 'Thinking about the problem',
        status: SubagentState.COMPLETED,
      },
      {
        id: '2',
        type: 'tool_call',
        content: 'Calling search_web',
        status: SubagentState.RUNNING,
      },
      {
        id: '3',
        type: 'tool_call',
        content: 'Calling read_file fail',
        status: SubagentState.ERROR,
      },
    ],
  };

  it('renders header with agent name and item count', async () => {
    const renderResult = await renderWithProviders(
      <SubagentHistoryMessage item={mockItem} terminalWidth={80} />,
    );
    await renderResult.waitUntilReady();

    const output = renderResult.lastFrame();
    expect(output).toContain('research Trace (3 items)');
    expect(output).toMatchSnapshot();
    await expect(renderResult).toMatchSvgSnapshot();
    renderResult.unmount();
  });

  it('renders thought activities with brain icon', async () => {
    const renderResult = await renderWithProviders(
      <SubagentHistoryMessage item={mockItem} terminalWidth={80} />,
    );
    await renderResult.waitUntilReady();

    const output = renderResult.lastFrame();
    expect(output).toContain('🧠 Thinking about the problem');
    renderResult.unmount();
  });

  it('renders tool call activities with tool icon', async () => {
    const renderResult = await renderWithProviders(
      <SubagentHistoryMessage item={mockItem} terminalWidth={80} />,
    );
    await renderResult.waitUntilReady();

    const output = renderResult.lastFrame();
    expect(output).toContain('🛠️ Calling search_web');
    renderResult.unmount();
  });

  it('renders status indicators correctly', async () => {
    const renderResult = await renderWithProviders(
      <SubagentHistoryMessage item={mockItem} terminalWidth={80} />,
    );
    await renderResult.waitUntilReady();

    const output = renderResult.lastFrame();
    expect(output).toContain('Calling search_web (Running...)');
    expect(output).toContain('Thinking about the problem ✅');
    expect(output).toContain('Calling read_file fail ❌');
    renderResult.unmount();
  });
});