mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-25 04:24:51 -07:00
refactor(core): adopt CoreToolCallStatus enum for type safety (#18998)
This commit is contained in:
@@ -11,6 +11,7 @@ import type { ToolResult } from '../tools/tools.js';
|
||||
import { makeFakeConfig } from '../test-utils/config.js';
|
||||
import { MockTool } from '../test-utils/mock-tool.js';
|
||||
import type { ScheduledToolCall } from './types.js';
|
||||
import { CoreToolCallStatus } from './types.js';
|
||||
import type { AnyToolInvocation } from '../index.js';
|
||||
import { SHELL_TOOL_NAME } from '../tools/tool-names.js';
|
||||
import * as fileUtils from '../utils/fileUtils.js';
|
||||
@@ -71,7 +72,7 @@ describe('ToolExecutor', () => {
|
||||
} as ToolResult);
|
||||
|
||||
const scheduledCall: ScheduledToolCall = {
|
||||
status: 'scheduled',
|
||||
status: CoreToolCallStatus.Scheduled,
|
||||
request: {
|
||||
callId: 'call-1',
|
||||
name: 'testTool',
|
||||
@@ -91,8 +92,8 @@ describe('ToolExecutor', () => {
|
||||
onUpdateToolCall,
|
||||
});
|
||||
|
||||
expect(result.status).toBe('success');
|
||||
if (result.status === 'success') {
|
||||
expect(result.status).toBe(CoreToolCallStatus.Success);
|
||||
if (result.status === CoreToolCallStatus.Success) {
|
||||
const response = result.response.responseParts[0]?.functionResponse
|
||||
?.response as Record<string, unknown>;
|
||||
expect(response).toEqual({ output: 'Tool output' });
|
||||
@@ -111,7 +112,7 @@ describe('ToolExecutor', () => {
|
||||
);
|
||||
|
||||
const scheduledCall: ScheduledToolCall = {
|
||||
status: 'scheduled',
|
||||
status: CoreToolCallStatus.Scheduled,
|
||||
request: {
|
||||
callId: 'call-2',
|
||||
name: 'failTool',
|
||||
@@ -130,8 +131,8 @@ describe('ToolExecutor', () => {
|
||||
onUpdateToolCall: vi.fn(),
|
||||
});
|
||||
|
||||
expect(result.status).toBe('error');
|
||||
if (result.status === 'error') {
|
||||
expect(result.status).toBe(CoreToolCallStatus.Error);
|
||||
if (result.status === CoreToolCallStatus.Error) {
|
||||
expect(result.response.error?.message).toBe('Tool Failed');
|
||||
}
|
||||
});
|
||||
@@ -151,7 +152,7 @@ describe('ToolExecutor', () => {
|
||||
);
|
||||
|
||||
const scheduledCall: ScheduledToolCall = {
|
||||
status: 'scheduled',
|
||||
status: CoreToolCallStatus.Scheduled,
|
||||
request: {
|
||||
callId: 'call-3',
|
||||
name: 'slowTool',
|
||||
@@ -174,7 +175,7 @@ describe('ToolExecutor', () => {
|
||||
controller.abort();
|
||||
const result = await promise;
|
||||
|
||||
expect(result.status).toBe('cancelled');
|
||||
expect(result.status).toBe(CoreToolCallStatus.Cancelled);
|
||||
});
|
||||
|
||||
it('should truncate large shell output', async () => {
|
||||
@@ -193,7 +194,7 @@ describe('ToolExecutor', () => {
|
||||
});
|
||||
|
||||
const scheduledCall: ScheduledToolCall = {
|
||||
status: 'scheduled',
|
||||
status: CoreToolCallStatus.Scheduled,
|
||||
request: {
|
||||
callId: 'call-trunc',
|
||||
name: SHELL_TOOL_NAME,
|
||||
@@ -228,8 +229,8 @@ describe('ToolExecutor', () => {
|
||||
10, // threshold (maxChars)
|
||||
);
|
||||
|
||||
expect(result.status).toBe('success');
|
||||
if (result.status === 'success') {
|
||||
expect(result.status).toBe(CoreToolCallStatus.Success);
|
||||
if (result.status === CoreToolCallStatus.Success) {
|
||||
const response = result.response.responseParts[0]?.functionResponse
|
||||
?.response as Record<string, unknown>;
|
||||
// The content should be the *truncated* version returned by the mock formatTruncatedToolOutput
|
||||
@@ -262,7 +263,7 @@ describe('ToolExecutor', () => {
|
||||
);
|
||||
|
||||
const scheduledCall: ScheduledToolCall = {
|
||||
status: 'scheduled',
|
||||
status: CoreToolCallStatus.Scheduled,
|
||||
request: {
|
||||
callId: 'call-pid',
|
||||
name: SHELL_TOOL_NAME,
|
||||
@@ -287,7 +288,7 @@ describe('ToolExecutor', () => {
|
||||
// 4. Verify PID was reported
|
||||
expect(onUpdateToolCall).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
status: 'executing',
|
||||
status: CoreToolCallStatus.Executing,
|
||||
pid: testPid,
|
||||
}),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user