@@ -259,7 +259,7 @@ func TestStreamEvaluate(t *testing.T) {
259259
260260 run , err := c .Evaluate (context .Background (), Options {IncludeEvents : true }, tool )
261261 if err != nil {
262- t .Errorf ("Error executing tool: %v" , err )
262+ t .Fatalf ("Error executing tool: %v" , err )
263263 }
264264
265265 for e := range run .Events () {
@@ -297,7 +297,7 @@ func TestStreamRun(t *testing.T) {
297297 var eventContent string
298298 run , err := c .Run (context .Background (), wd + "/test/catcher.gpt" , Options {IncludeEvents : true })
299299 if err != nil {
300- t .Errorf ("Error executing file: %v" , err )
300+ t .Fatalf ("Error executing file: %v" , err )
301301 }
302302
303303 for e := range run .Events () {
@@ -618,7 +618,7 @@ func TestToolWithGlobalTools(t *testing.T) {
618618
619619 run , err := c .Run (context .Background (), wd + "/test/global-tools.gpt" , Options {DisableCache : true , IncludeEvents : true })
620620 if err != nil {
621- t .Errorf ("Error executing tool: %v" , err )
621+ t .Fatalf ("Error executing tool: %v" , err )
622622 }
623623
624624 for e := range run .Events () {
@@ -808,6 +808,90 @@ func TestConfirmDeny(t *testing.T) {
808808 }
809809}
810810
811+ func TestPrompt (t * testing.T ) {
812+ var eventContent string
813+ tools := []fmt.Stringer {
814+ & ToolDef {
815+ Instructions : "Use the sys.prompt user to ask the user for 'first name' which is not sensitive. After you get their first name, say hello." ,
816+ Tools : []string {"sys.prompt" },
817+ },
818+ }
819+
820+ run , err := c .Evaluate (context .Background (), Options {IncludeEvents : true }, tools ... )
821+ if err != nil {
822+ t .Errorf ("Error executing tool: %v" , err )
823+ }
824+
825+ // Wait for the prompt event
826+ var promptFrame * PromptFrame
827+ for e := range run .Events () {
828+ if e .Call != nil {
829+ for _ , o := range e .Call .Output {
830+ eventContent += o .Content
831+ }
832+ }
833+ if e .Prompt != nil {
834+ if e .Prompt .Type == EventTypePrompt {
835+ promptFrame = e .Prompt
836+ break
837+ }
838+ }
839+ }
840+
841+ if promptFrame == nil {
842+ t .Fatalf ("No prompt call event" )
843+ }
844+
845+ if promptFrame .Sensitive {
846+ t .Errorf ("Unexpected sensitive prompt event: %v" , promptFrame .Sensitive )
847+ }
848+
849+ if ! strings .Contains (promptFrame .Message , "first name" ) {
850+ t .Errorf ("unexpected confirm input: %s" , promptFrame .Message )
851+ }
852+
853+ if len (promptFrame .Fields ) != 1 {
854+ t .Fatalf ("Unexpected number of fields: %d" , len (promptFrame .Fields ))
855+ }
856+
857+ if promptFrame .Fields [0 ] != "first name" {
858+ t .Errorf ("Unexpected field: %s" , promptFrame .Fields [0 ])
859+ }
860+
861+ if err = c .PromptResponse (context .Background (), PromptResponse {
862+ ID : promptFrame .ID ,
863+ Response : map [string ]string {promptFrame .Fields [0 ]: "Clicky" },
864+ }); err != nil {
865+ t .Errorf ("Error responding: %v" , err )
866+ }
867+
868+ // Read the remainder of the events
869+ for e := range run .Events () {
870+ if e .Call != nil {
871+ for _ , o := range e .Call .Output {
872+ eventContent += o .Content
873+ }
874+ }
875+ }
876+
877+ out , err := run .Text ()
878+ if err != nil {
879+ t .Errorf ("Error reading output: %v" , err )
880+ }
881+
882+ if ! strings .Contains (eventContent , "Clicky" ) {
883+ t .Errorf ("Unexpected event output: %s" , eventContent )
884+ }
885+
886+ if ! strings .Contains (out , "Hello" ) || ! strings .Contains (out , "Clicky" ) {
887+ t .Errorf ("Unexpected output: %s" , out )
888+ }
889+
890+ if len (run .ErrorOutput ()) != 0 {
891+ t .Errorf ("Should have no stderr output: %v" , run .ErrorOutput ())
892+ }
893+ }
894+
811895func TestGetCommand (t * testing.T ) {
812896 currentEnvVar := os .Getenv ("GPTSCRIPT_BIN" )
813897 t .Cleanup (func () {
0 commit comments