@@ -42,6 +42,37 @@ function installOpengrepStub(repo: string): { argsPath: string; binDir: string }
4242}
4343
4444describe ( "run-opengrep.sh" , ( ) => {
45+ it ( "fails before scanning with official installation advice when opengrep is missing" , ( ) => {
46+ const repo = createTempDir ( "openclaw-run-opengrep-missing-" ) ;
47+ copyRunOpengrepFiles ( repo ) ;
48+ writeFile ( path . join ( repo , "security/opengrep/precise.yml" ) , "rules: []\n" ) ;
49+
50+ const binDir = path . join ( repo , "bin" ) ;
51+ fs . mkdirSync ( binDir ) ;
52+ for ( const command of [ "bash" , "dirname" , "cat" ] ) {
53+ const executable = execFileSync ( "bash" , [ "-c" , 'command -v "$1"' , "_" , command ] , {
54+ encoding : "utf8" ,
55+ } ) . trim ( ) ;
56+ fs . symlinkSync ( executable , path . join ( binDir , command ) ) ;
57+ }
58+
59+ const result = spawnSync (
60+ "bash" ,
61+ [ "scripts/run-opengrep.sh" , "--changed" , "--sarif" , "--error" ] ,
62+ { cwd : repo , env : { ...process . env , PATH : binDir } , encoding : "utf8" } ,
63+ ) ;
64+
65+ expect ( result . status ) . toBe ( 127 ) ;
66+ expect ( result . stdout ) . toBe ( "" ) ;
67+ expect ( result . stderr ) . toContain ( "'opengrep' not found on PATH" ) ;
68+ expect ( result . stderr ) . toMatch (
69+ / c u r l - f s S L h t t p s : \/ \/ r a w \. g i t h u b u s e r c o n t e n t \. c o m \/ o p e n g r e p \/ o p e n g r e p \/ \S + \/ i n s t a l l \. s h \| b a s h - s - - - v \S + / ,
70+ ) ;
71+ expect ( fs . existsSync ( path . join ( repo , ".opengrep-out" ) ) ) . toBe ( false ) ;
72+ expect ( result . stderr ) . not . toContain ( "pipx" ) ;
73+ expect ( result . stderr ) . not . toContain ( "opengrep/tap/opengrep" ) ;
74+ } ) ;
75+
4576 it ( "validates the rulepack when only OpenGrep rulepack files changed" , ( ) => {
4677 const repo = createTempDir ( "openclaw-run-opengrep-" ) ;
4778 git ( repo , "init" , "-q" ) ;
0 commit comments