fix(cli): enable typechecking for ui/commands tests (#11413)

This commit is contained in:
Sandy Tao
2025-10-17 14:20:49 -07:00
committed by GitHub
parent 08e87a59d5
commit 21163a1636
7 changed files with 29 additions and 42 deletions

View File

@@ -9,7 +9,7 @@ import { describe, it, expect } from 'vitest';
import { toolsCommand } from './toolsCommand.js';
import { createMockCommandContext } from '../../test-utils/mockCommandContext.js';
import { MessageType } from '../types.js';
import type { Tool } from '@google/gemini-cli-core';
import type { ToolBuilder, ToolResult } from '@google/gemini-cli-core';
// Mock tools for testing
const mockTools = [
@@ -25,7 +25,7 @@ const mockTools = [
description: 'Edits code files.',
schema: {},
},
] as Tool[];
] as unknown as Array<ToolBuilder<object, ToolResult>>;
describe('toolsCommand', () => {
it('should display an error if the tool registry is unavailable', async () => {
@@ -53,7 +53,9 @@ describe('toolsCommand', () => {
const mockContext = createMockCommandContext({
services: {
config: {
getToolRegistry: () => ({ getAllTools: () => [] as Tool[] }),
getToolRegistry: () => ({
getAllTools: () => [] as Array<ToolBuilder<object, ToolResult>>,
}),
},
},
});
@@ -83,7 +85,8 @@ describe('toolsCommand', () => {
if (!toolsCommand.action) throw new Error('Action not defined');
await toolsCommand.action(mockContext, '');
const [message] = (mockContext.ui.addItem as vi.Mock).mock.calls[0];
const [message] = (mockContext.ui.addItem as ReturnType<typeof vi.fn>).mock
.calls[0];
expect(message.type).toBe(MessageType.TOOLS_LIST);
expect(message.showDescriptions).toBe(false);
expect(message.tools).toHaveLength(2);
@@ -103,7 +106,8 @@ describe('toolsCommand', () => {
if (!toolsCommand.action) throw new Error('Action not defined');
await toolsCommand.action(mockContext, 'desc');
const [message] = (mockContext.ui.addItem as vi.Mock).mock.calls[0];
const [message] = (mockContext.ui.addItem as ReturnType<typeof vi.fn>).mock
.calls[0];
expect(message.type).toBe(MessageType.TOOLS_LIST);
expect(message.showDescriptions).toBe(true);
expect(message.tools).toHaveLength(2);