]> git.giacomolli.uk - onechat/blobdiff - daemon_children_test.go
Bind external events to permanent agent IDs
[onechat] / daemon_children_test.go
index 8349586aa89224c95754591b993602bc97bb8e2e..8fcae369de4c8b30fefd50743e1c6b9b3f3b684e 100644 (file)
@@ -99,6 +99,37 @@ func TestDaemonToolsCreateAndTellAChildDuringATurn(t *testing.T) {
        }, 5*time.Second, time.Millisecond)
 }
 
+func TestRuntimeChildAcceptsNotificationsByItsPermanentID(t *testing.T) {
+       test := newDaemonChildrenTest(t)
+       test.server.reply = func(w http.ResponseWriter, _ ModelFakeCall) {
+               modelWriteEvents(w, modelCompletedEvent([]any{modelMessageItem("")}, 100, 0, 5))
+       }
+
+       _, err := test.runtime.Create("Garden", "Keep garden plans.")
+       require.NoError(t, err)
+
+       child := test.runtime.messages.Child(test.root.agent.config.Name, "Garden")
+       require.NotNil(t, child)
+
+       receipt, err := test.runtime.messages.Notify(&NotifyInput{
+               AgentID: child.agent.config.ID,
+               Source:  "check",
+               ID:      "runtime-child",
+               Text:    "A new result.",
+       })
+       require.NoError(t, err)
+       require.Equal(t, "accepted", receipt.Status)
+       require.Eventually(t, func() bool {
+               return child.memory.Len() == 1
+       }, 10*time.Second, time.Millisecond)
+       require.Zero(t, test.root.memory.Len())
+
+       logged, err := child.memory.Message(0)
+       require.NoError(t, err)
+       require.Equal(t, "work", logged.Kind)
+       require.Contains(t, logged.Text, "Untrusted external data")
+}
+
 func TestChildCreationRefusesUsedNames(t *testing.T) {
        test := newDaemonChildrenTest(t)
        box := test.root.tools