mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-12 21:03:05 -07:00
fix(core): override toolRegistry property for sub-agent schedulers (#21766)
This commit is contained in:
@@ -19,23 +19,24 @@ vi.mock('../scheduler/scheduler.js', () => ({
|
||||
}));
|
||||
|
||||
describe('agent-scheduler', () => {
|
||||
let mockConfig: Mocked<Config>;
|
||||
let mockToolRegistry: Mocked<ToolRegistry>;
|
||||
let mockMessageBus: Mocked<MessageBus>;
|
||||
|
||||
beforeEach(() => {
|
||||
vi.mocked(Scheduler).mockClear();
|
||||
mockMessageBus = {} as Mocked<MessageBus>;
|
||||
mockToolRegistry = {
|
||||
getTool: vi.fn(),
|
||||
getMessageBus: vi.fn().mockReturnValue(mockMessageBus),
|
||||
} as unknown as Mocked<ToolRegistry>;
|
||||
mockConfig = {
|
||||
getMessageBus: vi.fn().mockReturnValue(mockMessageBus),
|
||||
toolRegistry: mockToolRegistry,
|
||||
} as unknown as Mocked<Config>;
|
||||
});
|
||||
|
||||
it('should create a scheduler with agent-specific config', async () => {
|
||||
const mockConfig = {
|
||||
getMessageBus: vi.fn().mockReturnValue(mockMessageBus),
|
||||
toolRegistry: mockToolRegistry,
|
||||
} as unknown as Mocked<Config>;
|
||||
|
||||
const requests: ToolCallRequestInfo[] = [
|
||||
{
|
||||
callId: 'call-1',
|
||||
@@ -68,8 +69,46 @@ describe('agent-scheduler', () => {
|
||||
}),
|
||||
);
|
||||
|
||||
// Verify that the scheduler's config has the overridden tool registry
|
||||
const schedulerConfig = vi.mocked(Scheduler).mock.calls[0][0].config;
|
||||
expect(schedulerConfig.toolRegistry).toBe(mockToolRegistry);
|
||||
});
|
||||
|
||||
it('should override toolRegistry getter from prototype chain', async () => {
|
||||
const mainRegistry = { _id: 'main' } as unknown as Mocked<ToolRegistry>;
|
||||
const agentRegistry = {
|
||||
_id: 'agent',
|
||||
getMessageBus: vi.fn().mockReturnValue(mockMessageBus),
|
||||
} as unknown as Mocked<ToolRegistry>;
|
||||
|
||||
const config = {
|
||||
getMessageBus: vi.fn().mockReturnValue(mockMessageBus),
|
||||
} as unknown as Mocked<Config>;
|
||||
Object.defineProperty(config, 'toolRegistry', {
|
||||
get: () => mainRegistry,
|
||||
configurable: true,
|
||||
});
|
||||
|
||||
await scheduleAgentTools(
|
||||
config as unknown as Config,
|
||||
[
|
||||
{
|
||||
callId: 'c1',
|
||||
name: 'new_page',
|
||||
args: {},
|
||||
isClientInitiated: false,
|
||||
prompt_id: 'p1',
|
||||
},
|
||||
],
|
||||
{
|
||||
schedulerId: 'browser-1',
|
||||
toolRegistry: agentRegistry as unknown as ToolRegistry,
|
||||
signal: new AbortController().signal,
|
||||
},
|
||||
);
|
||||
|
||||
const schedulerConfig = vi.mocked(Scheduler).mock.calls[0][0].config;
|
||||
expect(schedulerConfig.toolRegistry).toBe(agentRegistry);
|
||||
expect(schedulerConfig.toolRegistry).not.toBe(mainRegistry);
|
||||
expect(schedulerConfig.getToolRegistry()).toBe(agentRegistry);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user