Remove unnecessary promiuse usage. (#6585)

This commit is contained in:
Tommaso Sciortino 2025-08-19 15:31:02 -07:00 committed by GitHub
parent 1244ec6954
commit 0cc2a1e7ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
18 changed files with 61 additions and 67 deletions

View File

@ -65,7 +65,7 @@ describe('runNonInteractive', () => {
mockConfig = {
initialize: vi.fn().mockResolvedValue(undefined),
getGeminiClient: vi.fn().mockReturnValue(mockGeminiClient),
getToolRegistry: vi.fn().mockResolvedValue(mockToolRegistry),
getToolRegistry: vi.fn().mockReturnValue(mockToolRegistry),
getMaxSessionTurns: vi.fn().mockReturnValue(10),
getIdeMode: vi.fn().mockReturnValue(false),
getFullContext: vi.fn().mockReturnValue(false),

View File

@ -39,7 +39,7 @@ export async function runNonInteractive(
});
const geminiClient = config.getGeminiClient();
const toolRegistry: ToolRegistry = await config.getToolRegistry();
const toolRegistry: ToolRegistry = config.getToolRegistry();
const abortController = new AbortController();
let currentMessages: Content[] = [

View File

@ -83,7 +83,7 @@ describe('mcpCommand', () => {
// Create mock config with all necessary methods
mockConfig = {
getToolRegistry: vi.fn().mockResolvedValue({
getToolRegistry: vi.fn().mockReturnValue({
getAllTools: vi.fn().mockReturnValue([]),
}),
getMcpServers: vi.fn().mockReturnValue({}),
@ -119,7 +119,7 @@ describe('mcpCommand', () => {
});
it('should show an error if tool registry is not available', async () => {
mockConfig.getToolRegistry = vi.fn().mockResolvedValue(undefined);
mockConfig.getToolRegistry = vi.fn().mockReturnValue(undefined);
const result = await mcpCommand.action!(mockContext, '');
@ -133,7 +133,7 @@ describe('mcpCommand', () => {
describe('no MCP servers configured', () => {
beforeEach(() => {
mockConfig.getToolRegistry = vi.fn().mockResolvedValue({
mockConfig.getToolRegistry = vi.fn().mockReturnValue({
getAllTools: vi.fn().mockReturnValue([]),
});
mockConfig.getMcpServers = vi.fn().mockReturnValue({});
@ -184,7 +184,7 @@ describe('mcpCommand', () => {
...mockServer3Tools,
];
mockConfig.getToolRegistry = vi.fn().mockResolvedValue({
mockConfig.getToolRegistry = vi.fn().mockReturnValue({
getAllTools: vi.fn().mockReturnValue(allTools),
});
@ -243,7 +243,7 @@ describe('mcpCommand', () => {
createMockMCPTool('tool2', 'server1', 'This is tool 2 description'),
];
mockConfig.getToolRegistry = vi.fn().mockResolvedValue({
mockConfig.getToolRegistry = vi.fn().mockReturnValue({
getAllTools: vi.fn().mockReturnValue(mockServerTools),
});
@ -296,7 +296,7 @@ describe('mcpCommand', () => {
createMockMCPTool('tool1', 'server1', 'This is tool 1 description'),
];
mockConfig.getToolRegistry = vi.fn().mockResolvedValue({
mockConfig.getToolRegistry = vi.fn().mockReturnValue({
getAllTools: vi.fn().mockReturnValue(mockServerTools),
});
@ -340,7 +340,7 @@ describe('mcpCommand', () => {
// Mock tools - only server1 has tools
const mockServerTools = [createMockMCPTool('server1_tool1', 'server1')];
mockConfig.getToolRegistry = vi.fn().mockResolvedValue({
mockConfig.getToolRegistry = vi.fn().mockReturnValue({
getAllTools: vi.fn().mockReturnValue(mockServerTools),
});
@ -386,7 +386,7 @@ describe('mcpCommand', () => {
createMockMCPTool('server2_tool1', 'server2'),
];
mockConfig.getToolRegistry = vi.fn().mockResolvedValue({
mockConfig.getToolRegistry = vi.fn().mockReturnValue({
getAllTools: vi.fn().mockReturnValue(mockServerTools),
});
@ -523,7 +523,7 @@ describe('mcpCommand', () => {
const mockServerTools = [tool1, tool2];
mockConfig.getToolRegistry = vi.fn().mockResolvedValue({
mockConfig.getToolRegistry = vi.fn().mockReturnValue({
getAllTools: vi.fn().mockReturnValue(mockServerTools),
});
@ -566,7 +566,7 @@ describe('mcpCommand', () => {
createMockMCPTool('tool1', 'server1', 'Tool without schema'),
];
mockConfig.getToolRegistry = vi.fn().mockResolvedValue({
mockConfig.getToolRegistry = vi.fn().mockReturnValue({
getAllTools: vi.fn().mockReturnValue(mockServerTools),
});
@ -603,7 +603,7 @@ describe('mcpCommand', () => {
createMockMCPTool('tool1', 'server1', 'Test tool'),
];
mockConfig.getToolRegistry = vi.fn().mockResolvedValue({
mockConfig.getToolRegistry = vi.fn().mockReturnValue({
getAllTools: vi.fn().mockReturnValue(mockServerTools),
});
});
@ -766,7 +766,7 @@ describe('mcpCommand', () => {
};
mockConfig.getMcpServers = vi.fn().mockReturnValue(mockMcpServers);
mockConfig.getToolRegistry = vi.fn().mockResolvedValue({
mockConfig.getToolRegistry = vi.fn().mockReturnValue({
getAllTools: vi.fn().mockReturnValue([]),
});
@ -787,7 +787,7 @@ describe('mcpCommand', () => {
};
mockConfig.getMcpServers = vi.fn().mockReturnValue(mockMcpServers);
mockConfig.getToolRegistry = vi.fn().mockResolvedValue({
mockConfig.getToolRegistry = vi.fn().mockReturnValue({
getAllTools: vi.fn().mockReturnValue([]),
});
@ -879,7 +879,7 @@ describe('mcpCommand', () => {
oauth: { enabled: true },
},
}),
getToolRegistry: vi.fn().mockResolvedValue(mockToolRegistry),
getToolRegistry: vi.fn().mockReturnValue(mockToolRegistry),
getGeminiClient: vi.fn().mockReturnValue(mockGeminiClient),
getPromptRegistry: vi.fn().mockResolvedValue({
removePromptsByServer: vi.fn(),
@ -984,7 +984,7 @@ describe('mcpCommand', () => {
config: {
getMcpServers: vi.fn().mockReturnValue({ server1: {} }),
getBlockedMcpServers: vi.fn().mockReturnValue([]),
getToolRegistry: vi.fn().mockResolvedValue(mockToolRegistry),
getToolRegistry: vi.fn().mockReturnValue(mockToolRegistry),
getGeminiClient: vi.fn().mockReturnValue(mockGeminiClient),
getPromptRegistry: vi.fn().mockResolvedValue({
getPromptsByServer: vi.fn().mockReturnValue([]),
@ -1040,7 +1040,7 @@ describe('mcpCommand', () => {
});
it('should show an error if tool registry is not available', async () => {
mockConfig.getToolRegistry = vi.fn().mockResolvedValue(undefined);
mockConfig.getToolRegistry = vi.fn().mockReturnValue(undefined);
const refreshCommand = mcpCommand.subCommands?.find(
(cmd) => cmd.name === 'refresh',

View File

@ -44,7 +44,7 @@ const getMcpStatus = async (
};
}
const toolRegistry = await config.getToolRegistry();
const toolRegistry = config.getToolRegistry();
if (!toolRegistry) {
return {
type: 'message',
@ -400,7 +400,7 @@ const authCommand: SlashCommand = {
);
// Trigger tool re-discovery to pick up authenticated server
const toolRegistry = await config.getToolRegistry();
const toolRegistry = config.getToolRegistry();
if (toolRegistry) {
context.ui.addItem(
{
@ -485,7 +485,7 @@ const refreshCommand: SlashCommand = {
};
}
const toolRegistry = await config.getToolRegistry();
const toolRegistry = config.getToolRegistry();
if (!toolRegistry) {
return {
type: 'message',

View File

@ -31,7 +31,7 @@ describe('toolsCommand', () => {
const mockContext = createMockCommandContext({
services: {
config: {
getToolRegistry: () => Promise.resolve(undefined),
getToolRegistry: () => undefined,
},
},
});
@ -52,8 +52,7 @@ describe('toolsCommand', () => {
const mockContext = createMockCommandContext({
services: {
config: {
getToolRegistry: () =>
Promise.resolve({ getAllTools: () => [] as Tool[] }),
getToolRegistry: () => ({ getAllTools: () => [] as Tool[] }),
},
},
});
@ -73,8 +72,7 @@ describe('toolsCommand', () => {
const mockContext = createMockCommandContext({
services: {
config: {
getToolRegistry: () =>
Promise.resolve({ getAllTools: () => mockTools }),
getToolRegistry: () => ({ getAllTools: () => mockTools }),
},
},
});
@ -92,8 +90,7 @@ describe('toolsCommand', () => {
const mockContext = createMockCommandContext({
services: {
config: {
getToolRegistry: () =>
Promise.resolve({ getAllTools: () => mockTools }),
getToolRegistry: () => ({ getAllTools: () => mockTools }),
},
},
});

View File

@ -24,7 +24,7 @@ export const toolsCommand: SlashCommand = {
useShowDescriptions = true;
}
const toolRegistry = await context.services.config?.getToolRegistry();
const toolRegistry = context.services.config?.getToolRegistry();
if (!toolRegistry) {
context.ui.addItem(
{

View File

@ -157,7 +157,7 @@ export async function handleAtCommand({
both: [],
};
const toolRegistry = await config.getToolRegistry();
const toolRegistry = config.getToolRegistry();
const readManyFilesTool = toolRegistry.getTool('read_many_files');
const globTool = toolRegistry.getTool('glob');

View File

@ -10,7 +10,6 @@ import {
AuthType,
Config,
GeminiChat,
ToolRegistry,
logToolCall,
ToolResult,
convertToFunctionResponse,
@ -366,7 +365,7 @@ class Session {
return errorResponse(new Error('Missing function name'));
}
const toolRegistry: ToolRegistry = await this.config.getToolRegistry();
const toolRegistry = this.config.getToolRegistry();
const tool = toolRegistry.getTool(fc.name as string);
if (!tool) {
@ -531,7 +530,7 @@ class Session {
const contentLabelsForDisplay: string[] = [];
const ignoredPaths: string[] = [];
const toolRegistry = await this.config.getToolRegistry();
const toolRegistry = this.config.getToolRegistry();
const readManyFilesTool = toolRegistry.getTool('read_many_files');
const globTool = toolRegistry.getTool('glob');

View File

@ -482,8 +482,8 @@ export class Config {
return this.workspaceContext;
}
getToolRegistry(): Promise<ToolRegistry> {
return Promise.resolve(this.toolRegistry);
getToolRegistry(): ToolRegistry {
return this.toolRegistry;
}
getPromptRegistry(): PromptRegistry {

View File

@ -183,7 +183,7 @@ describe('Gemini Client (client.ts)', () => {
getContentGeneratorConfig: vi
.fn()
.mockReturnValue(contentGeneratorConfig),
getToolRegistry: vi.fn().mockResolvedValue(mockToolRegistry),
getToolRegistry: vi.fn().mockReturnValue(mockToolRegistry),
getModel: vi.fn().mockReturnValue('test-model'),
getEmbeddingModel: vi.fn().mockReturnValue('test-embedding-model'),
getApiKey: vi.fn().mockReturnValue('test-key'),

View File

@ -201,7 +201,7 @@ export class GeminiClient {
}
async setTools(): Promise<void> {
const toolRegistry = await this.config.getToolRegistry();
const toolRegistry = this.config.getToolRegistry();
const toolDeclarations = toolRegistry.getFunctionDeclarations();
const tools: Tool[] = [{ functionDeclarations: toolDeclarations }];
this.getChat().setTools(tools);
@ -225,7 +225,7 @@ export class GeminiClient {
async startChat(extraHistory?: Content[]): Promise<GeminiChat> {
this.forceFullIdeContext = true;
const envParts = await getEnvironmentContext(this.config);
const toolRegistry = await this.config.getToolRegistry();
const toolRegistry = this.config.getToolRegistry();
const toolDeclarations = toolRegistry.getFunctionDeclarations();
const tools: Tool[] = [{ functionDeclarations: toolDeclarations }];
const history: Content[] = [

View File

@ -31,7 +31,7 @@ describe('CoreToolScheduler', () => {
const mockTool = new MockTool();
mockTool.shouldConfirm = true;
const declarativeTool = mockTool;
const toolRegistry = {
const mockToolRegistry = {
getTool: () => declarativeTool,
getFunctionDeclarations: () => [],
tools: new Map(),
@ -43,7 +43,7 @@ describe('CoreToolScheduler', () => {
discoverTools: async () => {},
getAllTools: () => [],
getToolsByServer: () => [],
};
} as unknown as ToolRegistry;
const onAllToolCallsComplete = vi.fn();
const onToolCallsUpdate = vi.fn();
@ -61,7 +61,7 @@ describe('CoreToolScheduler', () => {
const scheduler = new CoreToolScheduler({
config: mockConfig,
toolRegistry: Promise.resolve(toolRegistry as unknown as ToolRegistry),
toolRegistry: mockToolRegistry,
onAllToolCallsComplete,
onToolCallsUpdate,
getPreferredEditor: () => 'vscode',
@ -91,7 +91,7 @@ describe('CoreToolScheduler with payload', () => {
it('should update args and diff and execute tool when payload is provided', async () => {
const mockTool = new MockModifiableTool();
const declarativeTool = mockTool;
const toolRegistry = {
const mockToolRegistry = {
getTool: () => declarativeTool,
getFunctionDeclarations: () => [],
tools: new Map(),
@ -103,7 +103,7 @@ describe('CoreToolScheduler with payload', () => {
discoverTools: async () => {},
getAllTools: () => [],
getToolsByServer: () => [],
};
} as unknown as ToolRegistry;
const onAllToolCallsComplete = vi.fn();
const onToolCallsUpdate = vi.fn();
@ -121,7 +121,7 @@ describe('CoreToolScheduler with payload', () => {
const scheduler = new CoreToolScheduler({
config: mockConfig,
toolRegistry: Promise.resolve(toolRegistry as unknown as ToolRegistry),
toolRegistry: mockToolRegistry,
onAllToolCallsComplete,
onToolCallsUpdate,
getPreferredEditor: () => 'vscode',
@ -391,7 +391,7 @@ describe('CoreToolScheduler edit cancellation', () => {
it('should preserve diff when an edit is cancelled', async () => {
const mockEditTool = new MockEditTool();
const declarativeTool = mockEditTool;
const toolRegistry = {
const mockToolRegistry = {
getTool: () => declarativeTool,
getFunctionDeclarations: () => [],
tools: new Map(),
@ -403,7 +403,7 @@ describe('CoreToolScheduler edit cancellation', () => {
discoverTools: async () => {},
getAllTools: () => [],
getToolsByServer: () => [],
};
} as unknown as ToolRegistry;
const onAllToolCallsComplete = vi.fn();
const onToolCallsUpdate = vi.fn();
@ -421,7 +421,7 @@ describe('CoreToolScheduler edit cancellation', () => {
const scheduler = new CoreToolScheduler({
config: mockConfig,
toolRegistry: Promise.resolve(toolRegistry as unknown as ToolRegistry),
toolRegistry: mockToolRegistry,
onAllToolCallsComplete,
onToolCallsUpdate,
getPreferredEditor: () => 'vscode',
@ -481,7 +481,7 @@ describe('CoreToolScheduler YOLO mode', () => {
mockTool.shouldConfirm = true;
const declarativeTool = mockTool;
const toolRegistry = {
const mockToolRegistry = {
getTool: () => declarativeTool,
getToolByName: () => declarativeTool,
// Other properties are not needed for this test but are included for type consistency.
@ -494,7 +494,7 @@ describe('CoreToolScheduler YOLO mode', () => {
discoverTools: async () => {},
getAllTools: () => [],
getToolsByServer: () => [],
};
} as unknown as ToolRegistry;
const onAllToolCallsComplete = vi.fn();
const onToolCallsUpdate = vi.fn();
@ -513,7 +513,7 @@ describe('CoreToolScheduler YOLO mode', () => {
const scheduler = new CoreToolScheduler({
config: mockConfig,
toolRegistry: Promise.resolve(toolRegistry as unknown as ToolRegistry),
toolRegistry: mockToolRegistry,
onAllToolCallsComplete,
onToolCallsUpdate,
getPreferredEditor: () => 'vscode',
@ -572,7 +572,7 @@ describe('CoreToolScheduler request queueing', () => {
mockTool.executeFn.mockImplementation(() => firstCallPromise);
const declarativeTool = mockTool;
const toolRegistry = {
const mockToolRegistry = {
getTool: () => declarativeTool,
getToolByName: () => declarativeTool,
getFunctionDeclarations: () => [],
@ -584,7 +584,7 @@ describe('CoreToolScheduler request queueing', () => {
discoverTools: async () => {},
getAllTools: () => [],
getToolsByServer: () => [],
};
} as unknown as ToolRegistry;
const onAllToolCallsComplete = vi.fn();
const onToolCallsUpdate = vi.fn();
@ -602,7 +602,7 @@ describe('CoreToolScheduler request queueing', () => {
const scheduler = new CoreToolScheduler({
config: mockConfig,
toolRegistry: Promise.resolve(toolRegistry as unknown as ToolRegistry),
toolRegistry: mockToolRegistry,
onAllToolCallsComplete,
onToolCallsUpdate,
getPreferredEditor: () => 'vscode',
@ -685,7 +685,7 @@ describe('CoreToolScheduler request queueing', () => {
it('should handle two synchronous calls to schedule', async () => {
const mockTool = new MockTool();
const declarativeTool = mockTool;
const toolRegistry = {
const mockToolRegistry = {
getTool: () => declarativeTool,
getToolByName: () => declarativeTool,
getFunctionDeclarations: () => [],
@ -697,7 +697,7 @@ describe('CoreToolScheduler request queueing', () => {
discoverTools: async () => {},
getAllTools: () => [],
getToolsByServer: () => [],
};
} as unknown as ToolRegistry;
const onAllToolCallsComplete = vi.fn();
const onToolCallsUpdate = vi.fn();
@ -715,7 +715,7 @@ describe('CoreToolScheduler request queueing', () => {
const scheduler = new CoreToolScheduler({
config: mockConfig,
toolRegistry: Promise.resolve(toolRegistry as unknown as ToolRegistry),
toolRegistry: mockToolRegistry,
onAllToolCallsComplete,
onToolCallsUpdate,
getPreferredEditor: () => 'vscode',

View File

@ -226,7 +226,7 @@ const createErrorResponse = (
});
interface CoreToolSchedulerOptions {
toolRegistry: Promise<ToolRegistry>;
toolRegistry: ToolRegistry;
outputUpdateHandler?: OutputUpdateHandler;
onAllToolCallsComplete?: AllToolCallsCompleteHandler;
onToolCallsUpdate?: ToolCallsUpdateHandler;
@ -236,7 +236,7 @@ interface CoreToolSchedulerOptions {
}
export class CoreToolScheduler {
private toolRegistry: Promise<ToolRegistry>;
private toolRegistry: ToolRegistry;
private toolCalls: ToolCall[] = [];
private outputUpdateHandler?: OutputUpdateHandler;
private onAllToolCallsComplete?: AllToolCallsCompleteHandler;
@ -534,11 +534,10 @@ export class CoreToolScheduler {
);
}
const requestsToProcess = Array.isArray(request) ? request : [request];
const toolRegistry = await this.toolRegistry;
const newToolCalls: ToolCall[] = requestsToProcess.map(
(reqInfo): ToolCall => {
const toolInstance = toolRegistry.getTool(reqInfo.name);
const toolInstance = this.toolRegistry.getTool(reqInfo.name);
if (!toolInstance) {
return {
status: 'error',

View File

@ -428,7 +428,7 @@ export class GeminiChat {
isSchemaDepthError(error.message) ||
isInvalidArgumentError(error.message)
) {
const tools = (await this.config.getToolRegistry()).getAllTools();
const tools = this.config.getToolRegistry().getAllTools();
const cyclicSchemaTools: string[] = [];
for (const tool of tools) {
if (

View File

@ -59,7 +59,7 @@ async function createMockConfig(
...toolRegistryMocks,
} as unknown as ToolRegistry;
vi.spyOn(config, 'getToolRegistry').mockResolvedValue(mockToolRegistry);
vi.spyOn(config, 'getToolRegistry').mockReturnValue(mockToolRegistry);
return { config, toolRegistry: mockToolRegistry };
}

View File

@ -284,7 +284,7 @@ export class SubAgentScope {
outputConfig?: OutputConfig,
): Promise<SubAgentScope> {
if (toolConfig) {
const toolRegistry: ToolRegistry = await runtimeContext.getToolRegistry();
const toolRegistry = runtimeContext.getToolRegistry();
const toolsToLoad: string[] = [];
for (const tool of toolConfig.tools) {
if (typeof tool === 'string') {
@ -349,8 +349,7 @@ export class SubAgentScope {
}
const abortController = new AbortController();
const toolRegistry: ToolRegistry =
await this.runtimeContext.getToolRegistry();
const toolRegistry = this.runtimeContext.getToolRegistry();
// Prepare the list of tools available to the subagent.
const toolsList: FunctionDeclaration[] = [];

View File

@ -89,7 +89,7 @@ describe('getEnvironmentContext', () => {
}),
getFileService: vi.fn(),
getFullContext: vi.fn().mockReturnValue(false),
getToolRegistry: vi.fn().mockResolvedValue(mockToolRegistry),
getToolRegistry: vi.fn().mockReturnValue(mockToolRegistry),
};
vi.mocked(getFolderStructure).mockResolvedValue('Mock Folder Structure');

View File

@ -68,7 +68,7 @@ ${directoryContext}
`.trim();
const initialParts: Part[] = [{ text: context }];
const toolRegistry = await config.getToolRegistry();
const toolRegistry = config.getToolRegistry();
// Add full file context if the flag is set
if (config.getFullContext()) {