Something went wrong. Try again.
small gleam coding and persistent agent daemon with a detachable cli and a canvas ui forked from okami.mom/albedo
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135"""Prompts the model schedules for itself must show in the chat sidebar, sothe user sees what will wake the session without opening /schedule."""
import jsonimport sqlite3import unittestimport urllib.error
from harness import Albedo, Provider, exclusive, python, text
SCHEDULE = ( "await commands.schedule('add', 'in:5400 rebuild the index')\n" "await commands.schedule('heartbeat', 'every:600 check the ci')")
def reply(request): if request["messages"][-1].get("role") == "user": return python(SCHEDULE) return text("scheduled")
class ScheduleTests(unittest.TestCase): def test_http_refusals_preserve_status_code_and_detail(self): provider = Provider(lambda _: text("unused")) self.addCleanup(provider.close) with Albedo(provider) as app: session = app.session() candidate = { "session_id": session, "kind": "once", "prompt": "later", "delay_seconds": 3600, } for path, body, expected in [ ( "/extensions/schedule/jobs/9223372036854775807", None, (404, "not_found", "schedule not found"), ), ( "/extensions/schedule/jobs", {**candidate, "session_id": "absent-session"}, (404, "not_found", "session not found"), ), ( "/extensions/schedule/jobs", {**candidate, "prompt": ""}, (400, "invalid_request", "invalid schedule candidate"), ), ]: with self.subTest(path=path, body=body): with self.assertRaises(urllib.error.HTTPError) as caught: app.api(path, body) problem = json.load(caught.exception) self.assertEqual( (caught.exception.code, problem["code"], problem["detail"]), expected, ) with app.api("/extensions/schedule/jobs", candidate) as response: resource = json.load(response)["resource"] with app.api( resource["url"], {"prompt": "changed"}, method="PATCH", headers={"If-Match": resource["etag"]}, ) as response: response.read() with self.assertRaises(urllib.error.HTTPError) as caught: app.api( resource["url"], method="DELETE", headers={"If-Match": resource["etag"]}, ) problem = json.load(caught.exception) self.assertEqual( (caught.exception.code, problem["code"], problem["detail"]), (412, "precondition_failed", "the observed resource has changed"), )
# exclusive: installs a global schedule write trigger @exclusive def test_storage_refusal_is_not_reclassified_as_a_missing_schedule(self): provider = Provider(lambda _: text("unused")) self.addCleanup(provider.close) with Albedo(provider) as app: session = app.session() with sqlite3.connect(app.home / "albedo.sqlite") as db: db.execute( "CREATE TRIGGER reject_schedule BEFORE INSERT ON schedules " "BEGIN SELECT RAISE(FAIL, 'schedule not found'); END" ) with self.assertRaises(urllib.error.HTTPError) as caught: app.api( "/extensions/schedule/jobs", { "session_id": session, "kind": "once", "prompt": "later", "delay_seconds": 3600, }, ) problem = json.load(caught.exception) self.assertEqual(caught.exception.code, 503) self.assertEqual(problem["code"], "storage_failed") with app.api(f"/extensions/schedule/jobs?session_id={session}") as response: self.assertEqual(json.load(response)["items"], [])
def test_model_schedules_show_in_the_sidebar(self): provider = Provider(reply) self.addCleanup(provider.close) with Albedo(provider) as app: session = app.session() app.prompt(session, "remind yourself").close() app.idle(session) with app.api(f"/sessions/{session}?tail=0") as response: glances = json.load(response)["glances"] glance = next(g for g in glances if g["extension"] == "schedule") self.assertEqual(glance["title"], "scheduled") self.assertEqual( glance["url"], f"/extensions/schedule/jobs?session_id={session}" ) # soonest first, each led by when it fires self.assertEqual( [(row["badge"], row["text"]) for row in glance["rows"]], [ ("heartbeat", "heartbeat 10m · check the ci"), ("once", "in 1h · rebuild the index"), ], )
if __name__ == "__main__": unittest.main()