@@ -546,17 +546,21 @@ async def process_event(r: Run, frame: CallFrame | RunFrame | PromptFrame):
546546 event_output += output .content
547547 elif frame .type == RunEventType .callFinish :
548548 call_finish_seen = True
549+ for output in frame .output :
550+ event_output += output .content
549551
550- run = gptscript .run (os .getcwd () + "/tests/fixtures/global-tools.gpt" ,
552+ cwd = os .getcwd ().removesuffix ("/tests" )
553+ run = gptscript .run (cwd + "/tests/fixtures/global-tools.gpt" ,
551554 Options (
552555 disableCache = True ,
553556 credentialOverrides = ["github.com/gptscript-ai/gateway:OPENAI_API_KEY" ],
554557 ),
555558 event_handlers = [process_event ],
556559 )
557560
558- assert "Hello!" in await run .text (), "Unexpected output from global tool test"
559- assert "Hello" in event_output , "Unexpected stream output from global tool test"
561+ output = await run .text ()
562+ assert "Hello!" in output , "Unexpected output from global tool test: " + output
563+ assert "Hello" in event_output , "Unexpected stream output from global tool test: " + event_output
560564
561565 assert run_start_seen and call_start_seen and call_progress_seen and call_finish_seen and run_finish_seen , \
562566 f"One of these is False: { run_start_seen } , { call_start_seen } , { call_progress_seen } , { call_finish_seen } , { run_finish_seen } "
@@ -573,7 +577,7 @@ async def process_event(r: Run, frame: CallFrame | RunFrame | PromptFrame):
573577 confirm_event_found = True
574578 assert '"ls' in frame .input or '"dir' in frame .input , "Unexpected confirm input: " + frame .input
575579 await gptscript .confirm (AuthResponse (frame .id , True ))
576- elif frame .type == RunEventType .callProgress :
580+ elif frame .type == RunEventType .callProgress or frame . type == RunEventType . callFinish :
577581 for output in frame .output :
578582 event_content += output .content
579583
@@ -610,7 +614,7 @@ async def process_event(r: Run, frame: CallFrame | RunFrame | PromptFrame):
610614 confirm_event_found = True
611615 assert '"ls"' in frame .input , "Unexpected confirm input: " + frame .input
612616 await gptscript .confirm (AuthResponse (frame .id , False , "I will not allow it!" ))
613- elif frame .type == RunEventType .callProgress :
617+ elif frame .type == RunEventType .callProgress or frame . type == RunEventType . callFinish :
614618 for output in frame .output :
615619 event_content += output .content
616620
@@ -637,9 +641,9 @@ async def process_event(r: Run, frame: CallFrame | RunFrame | PromptFrame):
637641 if frame .type == RunEventType .prompt :
638642 prompt_event_found = True
639643 assert len (frame .fields ) == 1 , "Unexpected number of fields: " + str (frame .fields )
640- assert "first name" in frame .fields [0 ], "Unexpected field: " + frame .fields [0 ]
641- await gptscript .prompt (PromptResponse (frame .id , {frame .fields [0 ]: "Clicky" }))
642- elif frame .type == RunEventType .callProgress :
644+ assert "first name" in frame .fields [0 ]. name , "Unexpected field: " + frame .fields [0 ]. name
645+ await gptscript .prompt (PromptResponse (frame .id , {frame .fields [0 ]. name : "Clicky" }))
646+ elif frame .type == RunEventType .callProgress or frame . type == RunEventType . callFinish :
643647 for output in frame .output :
644648 event_content += output .content
645649
@@ -667,10 +671,10 @@ async def process_event(r: Run, frame: CallFrame | RunFrame | PromptFrame):
667671 if frame .type == RunEventType .prompt :
668672 prompt_event_found = True
669673 assert len (frame .fields ) == 1 , "Unexpected number of fields: " + str (frame .fields )
670- assert "first name" in frame .fields [0 ], "Unexpected field: " + frame .fields [0 ]
674+ assert "first name" in frame .fields [0 ]. name , "Unexpected field: " + frame .fields [0 ]. name
671675 assert "first_name" in frame .metadata , "Unexpected metadata: " + str (frame .metadata )
672676 assert frame .metadata ["first_name" ] == "Clicky" , "Unexpected metadata: " + str (frame .metadata )
673- await gptscript .prompt (PromptResponse (frame .id , {frame .fields [0 ]: "Clicky" }))
677+ await gptscript .prompt (PromptResponse (frame .id , {frame .fields [0 ]. name : "Clicky" }))
674678
675679 out = await gptscript .run (
676680 "sys.prompt" ,
@@ -691,8 +695,8 @@ async def process_event(r: Run, frame: CallFrame | RunFrame | PromptFrame):
691695 if frame .type == RunEventType .prompt :
692696 prompt_event_found = True
693697 assert len (frame .fields ) == 1 , "Unexpected number of fields: " + str (frame .fields )
694- assert "first name" in frame .fields [0 ], "Unexpected field: " + frame .fields [0 ]
695- await gptscript .prompt (PromptResponse (frame .id , {frame .fields [0 ]: "Clicky" }))
698+ assert "first name" in frame .fields [0 ]. name , "Unexpected field: " + frame .fields [0 ]. name
699+ await gptscript .prompt (PromptResponse (frame .id , {frame .fields [0 ]. name : "Clicky" }))
696700
697701 tool = ToolDef (
698702 tools = ["sys.prompt" ],
@@ -727,7 +731,7 @@ async def test_run_file_with_metadata(gptscript):
727731
728732@pytest .mark .asyncio
729733async def test_parse_with_metadata_then_run (gptscript ):
730- cwd = os .getcwd ().removesuffix ("tests" )
734+ cwd = os .getcwd ().removesuffix ("/ tests" )
731735 tools = await gptscript .parse (cwd + "/tests/fixtures/parse-with-metadata.gpt" )
732736 run = gptscript .evaluate (tools [0 ])
733737 assert "200" == await run .text (), "Expect file to have correct output"
0 commit comments