Skip to content

Commit

Permalink
Merge pull request #49 from thedadams/fix-confirm-flake
Browse files Browse the repository at this point in the history
fix: ensure that all ls/dir calls are confirmed in test
  • Loading branch information
thedadams authored Jul 29, 2024
2 parents 20d868b + 0a3fffc commit 9bb1c82
Showing 1 changed file with 28 additions and 44 deletions.
72 changes: 28 additions & 44 deletions gptscript_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -735,64 +735,48 @@ func TestConfirm(t *testing.T) {
t.Errorf("Error executing tool: %v", err)
}

// Wait for the confirm event
var confirmCallEvent *CallFrame
for e := range run.Events() {
if e.Call != nil {
for _, o := range e.Call.Output {
eventContent += o.Content
}

if e.Call.Type == EventTypeCallConfirm {
confirmCallEvent = e.Call
break
}
}
}

if confirmCallEvent == nil {
t.Fatalf("No confirm call event")
}

if !strings.Contains(confirmCallEvent.Input, "\"ls\"") {
t.Errorf("unexpected confirm input: %s", confirmCallEvent.Input)
}
done := make(chan struct{})
go func() {
defer close(done)

if err = g.Confirm(context.Background(), AuthResponse{
ID: confirmCallEvent.ID,
Accept: true,
}); err != nil {
t.Errorf("Error confirming: %v", err)
}
for e := range run.Events() {
if e.Call != nil {
for _, o := range e.Call.Output {
eventContent += o.Content
}

// Read the remainder of the events
for e := range run.Events() {
if e.Call != nil {
for _, o := range e.Call.Output {
eventContent += o.Content
}
if e.Call.Type == EventTypeCallConfirm {
confirmCallEvent = e.Call

if e.Call.Type == EventTypeCallConfirm {
// On Windows, ls may not be recognized as a command. The LLM will try to run the dir command. Confirm it.
if !strings.Contains(e.Call.Input, "\"dir\"") {
t.Errorf("unexpected confirm input: %s", e.Call.Input)
}
if !strings.Contains(confirmCallEvent.Input, "\"ls") && !strings.Contains(confirmCallEvent.Input, "\"dir") {
t.Errorf("unexpected confirm input: %s", confirmCallEvent.Input)
}

if err = g.Confirm(context.Background(), AuthResponse{
ID: e.Call.ID,
Accept: true,
}); err != nil {
t.Errorf("Error confirming: %v", err)
// Confirm the call
if err = g.Confirm(context.Background(), AuthResponse{
ID: confirmCallEvent.ID,
Accept: true,
}); err != nil {
t.Errorf("Error confirming: %v", err)
}
}
}
}
}
}()

out, err := run.Text()
if err != nil {
t.Errorf("Error reading output: %v", err)
}

// Wait for events processing to finish
<-done

if confirmCallEvent == nil {
t.Fatalf("No confirm call event")
}

if !strings.Contains(eventContent, "Makefile") || !strings.Contains(eventContent, "README.md") {
t.Errorf("Unexpected event output: %s", eventContent)
}
Expand Down

0 comments on commit 9bb1c82

Please sign in to comment.