mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-14 05:42:54 -07:00
feat(cli): improve /agents refresh logging (#26442)
This commit is contained in:
@@ -110,7 +110,15 @@ describe('agentsCommand', () => {
|
||||
});
|
||||
|
||||
it('should reload the agent registry when reload subcommand is called', async () => {
|
||||
const reloadSpy = vi.fn().mockResolvedValue(undefined);
|
||||
const reloadSpy = vi.fn().mockResolvedValue({
|
||||
totalLoaded: 3,
|
||||
localCount: 2,
|
||||
remoteCount: 1,
|
||||
newAgents: ['new-agent'],
|
||||
updatedAgents: ['updated-agent'],
|
||||
deletedAgents: ['deleted-agent'],
|
||||
errors: [],
|
||||
});
|
||||
mockConfig.getAgentRegistry = vi.fn().mockReturnValue({
|
||||
reload: reloadSpy,
|
||||
});
|
||||
@@ -120,7 +128,10 @@ describe('agentsCommand', () => {
|
||||
);
|
||||
expect(reloadCommand).toBeDefined();
|
||||
|
||||
const result = await reloadCommand!.action!(mockContext, '');
|
||||
const result = (await reloadCommand!.action!(mockContext, '')) as {
|
||||
type: 'message';
|
||||
content: string;
|
||||
};
|
||||
|
||||
expect(reloadSpy).toHaveBeenCalled();
|
||||
expect(mockContext.ui.addItem).toHaveBeenCalledWith(
|
||||
@@ -132,8 +143,42 @@ describe('agentsCommand', () => {
|
||||
expect(result).toEqual({
|
||||
type: 'message',
|
||||
messageType: 'info',
|
||||
content: 'Agents reloaded successfully',
|
||||
content: expect.stringContaining('Agents reloaded successfully:'),
|
||||
});
|
||||
expect(result.content).toContain('- Total: 3 (2 local, 1 remote)');
|
||||
expect(result.content).toContain('- New: new-agent');
|
||||
expect(result.content).toContain('- Updated: updated-agent');
|
||||
expect(result.content).toContain('- Deleted: deleted-agent');
|
||||
expect(result.content).toContain(
|
||||
'Run /agents list to see all available agents.',
|
||||
);
|
||||
});
|
||||
|
||||
it('should show "reloaded with errors" if errors occurred during reload', async () => {
|
||||
const reloadSpy = vi.fn().mockResolvedValue({
|
||||
totalLoaded: 1,
|
||||
localCount: 1,
|
||||
remoteCount: 0,
|
||||
newAgents: [],
|
||||
updatedAgents: [],
|
||||
deletedAgents: [],
|
||||
errors: ['Some error'],
|
||||
});
|
||||
mockConfig.getAgentRegistry = vi.fn().mockReturnValue({
|
||||
reload: reloadSpy,
|
||||
});
|
||||
|
||||
const reloadCommand = agentsCommand.subCommands?.find(
|
||||
(cmd) => cmd.name === 'reload',
|
||||
);
|
||||
|
||||
const result = (await reloadCommand!.action!(mockContext, '')) as {
|
||||
type: 'message';
|
||||
content: string;
|
||||
};
|
||||
|
||||
expect(result.content).toContain('Agents reloaded with errors:');
|
||||
expect(result.content).toContain('- Errors: 1 encountered during reload');
|
||||
});
|
||||
|
||||
it('should show an error if agent registry is not available during reload', async () => {
|
||||
|
||||
@@ -346,12 +346,33 @@ const agentsReloadCommand: SlashCommand = {
|
||||
text: 'Reloading agent registry...',
|
||||
});
|
||||
|
||||
await agentRegistry.reload();
|
||||
const summary = await agentRegistry.reload();
|
||||
|
||||
let content =
|
||||
summary.errors.length > 0
|
||||
? 'Agents reloaded with errors:'
|
||||
: 'Agents reloaded successfully:';
|
||||
content += `\n- Total: ${summary.totalLoaded} (${summary.localCount} local, ${summary.remoteCount} remote)`;
|
||||
|
||||
if (summary.newAgents.length > 0) {
|
||||
content += `\n- New: ${summary.newAgents.join(', ')}`;
|
||||
}
|
||||
if (summary.updatedAgents.length > 0) {
|
||||
content += `\n- Updated: ${summary.updatedAgents.join(', ')}`;
|
||||
}
|
||||
if (summary.deletedAgents.length > 0) {
|
||||
content += `\n- Deleted: ${summary.deletedAgents.join(', ')}`;
|
||||
}
|
||||
if (summary.errors.length > 0) {
|
||||
content += `\n- Errors: ${summary.errors.length} encountered during reload`;
|
||||
}
|
||||
|
||||
content += '\n\nRun /agents list to see all available agents.';
|
||||
|
||||
return {
|
||||
type: 'message',
|
||||
messageType: 'info',
|
||||
content: 'Agents reloaded successfully',
|
||||
content,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user