mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-21 03:21:11 -07:00
refactor(core): adopt CoreToolCallStatus enum for type safety (#18998)
This commit is contained in:
@@ -18,6 +18,7 @@ import {
|
||||
type ExecutingToolCall,
|
||||
type WaitingToolCall,
|
||||
type CancelledToolCall,
|
||||
CoreToolCallStatus,
|
||||
} from '@google/gemini-cli-core';
|
||||
import { ToolCallStatus } from '../types.js';
|
||||
|
||||
@@ -28,13 +29,13 @@ describe('toolMapping', () => {
|
||||
|
||||
describe('mapCoreStatusToDisplayStatus', () => {
|
||||
it.each([
|
||||
['validating', ToolCallStatus.Pending],
|
||||
['awaiting_approval', ToolCallStatus.Confirming],
|
||||
['executing', ToolCallStatus.Executing],
|
||||
['success', ToolCallStatus.Success],
|
||||
['cancelled', ToolCallStatus.Canceled],
|
||||
['error', ToolCallStatus.Error],
|
||||
['scheduled', ToolCallStatus.Pending],
|
||||
[CoreToolCallStatus.Validating, ToolCallStatus.Pending],
|
||||
[CoreToolCallStatus.AwaitingApproval, ToolCallStatus.Confirming],
|
||||
[CoreToolCallStatus.Executing, ToolCallStatus.Executing],
|
||||
[CoreToolCallStatus.Success, ToolCallStatus.Success],
|
||||
[CoreToolCallStatus.Cancelled, ToolCallStatus.Canceled],
|
||||
[CoreToolCallStatus.Error, ToolCallStatus.Error],
|
||||
[CoreToolCallStatus.Scheduled, ToolCallStatus.Pending],
|
||||
] as const)('maps %s to %s', (coreStatus, expectedDisplayStatus) => {
|
||||
expect(mapCoreStatusToDisplayStatus(coreStatus)).toBe(
|
||||
expectedDisplayStatus,
|
||||
@@ -77,7 +78,7 @@ describe('toolMapping', () => {
|
||||
|
||||
it('handles a single tool call input', () => {
|
||||
const toolCall: ScheduledToolCall = {
|
||||
status: 'scheduled',
|
||||
status: CoreToolCallStatus.Scheduled,
|
||||
request: mockRequest,
|
||||
tool: mockTool,
|
||||
invocation: mockInvocation,
|
||||
@@ -91,13 +92,13 @@ describe('toolMapping', () => {
|
||||
|
||||
it('handles an array of tool calls', () => {
|
||||
const toolCall1: ScheduledToolCall = {
|
||||
status: 'scheduled',
|
||||
status: CoreToolCallStatus.Scheduled,
|
||||
request: mockRequest,
|
||||
tool: mockTool,
|
||||
invocation: mockInvocation,
|
||||
};
|
||||
const toolCall2: ScheduledToolCall = {
|
||||
status: 'scheduled',
|
||||
status: CoreToolCallStatus.Scheduled,
|
||||
request: { ...mockRequest, callId: 'call-2' },
|
||||
tool: mockTool,
|
||||
invocation: mockInvocation,
|
||||
@@ -111,7 +112,7 @@ describe('toolMapping', () => {
|
||||
|
||||
it('maps successful tool call properties correctly', () => {
|
||||
const toolCall: SuccessfulToolCall = {
|
||||
status: 'success',
|
||||
status: CoreToolCallStatus.Success,
|
||||
request: mockRequest,
|
||||
tool: mockTool,
|
||||
invocation: mockInvocation,
|
||||
@@ -139,7 +140,7 @@ describe('toolMapping', () => {
|
||||
|
||||
it('maps executing tool call properties correctly with live output and ptyId', () => {
|
||||
const toolCall: ExecutingToolCall = {
|
||||
status: 'executing',
|
||||
status: CoreToolCallStatus.Executing,
|
||||
request: mockRequest,
|
||||
tool: mockTool,
|
||||
invocation: mockInvocation,
|
||||
@@ -166,7 +167,7 @@ describe('toolMapping', () => {
|
||||
};
|
||||
|
||||
const toolCall: WaitingToolCall = {
|
||||
status: 'awaiting_approval',
|
||||
status: CoreToolCallStatus.AwaitingApproval,
|
||||
request: mockRequest,
|
||||
tool: mockTool,
|
||||
invocation: mockInvocation,
|
||||
@@ -193,7 +194,7 @@ describe('toolMapping', () => {
|
||||
};
|
||||
|
||||
const toolCall: WaitingToolCall = {
|
||||
status: 'awaiting_approval',
|
||||
status: CoreToolCallStatus.AwaitingApproval,
|
||||
request: mockRequest,
|
||||
tool: mockTool,
|
||||
invocation: mockInvocation,
|
||||
@@ -211,7 +212,7 @@ describe('toolMapping', () => {
|
||||
it('maps error tool call missing tool definition', () => {
|
||||
// e.g. "TOOL_NOT_REGISTERED" errors
|
||||
const toolCall: ToolCall = {
|
||||
status: 'error',
|
||||
status: CoreToolCallStatus.Error,
|
||||
request: mockRequest, // name: 'test_tool'
|
||||
response: { ...mockResponse, resultDisplay: 'Tool not found' },
|
||||
// notice: no `tool` or `invocation` defined here
|
||||
@@ -229,7 +230,7 @@ describe('toolMapping', () => {
|
||||
|
||||
it('maps cancelled tool call properties correctly', () => {
|
||||
const toolCall: CancelledToolCall = {
|
||||
status: 'cancelled',
|
||||
status: CoreToolCallStatus.Cancelled,
|
||||
request: mockRequest,
|
||||
tool: mockTool,
|
||||
invocation: mockInvocation,
|
||||
@@ -248,7 +249,7 @@ describe('toolMapping', () => {
|
||||
|
||||
it('propagates borderTop and borderBottom options correctly', () => {
|
||||
const toolCall: ScheduledToolCall = {
|
||||
status: 'scheduled',
|
||||
status: CoreToolCallStatus.Scheduled,
|
||||
request: mockRequest,
|
||||
tool: mockTool,
|
||||
invocation: mockInvocation,
|
||||
@@ -264,7 +265,7 @@ describe('toolMapping', () => {
|
||||
|
||||
it('sets resultDisplay to undefined for pre-execution statuses', () => {
|
||||
const toolCall: ScheduledToolCall = {
|
||||
status: 'scheduled',
|
||||
status: CoreToolCallStatus.Scheduled,
|
||||
request: mockRequest,
|
||||
tool: mockTool,
|
||||
invocation: mockInvocation,
|
||||
|
||||
Reference in New Issue
Block a user