mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-20 11:00:40 -07:00
Clean up dead code (#17443)
This commit is contained in:
committed by
GitHub
parent
84e882770b
commit
80e1fa198f
@@ -6,12 +6,7 @@
|
||||
|
||||
import { vi } from 'vitest';
|
||||
import type { MessageBus } from '../confirmation-bus/message-bus.js';
|
||||
import {
|
||||
MessageBusType,
|
||||
type Message,
|
||||
type HookExecutionRequest,
|
||||
type HookExecutionResponse,
|
||||
} from '../confirmation-bus/types.js';
|
||||
import { MessageBusType, type Message } from '../confirmation-bus/types.js';
|
||||
|
||||
/**
|
||||
* Mock MessageBus for testing hook execution through MessageBus
|
||||
@@ -22,8 +17,6 @@ export class MockMessageBus {
|
||||
Set<(message: Message) => void>
|
||||
>();
|
||||
publishedMessages: Message[] = [];
|
||||
hookRequests: HookExecutionRequest[] = [];
|
||||
hookResponses: HookExecutionResponse[] = [];
|
||||
defaultToolDecision: 'allow' | 'deny' | 'ask_user' = 'allow';
|
||||
|
||||
/**
|
||||
@@ -32,26 +25,6 @@ export class MockMessageBus {
|
||||
publish = vi.fn((message: Message) => {
|
||||
this.publishedMessages.push(message);
|
||||
|
||||
// Capture hook-specific messages
|
||||
if (message.type === MessageBusType.HOOK_EXECUTION_REQUEST) {
|
||||
this.hookRequests.push(message);
|
||||
|
||||
// Auto-respond with success for testing
|
||||
const response: HookExecutionResponse = {
|
||||
type: MessageBusType.HOOK_EXECUTION_RESPONSE,
|
||||
correlationId: message.correlationId,
|
||||
success: true,
|
||||
output: {
|
||||
decision: 'allow',
|
||||
reason: 'Mock hook execution successful',
|
||||
},
|
||||
};
|
||||
this.hookResponses.push(response);
|
||||
|
||||
// Emit response to subscribers
|
||||
this.emit(MessageBusType.HOOK_EXECUTION_RESPONSE, response);
|
||||
}
|
||||
|
||||
// Handle tool confirmation requests
|
||||
if (message.type === MessageBusType.TOOL_CONFIRMATION_REQUEST) {
|
||||
if (this.defaultToolDecision === 'allow') {
|
||||
@@ -115,78 +88,13 @@ export class MockMessageBus {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Manually trigger a hook response (for testing custom scenarios)
|
||||
*/
|
||||
triggerHookResponse(
|
||||
correlationId: string,
|
||||
success: boolean,
|
||||
output?: Record<string, unknown>,
|
||||
error?: Error,
|
||||
) {
|
||||
const response: HookExecutionResponse = {
|
||||
type: MessageBusType.HOOK_EXECUTION_RESPONSE,
|
||||
correlationId,
|
||||
success,
|
||||
output,
|
||||
error,
|
||||
};
|
||||
this.hookResponses.push(response);
|
||||
this.emit(MessageBusType.HOOK_EXECUTION_RESPONSE, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last hook request published
|
||||
*/
|
||||
getLastHookRequest(): HookExecutionRequest | undefined {
|
||||
return this.hookRequests[this.hookRequests.length - 1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all hook requests for a specific event
|
||||
*/
|
||||
getHookRequestsForEvent(eventName: string): HookExecutionRequest[] {
|
||||
return this.hookRequests.filter((req) => req.eventName === eventName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all captured messages (for test isolation)
|
||||
*/
|
||||
clear() {
|
||||
this.publishedMessages = [];
|
||||
this.hookRequests = [];
|
||||
this.hookResponses = [];
|
||||
this.subscriptions.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that a hook execution request was published
|
||||
*/
|
||||
expectHookRequest(
|
||||
eventName: string,
|
||||
input?: Partial<Record<string, unknown>>,
|
||||
) {
|
||||
const request = this.hookRequests.find(
|
||||
(req) => req.eventName === eventName,
|
||||
);
|
||||
if (!request) {
|
||||
throw new Error(
|
||||
`Expected hook request for event "${eventName}" but none was found`,
|
||||
);
|
||||
}
|
||||
|
||||
if (input) {
|
||||
Object.entries(input).forEach(([key, value]) => {
|
||||
if (request.input[key] !== value) {
|
||||
throw new Error(
|
||||
`Expected hook input.${key} to be ${JSON.stringify(value)} but got ${JSON.stringify(request.input[key])}`,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return request;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user