summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts
diff options
context:
space:
mode:
authorEddie Santos <[email protected]>2025-06-04 14:01:38 -0700
committerGitHub <[email protected]>2025-06-04 14:01:38 -0700
commitd99d132cdfdfeb3d06118cb1787406f8eac4434a (patch)
tree39ded9d58f0fcf38c2bab89d972b4c8b8a9360f8 /packages/cli/src/ui/hooks/slashCommandProcessor.test.ts
parentfdc8bd8ed9ecab675f2eb0f52ec9c0263d45876b (diff)
Add `/tools` slash command to view available tools (#752)
Diffstat (limited to 'packages/cli/src/ui/hooks/slashCommandProcessor.test.ts')
-rw-r--r--packages/cli/src/ui/hooks/slashCommandProcessor.test.ts98
1 files changed, 98 insertions, 0 deletions
diff --git a/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts b/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts
index 747e09de..a3babddf 100644
--- a/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts
+++ b/packages/cli/src/ui/hooks/slashCommandProcessor.test.ts
@@ -329,4 +329,102 @@ Add any other context about the problem here.
expect(commandResult).toBe(true);
});
});
+
+ describe('/tools command', () => {
+ it('should show an error if tool registry is not available', async () => {
+ mockConfig = {
+ ...mockConfig,
+ getToolRegistry: vi.fn().mockResolvedValue(undefined),
+ } as unknown as Config;
+ const { handleSlashCommand } = getProcessor();
+ let commandResult: SlashCommandActionReturn | boolean = false;
+ await act(async () => {
+ commandResult = handleSlashCommand('/tools');
+ });
+
+ expect(mockAddItem).toHaveBeenNthCalledWith(
+ 2,
+ expect.objectContaining({
+ type: MessageType.ERROR,
+ text: 'Could not retrieve tools.',
+ }),
+ expect.any(Number),
+ );
+ expect(commandResult).toBe(true);
+ });
+
+ it('should show an error if getAllTools returns undefined', async () => {
+ mockConfig = {
+ ...mockConfig,
+ getToolRegistry: vi.fn().mockResolvedValue({
+ getAllTools: vi.fn().mockReturnValue(undefined),
+ }),
+ } as unknown as Config;
+ const { handleSlashCommand } = getProcessor();
+ let commandResult: SlashCommandActionReturn | boolean = false;
+ await act(async () => {
+ commandResult = handleSlashCommand('/tools');
+ });
+
+ expect(mockAddItem).toHaveBeenNthCalledWith(
+ 2,
+ expect.objectContaining({
+ type: MessageType.ERROR,
+ text: 'Could not retrieve tools.',
+ }),
+ expect.any(Number),
+ );
+ expect(commandResult).toBe(true);
+ });
+
+ it('should display available tools when tools are found', async () => {
+ const mockTools = [{ name: 'tool1' }, { name: 'tool2' }];
+ mockConfig = {
+ ...mockConfig,
+ getToolRegistry: vi.fn().mockResolvedValue({
+ getAllTools: vi.fn().mockReturnValue(mockTools),
+ }),
+ } as unknown as Config;
+ const { handleSlashCommand } = getProcessor();
+ let commandResult: SlashCommandActionReturn | boolean = false;
+ await act(async () => {
+ commandResult = handleSlashCommand('/tools');
+ });
+
+ expect(mockAddItem).toHaveBeenNthCalledWith(
+ 2,
+ expect.objectContaining({
+ type: MessageType.INFO,
+ text: 'Available tools:\n\ntool1\ntool2',
+ }),
+ expect.any(Number),
+ );
+ expect(commandResult).toBe(true);
+ });
+
+ it('should display a message when no tools are available', async () => {
+ const mockTools: unknown[] = [];
+ mockConfig = {
+ ...mockConfig,
+ getToolRegistry: vi.fn().mockResolvedValue({
+ getAllTools: vi.fn().mockReturnValue(mockTools),
+ }),
+ } as unknown as Config;
+ const { handleSlashCommand } = getProcessor();
+ let commandResult: SlashCommandActionReturn | boolean = false;
+ await act(async () => {
+ commandResult = handleSlashCommand('/tools');
+ });
+
+ expect(mockAddItem).toHaveBeenNthCalledWith(
+ 2,
+ expect.objectContaining({
+ type: MessageType.INFO,
+ text: 'Available tools:\n\n',
+ }),
+ expect.any(Number),
+ );
+ expect(commandResult).toBe(true);
+ });
+ });
});