feat(admin): resource schedules for bubbles, pool releases and wildlife (schema 65)
Foundation / checks (ecs) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 5s
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (network) (push) Successful in 5s
Foundation / checks (deploy) (push) Successful in 6s
Foundation / checks (postgres) (push) Successful in 5s
Foundation / checks (tsan) (push) Successful in 5s
Foundation / postgres-tools (push) Successful in 23s
Foundation / server-image (push) Successful in 4m38s
Foundation / image (push) Successful in 5m35s

ADR-0182 section 12: the game source as recurring admin commands. A schedule
repeats add_bubbles, release_pool or spawn_wildlife every 1 s to 24 h while
enabled; the region's pending-command read queues each due run as an ordinary
command (recorded in the trace, bound once), never two waiting per schedule,
so an idle region builds no backlog. Append-only schedule versions; admin API
GET/POST /api/regions/<n>/schedules and a portal card to add, stop and start.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-27 18:30:37 -04:00
co-authored by Claude Opus 5.5
parent 2485a028bb
commit 018b4b1817
13 changed files with 425 additions and 14 deletions
+43
View File
@@ -587,6 +587,49 @@ void admin_api_tests(const Realm& realm) {
CHECK(!reader->query("DELETE FROM evolution.admin_commands", {}, 5s));
}
// Resource schedules (schema 65): a due schedule queues one command, never a second
// while that one waits; the list shows the run; stopping writes a new version.
for (const std::string_view bad :
{"/api/regions/1/schedules?kind=add_pool&count=1&interval=5&energy=1",
"/api/regions/1/schedules?kind=add_bubbles&count=4&interval=0&energy=1",
"/api/regions/1/schedules?kind=add_bubbles&count=4&interval=90000&energy=1",
"/api/regions/1/schedules?kind=add_bubbles&count=4&interval=5"})
CHECK(post(bad).status == 400);
const auto made = must(JsonValue::parse(
post("/api/regions/1/schedules?kind=add_bubbles&count=4&interval=60&energy=100&"
"reason=feed")
.body));
const auto schedule_id = std::string(must(made.member("id")->string()));
const auto pending_now = [&] {
auto reader = connect_as(env("EVO_PG_RUNTIME_USER"));
const auto rows = reader->query(
"SELECT count(*) FROM evolution.load_pending_admin_commands_v1(9831, 1)", {}, 5s);
CHECK(rows && rows->size() == 1);
return std::string(*(*rows)[0][0]);
};
CHECK(pending_now() == "3" && pending_now() == "3");
const auto listed_schedules =
must(JsonValue::parse(get("/api/regions/1/schedules", admin).body));
const auto& schedule = listed_schedules.member("schedules")->array()->at(0);
CHECK(schedule.member("id")->string() == schedule_id &&
schedule.member("kind")->string() == "add_bubbles" &&
schedule.member("runs")->integer() == 1 &&
schedule.member("enabled")->boolean() == true &&
schedule.member("interval")->integer() == 60);
const auto queued_by_schedule =
must(JsonValue::parse(get("/api/regions/1/commands", admin).body));
CHECK(queued_by_schedule.member("commands")->array()->at(0).member("author")->string() ==
"schedule " + schedule_id);
CHECK(post("/api/regions/1/schedules?kind=add_bubbles&count=4&interval=60&energy=100&"
"enabled=0&id=" +
schedule_id)
.status == 200);
const auto stopped = must(JsonValue::parse(get("/api/regions/1/schedules", admin).body));
CHECK(stopped.member("schedules")->array()->size() == 1 &&
stopped.member("schedules")->array()->at(0).member("enabled")->boolean() == false);
CHECK(post("/api/regions/1/schedules?kind=add_bubbles&count=4&interval=60&energy=1&id=999999")
.status == 400);
// Accounts (schema 64): control claims recorded alice's sessions; a ban refuses grants
// and is listed with its reason; lifting it restores them; an admin logout succeeds.
CHECK(alice->member("sessions")->integer().value_or(0) >= 1 &&