Add M9.8c launcher, legend, labelled inspector and click selection

Toolkit-independent launcher, selection, label and outcome-log models with
bounded inputs and fixed error text; Dear ImGui overlay in the native adapter
with toolkit-first event routing and capture; engineering panels for fixture vs
dev region, legend, inspector, session outcomes, notices and dialog. Additive
SessionClient::unreachable_attempts() bounds unreachable connects. Docs, CI
targets and validation evidence updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-02 10:09:11 -04:00
co-authored by Claude Opus 5.5
parent a6e8094f57
commit 897055883a
36 changed files with 2106 additions and 200 deletions
+259
View File
@@ -0,0 +1,259 @@
// M9.8c toolkit-independent UI model: labels keep data states distinct, selection
// follows presentations, the launcher bounds credentials and errors, and the outcome
// log stays bounded.
#include "evo/client/labels.hpp"
#include "evo/client/launcher.hpp"
#include "evo/client/outcome_log.hpp"
#include "evo/client/selection.hpp"
#include <algorithm>
#include <chrono>
#include <cstdio>
#include <filesystem>
#include <fstream>
#include <source_location>
#include <stdexcept>
#include <string>
#include <vector>
namespace {
using namespace evo;
using namespace evo::client;
void check(bool ok, std::source_location at = std::source_location::current()) {
if (!ok)
throw std::runtime_error("client UI model line " + std::to_string(at.line()));
}
#define CHECK(...) check(static_cast<bool>(__VA_ARGS__))
constexpr world::WorldIdentity identity{3, 9};
EnvironmentCell cell(std::int64_t x) {
EnvironmentCell c;
c.voxel = {x, 0, 0};
c.chunk_revision = 4;
c.habitat = {{0}, {0}, {0}, {1000}, {1000}, {10}};
c.volume = {10'000'000};
c.substrate = {1};
c.terrain_material = {1};
c.terrain_fill = world::fill_scale;
c.presence[0] = FieldPresence::present; // Water: value.
c.quantity[0] = 80'000'000;
c.presence[2] = FieldPresence::present; // Phosphorus: present zero.
c.presence[1] = FieldPresence::missing; // Nitrogen: missing.
c.moisture_status = world::MoistureStatus::available;
c.moisture = {1, 4};
return c;
}
EnvironmentPresentation environment(std::vector<EnvironmentCell> cells, std::uint64_t tick = 1) {
auto p = EnvironmentPresentation::create({identity, tick, 1}, 0b111, 0, cells);
CHECK(p);
return std::move(*p);
}
OrganismCell organism(std::uint64_t id, std::uint64_t x_um) {
OrganismCell o;
o.id = id;
o.voxel = {0, 0, 0};
o.x = {x_um};
o.y = {500000};
o.phenotype.extent = 20;
o.phenotype.structural_mass = 8'000'000;
o.phenotype.membrane_mass = 1'000'000;
o.phenotype.total_mass = 9'000'000;
o.phenotype.conversion_per_thousand = 400;
o.growth.realized_per_thousand = 1000;
return o;
}
OrganismPresentation organisms(std::vector<OrganismCell> cells, std::uint64_t tick = 1) {
auto p = OrganismPresentation::create({identity, tick, 0}, 0, cells);
CHECK(p);
return std::move(*p);
}
void labels() {
const auto c = cell(0);
const auto water = describe_field(c, world::Field::water);
const auto nitrogen = describe_field(c, world::Field::nitrogen);
const auto phosphorus = describe_field(c, world::Field::phosphorus);
const auto carbon = describe_field(c, world::Field::organic_carbon);
CHECK(water.kind == ValueKind::value &&
water.text.starts_with("80000000 fg (8 fg/um3, log2 3.0)"));
CHECK(nitrogen.kind == ValueKind::missing && nitrogen.text.starts_with("MISSING"));
CHECK(phosphorus.kind == ValueKind::zero && phosphorus.text == "0 fg (present zero)");
CHECK(carbon.kind == ValueKind::not_requested);
// Every state reads differently: missing is never shown as 0, zero never as missing.
const std::vector<std::string> texts{water.text, nitrogen.text, phosphorus.text, carbon.text};
for (std::size_t i = 0; i < texts.size(); ++i)
for (std::size_t j = i + 1; j < texts.size(); ++j)
CHECK(texts[i] != texts[j]);
CHECK(nitrogen.text.find('0') == std::string::npos);
CHECK(describe_moisture(c).text == "25.00 % saturated");
auto dry = c;
dry.moisture_status = world::MoistureStatus::zero_capacity;
CHECK(describe_moisture(dry).kind == ValueKind::undefined);
dry.moisture_status = world::MoistureStatus::missing_water;
CHECK(describe_moisture(dry).kind == ValueKind::missing);
dry.moisture_status = world::MoistureStatus::available;
dry.moisture = {0, 1};
CHECK(describe_moisture(dry).kind == ValueKind::zero);
CHECK(field_name(world::Field::heat) == "Heat" && field_unit(world::Field::heat) == "pJ" &&
field_unit(world::Field::organic_other) == "fg");
CHECK(freshness_name(Freshness::stale).starts_with("STALE") &&
freshness_name(Freshness::none) != freshness_name(Freshness::current));
CHECK(density_scale(world::Field::water).find("-30") != std::string::npos);
const auto rows = organism_rows(organism(77, 500000));
CHECK(rows.size() == 15 && rows[0].value == "alive");
const auto extent =
std::ranges::find_if(rows, [](const Row& r) { return r.label == "Extent (side)"; });
CHECK(extent != rows.end() && extent->value == "20" && extent->unit == "um");
const auto speed =
std::ranges::find_if(rows, [](const Row& r) { return r.label == "Movement speed"; });
CHECK(speed != rows.end() && speed->value == "none");
for (const auto& r : rows)
CHECK(r.value.find("77") == std::string::npos); // The opaque id is never displayed.
const auto cell_info = cell_rows(c);
CHECK(cell_info[1].value == "rock" && cell_info[2].value == "100.0");
}
void selection() {
const auto env = environment({cell(0), cell(1)});
const auto orgs = organisms({organism(5, 500000), organism(6, 500010)});
auto camera = Camera::create({800, 600, 800, 600}, {500, 500}, 1000);
CHECK(camera);
Selection s;
s.pick({400, 300}, &env, &orgs, *camera); // Both organisms overlap: topmost (6) wins.
CHECK(s.kind() == Selection::Kind::organism && s.organism(&orgs) && s.organism(&orgs)->id == 6);
// The organism disappears from the next presentation: selection clears.
const auto later = organisms({organism(5, 500000)}, 2);
CHECK(s.refresh(&env, &later) == Selection::Change::organism_gone);
CHECK(s.kind() == Selection::Kind::none);
// No organism under the point: the habitat cell beneath it is selected.
s.pick({700, 300}, &env, &later, *camera);
CHECK(s.kind() == Selection::Kind::cell && s.cell(&env) && s.cell(&env)->voxel.x == 0);
// Without a presentation the selection is kept (unknown is not gone).
CHECK(s.refresh(nullptr, nullptr) == Selection::Change::none &&
s.kind() == Selection::Kind::cell);
const auto shrunk = environment({cell(1)}, 3);
CHECK(s.refresh(&shrunk, &later) == Selection::Change::cell_gone);
// Outside any data: nothing.
auto far = Camera::create({800, 600, 800, 600}, {-50000, 500}, 1000);
CHECK(far);
s.pick({400, 300}, &env, &orgs, *far);
CHECK(s.kind() == Selection::Kind::none);
}
void launcher() {
CHECK(parse_endpoint("127.0.0.1:17400") && parse_endpoint("127.0.0.1:17400")->port == 17400);
CHECK(parse_endpoint("dev-region.evolution.test:443"));
CHECK(parse_endpoint("[::1]:9") && parse_endpoint("[::1]:9")->host == "::1");
for (const auto* bad :
{"", "host", ":1", "host:0", "host:65536", "host:x", "bad host:1", "a;b:1", "[zz]:1"})
CHECK(!parse_endpoint(bad));
CHECK(!parse_endpoint(std::string(2000, 'a') + ":1"));
const auto dir = std::filesystem::temp_directory_path() /
("evo-launcher-" +
std::to_string(std::chrono::steady_clock::now().time_since_epoch().count()));
std::filesystem::create_directories(dir);
const auto write = [&](const char* name, const std::string& bytes) {
std::ofstream out{dir / name, std::ios::binary};
out << bytes;
return (dir / name).string();
};
ConnectForm form;
form.authority_path =
write("ca.pem", "-----BEGIN CERTIFICATE-----\nMIIB\n-----END CERTIFICATE-----\n");
form.grants_path = write("grants.bin", std::string(grant_record_bytes * 3, '\x01'));
const auto loaded = load_connect(form);
CHECK(loaded && loaded->grants.size() == 3 && loaded->endpoint.port == 17400);
const auto refused_with = [&](const ConnectForm& f, LaunchError e) {
const auto r = load_connect(f);
return !r && r.error() == e;
};
auto f = form;
f.endpoint = "nope";
CHECK(refused_with(f, LaunchError::endpoint));
f = form;
f.server_name = "bad name";
CHECK(refused_with(f, LaunchError::server_name));
f = form;
f.authority_path.clear();
CHECK(refused_with(f, LaunchError::authority_path));
f = form;
f.authority_path = (dir / "missing.pem").string();
CHECK(refused_with(f, LaunchError::authority_unreadable));
f = form;
f.authority_path = write("not-ca.pem", "hello");
CHECK(refused_with(f, LaunchError::authority_invalid));
f = form;
f.authority_path =
write("huge.pem", "-----BEGIN CERTIFICATE-----" + std::string(max_authority_bytes, 'A'));
CHECK(refused_with(f, LaunchError::authority_invalid));
f = form;
f.grants_path = write("partial.bin", std::string(grant_record_bytes + 1, '\x01'));
CHECK(refused_with(f, LaunchError::grants_invalid));
f = form;
f.grants_path =
write("many.bin", std::string(grant_record_bytes * (max_grant_records + 1), '\x01'));
CHECK(refused_with(f, LaunchError::grants_invalid));
f = form;
f.grants_path = (dir / "missing.bin").string();
CHECK(refused_with(f, LaunchError::grants_unreadable));
// Messages never echo file content.
for (auto e = 0; e <= static_cast<int>(LaunchError::no_session); ++e)
CHECK(launch_error_text(static_cast<LaunchError>(e)).find('\x01') ==
std::string_view::npos);
std::error_code ignored;
std::filesystem::remove_all(dir, ignored);
Launcher l;
CHECK(l.phase() == LaunchPhase::choosing && l.begin_connect());
CHECK(!l.begin_connect()); // Already connecting.
l.observe(ConnectSignal::not_ready);
l.observe(ConnectSignal::lost);
l.observe(ConnectSignal::lost);
CHECK(l.phase() == LaunchPhase::connecting);
l.observe(ConnectSignal::lost); // Third loss before any welcome: bounded failure.
CHECK(l.phase() == LaunchPhase::failed && l.error() == LaunchError::server_unreachable);
CHECK(l.begin_connect() && l.phase() == LaunchPhase::connecting); // Retry.
l.observe(ConnectSignal::refused);
CHECK(l.phase() == LaunchPhase::failed && l.error() == LaunchError::grant_refused);
l.cancel();
CHECK(l.phase() == LaunchPhase::choosing && l.begin_connect());
l.observe(ConnectSignal::welcome);
CHECK(l.phase() == LaunchPhase::connected && l.ever_connected());
for (int i = 0; i < 5; ++i)
l.observe(ConnectSignal::lost); // After a welcome: reconnecting, never failed.
CHECK(l.phase() == LaunchPhase::connecting);
l.observe(ConnectSignal::welcome);
l.observe(ConnectSignal::exhausted);
CHECK(l.phase() == LaunchPhase::failed && l.error() == LaunchError::grants_exhausted);
l.cancel();
l.start_fixture();
CHECK(l.phase() == LaunchPhase::fixture && !l.begin_connect());
l.observe(ConnectSignal::welcome); // Ignored outside a connect flow.
CHECK(l.phase() == LaunchPhase::fixture);
}
void outcome_log() {
OutcomeLog log;
log.record({1, OutcomeState::sent});
log.record({1, OutcomeState::admitted});
log.record({1, OutcomeState::durable, 0, 40, 3});
CHECK(log.entries().size() == 1 && log.entries()[0].state == OutcomeState::durable &&
log.entries()[0].commit_sequence == 3);
for (std::uint64_t s = 2; s < 2 + 200; ++s)
log.record({s, OutcomeState::unknown});
CHECK(log.entries().size() == OutcomeLog::capacity &&
log.evicted() == 201 - OutcomeLog::capacity);
CHECK(log.entries().back().sequence == 201);
}
} // namespace
int main() try {
labels();
selection();
launcher();
outcome_log();
std::puts("client UI model tests passed");
return 0;
} catch (const std::exception& e) {
std::fprintf(stderr, "%s\n", e.what());
return 1;
}