Files
aevolution/tests/client_ui_state.cpp
dingoandClaude Opus 5.5 3320a8a574
Foundation / checks (deploy) (push) Successful in 3m26s
Foundation / checks (ecs) (push) Successful in 2m2s
Foundation / checks (client) (push) Successful in 12m47s
Foundation / checks (tsan) (push) Canceled after 0s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (network) (push) Canceled after 11m44s
Foundation / checks (checks) (push) Canceled after 17m14s
Foundation / checks (postgres) (push) Canceled after 4m27s
client: skip used grants; scale the engineering UI with the window
- A stale_grant before Welcome spends only that grant: the session tries the next one
  in the bundle and ends as exhausted when none is left (other refusals still stop).
- UI scale (ADR-0084 amendment): embedded scalable font (ProggyForever), scale from
  logical window height (720 reference, 1.0-2.5) times a Ctrl+= / Ctrl+- nudge; panel
  sizes and table columns in logical units; movable panels placed again per scale.
- --size W,H for engineering review screenshots.
- Tests: client_remote_session (stale grant, exhausted), client_ui_state (scale).
Refresh the dev session window.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 12:09:57 -04:00

60 lines
2.6 KiB
C++

#include "evo/client/ui_state.hpp"
#include <cmath>
#include <cstdio>
#include <limits>
#include <stdexcept>
#include <string>
using namespace evo::client;
void check(bool ok) {
if (!ok)
throw std::runtime_error("UI state contract");
}
int main() try {
// UI scale: grows with the window from a 720-point reference, clamped, times the
// user's nudge on a 0.1 grid; nonsense inputs count as 1.
const auto near = [](float a, float b) { return std::fabs(a - b) < 1e-4F; };
check(near(ui_scale(640, 1), 1.0F) && near(ui_scale(720, 1), 1.0F));
check(near(ui_scale(1080, 1), 1.5F) && near(ui_scale(2160, 1), 2.5F)); // Clamped.
check(near(ui_scale(1080, 1.2F), 1.8F) && near(ui_scale(720, 5), 2.0F));
check(near(ui_scale(0, 1), 1.0F) && near(ui_scale(720, -1), 1.0F) &&
near(ui_scale(720, std::nanf("")), 1.0F));
check(near(ui_user_nudge(1, 1), 1.1F) && near(ui_user_nudge(1.1F, -1), 1.0F));
check(near(ui_user_nudge(2, 1), 2.0F) && near(ui_user_nudge(0.5F, -1), 0.5F));
float user = 1;
for (int i = 0; i < 7; ++i)
user = ui_user_nudge(user, 1);
check(near(user, 1.7F)); // No drift off the grid.
UiState ui;
check(ui.advance(100).has_value());
auto first = ui.notify("Connected", NoticeLevel::info, 10);
check(first.has_value());
check(ui.advance(109).has_value() && ui.notices().size() == 1);
check(ui.advance(110).has_value() && ui.notices().empty());
check(!ui.dismiss(*first));
check(!ui.advance(109));
check(!ui.notify(std::string(241, 'x'), NoticeLevel::info));
check(!ui.notify(std::string_view{"x\0y", 3}, NoticeLevel::info));
check(!ui.notify("invalid", NoticeLevel::info, 0));
for (int i = 0; i < 10000; ++i)
check(ui.notify("Burst", NoticeLevel::warning).has_value());
check(ui.notices().size() == 8 && ui.evicted_notices() == 9992);
auto dismissed = ui.notices().back().id;
check(ui.dismiss(dismissed));
check(ui.notices().size() == 7 && !ui.dismiss(dismissed));
auto dialog = ui.open_dialog("Disconnect?", "Current intentions may remain unknown.");
check(dialog.has_value());
check(!ui.open_dialog("Other", "Blocked"));
check(!ui.close_dialog(*dialog + 1));
check(ui.close_dialog(*dialog));
auto next = ui.open_dialog("New", "New modal");
check(next.has_value());
check(!ui.close_dialog(*dialog) && ui.dialog().has_value());
check(ui.close_dialog(*next));
check(ui.advance(std::numeric_limits<std::uint64_t>::max()).has_value());
check(!ui.notify("Overflow", NoticeLevel::error, 1));
return 0;
} catch (const std::exception& error) {
std::fprintf(stderr, "%s\n", error.what());
return 1;
}