mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-20 16:57:46 +00:00
Sync upstream Gemini-CLI v0.8.2 (#838)
This commit is contained in:
@@ -15,7 +15,7 @@ export const DEFAULT_CONFIG_PARAMETERS: ConfigParameters = {
|
||||
debugMode: false,
|
||||
sessionId: 'test-session-id',
|
||||
proxy: undefined,
|
||||
model: 'gemini-9001-super-duper',
|
||||
model: 'qwen-9001-super-duper',
|
||||
targetDir: '/',
|
||||
cwd: '/',
|
||||
};
|
||||
|
||||
7
packages/core/src/test-utils/index.ts
Normal file
7
packages/core/src/test-utils/index.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2025 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
export * from './mock-tool.js';
|
||||
@@ -4,7 +4,6 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { vi } from 'vitest';
|
||||
import type {
|
||||
ModifiableDeclarativeTool,
|
||||
ModifyContext,
|
||||
@@ -20,6 +19,24 @@ import {
|
||||
Kind,
|
||||
} from '../tools/tools.js';
|
||||
|
||||
interface MockToolOptions {
|
||||
name: string;
|
||||
displayName?: string;
|
||||
description?: string;
|
||||
canUpdateOutput?: boolean;
|
||||
isOutputMarkdown?: boolean;
|
||||
shouldConfirmExecute?: (
|
||||
params: { [key: string]: unknown },
|
||||
signal: AbortSignal,
|
||||
) => Promise<ToolCallConfirmationDetails | false>;
|
||||
execute?: (
|
||||
params: { [key: string]: unknown },
|
||||
signal?: AbortSignal,
|
||||
updateOutput?: (output: string) => void,
|
||||
) => Promise<ToolResult>;
|
||||
params?: object;
|
||||
}
|
||||
|
||||
class MockToolInvocation extends BaseToolInvocation<
|
||||
{ [key: string]: unknown },
|
||||
ToolResult
|
||||
@@ -31,29 +48,21 @@ class MockToolInvocation extends BaseToolInvocation<
|
||||
super(params);
|
||||
}
|
||||
|
||||
async execute(_abortSignal: AbortSignal): Promise<ToolResult> {
|
||||
const result = this.tool.executeFn(this.params);
|
||||
return (
|
||||
result ?? {
|
||||
llmContent: `Tool ${this.tool.name} executed successfully.`,
|
||||
returnDisplay: `Tool ${this.tool.name} executed successfully.`,
|
||||
}
|
||||
);
|
||||
execute(
|
||||
signal: AbortSignal,
|
||||
updateOutput?: (output: string) => void,
|
||||
): Promise<ToolResult> {
|
||||
if (updateOutput) {
|
||||
return this.tool.execute(this.params, signal, updateOutput);
|
||||
} else {
|
||||
return this.tool.execute(this.params);
|
||||
}
|
||||
}
|
||||
|
||||
override async shouldConfirmExecute(
|
||||
_abortSignal: AbortSignal,
|
||||
override shouldConfirmExecute(
|
||||
abortSignal: AbortSignal,
|
||||
): Promise<ToolCallConfirmationDetails | false> {
|
||||
if (this.tool.shouldConfirm) {
|
||||
return {
|
||||
type: 'exec' as const,
|
||||
title: `Confirm ${this.tool.displayName}`,
|
||||
command: this.tool.name,
|
||||
rootCommand: this.tool.name,
|
||||
onConfirm: async () => {},
|
||||
};
|
||||
}
|
||||
return false;
|
||||
return this.tool.shouldConfirmExecute(this.params, abortSignal);
|
||||
}
|
||||
|
||||
getDescription(): string {
|
||||
@@ -68,19 +77,42 @@ export class MockTool extends BaseDeclarativeTool<
|
||||
{ [key: string]: unknown },
|
||||
ToolResult
|
||||
> {
|
||||
executeFn = vi.fn();
|
||||
shouldConfirm = false;
|
||||
shouldConfirmExecute: (
|
||||
params: { [key: string]: unknown },
|
||||
signal: AbortSignal,
|
||||
) => Promise<ToolCallConfirmationDetails | false>;
|
||||
execute: (
|
||||
params: { [key: string]: unknown },
|
||||
signal?: AbortSignal,
|
||||
updateOutput?: (output: string) => void,
|
||||
) => Promise<ToolResult>;
|
||||
|
||||
constructor(
|
||||
name = 'mock-tool',
|
||||
displayName?: string,
|
||||
description = 'A mock tool for testing.',
|
||||
params = {
|
||||
type: 'object',
|
||||
properties: { param: { type: 'string' } },
|
||||
},
|
||||
) {
|
||||
super(name, displayName ?? name, description, Kind.Other, params);
|
||||
constructor(options: MockToolOptions) {
|
||||
super(
|
||||
options.name,
|
||||
options.displayName ?? options.name,
|
||||
options.description ?? options.name,
|
||||
Kind.Other,
|
||||
options.params,
|
||||
options.isOutputMarkdown ?? false,
|
||||
options.canUpdateOutput ?? false,
|
||||
);
|
||||
|
||||
if (options.shouldConfirmExecute) {
|
||||
this.shouldConfirmExecute = options.shouldConfirmExecute;
|
||||
} else {
|
||||
this.shouldConfirmExecute = () => Promise.resolve(false);
|
||||
}
|
||||
|
||||
if (options.execute) {
|
||||
this.execute = options.execute;
|
||||
} else {
|
||||
this.execute = () =>
|
||||
Promise.resolve({
|
||||
llmContent: `Tool ${this.name} executed successfully.`,
|
||||
returnDisplay: `Tool ${this.name} executed successfully.`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
protected createInvocation(params: {
|
||||
@@ -90,6 +122,15 @@ export class MockTool extends BaseDeclarativeTool<
|
||||
}
|
||||
}
|
||||
|
||||
export const MOCK_TOOL_SHOULD_CONFIRM_EXECUTE = () =>
|
||||
Promise.resolve({
|
||||
type: 'exec' as const,
|
||||
title: 'Confirm mockTool',
|
||||
command: 'mockTool',
|
||||
rootCommand: 'mockTool',
|
||||
onConfirm: async () => {},
|
||||
});
|
||||
|
||||
export class MockModifiableToolInvocation extends BaseToolInvocation<
|
||||
Record<string, unknown>,
|
||||
ToolResult
|
||||
@@ -138,12 +179,20 @@ export class MockModifiableToolInvocation extends BaseToolInvocation<
|
||||
* Configurable mock modifiable tool for testing.
|
||||
*/
|
||||
export class MockModifiableTool
|
||||
extends MockTool
|
||||
extends BaseDeclarativeTool<Record<string, unknown>, ToolResult>
|
||||
implements ModifiableDeclarativeTool<Record<string, unknown>>
|
||||
{
|
||||
// Should be overrided in test file. Functionality will be updated in follow
|
||||
// up PR which has MockModifiableTool expect MockTool
|
||||
executeFn: (params: Record<string, unknown>) => ToolResult | undefined = () =>
|
||||
undefined;
|
||||
shouldConfirm = true;
|
||||
|
||||
constructor(name = 'mockModifiableTool') {
|
||||
super(name);
|
||||
this.shouldConfirm = true;
|
||||
super(name, name, 'A mock modifiable tool for testing.', Kind.Other, {
|
||||
type: 'object',
|
||||
properties: { param: { type: 'string' } },
|
||||
});
|
||||
}
|
||||
|
||||
getModifyContext(
|
||||
@@ -161,7 +210,7 @@ export class MockModifiableTool
|
||||
};
|
||||
}
|
||||
|
||||
protected override createInvocation(
|
||||
protected createInvocation(
|
||||
params: Record<string, unknown>,
|
||||
): ToolInvocation<Record<string, unknown>, ToolResult> {
|
||||
return new MockModifiableToolInvocation(this, params);
|
||||
Reference in New Issue
Block a user