@@ -515,3 +515,54 @@ Deploy the app.`
515515 } )
516516 } )
517517} )
518+
519+ // Invariant NoExecutableEngine (docs/architecture/tla/CommandFrontmatter.tla): no header runs code.
520+ // Exercise the real parser through both public loading paths.
521+ describe . each ( [ "discovery" , "individual" ] ) ( "%s frontmatter security" , ( entryPoint ) => {
522+ async function load ( content : string ) {
523+ mockFs . stat = vi . fn ( ) . mockResolvedValue ( { isDirectory : ( ) => true } )
524+ mockFs . readdir = vi . fn ( ) . mockResolvedValue ( [ { name : "security-probe.md" , isFile : ( ) => true } ] )
525+ mockFs . readFile = vi . fn ( ) . mockResolvedValue ( content )
526+ return entryPoint === "discovery"
527+ ? ( await getCommands ( "/test/cwd" ) ) . find ( ( command ) => command . name === "security-probe" )
528+ : await getCommand ( "/test/cwd" , "security-probe" )
529+ }
530+
531+ it . each ( [ "javascript" , "js" , "JS" , "JavaScript" , " javascript " , "\uFEFF---js" , "\uFEFF\uFEFF---javascript" ] ) (
532+ "does not execute %s frontmatter" ,
533+ async ( header ) => {
534+ const execute = vi . fn ( ( ) => ( { description : "Executed" } ) )
535+ vi . stubGlobal ( "__commandFrontmatterProbe" , execute )
536+ try {
537+ const opening = header . startsWith ( "\uFEFF" ) ? header : `---${ header } `
538+ const content = `${ opening } \n(globalThis.__commandFrontmatterProbe())\n---\nCommand body`
539+ const result = await load ( content )
540+ expect ( execute ) . not . toHaveBeenCalled ( )
541+ expect ( result ?. description ) . toBeUndefined ( )
542+ expect ( result ?. content ) . toBe ( content . trim ( ) )
543+ } finally {
544+ vi . unstubAllGlobals ( )
545+ }
546+ } ,
547+ )
548+
549+ it . each ( [ "toml" , "coffee" , "constructor" , "__proto__" ] ) ( "keeps unsupported %s as text" , async ( header ) => {
550+ const content = `---${ header } \ndescription: Test\n---\nCommand body`
551+ const result = await load ( content )
552+ expect ( result ?. content ) . toBe ( content )
553+ expect ( result ?. description ) . toBeUndefined ( )
554+ } )
555+
556+ it . each ( [ "" , "yaml" , "yml" , "json" ] ) ( "accepts data frontmatter %s" , async ( header ) => {
557+ const data = { description : "Test" , "argument-hint" : "value" , mode : "code" }
558+ const metadata =
559+ header === "json" ? JSON . stringify ( data ) : "description: Test\nargument-hint: value\nmode: code"
560+ const result = await load ( `---${ header } \r\n${ metadata } \r\n---\r\nCommand body` )
561+ expect ( result ) . toMatchObject ( {
562+ description : "Test" ,
563+ argumentHint : "value" ,
564+ mode : "code" ,
565+ content : "Command body" ,
566+ } )
567+ } )
568+ } )
0 commit comments