]> git.giacomolli.uk - onechat/blobdiff - daemon_message_test.go
Give the root tools to start and message children
[onechat] / daemon_message_test.go
index f9c25f13ad8e231e9c180a8f496bf9e818c48618..060faf5e0a7d4310e043e40afe3208acd3f40038 100644 (file)
@@ -532,6 +532,33 @@ func TestInvalidAgentMessageQueueStopsStartup(t *testing.T) {
        }
 }
 
+func TestChildScheduleWakesOnlyItsOwner(t *testing.T) {
+       server := newModelFake(t)
+       server.reply = func(w http.ResponseWriter, _ ModelFakeCall) {
+               modelWriteEvents(w, modelCompletedEvent([]any{modelMessageItem("")}, 100, 0, 5))
+       }
+       test := newDaemonMessageTest(t, t.TempDir(), server)
+       child := test.agents[1]
+       at := child.clock().Add(time.Minute).Format(scheduleAtLayout)
+       output := test.loops[1].tools.run(t.Context(), "schedule_set", `{"text":"Check the plants.","at":"`+at+`","cron":null}`)
+       require.Contains(t, output, "Schedule 1 set.")
+       require.Equal(t, "Garden", child.schedules.sorted()[0].Owner)
+
+       child.schedules.clock = func() time.Time {
+               return child.clock().Add(time.Minute)
+       }
+       require.ErrorContains(t, child.schedules.deliver(t.Context(), test.loops[0]), "does not match")
+       require.NoError(t, child.schedules.deliver(t.Context(), test.loops[1]))
+       test.Start(t, 0, 1, 2)
+       test.events[1].WaitFor(t, "idle", 1)
+       require.Equal(t, 1, server.Calls())
+       require.Equal(t, child.agent.CacheKey(), server.Call(0).body["prompt_cache_key"])
+       require.Zero(t, test.agents[0].memory.Len())
+       require.Zero(t, test.agents[2].memory.Len())
+       require.Contains(t, test.events[1].LastEvent("work").Text, "Check the plants.")
+       require.Equal(t, scheduleSource, test.events[1].LastEvent("work").Source)
+}
+
 // DaemonMessageTest owns test agents and the loops selected by Start.
 type DaemonMessageTest struct {
        agents   DaemonAgents