@@ -273,9 +273,43 @@ func findHookCommand(t *testing.T, entries []copilotcli.CopilotHookEntry, hookNa
273273func resolveHookCommand (t * testing.T , command string ) string {
274274 t .Helper ()
275275
276+ return resolveHookCommandWithBinary (command , getTestBinary ())
277+ }
278+
279+ func TestResolveHookCommand_RewritesWrappedProductionCommand (t * testing.T ) {
280+ t .Parallel ()
281+
282+ command := `sh -c 'if ! command -v entire >/dev/null 2>&1; then exit 0; fi; exec entire hooks copilot-cli user-prompt-submitted'`
283+ got := resolveHookCommandWithBinary (command , "/tmp/entire-test-binary" )
284+
285+ if strings .Contains (got , "command -v entire" ) {
286+ t .Fatalf ("resolveHookCommand() should not depend on PATH lookup for entire, got %q" , got )
287+ }
288+ if strings .Contains (got , "exec entire hooks" ) {
289+ t .Fatalf ("resolveHookCommand() should rewrite wrapped exec target, got %q" , got )
290+ }
291+ if ! strings .Contains (got , `exec "/tmp/entire-test-binary" hooks copilot-cli user-prompt-submitted` ) {
292+ t .Fatalf ("resolveHookCommand() did not rewrite wrapped command correctly, got %q" , got )
293+ }
294+ }
295+
296+ func resolveHookCommandWithBinary (command , binaryPath string ) string {
297+ testBinary := fmt .Sprintf ("%q" , binaryPath )
298+
276299 if strings .HasPrefix (command , "entire " ) {
277- return fmt . Sprintf ( "%q%s" , getTestBinary (), strings .TrimPrefix (command , "entire" ) )
300+ return testBinary + strings .TrimPrefix (command , "entire" )
278301 }
302+
303+ if strings .Contains (command , "command -v entire" ) && strings .Contains (command , "exec entire " ) {
304+ resolved := strings .Replace (command ,
305+ "command -v entire >/dev/null 2>&1" ,
306+ "test -x " + testBinary ,
307+ 1 ,
308+ )
309+ resolved = strings .Replace (resolved , "exec entire " , "exec " + testBinary + " " , 1 )
310+ return resolved
311+ }
312+
279313 return command
280314}
281315
0 commit comments