Disallow unnecessary awaits. (#15172)

This commit is contained in:
Christian Gunderman
2025-12-16 21:28:18 -08:00
committed by GitHub
parent 3e9a0a7628
commit 7f2d33458a
38 changed files with 129 additions and 106 deletions
@@ -48,7 +48,7 @@ describe('chatCommand', () => {
beforeEach(() => {
mockGetHistory = vi.fn().mockReturnValue([]);
mockGetChat = vi.fn().mockResolvedValue({
mockGetChat = vi.fn().mockReturnValue({
getHistory: mockGetHistory,
});
mockSaveCheckpoint = vi.fn().mockResolvedValue(undefined);
+2 -2
View File
@@ -121,7 +121,7 @@ const saveCommand: SlashCommand = {
}
}
const chat = await config?.getGeminiClient()?.getChat();
const chat = config?.getGeminiClient()?.getChat();
if (!chat) {
return {
type: 'message',
@@ -332,7 +332,7 @@ const shareCommand: SlashCommand = {
};
}
const chat = await context.services.config?.getGeminiClient()?.getChat();
const chat = context.services.config?.getGeminiClient()?.getChat();
if (!chat) {
return {
type: 'message',
+1 -1
View File
@@ -15,7 +15,7 @@ export const copyCommand: SlashCommand = {
kind: CommandKind.BUILT_IN,
autoExecute: true,
action: async (context, _args): Promise<SlashCommandActionReturn | void> => {
const chat = await context.services.config?.getGeminiClient()?.getChat();
const chat = context.services.config?.getGeminiClient()?.getChat();
const history = chat?.getHistory();
// Get the last message from the AI (model role)
@@ -85,7 +85,7 @@ describe('mcpCommand', () => {
}),
getMcpServers: vi.fn().mockReturnValue({}),
getBlockedMcpServers: vi.fn().mockReturnValue([]),
getPromptRegistry: vi.fn().mockResolvedValue({
getPromptRegistry: vi.fn().mockReturnValue({
getAllPrompts: vi.fn().mockReturnValue([]),
getPromptsByServer: vi.fn().mockReturnValue([]),
}),
+1 -1
View File
@@ -216,7 +216,7 @@ const listAction = async (
const allTools = toolRegistry.getAllTools();
const mcpTools = allTools.filter((tool) => tool instanceof DiscoveredMCPTool);
const promptRegistry = await config.getPromptRegistry();
const promptRegistry = config.getPromptRegistry();
const mcpPrompts = promptRegistry
.getAllPrompts()
.filter(
@@ -85,7 +85,7 @@ export const memoryCommand: SlashCommand = {
);
try {
const config = await context.services.config;
const config = context.services.config;
if (config) {
const { memoryContent, fileCount } =
await refreshServerHierarchicalMemory(config);
@@ -116,7 +116,7 @@ async function restoreAction(
} else if (action.type === 'load_history' && loadHistory) {
loadHistory(action.history);
if (action.clientHistory) {
await config?.getGeminiClient()?.setHistory(action.clientHistory);
config?.getGeminiClient()?.setHistory(action.clientHistory);
}
}
}
@@ -89,7 +89,7 @@ describe('MultiFolderTrustDialog', () => {
const keypressCallback = mockedUseKeypress.mock.calls[0][0];
await act(async () => {
await keypressCallback({
keypressCallback({
name: 'escape',
ctrl: false,
meta: false,
@@ -117,7 +117,7 @@ describe('MultiFolderTrustDialog', () => {
const { onSelect } = mockedRadioButtonSelect.mock.calls[0][0];
await act(async () => {
await onSelect(MultiFolderTrustChoice.NO);
onSelect(MultiFolderTrustChoice.NO);
});
expect(mockFinishAddingDirectories).toHaveBeenCalledWith(
@@ -145,7 +145,7 @@ describe('MultiFolderTrustDialog', () => {
const { onSelect } = mockedRadioButtonSelect.mock.calls[0][0];
await act(async () => {
await onSelect(MultiFolderTrustChoice.YES);
onSelect(MultiFolderTrustChoice.YES);
});
expect(mockAddDirectory).toHaveBeenCalledWith('/path/to/folder1');
@@ -166,7 +166,7 @@ describe('MultiFolderTrustDialog', () => {
const { onSelect } = mockedRadioButtonSelect.mock.calls[0][0];
await act(async () => {
await onSelect(MultiFolderTrustChoice.YES_AND_REMEMBER);
onSelect(MultiFolderTrustChoice.YES_AND_REMEMBER);
});
expect(mockAddDirectory).toHaveBeenCalledWith('/path/to/folder1');
@@ -192,7 +192,7 @@ describe('MultiFolderTrustDialog', () => {
const { onSelect } = mockedRadioButtonSelect.mock.calls[0][0];
await act(async () => {
await onSelect(MultiFolderTrustChoice.NO);
onSelect(MultiFolderTrustChoice.NO);
});
expect(lastFrame()).toContain('Applying trust settings...');
@@ -210,7 +210,7 @@ describe('MultiFolderTrustDialog', () => {
const { onSelect } = mockedRadioButtonSelect.mock.calls[0][0];
await act(async () => {
await onSelect(MultiFolderTrustChoice.YES);
onSelect(MultiFolderTrustChoice.YES);
});
expect(mockAddItem).toHaveBeenCalledWith(
@@ -243,7 +243,7 @@ describe('MultiFolderTrustDialog', () => {
const { onSelect } = mockedRadioButtonSelect.mock.calls[0][0];
await act(async () => {
await onSelect(MultiFolderTrustChoice.YES);
onSelect(MultiFolderTrustChoice.YES);
});
expect(mockAddDirectory).toHaveBeenCalledWith('/path/to/good');
@@ -55,7 +55,7 @@ export const VimModeProvider = ({
if (newValue) {
setVimMode('NORMAL');
}
await settings.setValue(SettingScope.User, 'general.vimMode', newValue);
settings.setValue(SettingScope.User, 'general.vimMode', newValue);
return newValue;
}, [vimEnabled, settings]);
@@ -1120,7 +1120,7 @@ describe('useSlashCommandProcessor', () => {
// We should not see a change until we fire an event.
await waitFor(() => expect(result.current.slashCommands).toEqual([]));
await act(() => {
act(() => {
appEvents.emit('extensionsStarting');
});
await waitFor(() =>
@@ -140,9 +140,7 @@ describe('useFolderTrust', () => {
});
await act(async () => {
await result.current.handleFolderTrustSelect(
FolderTrustChoice.TRUST_FOLDER,
);
result.current.handleFolderTrustSelect(FolderTrustChoice.TRUST_FOLDER);
});
await waitFor(() => {
@@ -136,7 +136,7 @@ describe('useQuotaAndFallback', () => {
mockGoogleApiError,
1000 * 60 * 5,
); // 5 minutes
await act(() => {
act(() => {
promise = handler('gemini-pro', 'gemini-flash', error);
});
@@ -155,7 +155,7 @@ describe('useQuotaAndFallback', () => {
expect(mockHistoryManager.addItem).not.toHaveBeenCalled();
// Simulate the user choosing to continue with the fallback model
await act(() => {
act(() => {
result.current.handleProQuotaChoice('retry_always');
});
@@ -182,7 +182,7 @@ describe('useQuotaAndFallback', () => {
.calls[0][0] as FallbackModelHandler;
let promise1: Promise<FallbackIntent | null>;
await act(() => {
act(() => {
promise1 = handler(
'gemini-pro',
'gemini-flash',
@@ -206,7 +206,7 @@ describe('useQuotaAndFallback', () => {
expect(result2!).toBe('stop');
expect(result.current.proQuotaRequest).toBe(firstRequest);
await act(() => {
act(() => {
result.current.handleProQuotaChoice('retry_always');
});
@@ -247,7 +247,7 @@ describe('useQuotaAndFallback', () => {
.calls[0][0] as FallbackModelHandler;
let promise: Promise<FallbackIntent | null>;
await act(() => {
act(() => {
promise = handler('model-A', 'model-B', error);
});
@@ -265,7 +265,7 @@ describe('useQuotaAndFallback', () => {
);
// Simulate the user choosing to continue with the fallback model
await act(() => {
act(() => {
result.current.handleProQuotaChoice('retry_always');
});
@@ -303,7 +303,7 @@ describe('useQuotaAndFallback', () => {
let promise: Promise<FallbackIntent | null>;
const error = new ModelNotFoundError('model not found', 404);
await act(() => {
act(() => {
promise = handler('gemini-3-pro-preview', 'gemini-2.5-pro', error);
});
@@ -322,7 +322,7 @@ To disable Gemini 3, disable "Preview features" in /settings.`,
);
// Simulate the user choosing to switch
await act(() => {
act(() => {
result.current.handleProQuotaChoice('retry_always');
});
@@ -364,7 +364,7 @@ To disable Gemini 3, disable "Preview features" in /settings.`,
const handler = setFallbackHandlerSpy.mock
.calls[0][0] as FallbackModelHandler;
let promise: Promise<FallbackIntent | null>;
await act(() => {
act(() => {
promise = handler(
'gemini-pro',
'gemini-flash',
@@ -372,7 +372,7 @@ To disable Gemini 3, disable "Preview features" in /settings.`,
);
});
await act(() => {
act(() => {
result.current.handleProQuotaChoice('retry_later');
});
@@ -395,7 +395,7 @@ To disable Gemini 3, disable "Preview features" in /settings.`,
.calls[0][0] as FallbackModelHandler;
let promise: Promise<FallbackIntent | null>;
await act(() => {
act(() => {
promise = handler(
'gemini-pro',
'gemini-flash',
@@ -403,7 +403,7 @@ To disable Gemini 3, disable "Preview features" in /settings.`,
);
});
await act(() => {
act(() => {
result.current.handleProQuotaChoice('retry_always');
});
@@ -431,7 +431,7 @@ To disable Gemini 3, disable "Preview features" in /settings.`,
const handler = setFallbackHandlerSpy.mock
.calls[0][0] as FallbackModelHandler;
let promise: Promise<FallbackIntent | null>;
await act(() => {
act(() => {
promise = handler(
PREVIEW_GEMINI_MODEL,
DEFAULT_GEMINI_MODEL,
@@ -439,7 +439,7 @@ To disable Gemini 3, disable "Preview features" in /settings.`,
);
});
await act(() => {
act(() => {
result.current.handleProQuotaChoice('retry_always');
});
@@ -466,7 +466,7 @@ To disable Gemini 3, disable "Preview features" in /settings.`,
const handler = setFallbackHandlerSpy.mock
.calls[0][0] as FallbackModelHandler;
let promise: Promise<FallbackIntent | null>;
await act(() => {
act(() => {
promise = handler(
PREVIEW_GEMINI_MODEL,
DEFAULT_GEMINI_FLASH_MODEL,
@@ -474,7 +474,7 @@ To disable Gemini 3, disable "Preview features" in /settings.`,
);
});
await act(() => {
act(() => {
result.current.handleProQuotaChoice('retry_always');
});