mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-26 14:01:14 -07:00
Disallow unnecessary awaits. (#15172)
This commit is contained in:
committed by
GitHub
parent
3e9a0a7628
commit
7f2d33458a
@@ -270,9 +270,7 @@ describe('AgentExecutor', () => {
|
||||
);
|
||||
parentToolRegistry.registerTool(MOCK_TOOL_NOT_ALLOWED);
|
||||
|
||||
vi.spyOn(mockConfig, 'getToolRegistry').mockResolvedValue(
|
||||
parentToolRegistry,
|
||||
);
|
||||
vi.spyOn(mockConfig, 'getToolRegistry').mockReturnValue(parentToolRegistry);
|
||||
|
||||
mockedGetDirectoryContextString.mockResolvedValue(
|
||||
'Mocked Environment Context',
|
||||
|
||||
@@ -106,7 +106,7 @@ export class AgentExecutor<TOutput extends z.ZodTypeAny> {
|
||||
): Promise<AgentExecutor<TOutput>> {
|
||||
// Create an isolated tool registry for this agent instance.
|
||||
const agentToolRegistry = new ToolRegistry(runtimeContext);
|
||||
const parentToolRegistry = await runtimeContext.getToolRegistry();
|
||||
const parentToolRegistry = runtimeContext.getToolRegistry();
|
||||
|
||||
if (definition.toolConfig) {
|
||||
for (const toolRef of definition.toolConfig.tools) {
|
||||
|
||||
@@ -189,7 +189,7 @@ describe('oauth2', () => {
|
||||
end: vi.fn(),
|
||||
} as unknown as http.ServerResponse;
|
||||
|
||||
await requestCallback(mockReq, mockRes);
|
||||
requestCallback(mockReq, mockRes);
|
||||
|
||||
const client = await clientPromise;
|
||||
expect(client).toBe(mockOAuth2Client);
|
||||
@@ -203,7 +203,9 @@ describe('oauth2', () => {
|
||||
|
||||
// Manually trigger the 'tokens' event listener
|
||||
if (tokensListener) {
|
||||
await tokensListener(mockTokens);
|
||||
await (
|
||||
tokensListener as unknown as (tokens: Credentials) => Promise<void>
|
||||
)(mockTokens);
|
||||
}
|
||||
|
||||
// Verify Google Account was cached
|
||||
@@ -575,9 +577,7 @@ describe('oauth2', () => {
|
||||
const mockExternalAccountClient = {
|
||||
getAccessToken: vi.fn().mockResolvedValue({ token: 'byoid-token' }),
|
||||
};
|
||||
const mockFromJSON = vi
|
||||
.fn()
|
||||
.mockResolvedValue(mockExternalAccountClient);
|
||||
const mockFromJSON = vi.fn().mockReturnValue(mockExternalAccountClient);
|
||||
const mockGoogleAuthInstance = {
|
||||
fromJSON: mockFromJSON,
|
||||
};
|
||||
@@ -834,7 +834,7 @@ describe('oauth2', () => {
|
||||
} as unknown as http.ServerResponse;
|
||||
|
||||
await expect(async () => {
|
||||
await requestCallback(mockReq, mockRes);
|
||||
requestCallback(mockReq, mockRes);
|
||||
await clientPromise;
|
||||
}).rejects.toThrow(
|
||||
'Google OAuth error: access_denied. User denied access',
|
||||
@@ -891,7 +891,7 @@ describe('oauth2', () => {
|
||||
} as unknown as http.ServerResponse;
|
||||
|
||||
await expect(async () => {
|
||||
await requestCallback(mockReq, mockRes);
|
||||
requestCallback(mockReq, mockRes);
|
||||
await clientPromise;
|
||||
}).rejects.toThrow(
|
||||
'Google OAuth error: server_error. No additional details provided',
|
||||
@@ -954,7 +954,7 @@ describe('oauth2', () => {
|
||||
} as unknown as http.ServerResponse;
|
||||
|
||||
await expect(async () => {
|
||||
await requestCallback(mockReq, mockRes);
|
||||
requestCallback(mockReq, mockRes);
|
||||
await clientPromise;
|
||||
}).rejects.toThrow(
|
||||
'Failed to exchange authorization code for tokens: Token exchange failed',
|
||||
@@ -1038,7 +1038,7 @@ describe('oauth2', () => {
|
||||
end: vi.fn(),
|
||||
} as unknown as http.ServerResponse;
|
||||
|
||||
await requestCallback(mockReq, mockRes);
|
||||
requestCallback(mockReq, mockRes);
|
||||
const client = await clientPromise;
|
||||
|
||||
// Authentication should succeed even if fetchAndCacheUserInfo fails
|
||||
|
||||
@@ -120,7 +120,7 @@ async function initOauthClient(
|
||||
const auth = new GoogleAuth({
|
||||
scopes: OAUTH_SCOPE,
|
||||
});
|
||||
const byoidClient = await auth.fromJSON({
|
||||
const byoidClient = auth.fromJSON({
|
||||
...credentials,
|
||||
refresh_token: credentials.refresh_token ?? undefined,
|
||||
});
|
||||
|
||||
@@ -304,12 +304,12 @@ describe('Gemini Client (client.ts)', () => {
|
||||
it('should create a new chat session, clearing the old history', async () => {
|
||||
// 1. Get the initial chat instance and add some history.
|
||||
const initialChat = client.getChat();
|
||||
const initialHistory = await client.getHistory();
|
||||
const initialHistory = client.getHistory();
|
||||
await client.addHistory({
|
||||
role: 'user',
|
||||
parts: [{ text: 'some old message' }],
|
||||
});
|
||||
const historyWithOldMessage = await client.getHistory();
|
||||
const historyWithOldMessage = client.getHistory();
|
||||
expect(historyWithOldMessage.length).toBeGreaterThan(
|
||||
initialHistory.length,
|
||||
);
|
||||
@@ -319,7 +319,7 @@ describe('Gemini Client (client.ts)', () => {
|
||||
|
||||
// 3. Get the new chat instance and its history.
|
||||
const newChat = client.getChat();
|
||||
const newHistory = await client.getHistory();
|
||||
const newHistory = client.getHistory();
|
||||
|
||||
// 4. Assert that the chat instance is new and the history is reset.
|
||||
expect(newChat).not.toBe(initialChat);
|
||||
|
||||
@@ -540,7 +540,7 @@ export class GeminiClient {
|
||||
if (this.currentSequenceModel) {
|
||||
modelToUse = this.currentSequenceModel;
|
||||
} else {
|
||||
const router = await this.config.getModelRouterService();
|
||||
const router = this.config.getModelRouterService();
|
||||
const decision = await router.route(routingContext);
|
||||
modelToUse = decision.model;
|
||||
}
|
||||
|
||||
@@ -300,7 +300,7 @@ export async function initializeTelemetry(
|
||||
});
|
||||
|
||||
try {
|
||||
await sdk.start();
|
||||
sdk.start();
|
||||
if (config.getDebugMode()) {
|
||||
debugLogger.log('OpenTelemetry SDK started successfully.');
|
||||
}
|
||||
@@ -355,7 +355,7 @@ export async function shutdownTelemetry(
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await ClearcutLogger.getInstance()?.shutdown();
|
||||
ClearcutLogger.getInstance()?.shutdown();
|
||||
await sdk.shutdown();
|
||||
if (config.getDebugMode() && fromProcessExit) {
|
||||
debugLogger.log('OpenTelemetry SDK shut down successfully.');
|
||||
|
||||
@@ -149,7 +149,7 @@ describe('checkpoint utils', () => {
|
||||
] as ToolCallRequestInfo[];
|
||||
|
||||
(mockGitService.createFileSnapshot as Mock).mockResolvedValue('hash123');
|
||||
(mockGeminiClient.getHistory as Mock).mockResolvedValue([
|
||||
(mockGeminiClient.getHistory as Mock).mockReturnValue([
|
||||
{ role: 'user', parts: [] },
|
||||
]);
|
||||
|
||||
|
||||
@@ -125,7 +125,7 @@ export async function processRestorableToolCalls<HistoryType>(
|
||||
continue;
|
||||
}
|
||||
|
||||
const clientHistory = await geminiClient.getHistory();
|
||||
const clientHistory = geminiClient.getHistory();
|
||||
const checkpointData: ToolCallData<HistoryType> = {
|
||||
history,
|
||||
clientHistory,
|
||||
|
||||
@@ -237,7 +237,7 @@ describe('editCorrector', () => {
|
||||
mockGeminiClientInstance = new GeminiClient(
|
||||
mockConfigInstance,
|
||||
) as Mocked<GeminiClient>;
|
||||
mockGeminiClientInstance.getHistory = vi.fn().mockResolvedValue([]);
|
||||
mockGeminiClientInstance.getHistory = vi.fn().mockReturnValue([]);
|
||||
mockBaseLlmClientInstance = {
|
||||
generateJson: mockGenerateJson,
|
||||
config: {
|
||||
@@ -606,9 +606,7 @@ describe('editCorrector', () => {
|
||||
],
|
||||
},
|
||||
];
|
||||
(mockGeminiClientInstance.getHistory as Mock).mockResolvedValue(
|
||||
history,
|
||||
);
|
||||
(mockGeminiClientInstance.getHistory as Mock).mockReturnValue(history);
|
||||
|
||||
const result = await ensureCorrectEdit(
|
||||
filePath,
|
||||
|
||||
@@ -90,7 +90,7 @@ async function findLastEditTimestamp(
|
||||
filePath: string,
|
||||
client: GeminiClient,
|
||||
): Promise<number> {
|
||||
const history = (await client.getHistory()) ?? [];
|
||||
const history = client.getHistory() ?? [];
|
||||
|
||||
// Tools that may reference the file path in their FunctionResponse `output`.
|
||||
const toolsInResp = new Set([
|
||||
|
||||
Reference in New Issue
Block a user