|
| 1 | +import { describe, it, expect, vi, beforeEach } from 'vitest'; |
| 2 | +import { ListSkillsTool } from './list-skills.js'; |
| 3 | +import { Config } from '../config/config.js'; |
| 4 | +import { SkillsContextBuilder } from '../skills/skills-context-builder.js'; |
| 5 | + |
| 6 | +vi.mock('../skills/skills-context-builder.js'); |
| 7 | +vi.mock('../config/config.js'); |
| 8 | + |
| 9 | +describe('ListSkillsTool', () => { |
| 10 | + let tool: ListSkillsTool; |
| 11 | + let mockConfig: any; |
| 12 | + let mockContextBuilder: any; |
| 13 | + |
| 14 | + beforeEach(() => { |
| 15 | + mockConfig = { |
| 16 | + getProjectRoot: vi.fn().mockReturnValue('/mock/root'), |
| 17 | + }; |
| 18 | + |
| 19 | + mockContextBuilder = { |
| 20 | + listSkills: vi.fn(), |
| 21 | + }; |
| 22 | + |
| 23 | + (SkillsContextBuilder as any).mockImplementation(() => mockContextBuilder); |
| 24 | + |
| 25 | + tool = new ListSkillsTool(mockConfig as any); |
| 26 | + }); |
| 27 | + |
| 28 | + it('should return a specific message when no skills are found without filters', async () => { |
| 29 | + mockContextBuilder.listSkills.mockReturnValue([]); |
| 30 | + |
| 31 | + const result = await tool.execute({}, new AbortController().signal); |
| 32 | + |
| 33 | + expect(result.llmContent).toBe('No skills are currently installed.'); |
| 34 | + expect(result.returnDisplay).toBe('No skills found'); |
| 35 | + }); |
| 36 | + |
| 37 | + it('should return a helpful message when no skills match the filter', async () => { |
| 38 | + mockContextBuilder.listSkills.mockReturnValue([ |
| 39 | + { id: 's1', marketplaceId: 'm1', pluginId: 'p1', name: 'skill1' } |
| 40 | + ]); |
| 41 | + |
| 42 | + const result = await tool.execute({ marketplaceId: 'non-existent' }, new AbortController().signal); |
| 43 | + |
| 44 | + expect(result.llmContent).toContain('No skills are currently installed or match the filter criteria'); |
| 45 | + expect(result.llmContent).toContain('Try calling this tool without any arguments'); |
| 46 | + expect(result.returnDisplay).toBe('No skills found'); |
| 47 | + }); |
| 48 | + |
| 49 | + it('should list matching skills when filters are applied', async () => { |
| 50 | + const skills = [ |
| 51 | + { id: 's1', marketplaceId: 'm1', pluginId: 'p1', name: 'skill1', description: 'desc1', path: 'path1', skillMdPath: 'md1' }, |
| 52 | + { id: 's2', marketplaceId: 'm2', pluginId: 'p2', name: 'skill2', description: 'desc2', path: 'path2', skillMdPath: 'md2' } |
| 53 | + ]; |
| 54 | + mockContextBuilder.listSkills.mockReturnValue(skills); |
| 55 | + |
| 56 | + const result = await tool.execute({ marketplaceId: 'm1' }, new AbortController().signal); |
| 57 | + |
| 58 | + expect(result.llmContent).toContain('Found 1 skill(s)'); |
| 59 | + expect(result.llmContent).toContain('skill1'); |
| 60 | + expect(result.llmContent).not.toContain('skill2'); |
| 61 | + expect(result.returnDisplay).toBe('Found 1 skill(s)'); |
| 62 | + }); |
| 63 | +}); |
0 commit comments