@@ -109,6 +109,8 @@ vi.mock("../../../i18n", () => ({
109109 } ,
110110} ) )
111111
112+ import matter from "gray-matter"
113+
112114import { SkillsManager } from "../SkillsManager"
113115import { ClineProvider } from "../../../core/webview/ClineProvider"
114116
@@ -391,6 +393,105 @@ description: Name doesn't match directory
391393 expect ( skills ) . toHaveLength ( 0 )
392394 } )
393395
396+ it ( "should skip skills with invalid YAML frontmatter and log the real cause (issue #859)" , async ( ) => {
397+ const badSkillDir = p ( globalSkillsDir , "test-skill" )
398+ const badSkillMd = p ( badSkillDir , "SKILL.md" )
399+
400+ mockDirectoryExists . mockImplementation ( async ( dir : string ) => {
401+ return dir === globalSkillsDir
402+ } )
403+ mockRealpath . mockImplementation ( async ( pathArg : string ) => pathArg )
404+ mockReaddir . mockImplementation ( async ( dir : string ) => {
405+ return dir === globalSkillsDir ? [ "test-skill" ] : [ ]
406+ } )
407+ mockStat . mockImplementation ( async ( pathArg : string ) => {
408+ if ( pathArg === badSkillDir ) {
409+ return { isDirectory : ( ) => true }
410+ }
411+ throw new Error ( "Not found" )
412+ } )
413+ mockFileExists . mockImplementation ( async ( file : string ) => file === badSkillMd )
414+ mockReadFile . mockImplementation ( async ( file : string ) => {
415+ if ( file === badSkillMd ) {
416+ return `---
417+ name: test-skill
418+ description: Use when implementing features. Triggers on: "TDD", "test-driven development"
419+ ---
420+
421+ # Test Skill
422+
423+ Instructions here.`
424+ }
425+ throw new Error ( "File not found" )
426+ } )
427+
428+ const consoleErrorSpy = vi . spyOn ( console , "error" ) . mockImplementation ( ( ) => { } )
429+
430+ try {
431+ await skillsManager . discoverSkills ( )
432+
433+ // The skill is skipped...
434+ expect ( skillsManager . getAllSkills ( ) ) . toHaveLength ( 0 )
435+
436+ // ...and the real cause (a YAML syntax error) is reported instead
437+ // of the misleading "missing required 'name' field" message.
438+ const logged = consoleErrorSpy . mock . calls . map ( ( call ) => call . join ( " " ) )
439+ expect ( logged . some ( ( line ) => line . includes ( "invalid YAML frontmatter" ) ) ) . toBe ( true )
440+ expect ( logged . some ( ( line ) => line . includes ( "missing required 'name' field" ) ) ) . toBe ( false )
441+ // The unescaped-double-quotes hint points at the exact problem.
442+ expect ( logged . some ( ( line ) => line . includes ( "unescaped double quotes" ) ) ) . toBe ( true )
443+ } finally {
444+ consoleErrorSpy . mockRestore ( )
445+ }
446+ } )
447+
448+ it ( "should log a distinct YAML error for other malformed frontmatter (no quote hint)" , async ( ) => {
449+ const badSkillDir = p ( globalSkillsDir , "broken-skill" )
450+ const badSkillMd = p ( badSkillDir , "SKILL.md" )
451+
452+ mockDirectoryExists . mockImplementation ( async ( dir : string ) => {
453+ return dir === globalSkillsDir
454+ } )
455+ mockRealpath . mockImplementation ( async ( pathArg : string ) => pathArg )
456+ mockReaddir . mockImplementation ( async ( dir : string ) => {
457+ return dir === globalSkillsDir ? [ "broken-skill" ] : [ ]
458+ } )
459+ mockStat . mockImplementation ( async ( pathArg : string ) => {
460+ if ( pathArg === badSkillDir ) {
461+ return { isDirectory : ( ) => true }
462+ }
463+ throw new Error ( "Not found" )
464+ } )
465+ mockFileExists . mockImplementation ( async ( file : string ) => file === badSkillMd )
466+ mockReadFile . mockImplementation ( async ( file : string ) => {
467+ if ( file === badSkillMd ) {
468+ return `---
469+ name broken-skill
470+ description: Missing colon makes this invalid YAML
471+ ---
472+
473+ # Broken skill`
474+ }
475+ throw new Error ( "File not found" )
476+ } )
477+
478+ const consoleErrorSpy = vi . spyOn ( console , "error" ) . mockImplementation ( ( ) => { } )
479+
480+ try {
481+ await skillsManager . discoverSkills ( )
482+
483+ expect ( skillsManager . getAllSkills ( ) ) . toHaveLength ( 0 )
484+
485+ const logged = consoleErrorSpy . mock . calls . map ( ( call ) => call . join ( " " ) )
486+ expect ( logged . some ( ( line ) => line . includes ( "invalid YAML frontmatter" ) ) ) . toBe ( true )
487+ // The unescaped-quotes hint only applies when the description line
488+ // actually contains double quotes.
489+ expect ( logged . some ( ( line ) => line . includes ( "unescaped double quotes" ) ) ) . toBe ( false )
490+ } finally {
491+ consoleErrorSpy . mockRestore ( )
492+ }
493+ } )
494+
394495 it ( "should skip skills with invalid name formats (spec compliance)" , async ( ) => {
395496 const invalidNames = [
396497 "PDF-processing" , // uppercase
@@ -1246,6 +1347,65 @@ Instructions`)
12461347 expect ( createdPath ) . toBe ( p ( PROJECT_DIR , ".roo" , "skills" , "project-skill" , "SKILL.md" ) )
12471348 } )
12481349
1350+ it ( "should escape double quotes in the description so the created skill loads (issue #859)" , async ( ) => {
1351+ mockDirectoryExists . mockResolvedValue ( false )
1352+ mockRealpath . mockImplementation ( async ( p : string ) => p )
1353+ mockReaddir . mockResolvedValue ( [ ] )
1354+ mockFileExists . mockResolvedValue ( false )
1355+ mockMkdir . mockResolvedValue ( undefined )
1356+ mockWriteFile . mockResolvedValue ( undefined )
1357+
1358+ const description = 'Use when implementing features. Triggers on: "TDD", "test-driven development"'
1359+ const createdPath = await skillsManager . createSkill ( "test-skill" , "global" , description )
1360+
1361+ // The written frontmatter must be valid YAML that round-trips the
1362+ // description, with the raw value quoted instead of unescaped.
1363+ const writtenContent = String ( mockWriteFile . mock . calls [ 0 ] [ 1 ] )
1364+ const parsed = matter ( writtenContent )
1365+ expect ( parsed . data . name ) . toBe ( "test-skill" )
1366+ expect ( parsed . data . description ) . toBe ( description )
1367+ expect ( writtenContent ) . toContain ( `description: '${ description } '` )
1368+
1369+ // Re-discovery loads the created skill instead of silently skipping it.
1370+ mockDirectoryExists . mockImplementation ( async ( dir : string ) => dir === globalSkillsDir )
1371+ mockReaddir . mockImplementation ( async ( dir : string ) => ( dir === globalSkillsDir ? [ "test-skill" ] : [ ] ) )
1372+ mockStat . mockImplementation ( async ( pathArg : string ) => {
1373+ if ( pathArg === p ( globalSkillsDir , "test-skill" ) ) {
1374+ return { isDirectory : ( ) => true }
1375+ }
1376+ throw new Error ( "Not found" )
1377+ } )
1378+ mockFileExists . mockImplementation ( async ( file : string ) => file === createdPath )
1379+ mockReadFile . mockImplementation ( async ( file : string ) =>
1380+ file === createdPath ? writtenContent : Promise . reject ( new Error ( "File not found" ) ) ,
1381+ )
1382+
1383+ await skillsManager . discoverSkills ( )
1384+
1385+ const skills = skillsManager . getAllSkills ( )
1386+ expect ( skills ) . toHaveLength ( 1 )
1387+ expect ( skills [ 0 ] . name ) . toBe ( "test-skill" )
1388+ expect ( skills [ 0 ] . description ) . toBe ( description )
1389+ } )
1390+
1391+ it ( "should quote descriptions that would otherwise parse as YAML non-strings" , async ( ) => {
1392+ mockDirectoryExists . mockResolvedValue ( false )
1393+ mockRealpath . mockImplementation ( async ( p : string ) => p )
1394+ mockReaddir . mockResolvedValue ( [ ] )
1395+ mockFileExists . mockResolvedValue ( false )
1396+ mockMkdir . mockResolvedValue ( undefined )
1397+ mockWriteFile . mockResolvedValue ( undefined )
1398+
1399+ await skillsManager . createSkill ( "flag-skill" , "global" , "yes" )
1400+
1401+ const writtenContent = String ( mockWriteFile . mock . calls [ 0 ] [ 1 ] )
1402+ const parsed = matter ( writtenContent )
1403+ // Without quoting, js-yaml resolves "yes" to a boolean and the skill
1404+ // is rejected with a misleading "missing required 'description' field".
1405+ expect ( typeof parsed . data . description ) . toBe ( "string" )
1406+ expect ( parsed . data . description ) . toBe ( "yes" )
1407+ } )
1408+
12491409 it ( "should throw error for invalid skill name" , async ( ) => {
12501410 await expect ( skillsManager . createSkill ( "Invalid-Name" , "global" , "Description" ) ) . rejects . toThrow (
12511411 "Skill name must be lowercase letters/numbers/hyphens only" ,
0 commit comments