@@ -6,6 +6,23 @@ description: Use when the user needs to crawl pages. Keywords: crawl, scrape
66---
77body`
88
9+ // YAML reads a leading `[`/`{` as a flow collection. An unquoted plain scalar
10+ // like `[Team] Does a thing` is not valid flow syntax, so the whole frontmatter
11+ // block used to throw and the document (e.g. an agent) was dropped silently.
12+ const flowScalar = `---
13+ description: [Team] Does a thing
14+ mode: subagent
15+ ---
16+ body`
17+
18+ // A value that still cannot be parsed after the fallback (`*ref` is a YAML
19+ // alias that is never defined here), used to keep the throw-on-every-call
20+ // guard meaningful.
21+ const unparseable = `---
22+ description: *ref thing
23+ ---
24+ body`
25+
926describe ( "ConfigMarkdown.parse" , ( ) => {
1027 test ( "recovers unquoted-colon frontmatter via the sanitize fallback" , ( ) => {
1128 const parsed = ConfigMarkdown . parse ( invalidYaml )
@@ -16,20 +33,42 @@ describe("ConfigMarkdown.parse", () => {
1633 test ( "recovers the same content again after a previous failed parse" , ( ) => {
1734 // gray-matter caches by content before parsing; a poisoned entry used to
1835 // make every later parse of the same text return silently without data.
19- expect ( ( ) => ConfigMarkdown . parse ( "---\ndescription: [unclosed\n---\nbody" ) ) . toThrow ( )
36+ expect ( ( ) => ConfigMarkdown . parse ( unparseable ) ) . toThrow ( )
2037 const parsed = ConfigMarkdown . parse ( invalidYaml )
2138 expect ( parsed . data . description ) . toBe ( "Use when the user needs to crawl pages. Keywords: crawl, scrape" )
2239 } )
2340
2441 test ( "keeps throwing for the same unparseable content on every call" , ( ) => {
25- const input = "---\ndescription: [unclosed\n---\nbody"
26- expect ( ( ) => ConfigMarkdown . parse ( input ) ) . toThrow ( )
27- expect ( ( ) => ConfigMarkdown . parse ( input ) ) . toThrow ( )
42+ expect ( ( ) => ConfigMarkdown . parse ( unparseable ) ) . toThrow ( )
43+ expect ( ( ) => ConfigMarkdown . parse ( unparseable ) ) . toThrow ( )
2844 } )
2945
3046 test ( "parses plain content without frontmatter" , ( ) => {
3147 const parsed = ConfigMarkdown . parse ( "just body" )
3248 expect ( parsed . content ) . toBe ( "just body" )
3349 expect ( parsed . data ) . toEqual ( { } )
3450 } )
35- } )
51+
52+ test ( "keeps a frontmatter value that starts with an unquoted [" , ( ) => {
53+ const parsed = ConfigMarkdown . parse ( flowScalar )
54+ expect ( parsed . data . description ) . toBe ( "[Team] Does a thing" )
55+ expect ( parsed . data . mode ) . toBe ( "subagent" )
56+ expect ( parsed . content . trim ( ) ) . toBe ( "body" )
57+ } )
58+
59+ test ( "still parses a real flow sequence" , ( ) => {
60+ const parsed = ConfigMarkdown . parse ( `---\ndescription: ['a', 'b']\n---\nbody` )
61+ expect ( parsed . data . description ) . toEqual ( [ "a" , "b" ] )
62+ } )
63+
64+ test ( "still parses a real flow mapping" , ( ) => {
65+ const parsed = ConfigMarkdown . parse ( `---\ndescription: [Team] x\ntools: {write: false}\n---\nbody` )
66+ expect ( parsed . data . description ) . toBe ( "[Team] x" )
67+ expect ( parsed . data . tools ) . toEqual ( { write : false } )
68+ } )
69+
70+ test ( "still keeps unquoted colons working" , ( ) => {
71+ const parsed = ConfigMarkdown . parse ( invalidYaml )
72+ expect ( parsed . data . description ) . toBe ( "Use when the user needs to crawl pages. Keywords: crawl, scrape" )
73+ } )
74+ } )
0 commit comments