Skip to content

Commit bd03e84

Browse files
CodebuffAICodebuffAI
authored andcommitted
Fix load skills test coverage
1 parent 2473fe4 commit bd03e84

File tree

1 file changed

+41
-10
lines changed

1 file changed

+41
-10
lines changed

sdk/src/__tests__/load-skills.test.ts

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { beforeEach, afterEach, describe, expect, mock, spyOn, test } from 'bun:test'
1+
import { afterEach, beforeEach, describe, expect, mock, spyOn, test } from 'bun:test'
22
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'fs'
33
import os from 'os'
44
import path from 'path'
@@ -98,6 +98,31 @@ describe('loadSkills', () => {
9898
)
9999
})
100100

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+
101126
test('applies override precedence as project over global and .agents over .claude', async () => {
102127
writeSkill({
103128
skillsRoot: path.join(homeDir, '.claude', 'skills'),
@@ -140,19 +165,23 @@ describe('loadSkills', () => {
140165
description: 'project claude',
141166
})
142167

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 })
148179

149180
const malformedDir = path.join(skillsRoot, 'malformed-frontmatter')
150181
mkdirSync(malformedDir, { recursive: true })
151182
writeFileSync(
152183
path.join(malformedDir, 'SKILL.md'),
153-
['---', 'name malformed-frontmatter', 'description: missing colon', '---'].join(
154-
'\n',
155-
),
184+
['---', '{invalid yaml: [unclosed', '---'].join('\n'),
156185
'utf8',
157186
)
158187

@@ -195,7 +224,9 @@ describe('loadSkills', () => {
195224
expect.stringContaining('Invalid frontmatter in skill file'),
196225
)
197226
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+
),
199230
)
200231
expect(consoleWarn).toHaveBeenCalledWith(
201232
`Skipping invalid skill directory name: ${tooLongName}`,

0 commit comments

Comments
 (0)