mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-06-28 20:27:08 -07:00
Disallow redundant typecasts. (#15030)
This commit is contained in:
committed by
GitHub
parent
fcc3b2b5ec
commit
942bcfc61e
@@ -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,
|
||||
'',
|
||||
);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ vi.mock('./HistoryItemDisplay.js', async () => {
|
||||
const { Text } = await vi.importActual('ink');
|
||||
return {
|
||||
HistoryItemDisplay: ({ item }: { item: { content: string } }) =>
|
||||
React.createElement(Text as unknown as React.FC, null, item.content),
|
||||
React.createElement(Text as React.FC, null, item.content),
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
@@ -326,7 +326,7 @@ describe('SettingsDialog', () => {
|
||||
|
||||
// Navigate down
|
||||
act(() => {
|
||||
stdin.write(down as string);
|
||||
stdin.write(down);
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
@@ -335,7 +335,7 @@ describe('SettingsDialog', () => {
|
||||
|
||||
// Navigate up
|
||||
act(() => {
|
||||
stdin.write(up as string);
|
||||
stdin.write(up);
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
|
||||
@@ -144,7 +144,7 @@ export const ToolStatsDisplay: React.FC = () => {
|
||||
|
||||
{/* Tool Rows */}
|
||||
{activeTools.map(([name, stats]) => (
|
||||
<StatRow key={name} name={name} stats={stats as ToolCallStats} />
|
||||
<StatRow key={name} name={name} stats={stats} />
|
||||
))}
|
||||
|
||||
<Box height={1} />
|
||||
|
||||
@@ -119,7 +119,7 @@ export const TodoTray: React.FC = () => {
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
return tool.resultDisplay as TodoList;
|
||||
return tool.resultDisplay;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -11,8 +11,6 @@ import { DiffRenderer } from './DiffRenderer.js';
|
||||
import { RenderInline } from '../../utils/InlineMarkdownRenderer.js';
|
||||
import type {
|
||||
ToolCallConfirmationDetails,
|
||||
ToolExecuteConfirmationDetails,
|
||||
ToolMcpConfirmationDetails,
|
||||
Config,
|
||||
} from '@google/gemini-cli-core';
|
||||
import { IdeClient, ToolConfirmationOutcome } from '@google/gemini-cli-core';
|
||||
@@ -135,8 +133,7 @@ export const ToolConfirmationMessage: React.FC<
|
||||
});
|
||||
}
|
||||
} else if (confirmationDetails.type === 'exec') {
|
||||
const executionProps =
|
||||
confirmationDetails as ToolExecuteConfirmationDetails;
|
||||
const executionProps = confirmationDetails;
|
||||
|
||||
question = `Allow execution of: '${executionProps.rootCommand}'?`;
|
||||
options.push({
|
||||
@@ -187,7 +184,7 @@ export const ToolConfirmationMessage: React.FC<
|
||||
});
|
||||
} else {
|
||||
// mcp tool confirmation
|
||||
const mcpProps = confirmationDetails as ToolMcpConfirmationDetails;
|
||||
const mcpProps = confirmationDetails;
|
||||
question = `Allow execution of MCP tool "${mcpProps.toolName}" from server "${mcpProps.serverName}"?`;
|
||||
options.push({
|
||||
label: 'Yes, allow once',
|
||||
@@ -258,8 +255,7 @@ export const ToolConfirmationMessage: React.FC<
|
||||
);
|
||||
}
|
||||
} else if (confirmationDetails.type === 'exec') {
|
||||
const executionProps =
|
||||
confirmationDetails as ToolExecuteConfirmationDetails;
|
||||
const executionProps = confirmationDetails;
|
||||
let bodyContentHeight = availableBodyContentHeight();
|
||||
if (bodyContentHeight !== undefined) {
|
||||
bodyContentHeight -= 2; // Account for padding;
|
||||
@@ -312,7 +308,7 @@ export const ToolConfirmationMessage: React.FC<
|
||||
);
|
||||
} else {
|
||||
// mcp tool confirmation
|
||||
const mcpProps = confirmationDetails as ToolMcpConfirmationDetails;
|
||||
const mcpProps = confirmationDetails;
|
||||
|
||||
bodyContent = (
|
||||
<Box flexDirection="column">
|
||||
|
||||
@@ -59,7 +59,7 @@ function findLastIndex<T>(
|
||||
predicate: (value: T, index: number, obj: T[]) => unknown,
|
||||
): number {
|
||||
for (let i = array.length - 1; i >= 0; i--) {
|
||||
if (predicate(array[i]!, i, array)) {
|
||||
if (predicate(array[i], i, array)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
@@ -192,7 +192,7 @@ function VirtualizedList<T>(
|
||||
return { index: 0, offset: 0 };
|
||||
}
|
||||
|
||||
return { index, offset: scrollTop - offsets[index]! };
|
||||
return { index, offset: scrollTop - offsets[index] };
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
@@ -433,7 +433,7 @@ export async function handleAtCommand({
|
||||
const processedQueryParts: PartListUnion = [{ text: initialQueryText }];
|
||||
|
||||
const resourcePromises = resourceAttachments.map(async (resource) => {
|
||||
const uri = resource.uri!;
|
||||
const uri = resource.uri;
|
||||
const client = mcpClientManager?.getClient(resource.serverName);
|
||||
try {
|
||||
if (!client) {
|
||||
|
||||
@@ -26,9 +26,7 @@ import { MessageType } from '../types.js';
|
||||
vi.mock('./useKeypress.js');
|
||||
|
||||
vi.mock('@google/gemini-cli-core', async () => {
|
||||
const actualServerModule = (await vi.importActual(
|
||||
'@google/gemini-cli-core',
|
||||
)) as Record<string, unknown>;
|
||||
const actualServerModule = await vi.importActual('@google/gemini-cli-core');
|
||||
return {
|
||||
...actualServerModule,
|
||||
Config: vi.fn(),
|
||||
|
||||
@@ -24,7 +24,6 @@ import { useReactToolScheduler } from './useReactToolScheduler.js';
|
||||
import type {
|
||||
Config,
|
||||
EditorType,
|
||||
GeminiClient,
|
||||
AnyToolInvocation,
|
||||
} from '@google/gemini-cli-core';
|
||||
import {
|
||||
@@ -809,8 +808,8 @@ describe('useGeminiStream', () => {
|
||||
expect(client.addHistory).toHaveBeenCalledWith({
|
||||
role: 'user',
|
||||
parts: [
|
||||
...(cancelledToolCall1.response.responseParts as Part[]),
|
||||
...(cancelledToolCall2.response.responseParts as Part[]),
|
||||
...cancelledToolCall1.response.responseParts,
|
||||
...cancelledToolCall2.response.responseParts,
|
||||
],
|
||||
});
|
||||
|
||||
@@ -2074,7 +2073,7 @@ describe('useGeminiStream', () => {
|
||||
|
||||
const { result } = renderHook(() =>
|
||||
useGeminiStream(
|
||||
mockConfig.getGeminiClient() as GeminiClient,
|
||||
mockConfig.getGeminiClient(),
|
||||
[],
|
||||
mockAddItem,
|
||||
mockConfig,
|
||||
|
||||
@@ -833,10 +833,7 @@ export const useGeminiStream = (
|
||||
);
|
||||
break;
|
||||
case ServerGeminiEventType.Finished:
|
||||
handleFinishedEvent(
|
||||
event as ServerGeminiFinishedEvent,
|
||||
userMessageTimestamp,
|
||||
);
|
||||
handleFinishedEvent(event, userMessageTimestamp);
|
||||
break;
|
||||
case ServerGeminiEventType.Citation:
|
||||
handleCitationEvent(event.value, userMessageTimestamp);
|
||||
|
||||
@@ -183,7 +183,7 @@ describe('useIncludeDirsTrust', () => {
|
||||
).props;
|
||||
expect(dialogProps.folders).toEqual(['/undefined']);
|
||||
expect(dialogProps.trustedDirs).toEqual(['/trusted']);
|
||||
expect(dialogProps.errors as string[]).toEqual([
|
||||
expect(dialogProps.errors).toEqual([
|
||||
`The following directories are explicitly untrusted and cannot be added to a trusted workspace:\n- /untrusted\nPlease use the permissions command to modify their trust level.`,
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -99,7 +99,7 @@ export function useReactToolScheduler(
|
||||
setToolCallsForDisplay((prevCalls) =>
|
||||
prevCalls.map((tc) => {
|
||||
if (tc.request.callId === toolCallId && tc.status === 'executing') {
|
||||
const executingTc = tc as TrackedExecutingToolCall;
|
||||
const executingTc = tc;
|
||||
return { ...executingTc, liveOutput: outputChunk };
|
||||
}
|
||||
return tc;
|
||||
@@ -137,7 +137,7 @@ export function useReactToolScheduler(
|
||||
...coreTc,
|
||||
responseSubmittedToGemini,
|
||||
liveOutput,
|
||||
pid: (coreTc as ExecutingToolCall).pid,
|
||||
pid: coreTc.pid,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
@@ -312,10 +312,9 @@ export function mapToDisplay(
|
||||
return {
|
||||
...baseDisplayProperties,
|
||||
status: mapCoreStatusToDisplayStatus(trackedCall.status),
|
||||
resultDisplay:
|
||||
(trackedCall as TrackedExecutingToolCall).liveOutput ?? undefined,
|
||||
resultDisplay: trackedCall.liveOutput ?? undefined,
|
||||
confirmationDetails: undefined,
|
||||
ptyId: (trackedCall as TrackedExecutingToolCall).pid,
|
||||
ptyId: trackedCall.pid,
|
||||
};
|
||||
case 'validating': // Fallthrough
|
||||
case 'scheduled':
|
||||
|
||||
@@ -106,7 +106,7 @@ const computeInitialIndex = (
|
||||
|
||||
if (initialKey !== undefined) {
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
if (items[i]!.key === initialKey && !items[i]!.disabled) {
|
||||
if (items[i].key === initialKey && !items[i].disabled) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
@@ -212,7 +212,7 @@ function areBaseItemsEqual(
|
||||
if (a.length !== b.length) return false;
|
||||
|
||||
for (let i = 0; i < a.length; i++) {
|
||||
if (a[i]!.key !== b[i]!.key || a[i]!.disabled !== b[i]!.disabled) {
|
||||
if (a[i].key !== b[i].key || a[i].disabled !== b[i].disabled) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -283,7 +283,7 @@ export function useSelectionList<T>({
|
||||
let needsClear = false;
|
||||
|
||||
if (state.pendingHighlight && items[state.activeIndex]) {
|
||||
onHighlight?.(items[state.activeIndex]!.value);
|
||||
onHighlight?.(items[state.activeIndex].value);
|
||||
needsClear = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -231,7 +231,7 @@ describe('commandUtils', () => {
|
||||
const expected = `${ESC}]52;c;${b64}${BEL}`;
|
||||
|
||||
expect(tty.write).toHaveBeenCalledTimes(1);
|
||||
expect((tty.write as Mock).mock.calls[0][0]).toBe(expected);
|
||||
expect(tty.write.mock.calls[0][0]).toBe(expected);
|
||||
expect(tty.end).toHaveBeenCalledTimes(1); // /dev/tty closed after write
|
||||
expect(mockClipboardyWrite).not.toHaveBeenCalled();
|
||||
});
|
||||
@@ -245,7 +245,7 @@ describe('commandUtils', () => {
|
||||
|
||||
await copyToClipboard(testText);
|
||||
|
||||
const written = (tty.write as Mock).mock.calls[0][0] as string;
|
||||
const written = tty.write.mock.calls[0][0] as string;
|
||||
// Starts with tmux DCS wrapper and ends with ST
|
||||
expect(written.startsWith(`${ESC}Ptmux;`)).toBe(true);
|
||||
expect(written.endsWith(ST)).toBe(true);
|
||||
@@ -264,7 +264,7 @@ describe('commandUtils', () => {
|
||||
|
||||
await copyToClipboard(testText);
|
||||
|
||||
const written = (tty.write as Mock).mock.calls[0][0] as string;
|
||||
const written = tty.write.mock.calls[0][0] as string;
|
||||
const chunkStarts = (written.match(new RegExp(`${ESC}P`, 'g')) || [])
|
||||
.length;
|
||||
const chunkEnds = written.split(ST).length - 1;
|
||||
|
||||
Reference in New Issue
Block a user