File size: 2,163 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
70
71
72
73
/**
 * @license
 * Copyright 2025 Google LLC
 * SPDX-License-Identifier: Apache-2.0
 */

import { describe, it, expect } from 'vitest';
import { Type } from '@google/genai';
import { resolveToolDeclaration } from './resolver.js';
import type { ToolDefinition } from './types.js';

describe('resolveToolDeclaration', () => {
  const mockDefinition: ToolDefinition = {
    base: {
      name: 'test_tool',
      description: 'A test tool description',
      parameters: {
        type: Type.OBJECT,
        properties: {
          param1: { type: Type.STRING },
        },
      },
    },
  };

  it('should return the base definition when no modelId is provided', () => {
    const result = resolveToolDeclaration(mockDefinition);
    expect(result).toEqual(mockDefinition.base);
  });

  it('should return overridden description when modelId matches override criteria', () => {
    const definitionWithOverride: ToolDefinition = {
      ...mockDefinition,
      overrides: (modelId: string) => {
        if (modelId === 'special-model') {
          return { description: 'Overridden description' };
        }
        return undefined;
      },
    };

    const result = resolveToolDeclaration(
      definitionWithOverride,
      'special-model',
    );
    expect(result.description).toBe('Overridden description');
    expect(result.name).toBe(mockDefinition.base.name);
  });

  it('should return base definition when modelId does not match override criteria', () => {
    const definitionWithOverride: ToolDefinition = {
      ...mockDefinition,
      overrides: (modelId: string) => {
        if (modelId === 'special-model') {
          return { description: 'Overridden description' };
        }
        return undefined;
      },
    };

    const result = resolveToolDeclaration(
      definitionWithOverride,
      'regular-model',
    );
    expect(result.description).toBe(mockDefinition.base.description);
  });

  it('should return the base definition when a modelId is provided but no overrides exist', () => {
    const result = resolveToolDeclaration(mockDefinition, 'gemini-1.5-pro');
    expect(result).toEqual(mockDefinition.base);
  });
});