Bold questions
This commit is contained in:
@@ -2,6 +2,7 @@ package agents
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -51,6 +52,65 @@ func TestValidateAsk(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAsksQuestion(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
text string
|
||||
want bool
|
||||
}{
|
||||
{"prose question (seq 61)", "Which of these do you want to start with?", true},
|
||||
{"question mid-message", "I can do either.\n\nWhich do you want first? I'd start with the spinner.", true},
|
||||
{"bold question", "**Should I deploy now?**", true},
|
||||
{"question mark only inside quotes (seq 108)", "- **A:** block if the final message contains a \"?\".\n- **C:** block if the turn's report lists open questions.\n\nMy recommendation is A and C together.", false},
|
||||
{"quoted question", "Without it, a question like \"Which of these do you want to start with?\" still reaches you as plain text.", false},
|
||||
{"inline code", "The view calls `GET /api/inbox?task=x` on load.", false},
|
||||
{"fenced code", "Run:\n```\nif ok? then\n```\nDone.", false},
|
||||
{"url query", "See https://example.com/?a=1 for details.", false},
|
||||
{"blockquote", "> did it work?\n\nIt did.", false},
|
||||
{"no question", "I committed everything and the tests pass.", false},
|
||||
}
|
||||
for _, c := range cases {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
if got := asksQuestion(c.text); got != c.want {
|
||||
t.Fatalf("asksQuestion(%q) = %v, want %v", c.text, got, c.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestBounceProseQuestion(t *testing.T) {
|
||||
m := &Manager{}
|
||||
stop := func(l *live, text string) map[string]any {
|
||||
t.Helper()
|
||||
input, err := json.Marshal(map[string]any{"hook_event_name": "Stop", "last_assistant_message": text})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
out, err := m.bounceProseQuestion(l)(context.Background(), input)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
l := &live{}
|
||||
if out := stop(l, "Which of these do you want to start with?"); out["decision"] != "block" || out["reason"] != proseQuestionNudge {
|
||||
t.Fatalf("prose question not bounced: %v", out)
|
||||
}
|
||||
if out := stop(l, "Which of these do you want to start with?"); len(out) != 0 {
|
||||
t.Fatalf("bounced twice in one turn: %v", out)
|
||||
}
|
||||
|
||||
asked := &live{asked: true}
|
||||
if out := stop(asked, "Should I go ahead?"); len(out) != 0 {
|
||||
t.Fatalf("bounced a turn that called ask_human: %v", out)
|
||||
}
|
||||
|
||||
if out := stop(&live{}, "I committed everything and the tests pass."); len(out) != 0 {
|
||||
t.Fatalf("bounced a message with no question: %v", out)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeliveryMessage(t *testing.T) {
|
||||
str := func(s string) *string { return &s }
|
||||
question := api.InboxItem{Id: "q1", ThreadId: "q1", Kind: api.Question, Payload: map[string]any{"question": "Which color?"}}
|
||||
|
||||
Reference in New Issue
Block a user