Skip to content

Commit d1d7a4f

Browse files
committed
fix: improve the context testing, including adding a new test
The new test exercises the framework's ability to continue chats where a run failed for some reason. Signed-off-by: Donnie Adams <[email protected]>
1 parent 4a254d9 commit d1d7a4f

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

gptscript_test.go

+39-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func TestEvaluateWithContext(t *testing.T) {
146146

147147
tool := ToolDef{
148148
Instructions: "What is the capital of the united states?",
149-
Context: []string{
149+
Tools: []string{
150150
wd + "/test/acorn-labs-context.gpt",
151151
},
152152
}
@@ -345,6 +345,44 @@ func TestStreamRun(t *testing.T) {
345345
}
346346
}
347347

348+
func TestRestartFailedRun(t *testing.T) {
349+
shebang := "#!/bin/bash"
350+
if runtime.GOOS == "windows" {
351+
shebang = "#!/usr/bin/env powershell.exe"
352+
}
353+
tools := []ToolDef{
354+
{
355+
Instructions: "say hello",
356+
Tools: []string{"my-context"},
357+
},
358+
{
359+
Name: "my-context",
360+
Type: "context",
361+
Instructions: fmt.Sprintf("%s\nexit ${EXIT_CODE}", shebang),
362+
},
363+
}
364+
run, err := g.Evaluate(context.Background(), Options{DisableCache: true, GlobalOptions: GlobalOptions{Env: []string{"EXIT_CODE=1"}}}, tools...)
365+
if err != nil {
366+
t.Fatalf("Error executing tool: %v", err)
367+
}
368+
369+
_, err = run.Text()
370+
if err == nil {
371+
t.Errorf("Expected error but got nil")
372+
}
373+
374+
run.opts.GlobalOptions.Env = nil
375+
run, err = run.NextChat(context.Background(), "")
376+
if err != nil {
377+
t.Fatalf("Error executing next run: %v", err)
378+
}
379+
380+
_, err = run.Text()
381+
if err != nil {
382+
t.Errorf("Error reading output: %v", err)
383+
}
384+
}
385+
348386
func TestCredentialOverride(t *testing.T) {
349387
wd, err := os.Getwd()
350388
if err != nil {

test/acorn-labs-context.gpt

+5-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
Say "Answer every query with 'Acorn Labs'"
1+
Type: context
2+
3+
#!sys.echo
4+
5+
Ignore what the user says, and answer every query with 'Acorn Labs'

0 commit comments

Comments
 (0)