@@ -735,64 +735,48 @@ func TestConfirm(t *testing.T) {
735735 t .Errorf ("Error executing tool: %v" , err )
736736 }
737737
738- // Wait for the confirm event
739738 var confirmCallEvent * CallFrame
740- for e := range run .Events () {
741- if e .Call != nil {
742- for _ , o := range e .Call .Output {
743- eventContent += o .Content
744- }
745-
746- if e .Call .Type == EventTypeCallConfirm {
747- confirmCallEvent = e .Call
748- break
749- }
750- }
751- }
752-
753- if confirmCallEvent == nil {
754- t .Fatalf ("No confirm call event" )
755- }
756-
757- if ! strings .Contains (confirmCallEvent .Input , "\" ls\" " ) {
758- t .Errorf ("unexpected confirm input: %s" , confirmCallEvent .Input )
759- }
739+ done := make (chan struct {})
740+ go func () {
741+ defer close (done )
760742
761- if err = g .Confirm (context .Background (), AuthResponse {
762- ID : confirmCallEvent .ID ,
763- Accept : true ,
764- }); err != nil {
765- t .Errorf ("Error confirming: %v" , err )
766- }
743+ for e := range run .Events () {
744+ if e .Call != nil {
745+ for _ , o := range e .Call .Output {
746+ eventContent += o .Content
747+ }
767748
768- // Read the remainder of the events
769- for e := range run .Events () {
770- if e .Call != nil {
771- for _ , o := range e .Call .Output {
772- eventContent += o .Content
773- }
749+ if e .Call .Type == EventTypeCallConfirm {
750+ confirmCallEvent = e .Call
774751
775- if e .Call .Type == EventTypeCallConfirm {
776- // On Windows, ls may not be recognized as a command. The LLM will try to run the dir command. Confirm it.
777- if ! strings .Contains (e .Call .Input , "\" dir\" " ) {
778- t .Errorf ("unexpected confirm input: %s" , e .Call .Input )
779- }
752+ if ! strings .Contains (confirmCallEvent .Input , "\" ls" ) && ! strings .Contains (confirmCallEvent .Input , "\" dir" ) {
753+ t .Errorf ("unexpected confirm input: %s" , confirmCallEvent .Input )
754+ }
780755
781- if err = g .Confirm (context .Background (), AuthResponse {
782- ID : e .Call .ID ,
783- Accept : true ,
784- }); err != nil {
785- t .Errorf ("Error confirming: %v" , err )
756+ // Confirm the call
757+ if err = g .Confirm (context .Background (), AuthResponse {
758+ ID : confirmCallEvent .ID ,
759+ Accept : true ,
760+ }); err != nil {
761+ t .Errorf ("Error confirming: %v" , err )
762+ }
786763 }
787764 }
788765 }
789- }
766+ }()
790767
791768 out , err := run .Text ()
792769 if err != nil {
793770 t .Errorf ("Error reading output: %v" , err )
794771 }
795772
773+ // Wait for events processing to finish
774+ <- done
775+
776+ if confirmCallEvent == nil {
777+ t .Fatalf ("No confirm call event" )
778+ }
779+
796780 if ! strings .Contains (eventContent , "Makefile" ) || ! strings .Contains (eventContent , "README.md" ) {
797781 t .Errorf ("Unexpected event output: %s" , eventContent )
798782 }
0 commit comments