Disallow redundant typecasts. (#15030)

This commit is contained in:
Christian Gunderman
2025-12-12 17:43:43 -08:00
committed by GitHub
parent fcc3b2b5ec
commit 942bcfc61e
86 changed files with 235 additions and 371 deletions
@@ -326,7 +326,7 @@ describe('chatCommand', () => {
const fakeFiles = ['checkpoint-alpha.json', 'checkpoint-beta.json'];
mockFs.readdir.mockImplementation(
(async (_: string): Promise<string[]> =>
fakeFiles as string[]) as unknown as typeof fsPromises.readdir,
fakeFiles) as unknown as typeof fsPromises.readdir,
);
mockFs.stat.mockImplementation(
@@ -346,7 +346,7 @@ describe('chatCommand', () => {
const date = new Date();
mockFs.readdir.mockImplementation(
(async (_: string): Promise<string[]> =>
fakeFiles as string[]) as unknown as typeof fsPromises.readdir,
fakeFiles) as unknown as typeof fsPromises.readdir,
);
mockFs.stat.mockImplementation((async (
path: string,
@@ -406,7 +406,7 @@ describe('chatCommand', () => {
const fakeFiles = ['checkpoint-alpha.json', 'checkpoint-beta.json'];
mockFs.readdir.mockImplementation(
(async (_: string): Promise<string[]> =>
fakeFiles as string[]) as unknown as typeof fsPromises.readdir,
fakeFiles) as unknown as typeof fsPromises.readdir,
);
mockFs.stat.mockImplementation(
@@ -110,7 +110,7 @@ describe('ideCommand', () => {
status: core.IDEConnectionStatus.Connected,
});
const command = await ideCommand();
const result = await command!.subCommands!.find(
const result = await command.subCommands!.find(
(c) => c.name === 'status',
)!.action!(mockContext, '');
expect(vi.mocked(mockIdeClient.getConnectionStatus)).toHaveBeenCalled();
@@ -126,7 +126,7 @@ describe('ideCommand', () => {
status: core.IDEConnectionStatus.Connecting,
});
const command = await ideCommand();
const result = await command!.subCommands!.find(
const result = await command.subCommands!.find(
(c) => c.name === 'status',
)!.action!(mockContext, '');
expect(vi.mocked(mockIdeClient.getConnectionStatus)).toHaveBeenCalled();
@@ -141,7 +141,7 @@ describe('ideCommand', () => {
status: core.IDEConnectionStatus.Disconnected,
});
const command = await ideCommand();
const result = await command!.subCommands!.find(
const result = await command.subCommands!.find(
(c) => c.name === 'status',
)!.action!(mockContext, '');
expect(vi.mocked(mockIdeClient.getConnectionStatus)).toHaveBeenCalled();
@@ -159,7 +159,7 @@ describe('ideCommand', () => {
details,
});
const command = await ideCommand();
const result = await command!.subCommands!.find(
const result = await command.subCommands!.find(
(c) => c.name === 'status',
)!.action!(mockContext, '');
expect(vi.mocked(mockIdeClient.getConnectionStatus)).toHaveBeenCalled();
@@ -200,7 +200,7 @@ describe('ideCommand', () => {
status: core.IDEConnectionStatus.Connected,
});
const actionPromise = command!.subCommands!.find(
const actionPromise = command.subCommands!.find(
(c) => c.name === 'install',
)!.action!(mockContext, '');
await vi.runAllTimersAsync();
@@ -239,7 +239,7 @@ describe('ideCommand', () => {
});
const command = await ideCommand();
await command!.subCommands!.find((c) => c.name === 'install')!.action!(
await command.subCommands!.find((c) => c.name === 'install')!.action!(
mockContext,
'',
);
+6 -15
View File
@@ -10,11 +10,7 @@ import type {
CommandContext,
} from './types.js';
import { CommandKind } from './types.js';
import type {
DiscoveredMCPPrompt,
DiscoveredMCPResource,
MessageActionReturn,
} from '@google/gemini-cli-core';
import type { MessageActionReturn } from '@google/gemini-cli-core';
import {
DiscoveredMCPTool,
getMCPDiscoveryState,
@@ -218,25 +214,20 @@ const listAction = async (
connectingServers.length > 0;
const allTools = toolRegistry.getAllTools();
const mcpTools = allTools.filter(
(tool) => tool instanceof DiscoveredMCPTool,
) as DiscoveredMCPTool[];
const mcpTools = allTools.filter((tool) => tool instanceof DiscoveredMCPTool);
const promptRegistry = await config.getPromptRegistry();
const mcpPrompts = promptRegistry
.getAllPrompts()
.filter(
(prompt) =>
'serverName' in prompt &&
serverNames.includes(prompt.serverName as string),
) as DiscoveredMCPPrompt[];
'serverName' in prompt && serverNames.includes(prompt.serverName),
);
const resourceRegistry = config.getResourceRegistry();
const mcpResources = resourceRegistry
.getAllResources()
.filter((entry) =>
serverNames.includes(entry.serverName),
) as DiscoveredMCPResource[];
.filter((entry) => serverNames.includes(entry.serverName));
const authStatus: HistoryItemMcpStatus['authStatus'] = {};
const tokenStorage = new MCPOAuthTokenStorage();
@@ -269,7 +260,7 @@ const listAction = async (
schema: tool.schema,
})),
prompts: mcpPrompts.map((prompt) => ({
serverName: prompt.serverName as string,
serverName: prompt.serverName,
name: prompt.name,
description: prompt.description,
})),
@@ -22,7 +22,6 @@ import {
CommandKind,
} from './types.js';
import type { HistoryItem } from '../types.js';
import type { Content } from '@google/genai';
const HistoryItemSchema = z
.object({
@@ -117,9 +116,7 @@ async function restoreAction(
} else if (action.type === 'load_history' && loadHistory) {
loadHistory(action.history);
if (action.clientHistory) {
await config
?.getGeminiClient()
?.setHistory(action.clientHistory as Content[]);
await config?.getGeminiClient()?.setHistory(action.clientHistory);
}
}
}