]> git.giacomolli.uk - onechat/blobdiff - daemon_message_test.go
Select notification targets by stable ID
[onechat] / daemon_message_test.go
index b401eb78cc7c90ee30e7071005909df35e21fe2f..0ef67fce60038084ef8d00bef6ab9fa16f7c1f0f 100644 (file)
@@ -780,6 +780,37 @@ func TestNotificationBatchesStayOrderedForEachChild(t *testing.T) {
        }
 }
 
+func TestChildNotificationReportsOnlyItsFinalReplyToTheRoot(t *testing.T) {
+       server := newModelFake(t)
+       server.reply = func(w http.ResponseWriter, call ModelFakeCall) {
+               reply := ""
+               if call.body["model"] == "gpt-test-garden" {
+                       reply = "A result needs the user."
+               }
+
+               modelWriteEvents(w, modelCompletedEvent([]any{modelMessageItem(reply)}, 100, 0, 5))
+       }
+
+       test := newDaemonMessageTest(t, t.TempDir(), server)
+       test.Start(t, 0, 1, 2)
+
+       _, err := test.messages.Notify(&NotifyInput{
+               AgentID: test.agents[1].agent.config.ID,
+               Source:  "check",
+               ID:      "report",
+               Text:    "Private child event data.",
+       })
+       require.NoError(t, err)
+       test.events[1].WaitFor(t, "idle", 1)
+       test.events[0].WaitFor(t, "idle", 1)
+       require.Equal(t, 2, server.Calls())
+       require.Equal(t, "[Garden] A result needs the user.", test.events[0].Last("work"))
+       require.Equal(t, 1, test.events[0].Count("work"))
+       require.Equal(t, notifySource, test.events[1].LastEvent("work").Source)
+       require.Zero(t, test.agents[2].memory.Len())
+       require.Empty(t, test.Queue(t).Pending)
+}
+
 func TestParentMessageWakesChildAndFinalReplyWakesParent(t *testing.T) {
        server := newModelFake(t)
        server.reply = func(w http.ResponseWriter, call ModelFakeCall) {