@@ -119,16 +119,49 @@ async def test_list_tools(gptscript):
119119
120120@pytest .mark .asyncio
121121async def test_abort_run (gptscript ):
122- async def about_run (run : Run , e : CallFrame | RunFrame | PromptFrame ):
122+ async def abort_run (run : Run , e : CallFrame | RunFrame | PromptFrame ):
123123 await run .aclose ()
124124
125125 run = gptscript .evaluate (ToolDef (instructions = "What is the capital of the united states?" ),
126- Options (disableCache = True ), event_handlers = [about_run ])
126+ Options (disableCache = True ), event_handlers = [abort_run ])
127127
128128 assert "Run was aborted" in await run .text (), "Unexpected output from abort_run"
129129 assert RunState .Error == run .state (), "Unexpected run state after aborting"
130130
131131
132+ @pytest .mark .asyncio
133+ async def test_restart_failed_run (gptscript ):
134+ shebang = "#!/bin/bash"
135+ instructions = f"""{ shebang }
136+ exit ${{EXIT_CODE}}
137+ """
138+ if platform .system ().lower () == "windows" :
139+ shebang = "#!/usr/bin/env powershell.exe"
140+ instructions = f"""{ shebang }
141+ exit $env:EXIT_CODE
142+ """
143+ tools = [
144+ ToolDef (tools = ["my-context" ]),
145+ ToolDef (
146+ name = "my-context" ,
147+ type = "context" ,
148+ instructions = instructions ,
149+ ),
150+ ]
151+
152+ run = gptscript .evaluate (tools , Options (disableCache = True , env = ["EXIT_CODE=1" ]))
153+ await run .text ()
154+
155+ assert run .state () == RunState .Error , "Unexpected run state after exit 1"
156+
157+ run .opts .env = None
158+
159+ run = run .next_chat ("" )
160+ await run .text ()
161+
162+ assert run .state () != RunState .Error , "Unexpected run state after restart"
163+
164+
132165@pytest .mark .asyncio
133166async def test_eval_simple_tool (gptscript , simple_tool ):
134167 run = gptscript .evaluate (simple_tool )
@@ -208,7 +241,7 @@ async def test_eval_with_context(gptscript):
208241 wd = os .getcwd ()
209242 tool = ToolDef (
210243 instructions = "What is the capital of the united states?" ,
211- context = [wd + "/tests/fixtures/acorn-labs-context.gpt" ],
244+ tools = [wd + "/tests/fixtures/acorn-labs-context.gpt" ],
212245 )
213246
214247 run = gptscript .evaluate (tool )
0 commit comments