Deliver inbox answers mid-turn through the PostToolUse hook
This commit is contained in:
@@ -503,6 +503,64 @@ func TestAskHumanRoundTrip(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
const shapePrompt = `Ask me with ask_human (not blocking) whether shape.txt should say circle or square, recommending circle. ` +
|
||||
"Then, without waiting for my answer, run these Bash commands one at a time, each as its own tool call: `sleep 8`, then `echo second`, then `echo third`. " +
|
||||
`After those, write shape.txt containing exactly my answer if you have received it by then, or exactly unknown if not.`
|
||||
|
||||
func TestAnswerDeliveredMidTurn(t *testing.T) {
|
||||
t.Parallel()
|
||||
e := newEnv(t)
|
||||
m := e.manager()
|
||||
|
||||
sess, err := m.Create(e.ctx, e.task, e.user, shapePrompt, testModel)
|
||||
if err != nil {
|
||||
t.Fatalf("create session: %v", err)
|
||||
}
|
||||
e.waitFor("question filed", func(ev api.Event) bool {
|
||||
return ev.Kind == "inbox.created" && ev.Payload["kind"] == string(api.Question)
|
||||
})
|
||||
|
||||
questions := e.openQuestions(sess.Id)
|
||||
if len(questions) != 1 {
|
||||
t.Fatalf("want one open question, got %+v", questions)
|
||||
}
|
||||
square := ""
|
||||
options, _ := questions[0].Payload["options"].([]any)
|
||||
for _, o := range options {
|
||||
if strings.Contains(fmt.Sprint(o), "square") {
|
||||
square = fmt.Sprint(o)
|
||||
}
|
||||
}
|
||||
e.respond(m, questions[0], api.Option, square, "", api.Answered)
|
||||
events := e.waitIdle()
|
||||
|
||||
midTurn := false
|
||||
for _, ev := range events {
|
||||
if ev.Kind == "user.message" && ev.Payload["mid_turn"] == true && strings.Contains(ev.Payload["text"].(string), "chose: "+square) {
|
||||
midTurn = true
|
||||
}
|
||||
if ev.Kind == "turn.ended" && !midTurn {
|
||||
t.Fatalf("turn ended before the answer was delivered mid-turn: %v", kinds(events))
|
||||
}
|
||||
}
|
||||
if !midTurn {
|
||||
t.Fatalf("answer was not delivered mid-turn: %v", kinds(events))
|
||||
}
|
||||
|
||||
out, err := os.ReadFile(filepath.Join(e.task.WorktreePath, "shape.txt"))
|
||||
if err != nil {
|
||||
t.Fatalf("agent didn't write shape.txt: %v", err)
|
||||
}
|
||||
if strings.TrimSpace(string(out)) != "square" {
|
||||
t.Fatalf("shape.txt contains %q, want square", out)
|
||||
}
|
||||
|
||||
pending, err := e.store.Undelivered(e.ctx, sess.Id)
|
||||
if err != nil || len(pending) != 0 {
|
||||
t.Fatalf("responses left undelivered: %+v %v", pending, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCompactCarriesHandoff(t *testing.T) {
|
||||
t.Parallel()
|
||||
e := newEnv(t)
|
||||
|
||||
Reference in New Issue
Block a user