@@ -119,16 +119,49 @@ async def test_list_tools(gptscript):
119
119
120
120
@pytest .mark .asyncio
121
121
async 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 ):
123
123
await run .aclose ()
124
124
125
125
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 ])
127
127
128
128
assert "Run was aborted" in await run .text (), "Unexpected output from abort_run"
129
129
assert RunState .Error == run .state (), "Unexpected run state after aborting"
130
130
131
131
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
+
132
165
@pytest .mark .asyncio
133
166
async def test_eval_simple_tool (gptscript , simple_tool ):
134
167
run = gptscript .evaluate (simple_tool )
@@ -208,7 +241,7 @@ async def test_eval_with_context(gptscript):
208
241
wd = os .getcwd ()
209
242
tool = ToolDef (
210
243
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" ],
212
245
)
213
246
214
247
run = gptscript .evaluate (tool )
0 commit comments