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

import { describe, it, expect } from 'vitest';
import { CliHelpAgent } from './cli-help-agent.js';
import { GET_INTERNAL_DOCS_TOOL_NAME } from '../tools/tool-names.js';
import { GEMINI_MODEL_ALIAS_FLASH } from '../config/models.js';
import type { LocalAgentDefinition } from './types.js';
import type { Config } from '../config/config.js';

describe('CliHelpAgent', () => {
  const fakeConfig = {
    getMessageBus: () => ({}),
    isAgentsEnabled: () => false,
  } as unknown as Config;
  const localAgent = CliHelpAgent(fakeConfig) as LocalAgentDefinition;

  it('should have the correct agent definition metadata', () => {
    expect(localAgent.name).toBe('cli_help');
    expect(localAgent.kind).toBe('local');
    expect(localAgent.displayName).toBe('CLI Help Agent');
    expect(localAgent.description).toContain('Gemini CLI');
  });

  it('should have correctly configured inputs and outputs', () => {
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    const inputSchema = localAgent.inputConfig.inputSchema as any;
    expect(inputSchema.properties['question']).toBeDefined();
    expect(inputSchema.required).toContain('question');

    expect(localAgent.outputConfig?.outputName).toBe('report');
    expect(localAgent.outputConfig?.description).toBeDefined();
  });

  it('should use the correct model and tools', () => {
    expect(localAgent.modelConfig?.model).toBe(GEMINI_MODEL_ALIAS_FLASH);

    const tools = localAgent.toolConfig?.tools || [];
    const hasInternalDocsTool = tools.some(
      (t) => typeof t !== 'string' && t.name === GET_INTERNAL_DOCS_TOOL_NAME,
    );
    expect(hasInternalDocsTool).toBe(true);
  });

  it('should have expected prompt placeholders', () => {
    const systemPrompt = localAgent.promptConfig.systemPrompt || '';
    expect(systemPrompt).toContain('${cliVersion}');
    expect(systemPrompt).toContain('${activeModel}');
    expect(systemPrompt).toContain('${today}');

    const query = localAgent.promptConfig.query || '';
    expect(query).toContain('${question}');
  });

  it('should process output to a formatted markdown string', () => {
    const mockOutput = {
      answer: '  This is the answer.  ',
      sources: ['file1.md', 'file2.md', 'file1.md', '   ', ''],
    };
    const processed = localAgent.processOutput?.(mockOutput);
    expect(processed).toBe(
      'This is the answer.\n\n**Sources:**\n- file1.md\n- file2.md',
    );
  });
});