Skip to content

Commit 5924712

Browse files
committed
chore: add test for prompt with metadata
Signed-off-by: Donnie Adams <donnie@acorn.io>
1 parent 14a861d commit 5924712

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

gptscript_test.go

+62
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,68 @@ func TestPrompt(t *testing.T) {
11071107
}
11081108
}
11091109

1110+
func TestPromptWithMetadata(t *testing.T) {
1111+
run, err := g.Run(context.Background(), "sys.prompt", Options{IncludeEvents: true, Prompt: true, Input: `{"fields":"first name","metadata":{"key":"value"}}`})
1112+
if err != nil {
1113+
t.Errorf("Error executing tool: %v", err)
1114+
}
1115+
1116+
// Wait for the prompt event
1117+
var promptFrame *PromptFrame
1118+
for e := range run.Events() {
1119+
if e.Prompt != nil {
1120+
if e.Prompt.Type == EventTypePrompt {
1121+
promptFrame = e.Prompt
1122+
break
1123+
}
1124+
}
1125+
}
1126+
1127+
if promptFrame == nil {
1128+
t.Fatalf("No prompt call event")
1129+
}
1130+
1131+
if promptFrame.Sensitive {
1132+
t.Errorf("Unexpected sensitive prompt event: %v", promptFrame.Sensitive)
1133+
}
1134+
1135+
if len(promptFrame.Fields) != 1 {
1136+
t.Fatalf("Unexpected number of fields: %d", len(promptFrame.Fields))
1137+
}
1138+
1139+
if promptFrame.Fields[0] != "first name" {
1140+
t.Errorf("Unexpected field: %s", promptFrame.Fields[0])
1141+
}
1142+
1143+
if promptFrame.Metadata["key"] != "value" {
1144+
t.Errorf("Unexpected metadata: %v", promptFrame.Metadata)
1145+
}
1146+
1147+
if err = g.PromptResponse(context.Background(), PromptResponse{
1148+
ID: promptFrame.ID,
1149+
Responses: map[string]string{promptFrame.Fields[0]: "Clicky"},
1150+
}); err != nil {
1151+
t.Errorf("Error responding: %v", err)
1152+
}
1153+
1154+
// Read the remainder of the events
1155+
for range run.Events() {
1156+
}
1157+
1158+
out, err := run.Text()
1159+
if err != nil {
1160+
t.Errorf("Error reading output: %v", err)
1161+
}
1162+
1163+
if !strings.Contains(out, "Clicky") {
1164+
t.Errorf("Unexpected output: %s", out)
1165+
}
1166+
1167+
if len(run.ErrorOutput()) != 0 {
1168+
t.Errorf("Should have no stderr output: %v", run.ErrorOutput())
1169+
}
1170+
}
1171+
11101172
func TestPromptWithoutPromptAllowed(t *testing.T) {
11111173
tools := ToolDef{
11121174
Instructions: "Use the sys.prompt user to ask the user for 'first name' which is not sensitive. After you get their first name, say hello.",

0 commit comments

Comments
 (0)