Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / checks (network) (push) Successful in 4s
Foundation / checks (postgres) (push) Successful in 4s
Foundation / checks (tsan) (push) Successful in 5s
Foundation / checks (deploy) (push) Successful in 4m33s
Foundation / postgres-tools (push) Successful in 2m14s
Foundation / server-image (push) Successful in 5m21s
Foundation / image (push) Successful in 6m18s
The dev session window moves from Git to SQL (ADR-0087 amendment): the admin portal opens, extends (30 min to 4 h from now) and closes it, and the cellular region re-reads it every 5 s with --session-window-source db. No push, sync or restart per window; a closed window keeps the region running instead of crash-looping. - Schema 62: append-only session_windows (4 h cap, no rewrites), load_session_window_v1 for the runtime group, admin_set_session_window_v1 and admin_session_windows_v1 for a dedicated admin group role, granted and audited each migration run when EVO_PG_ADMIN_ROLE is set (aevolution_admin in DEV). Schema 61's views are revoked from the runtime group. - RegionSessions admission switch: while closed every Hello is refused before signature work and closing closes open sessions (new sessions were still admitted after expiry before). - Admin API: GET/POST /api/regions/<n>/session-window, window state in the regions list; the portal's session-window card with history. - Git: REGION_SESSION_WINDOW and the pre-push refresh rule are removed; the policy check requires the database source and refuses a committed window. Needs the new image and the aevolution_admin role (with the portal's login in aevolution-admin-pg) before a sync. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
85 lines
4.3 KiB
C++
85 lines
4.3 KiB
C++
#include "evo/server/session_window.hpp"
|
|
#include <cstdio>
|
|
#include <optional>
|
|
#include <string>
|
|
|
|
using evo::server::SessionWindow;
|
|
|
|
#define CHECK(...) \
|
|
do { \
|
|
if (!(__VA_ARGS__)) { \
|
|
std::fprintf(stderr, "CHECK failed: %s at line %d\n", #__VA_ARGS__, __LINE__); \
|
|
return 1; \
|
|
} \
|
|
} while (false)
|
|
|
|
int main() {
|
|
constexpr std::uint64_t now = 1'000;
|
|
static_assert(SessionWindow::max_duration_seconds == std::uint64_t{14'400});
|
|
|
|
auto opened = SessionWindow::open("dev-42:1200", now);
|
|
CHECK(opened.has_value());
|
|
CHECK(opened->activation_id() == "dev-42");
|
|
CHECK(opened->deadline_seconds() == 1200);
|
|
CHECK(opened->accepting(1'199));
|
|
CHECK(!opened->accepting(1'200));
|
|
CHECK(opened->closed());
|
|
|
|
// A restart re-reads the same absolute deadline; it does not get a new duration.
|
|
auto restarted = SessionWindow::open("dev-42:1200", 1'100);
|
|
CHECK(restarted.has_value());
|
|
CHECK(restarted->deadline_seconds() == 1200);
|
|
CHECK(!SessionWindow::open("dev-42:1200", 1'200).has_value());
|
|
CHECK(!SessionWindow::open("dev-42:1200", 1'201).has_value());
|
|
|
|
// Delayed application and clock movement cannot extend an expired window.
|
|
CHECK(!SessionWindow::open("dev-43:1200", 1'300).has_value());
|
|
CHECK(restarted->accepting(1'150));
|
|
CHECK(restarted->accepting(1'050));
|
|
CHECK(!restarted->accepting(1'200));
|
|
|
|
// Invalid activation/deadline forms and windows over four hours fail closed.
|
|
CHECK(!SessionWindow::open(":1200", now).has_value());
|
|
CHECK(!SessionWindow::open("dev space:1200", now).has_value());
|
|
CHECK(!SessionWindow::open("dev-44:not-a-number", now).has_value());
|
|
const auto maximum_deadline = now + SessionWindow::max_duration_seconds;
|
|
const auto maximum_window =
|
|
SessionWindow::open("dev-45:" + std::to_string(maximum_deadline), now);
|
|
CHECK(maximum_window.has_value());
|
|
CHECK(maximum_window->deadline_seconds() == maximum_deadline);
|
|
CHECK(!SessionWindow::open("dev-46:" + std::to_string(maximum_deadline + 1), now).has_value());
|
|
|
|
auto close = SessionWindow::open("dev-47:1200", now);
|
|
CHECK(close.has_value());
|
|
close->close();
|
|
CHECK(!close->accepting(1'001));
|
|
|
|
// ADR-0087 amendment: the database feed. No record keeps sessions closed.
|
|
using Feed = evo::server::SessionWindowFeed;
|
|
using Change = Feed::Change;
|
|
Feed feed;
|
|
CHECK(feed.observe(std::nullopt, now) == Change::none && !feed.accepting(now));
|
|
CHECK(feed.observe(Feed::Record{"adm-1", 1'200}, now) == Change::opened);
|
|
const auto& admitted = feed.window();
|
|
CHECK(feed.accepting(1'100) && admitted && admitted->deadline_seconds() == 1'200);
|
|
// Re-reading the same record changes nothing; a newer activation extends.
|
|
CHECK(feed.observe(Feed::Record{"adm-1", 1'200}, 1'150) == Change::none);
|
|
CHECK(feed.observe(Feed::Record{"adm-2", 5'000}, 1'150) == Change::opened);
|
|
CHECK(feed.accepting(1'250) && admitted && admitted->activation_id() == "adm-2");
|
|
// Its own deadline still closes it, and the same record cannot reopen it.
|
|
CHECK(!feed.accepting(5'000));
|
|
CHECK(feed.observe(Feed::Record{"adm-2", 5'000}, 4'000) == Change::none);
|
|
CHECK(!feed.accepting(4'001));
|
|
// A closing record closes; an expired or over-long newer one is refused and stays closed.
|
|
CHECK(feed.observe(Feed::Record{"adm-3", 9'000}, 6'000) == Change::opened);
|
|
CHECK(feed.observe(Feed::Record{"adm-4", std::nullopt}, 6'001) == Change::closed);
|
|
CHECK(!feed.accepting(6'002));
|
|
CHECK(feed.observe(Feed::Record{"adm-5", 6'000}, 6'010) == Change::refused);
|
|
CHECK(feed.observe(Feed::Record{"adm-6", 6'010 + 14'401}, 6'010) == Change::refused);
|
|
CHECK(!feed.accepting(6'011));
|
|
// A record that disappears (a restored database) closes the window.
|
|
CHECK(feed.observe(Feed::Record{"adm-7", 7'000}, 6'100) == Change::opened);
|
|
CHECK(feed.observe(std::nullopt, 6'101) == Change::closed && !feed.accepting(6'102));
|
|
return 0;
|
|
}
|