|
| 1 | +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; |
| 2 | +import fs from 'node:fs'; |
| 3 | +import os from 'node:os'; |
| 4 | +import path from 'node:path'; |
| 5 | + |
| 6 | +vi.mock('../../src/generated/skills.js', () => ({ |
| 7 | + SKILLS: [ |
| 8 | + { |
| 9 | + slug: 'dumplingai-cli', |
| 10 | + files: { |
| 11 | + 'SKILL.md': '# Test skill', |
| 12 | + }, |
| 13 | + }, |
| 14 | + ], |
| 15 | +})); |
| 16 | + |
| 17 | +describe('setup skill', () => { |
| 18 | + let tmpDir: string; |
| 19 | + let makeSetupSkillCommand: typeof import('../../src/commands/setup-skill.js').makeSetupSkillCommand; |
| 20 | + |
| 21 | + beforeEach(async () => { |
| 22 | + vi.resetModules(); |
| 23 | + tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'dumplingai-setup-skill-')); |
| 24 | + vi.spyOn(process.stderr, 'write').mockImplementation(() => true); |
| 25 | + ({ makeSetupSkillCommand } = await import('../../src/commands/setup-skill.js')); |
| 26 | + }); |
| 27 | + |
| 28 | + afterEach(() => { |
| 29 | + fs.rmSync(tmpDir, { recursive: true, force: true }); |
| 30 | + vi.restoreAllMocks(); |
| 31 | + }); |
| 32 | + |
| 33 | + it('installs bundled skills into the .agents skills directory when detected', async () => { |
| 34 | + fs.mkdirSync(path.join(tmpDir, '.agents'), { recursive: true }); |
| 35 | + |
| 36 | + const previousCwd = process.cwd(); |
| 37 | + process.chdir(tmpDir); |
| 38 | + |
| 39 | + try { |
| 40 | + await makeSetupSkillCommand().parseAsync(['skill'], { from: 'user' }); |
| 41 | + } finally { |
| 42 | + process.chdir(previousCwd); |
| 43 | + } |
| 44 | + |
| 45 | + const installedSkill = path.join(tmpDir, '.agents', 'skills', 'dumplingai-cli', 'SKILL.md'); |
| 46 | + expect(fs.existsSync(installedSkill)).toBe(true); |
| 47 | + }); |
| 48 | + |
| 49 | + it('includes .agents in the no-environment hint', async () => { |
| 50 | + const stderrWrite = vi.spyOn(process.stderr, 'write'); |
| 51 | + const previousCwd = process.cwd(); |
| 52 | + process.chdir(tmpDir); |
| 53 | + |
| 54 | + try { |
| 55 | + await makeSetupSkillCommand().parseAsync(['skill'], { from: 'user' }); |
| 56 | + } finally { |
| 57 | + process.chdir(previousCwd); |
| 58 | + } |
| 59 | + |
| 60 | + expect(stderrWrite).toHaveBeenCalledWith( |
| 61 | + expect.stringContaining('No agent environments detected (.claude, .cursor, .codex, .agents).'), |
| 62 | + ); |
| 63 | + }); |
| 64 | +}); |
0 commit comments