|
1 | | -import { beforeEach, afterEach, describe, expect, mock, spyOn, test } from 'bun:test' |
| 1 | +import { afterEach, beforeEach, describe, expect, mock, spyOn, test } from 'bun:test' |
2 | 2 | import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'fs' |
3 | 3 | import os from 'os' |
4 | 4 | import path from 'path' |
@@ -98,6 +98,31 @@ describe('loadSkills', () => { |
98 | 98 | ) |
99 | 99 | }) |
100 | 100 |
|
| 101 | + test('loads skills from an explicit skillsPath only', async () => { |
| 102 | + const explicitSkillsDir = path.join(tempRoot, 'custom-skills') |
| 103 | + |
| 104 | + writeSkill({ |
| 105 | + skillsRoot: explicitSkillsDir, |
| 106 | + skillDirName: 'custom-skill', |
| 107 | + description: 'Loaded from explicit skillsPath', |
| 108 | + }) |
| 109 | + writeSkill({ |
| 110 | + skillsRoot: path.join(projectDir, '.agents', 'skills'), |
| 111 | + skillDirName: 'project-skill', |
| 112 | + description: 'Should be ignored when skillsPath is set', |
| 113 | + }) |
| 114 | + |
| 115 | + const skills = await loadSkills({ |
| 116 | + cwd: projectDir, |
| 117 | + skillsPath: explicitSkillsDir, |
| 118 | + }) |
| 119 | + |
| 120 | + expect(Object.keys(skills)).toEqual(['custom-skill']) |
| 121 | + expect(skills['custom-skill']?.description).toBe( |
| 122 | + 'Loaded from explicit skillsPath', |
| 123 | + ) |
| 124 | + }) |
| 125 | + |
101 | 126 | test('applies override precedence as project over global and .agents over .claude', async () => { |
102 | 127 | writeSkill({ |
103 | 128 | skillsRoot: path.join(homeDir, '.claude', 'skills'), |
@@ -140,19 +165,23 @@ describe('loadSkills', () => { |
140 | 165 | description: 'project claude', |
141 | 166 | }) |
142 | 167 |
|
143 | | - writeFileSync( |
144 | | - path.join(malformedDir, 'SKILL.md'), |
145 | | - ['---', '{invalid yaml: [unclosed', '---'].join('\n'), |
146 | | - 'utf8', |
147 | | - ) |
| 168 | + const skills = await loadSkills({ cwd: projectDir }) |
| 169 | + |
| 170 | + expect(skills['priority-skill']?.description).toBe('project claude') |
| 171 | + }) |
| 172 | + |
| 173 | + test('skips invalid skill directories and malformed skill definitions', async () => { |
| 174 | + const skillsRoot = path.join(projectDir, '.agents', 'skills') |
| 175 | + const consoleError = spyOn(console, 'error').mockImplementation(() => {}) |
| 176 | + const consoleWarn = spyOn(console, 'warn').mockImplementation(() => {}) |
| 177 | + |
| 178 | + mkdirSync(path.join(skillsRoot, 'missing-skill-file'), { recursive: true }) |
148 | 179 |
|
149 | 180 | const malformedDir = path.join(skillsRoot, 'malformed-frontmatter') |
150 | 181 | mkdirSync(malformedDir, { recursive: true }) |
151 | 182 | writeFileSync( |
152 | 183 | path.join(malformedDir, 'SKILL.md'), |
153 | | - ['---', 'name malformed-frontmatter', 'description: missing colon', '---'].join( |
154 | | - '\n', |
155 | | - ), |
| 184 | + ['---', '{invalid yaml: [unclosed', '---'].join('\n'), |
156 | 185 | 'utf8', |
157 | 186 | ) |
158 | 187 |
|
@@ -195,7 +224,9 @@ describe('loadSkills', () => { |
195 | 224 | expect.stringContaining('Invalid frontmatter in skill file'), |
196 | 225 | ) |
197 | 226 | expect(consoleError).toHaveBeenCalledWith( |
198 | | - expect.stringContaining("Skill name 'different-name' does not match directory name 'mismatch-dir'"), |
| 227 | + expect.stringContaining( |
| 228 | + "Skill name 'different-name' does not match directory name 'mismatch-dir'", |
| 229 | + ), |
199 | 230 | ) |
200 | 231 | expect(consoleWarn).toHaveBeenCalledWith( |
201 | 232 | `Skipping invalid skill directory name: ${tooLongName}`, |
|
0 commit comments