Skip to content

fix: ensure that all ls/dir calls are confirmed in test #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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