@@ -22,6 +22,49 @@ describe("Command loading with frontmatter", () => {
2222 vi . clearAllMocks ( )
2323 } )
2424
25+ describe . each ( [ "lookup" , "discovery" ] as const ) ( "%s engine restrictions" , ( entryPoint ) => {
26+ async function load ( content : string ) {
27+ mockFs . stat = vi . fn ( ) . mockResolvedValue ( { isDirectory : ( ) => true } )
28+ mockFs . readFile = vi . fn ( ) . mockResolvedValue ( content )
29+ mockFs . readdir = vi . fn ( ) . mockResolvedValue ( [ { name : "test.md" , isFile : ( ) => true } ] )
30+ return entryPoint === "lookup"
31+ ? getCommand ( "/test/cwd" , "test" )
32+ : ( await getCommands ( "/test/cwd" ) ) . find ( ( command ) => command . name === "test" )
33+ }
34+
35+ it . each ( [ "js" , "javascript" , "JavaScript" , " js" , "javascript\r" , "python" ] ) (
36+ "treats %s frontmatter as text without executing it" ,
37+ async ( language ) => {
38+ const executed = vi . fn ( )
39+ vi . stubGlobal ( "__commandFrontmatterExecuted" , executed )
40+ try {
41+ // Include a BOM to exercise gray-matter's input normalization.
42+ const content = `\uFEFF---${ language } \n(globalThis.__commandFrontmatterExecuted(), {description: "unsafe"})\n---\nBody`
43+ const command = await load ( content )
44+ expect ( executed ) . not . toHaveBeenCalled ( )
45+ expect ( command ) . toMatchObject ( { content : content . trim ( ) } )
46+ expect ( command ?. description ) . toBeUndefined ( )
47+ } finally {
48+ vi . unstubAllGlobals ( )
49+ }
50+ } ,
51+ )
52+
53+ it . each ( [ "" , "yaml" , "yml" , "json" ] ) ( "accepts data-only %s frontmatter" , async ( language ) => {
54+ const metadata =
55+ language === "json"
56+ ? '{"description":"Safe", "argument-hint":"input", "mode":"code"}'
57+ : "description: Safe\nargument-hint: input\nmode: code"
58+ const command = await load ( `---${ language } \n${ metadata } \n---\nBody` )
59+ expect ( command ) . toMatchObject ( {
60+ content : "Body" ,
61+ description : "Safe" ,
62+ argumentHint : "input" ,
63+ mode : "code" ,
64+ } )
65+ } )
66+ } )
67+
2568 describe ( "getCommand with frontmatter" , ( ) => {
2669 it ( "should load command with description from frontmatter" , async ( ) => {
2770 const commandContent = `---
0 commit comments