@@ -97,6 +97,7 @@ function scopeScript(): string {
9797}
9898
9999async function runScope ( options : {
100+ diffExitCode ?: number ;
100101 draft ?: boolean ;
101102 eventName ?: string ;
102103 files ?: Array < string | { filename : string ; previous_filename ?: string } > ;
@@ -111,6 +112,7 @@ async function runScope(options: {
111112 eventName : options . eventName ?? "pull_request" ,
112113 payload : {
113114 pull_request : {
115+ base : { sha : "base-sha" } ,
114116 draft : options . draft ?? false ,
115117 number : 123 ,
116118 } ,
@@ -120,25 +122,35 @@ async function runScope(options: {
120122 repo : "openclaw" ,
121123 } ,
122124 } ;
123- const github = {
124- rest : {
125- pulls : {
126- listFiles ( ) { } ,
127- } ,
128- } ,
129- async paginate ( ) {
130- return ( options . files ?? [ ] ) . map ( ( file ) =>
131- typeof file === "string" ? { filename : file } : file ,
125+ const exec = {
126+ async getExecOutput ( command : string , args : string [ ] ) {
127+ if ( command !== "git" || args . slice ( 0 , 5 ) . join ( " " ) !== "diff --quiet base-sha HEAD --" ) {
128+ throw new Error ( `unexpected scope command: ${ command } ${ args . join ( " " ) } ` ) ;
129+ }
130+ if ( options . diffExitCode !== undefined ) {
131+ return { exitCode : options . diffExitCode } ;
132+ }
133+ const pathspecs = args . slice ( 5 ) ;
134+ const filenames = ( options . files ?? [ ] ) . flatMap ( ( file ) =>
135+ typeof file === "string"
136+ ? [ file ]
137+ : [ file . filename , file . previous_filename ] . filter ( ( name ) : name is string => Boolean ( name ) ) ,
132138 ) ;
139+ const changed = filenames . some ( ( filename ) =>
140+ pathspecs . some ( ( pathspec ) =>
141+ pathspec . endsWith ( "/" ) ? filename . startsWith ( pathspec ) : filename === pathspec ,
142+ ) ,
143+ ) ;
144+ return { exitCode : changed ? 1 : 0 } ;
133145 } ,
134146 } ;
135147 const execute = compileFunction ( `return (async () => {\n${ scopeScript ( ) } \n})();` , [
136148 "context" ,
137149 "core" ,
138- "github " ,
139- ] ) as ( context : unknown , core : unknown , github : unknown ) => Promise < void > ;
150+ "exec " ,
151+ ] ) as ( context : unknown , core : unknown , exec : unknown ) => Promise < void > ;
140152
141- await execute ( context , core , github ) ;
153+ await execute ( context , core , exec ) ;
142154 return outputs . get ( "should-scan" ) ;
143155}
144156
@@ -465,9 +477,11 @@ describe("iOS Periphery comment workflow", () => {
465477 compileFunction ( `return (async () => {\n${ scopeScript ( ) } \n})();` , [
466478 "context" ,
467479 "core" ,
468- "github " ,
480+ "exec " ,
469481 ] ) ,
470482 ) . not . toThrow ( ) ;
483+ expect ( scopeScript ( ) ) . toContain ( "exec.getExecOutput" ) ;
484+ expect ( scopeScript ( ) ) . not . toContain ( "pulls.listFiles" ) ;
471485 } ) ;
472486
473487 it . each ( [
@@ -510,6 +524,12 @@ describe("iOS Periphery comment workflow", () => {
510524 await expect ( runScope ( { ...options , files } ) ) . resolves . toBe ( expected ) ;
511525 } ) ;
512526
527+ it ( "fails closed when git cannot compare the base and head" , async ( ) => {
528+ await expect ( runScope ( { diffExitCode : 128 } ) ) . rejects . toThrow (
529+ "git diff failed with exit code 128" ,
530+ ) ;
531+ } ) ;
532+
513533 it ( "accepts a valid small Periphery artifact" , async ( ) => {
514534 const archive = makeZip ( {
515535 "periphery.json" : "[]\n" ,
0 commit comments