okami.mom/albedo

git clone https://git.nkp.pet/okami.mom/albedo

nekomimi.petmake schedule visible7f83187

main
1.6 KiB47 linesraw
1"""Prompts the model schedules for itself must show in the chat sidebar, so
2the user sees what will wake the session without opening /schedule."""
3
4import json
5import unittest
6
7from harness import Albedo, Provider, python, text
8
9SCHEDULE = (
10    "await commands.schedule('add', 'in:5400 rebuild the index')\n"
11    "await commands.schedule('heartbeat', 'every:600 check the ci')"
12)
13
14
15def reply(request):
16    if request["messages"][-1].get("role") == "user":
17        return python(SCHEDULE)
18    return text("scheduled")
19
20
21class ScheduleTests(unittest.TestCase):
22    def test_model_schedules_show_in_the_sidebar(self):
23        provider = Provider(reply)
24        self.addCleanup(provider.close)
25        with Albedo(provider) as app:
26            session = app.session()
27            app.prompt(session, "remind yourself").close()
28            app.idle(session)
29            with app.api(f"/sessions/{session}?tail=0") as response:
30                glances = json.load(response)["glances"]
31            glance = next(g for g in glances if g["extension"] == "schedule")
32            self.assertEqual(glance["title"], "scheduled")
33            self.assertEqual(
34                glance["url"], f"/extensions/schedule/jobs?session_id={session}"
35            )
36            # soonest first, each led by when it fires
37            self.assertEqual(
38                [(row["badge"], row["text"]) for row in glance["rows"]],
39                [
40                    ("heartbeat", "heartbeat 10m · check the ci"),
41                    ("once", "in 1h · rebuild the index"),
42                ],
43            )
44
45
46if __name__ == "__main__":
47    unittest.main()