63 lines
1.5 KiB
Go
63 lines
1.5 KiB
Go
package gateway
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
type recordingTaskCreator struct {
|
|
req SpawnRequest
|
|
called bool
|
|
}
|
|
|
|
func (r *recordingTaskCreator) CreateTask(_ context.Context, req SpawnRequest) (int64, error) {
|
|
r.req = req
|
|
r.called = true
|
|
return 1, nil
|
|
}
|
|
|
|
func TestTaskSpawnBoundsTitleAndCarriesInstructions(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
title string
|
|
instructions string
|
|
wantErr bool
|
|
wantBody string
|
|
}{
|
|
{"title at the 80 character limit", strings.Repeat("a", 80), " the details ", false, "the details"},
|
|
{"title over the 80 character limit", strings.Repeat("a", 81), "", true, ""},
|
|
{"title alone is complete", "Fix the flaky test", "", false, ""},
|
|
}
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
creator := &recordingTaskCreator{}
|
|
entry := taskSpawnTool(creator, "identity")
|
|
input := map[string]any{"title": tc.title}
|
|
if tc.instructions != "" {
|
|
input["instructions"] = tc.instructions
|
|
}
|
|
|
|
_, err := entry.Handler(context.Background(), input)
|
|
if tc.wantErr {
|
|
if err == nil {
|
|
t.Fatal("expected an error")
|
|
}
|
|
if creator.called {
|
|
t.Fatal("task was created despite the error")
|
|
}
|
|
return
|
|
}
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if creator.req.Title != tc.title {
|
|
t.Errorf("title = %q, want %q", creator.req.Title, tc.title)
|
|
}
|
|
if creator.req.Body != tc.wantBody {
|
|
t.Errorf("body = %q, want %q", creator.req.Body, tc.wantBody)
|
|
}
|
|
})
|
|
}
|
|
}
|