Skip to content

Commit 98216b8

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 98216b8

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

gptscript_test.go

+42-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,47 @@ func TestStreamRun(t *testing.T) {
345345
}
346346
}
347347

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