|
| 1 | +import path from 'node:path' |
| 2 | +import { describe, expect, it } from '@rstest/core' |
| 3 | +import { |
| 4 | + cleanupTempProject, |
| 5 | + createSkillSource, |
| 6 | + createTempProject, |
| 7 | + formatProjectTerminalSnapshot, |
| 8 | + isSymlink, |
| 9 | + pathExists, |
| 10 | + readJson, |
| 11 | + runSpm, |
| 12 | +} from '../helpers/cli' |
| 13 | + |
| 14 | +describe('spm add e2e', () => { |
| 15 | + it('lists skills from a local source without writing a manifest', () => { |
| 16 | + const project = createTempProject('add-list') |
| 17 | + |
| 18 | + try { |
| 19 | + createSkillSource(project, 'listed-skill', 'Listed skill') |
| 20 | + |
| 21 | + const result = runSpm(['add', './skill-source', '--list'], { cwd: project }) |
| 22 | + |
| 23 | + expect(result.status).toBe(0) |
| 24 | + expect(pathExists(path.join(project, 'skills.json'))).toBe(false) |
| 25 | + expect(formatProjectTerminalSnapshot(result, project)).toMatchSnapshot() |
| 26 | + } finally { |
| 27 | + cleanupTempProject(project) |
| 28 | + } |
| 29 | + }) |
| 30 | + |
| 31 | + it('adds, installs, and links a selected local skill for an agent', () => { |
| 32 | + const project = createTempProject('add-agent') |
| 33 | + |
| 34 | + try { |
| 35 | + createSkillSource(project, 'agent-skill', 'Agent skill') |
| 36 | + |
| 37 | + const result = runSpm( |
| 38 | + ['add', './skill-source', '--skill', 'agent-skill', '--agent', 'claude-code', '-y'], |
| 39 | + { |
| 40 | + cwd: project, |
| 41 | + }, |
| 42 | + ) |
| 43 | + const manifest = readJson<{ skills: Record<string, string>; linkTargets: string[] }>( |
| 44 | + path.join(project, 'skills.json'), |
| 45 | + ) |
| 46 | + |
| 47 | + expect(result.status).toBe(0) |
| 48 | + expect(manifest.skills['agent-skill'].startsWith('link:')).toBe(true) |
| 49 | + expect(manifest.skills['agent-skill'].replace(/\\/g, '/')).toContain( |
| 50 | + '/skill-source/skills/agent-skill', |
| 51 | + ) |
| 52 | + expect(manifest.linkTargets).toEqual(['.claude/skills']) |
| 53 | + expect(pathExists(path.join(project, '.agents/skills/agent-skill/SKILL.md'))).toBe(true) |
| 54 | + expect(isSymlink(path.join(project, '.claude/skills/agent-skill'))).toBe(true) |
| 55 | + expect(formatProjectTerminalSnapshot(result, project)).toMatchSnapshot() |
| 56 | + } finally { |
| 57 | + cleanupTempProject(project) |
| 58 | + } |
| 59 | + }) |
| 60 | +}) |
0 commit comments