]> git.giacomolli.uk - onechat/blobdiff - schedule_test.go
Give the root agent the schedule tools
[onechat] / schedule_test.go
index 5ef174bbf9090bbccf1c9f47514d64a6b61e98bb..c13f023ff4ed23b29d25b0081e0b82d9732296c0 100644 (file)
@@ -245,3 +245,24 @@ func scheduleTestOpen(t *testing.T) (*Schedules, string) {
 
        return schedules, path
 }
+
+func TestToolboxRunsTheScheduleTools(t *testing.T) {
+       schedules, _ := scheduleTestOpen(t)
+       box := &Toolbox{
+               schedules: schedules,
+       }
+
+       require.Equal(t, "Schedule 1 set. Next: Monday 2026-11-09 08:00 -03:00.", box.run(t.Context(), "schedule_set", `{"text":"Tell the user the news.","at":null,"cron":"0 8 * * 1-5"}`))
+       require.Equal(t, "Schedule 2 set. Next: Sunday 2026-11-08 20:02 -03:00.", box.run(t.Context(), "schedule_set", `{"text":"Remind the user to drink water.","at":"2026-11-08 20:02","cron":null}`))
+       require.Equal(t, "2 | Sunday 2026-11-08 20:02 -03:00 | once | Remind the user to drink water.\n1 | Monday 2026-11-09 08:00 -03:00 | 0 8 * * 1-5 | Tell the user the news.", box.run(t.Context(), "schedule_list", `{}`))
+       require.Equal(t, "Schedule 1 removed.", box.run(t.Context(), "schedule_remove", `{"id":1}`))
+       require.Equal(t, "error: no schedule 1", box.run(t.Context(), "schedule_remove", `{"id":1}`))
+       require.Equal(t, "error: give either at or cron, and null for the other", box.run(t.Context(), "schedule_set", `{"text":"x","at":null,"cron":null}`))
+}
+
+func TestSubagentHasNoScheduleTools(t *testing.T) {
+       box := &Toolbox{}
+       require.Equal(t, `error: unknown tool "schedule_set"`, box.run(t.Context(), "schedule_set", `{"text":"x","at":"2026-11-09 09:00","cron":null}`))
+       require.Equal(t, `error: unknown tool "schedule_list"`, box.run(t.Context(), "schedule_list", `{}`))
+       require.Equal(t, `error: unknown tool "schedule_remove"`, box.run(t.Context(), "schedule_remove", `{"id":1}`))
+}