|
| 1 | +/** |
| 2 | + * @vitest-environment node |
| 3 | + */ |
| 4 | + |
| 5 | +import { beforeEach, describe, expect, it, vi } from 'vitest' |
| 6 | +import type { ChatContext } from '@/stores/panel' |
| 7 | + |
| 8 | +const { getSkillById } = vi.hoisted(() => ({ getSkillById: vi.fn() })) |
| 9 | + |
| 10 | +vi.mock('@sim/db', () => ({ db: {} })) |
| 11 | +vi.mock('@sim/db/schema', () => ({ document: {}, knowledgeBase: {} })) |
| 12 | +vi.mock('@/lib/workflows/skills/operations', () => ({ getSkillById })) |
| 13 | + |
| 14 | +import { processContextsServer } from './process-contents' |
| 15 | + |
| 16 | +describe('processContextsServer - skill contexts', () => { |
| 17 | + beforeEach(() => { |
| 18 | + vi.clearAllMocks() |
| 19 | + }) |
| 20 | + |
| 21 | + it('resolves a tagged skill to full content + encoded VFS path', async () => { |
| 22 | + getSkillById.mockResolvedValue({ |
| 23 | + id: 'sk-1', |
| 24 | + name: 'My Skill — PostHog', |
| 25 | + description: 'desc', |
| 26 | + content: '# My Skill\n\nDo the thing.', |
| 27 | + }) |
| 28 | + |
| 29 | + const result = await processContextsServer( |
| 30 | + [{ kind: 'skill', skillId: 'sk-1', label: 'My Skill — PostHog' } as ChatContext], |
| 31 | + 'user-1', |
| 32 | + 'hello', |
| 33 | + 'ws-1' |
| 34 | + ) |
| 35 | + |
| 36 | + expect(getSkillById).toHaveBeenCalledWith({ skillId: 'sk-1', workspaceId: 'ws-1' }) |
| 37 | + expect(result).toEqual([ |
| 38 | + { |
| 39 | + type: 'skill', |
| 40 | + tag: '@My Skill — PostHog', |
| 41 | + content: '# My Skill\n\nDo the thing.', |
| 42 | + path: 'agent/skills/My%20Skill%20%E2%80%94%20PostHog.json', |
| 43 | + }, |
| 44 | + ]) |
| 45 | + }) |
| 46 | + |
| 47 | + it('drops a skill that does not resolve (unknown or cross-workspace)', async () => { |
| 48 | + getSkillById.mockResolvedValue(null) |
| 49 | + |
| 50 | + const result = await processContextsServer( |
| 51 | + [{ kind: 'skill', skillId: 'missing', label: 'x' } as ChatContext], |
| 52 | + 'user-1', |
| 53 | + 'hello', |
| 54 | + 'ws-1' |
| 55 | + ) |
| 56 | + |
| 57 | + expect(result).toEqual([]) |
| 58 | + }) |
| 59 | + |
| 60 | + it('drops a skill when no workspace is in scope', async () => { |
| 61 | + const result = await processContextsServer( |
| 62 | + [{ kind: 'skill', skillId: 'sk-1', label: 'x' } as ChatContext], |
| 63 | + 'user-1', |
| 64 | + 'hello', |
| 65 | + undefined |
| 66 | + ) |
| 67 | + |
| 68 | + expect(getSkillById).not.toHaveBeenCalled() |
| 69 | + expect(result).toEqual([]) |
| 70 | + }) |
| 71 | +}) |
0 commit comments