feat(core,cli): enforce mandatory MessageBus injection (Phase 3 Hard Migration) (#15776)

This commit is contained in:
Abhi
2026-01-04 17:11:43 -05:00
committed by GitHub
parent 90be9c3587
commit 12c7c9cc42
57 changed files with 442 additions and 278 deletions

View File

@@ -13,10 +13,10 @@ import {
getMCPServerStatus,
getMCPDiscoveryState,
DiscoveredMCPTool,
type MessageBus,
} from '@google/gemini-cli-core';
import type { CallableTool } from '@google/genai';
import { Type } from '@google/genai';
import { MessageType } from '../types.js';
vi.mock('@google/gemini-cli-core', async (importOriginal) => {
@@ -37,6 +37,12 @@ vi.mock('@google/gemini-cli-core', async (importOriginal) => {
};
});
const mockMessageBus = {
publish: vi.fn(),
subscribe: vi.fn(),
unsubscribe: vi.fn(),
} as unknown as MessageBus;
// Helper function to create a mock DiscoveredMCPTool
const createMockMCPTool = (
name: string,
@@ -50,8 +56,14 @@ const createMockMCPTool = (
} as unknown as CallableTool,
serverName,
name,
description || `Description for ${name}`,
{ type: Type.OBJECT, properties: {} },
description || 'Mock tool description',
{ type: 'object', properties: {} },
mockMessageBus,
undefined, // trust
undefined, // nameOverride
undefined, // cliConfig
undefined, // extensionName
undefined, // extensionId
);
describe('mcpCommand', () => {

View File

@@ -54,6 +54,12 @@ describe('handleAtCommand', () => {
const getToolRegistry = vi.fn();
const mockMessageBus = {
publish: vi.fn(),
subscribe: vi.fn(),
unsubscribe: vi.fn(),
} as unknown as core.MessageBus;
mockConfig = {
getToolRegistry,
getTargetDir: () => testRootDir,
@@ -94,11 +100,12 @@ describe('handleAtCommand', () => {
getMcpClientManager: () => ({
getClient: () => undefined,
}),
getMessageBus: () => mockMessageBus,
} as unknown as Config;
const registry = new ToolRegistry(mockConfig);
registry.registerTool(new ReadManyFilesTool(mockConfig));
registry.registerTool(new GlobTool(mockConfig));
const registry = new ToolRegistry(mockConfig, mockMessageBus);
registry.registerTool(new ReadManyFilesTool(mockConfig, mockMessageBus));
registry.registerTool(new GlobTool(mockConfig, mockMessageBus));
getToolRegistry.mockReturnValue(registry);
});

View File

@@ -164,7 +164,10 @@ export async function handleAtCommand({
};
const toolRegistry = config.getToolRegistry();
const readManyFilesTool = new ReadManyFilesTool(config);
const readManyFilesTool = new ReadManyFilesTool(
config,
config.getMessageBus(),
);
const globTool = toolRegistry.getTool('glob');
if (!readManyFilesTool) {