Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions packages/cli/src/ui/commands/extensionsCommand.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ describe('extensionsCommand', () => {
let mockContext: CommandContext;
const mockDispatchExtensionState = vi.fn();
let mockExtensionLoader: unknown;
let mockReloadSkills: MockedFunction<() => Promise<void>>;
let mockReloadAgents: MockedFunction<() => Promise<void>>;

beforeEach(() => {
vi.resetAllMocks();
Expand All @@ -148,12 +150,19 @@ describe('extensionsCommand', () => {

mockGetExtensions.mockReturnValue([inactiveExt, activeExt, allExt]);
vi.mocked(open).mockClear();
mockReloadAgents = vi.fn().mockResolvedValue(undefined);
mockReloadSkills = vi.fn().mockResolvedValue(undefined);

mockContext = createMockCommandContext({
services: {
config: {
getExtensions: mockGetExtensions,
getExtensionLoader: vi.fn().mockReturnValue(mockExtensionLoader),
getWorkingDir: () => '/test/dir',
reloadSkills: mockReloadSkills,
getAgentRegistry: vi.fn().mockReturnValue({
reload: mockReloadAgents,
}),
},
},
ui: {
Expand Down Expand Up @@ -892,6 +901,27 @@ describe('extensionsCommand', () => {
type: 'RESTARTED',
payload: { name: 'ext2' },
});
expect(mockReloadSkills).toHaveBeenCalled();
expect(mockReloadAgents).toHaveBeenCalled();
});

it('handles errors during skill or agent reload', async () => {
const mockExtensions = [
{ name: 'ext1', isActive: true },
] as GeminiCLIExtension[];
mockGetExtensions.mockReturnValue(mockExtensions);
mockReloadSkills.mockRejectedValue(new Error('Failed to reload skills'));

await restartAction!(mockContext, '--all');

expect(mockRestartExtension).toHaveBeenCalledWith(mockExtensions[0]);
expect(mockReloadSkills).toHaveBeenCalled();
expect(mockContext.ui.addItem).toHaveBeenCalledWith(
expect.objectContaining({
type: MessageType.ERROR,
text: 'Failed to reload skills or agents: Failed to reload skills',
}),
);
});

it('restarts only specified active extensions', async () => {
Expand Down
12 changes: 12 additions & 0 deletions packages/cli/src/ui/commands/extensionsCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,18 @@ async function restartAction(
(result): result is PromiseRejectedResult => result.status === 'rejected',
);

if (failures.length < extensionsToRestart.length) {
try {
await context.services.config?.reloadSkills();
await context.services.config?.getAgentRegistry()?.reload();
} catch (error) {
context.ui.addItem({
type: MessageType.ERROR,
text: `Failed to reload skills or agents: ${getErrorMessage(error)}`,
});
}
}
Comment thread
NTaylorMullen marked this conversation as resolved.

if (failures.length > 0) {
const errorMessages = failures
.map((failure, index) => {
Expand Down
Loading