Upgrade cellular client to v10 with readable play and assisted steering

This commit is contained in:
dingo
2026-10-14 19:53:28 -04:00
parent 75b8bbb333
commit 68958a9e54
21 changed files with 1603 additions and 93 deletions
+8 -6
View File
@@ -286,13 +286,15 @@ void toolkit_capture() {
int presses = 0;
bool text_focus = false;
std::array<char, 32> text{}, field{};
ImVec2 field_min{}, field_max{};
ImVec2 field_min{}, field_max{}, button_centre{};
app->set_overlay([&] {
ImGui::SetNextWindowPos({0, 0}, ImGuiCond_Always);
ImGui::SetNextWindowSize({150, 150}, ImGuiCond_Always);
ImGui::SetNextWindowSize({180, 190}, ImGuiCond_Always);
ImGui::Begin("panel", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize);
if (ImGui::Button("Press", {130, 40}))
++presses;
const auto button_min = ImGui::GetItemRectMin(), button_max = ImGui::GetItemRectMax();
button_centre = {(button_min.x + button_max.x) / 2, (button_min.y + button_max.y) / 2};
ImGui::InputText("field", field.data(), field.size());
field_min = ImGui::GetItemRectMin();
field_max = ImGui::GetItemRectMax();
@@ -331,7 +333,7 @@ void toolkit_capture() {
// Over the widget: the button activates once, the world sees no click.
// The panel exists before the user clicks (as every application panel does).
CHECK(app->present(frame) == Step::rendered && app->present(frame) == Step::rendered);
CHECK(!click(60, 30) && presses == 1 && app->ui_wants_pointer());
CHECK(!click(button_centre.x, button_centre.y) && presses == 1 && app->ui_wants_pointer());
// Open world: a click is delivered once, then consumed.
const auto world = click(260, 200);
CHECK(world && world->x == 260 && world->y == 200 && presses == 1);
@@ -347,9 +349,9 @@ void toolkit_capture() {
// nothing and the widget still activates on the toolkit's next frames.
mouse(SDL_EVENT_MOUSE_MOTION, 260, 200);
CHECK(app->poll_events() && app->present(frame) == Step::rendered && !app->ui_wants_pointer());
mouse(SDL_EVENT_MOUSE_MOTION, 60, 30);
mouse(SDL_EVENT_MOUSE_BUTTON_DOWN, 60, 30);
mouse(SDL_EVENT_MOUSE_BUTTON_UP, 60, 30);
mouse(SDL_EVENT_MOUSE_MOTION, button_centre.x, button_centre.y);
mouse(SDL_EVENT_MOUSE_BUTTON_DOWN, button_centre.x, button_centre.y);
mouse(SDL_EVENT_MOUSE_BUTTON_UP, button_centre.x, button_centre.y);
CHECK(app->poll_events() && !app->take_navigation().click);
for (int i = 0; i < 5 && presses == 1; ++i)
CHECK(app->present(frame) == Step::rendered && app->poll_events());
+167 -1
View File
@@ -2,8 +2,10 @@
// software renderer, pinned toolkit). Notices fit their fixed-width window with a
// visible close button; clicking it (move + press + release in one batch, no settling
// frame) dismisses exactly that notice and never reaches the world.
#include "cellular_scene.hpp"
#include "controls_flow.hpp"
#include "evo/client/application.hpp"
#include "evo/render/organism.hpp"
#include "panels.hpp"
#include <SDL3/SDL.h>
#include <array>
@@ -25,6 +27,11 @@ void check(bool ok, std::source_location at = std::source_location::current()) {
throw std::runtime_error("client panels line " + std::to_string(at.line()));
}
#define CHECK(...) check(static_cast<bool>(__VA_ARGS__))
template <class T> const T& required(const std::optional<T>& value) {
if (!value)
throw std::runtime_error("missing panel test value");
return *value;
}
SDL_Window* window() {
int count{};
SDL_Window** windows = SDL_GetWindows(&count);
@@ -349,12 +356,171 @@ void apply_save_restart() {
CHECK(intention && intention->move_x == -1000);
std::filesystem::remove_all(dir);
}
void cellular_panels(const std::filesystem::path& review) {
for (const auto size : {std::pair{960, 640}, std::pair{1280, 800}, std::pair{640, 480}}) {
const auto [width, height] = size;
auto opened = Application::open({width, height, false, "software"});
CHECK(opened);
auto app = std::move(*opened);
const auto id = SDL_GetWindowID(window());
SDL_Event focus{};
focus.type = SDL_EVENT_WINDOW_FOCUS_GAINED;
focus.window.windowID = id;
CHECK(SDL_PushEvent(&focus) && app->poll_events());
std::vector<render::Rectangle> boxes{
{0, 0, static_cast<float>(width), static_cast<float>(height), {8, 19, 25, 255}}};
const auto camera =
Camera::create({width, height, width, height}, {width < 880 ? 0.29 : 2.1, 3.29}, 100);
CHECK(camera);
for (int x = 0; x < 5; ++x)
for (int y = 0; y < 6; ++y) {
const auto low =
camera->world_to_screen({static_cast<double>(x), static_cast<double>(y)});
const auto high = camera->world_to_screen({x + 1.0, y + 1.0});
CHECK(low && high);
patch_box(boxes, *low, *high, (x + y) % 4 != 0, x == 2 && y == 3, width, height);
}
OrganismCell organism;
organism.id = 901;
organism.x = {2200};
organism.y = {3200};
organism.phenotype.extent = 300;
organism.phenotype.total_mass = 10000;
organism.phenotype.structural_mass = 9000;
organism.phenotype.membrane_mass = 1000;
organism.phenotype.conversion_per_thousand = 650;
organism.phenotype.movement_speed = 500;
organism.phenotype.ingestion_rate = 400;
organism.growth.realized_per_thousand = 1000;
const auto population =
OrganismPresentation::create({{100, 1}, 102, 1}, 0, std::array{organism});
CHECK(population);
CHECK(render::append_organisms(boxes, 100, &*population, Freshness::current, *camera));
const auto frame = render::Frame::create(boxes);
CHECK(frame);
UiState ui;
Launcher launch;
Selection selection;
EnvironmentLayer environment;
OrganismLayer organisms;
CellularPlay play;
play.initialize(100);
play.connected();
network::CellularLifeDiagnostics diagnostics;
diagnostics.reserve_energy_pj = 248000;
diagnostics.reserve_matter_fg = {15000, 2400, 800, 6000};
diagnostics.has_tick_effects = true;
diagnostics.maintenance_cost_pj = 80;
diagnostics.movement_cost_pj = 20;
diagnostics.movement = network::CellularMovementResult::moved;
diagnostics.intake = network::CellularIntakeResult::acquired;
diagnostics.engulf = network::CellularEngulfResult::membrane_too_thick;
network::CellularPerception perception{
102, 901, {{1000, 2000, 50000, {100, 20, 10, 40}}}, diagnostics};
play.observe(perception);
play.observe_offer(network::CellularMutationOffer{
102,
901,
1,
100,
{{3, 2, 0, 500, 1600, 22000, 1200, {100, 20, 10, 40}},
{5, 1, 0, 2, 2000, 26000, 5000, {500, 80, 20, 120}},
{8, 3, 0, 400, 1800, 24000, 300000, {400, 60, 20, 100}}}});
FormBuffers form;
render::EnvironmentDisplay display;
PanelView view;
view.mode = Mode::remote;
view.launcher = &launch;
view.environment = &environment;
view.organisms = &organisms;
view.selection = &selection;
view.ui = &ui;
view.bindings = &app->bindings();
view.cellular_perception = &perception;
view.cellular_play = &play;
view.remote.emplace();
view.remote->phase = "connected";
view.remote->cellular_trial = true;
view.remote->server_tick = 102;
view.remote->region = 4;
PanelActions action;
app->set_overlay([&] { action = draw_panels(view, form, display); });
const auto draw = [&] {
CHECK(app->poll_events() && app->present(*frame) == Step::rendered);
};
for (int i = 0; i < 3; ++i)
draw();
const auto* journal = ImGui::FindWindowByName("Cellular field journal");
CHECK(journal && journal->Active && journal->ScrollMax.x == 0);
CHECK(journal->Pos.x >= 0 && journal->Pos.y >= 0 &&
journal->Pos.x + journal->Size.x <= static_cast<float>(width) &&
journal->Pos.y + journal->Size.y <= static_cast<float>(height));
if (!review.empty()) {
std::filesystem::create_directories(review);
CHECK(app->request_screenshot(
(review / ("cellular-" + std::to_string(width) + ".bmp")).string()));
draw();
}
if (width != 960)
continue;
const auto* evolution = ImGui::FindWindowByName("Evolution");
CHECK(evolution && evolution->Active && evolution->ScrollMax.x == 0);
CHECK(evolution->Pos.x >= journal->Pos.x + journal->Size.x &&
evolution->Pos.x + evolution->Size.x <= static_cast<float>(width));
// Click the first production choice. Pointer ownership prevents world selection.
const auto probe = [&](const ImGuiWindow* panel, float x_fraction, const auto& done) {
const float x = panel->Pos.x + panel->Size.x * x_fraction;
for (int offset = 90; static_cast<float>(offset) < panel->Size.y - 10; offset += 5) {
const float y = panel->Pos.y + static_cast<float>(offset);
mouse(id, SDL_EVENT_MOUSE_MOTION, x, y);
mouse(id, SDL_EVENT_MOUSE_BUTTON_DOWN, x, y);
mouse(id, SDL_EVENT_MOUSE_BUTTON_UP, x, y);
CHECK(app->poll_events() && !app->take_navigation().click);
for (int i = 0; i < 3; ++i) {
CHECK(app->present(*frame) == Step::rendered && app->poll_events());
if (done())
return true;
}
}
return false;
};
auto depleted = diagnostics;
depleted.reserve_energy_pj = 0;
perception.diagnostics = depleted;
draw();
CHECK(!probe(evolution, 0.5F, [&] { return action.mutation.has_value(); }));
perception.diagnostics = diagnostics;
draw();
CHECK(probe(evolution, 0.5F, [&] { return action.mutation.has_value(); }));
CHECK(action.mutation == MutationChoice{901, 1, 100, 3});
CHECK(play.queue(CellAction::mutation, 102, required(action.mutation)));
const auto mutation_id = required(play.pending()).id;
draw();
CHECK(!probe(evolution, 0.5F, [&] { return action.mutation.has_value(); }));
play.outcome({mutation_id, network::ActionResult::committed, 103, 5});
draw();
CHECK(probe(journal, 0.75F, [&] { return action.cell_action == CellAction::bud; }));
play.observe_end({104, 901, network::CellularDeathReason::engulfed});
perception = {104, 0, {}, {}};
play.observe(perception);
draw();
if (!review.empty()) {
CHECK(app->request_screenshot((review / "cellular-death.bmp").string()));
draw();
}
CHECK(probe(evolution, 0.5F, [&] { return action.restart_life; }));
CHECK(play.restart());
draw();
CHECK(!probe(evolution, 0.5F, [&] { return action.restart_life; }));
}
}
} // namespace
int main() try {
int main(int argc, char** argv) try {
notices();
controls_panel();
apply_save_restart();
cellular_panels(argc == 2 ? std::filesystem::path{argv[1]} : std::filesystem::path{});
std::puts("client panel tests passed");
return 0;
} catch (const std::exception& e) {
+157 -3
View File
@@ -36,6 +36,11 @@ void check(bool ok, std::source_location at = std::source_location::current()) {
throw std::runtime_error("client remote session line " + std::to_string(at.line()));
}
#define CHECK(...) check(static_cast<bool>(__VA_ARGS__))
template <class T> const T& required(const std::optional<T>& value) {
if (!value)
throw std::runtime_error("missing remote client test value");
return *value;
}
constexpr std::string_view name = "dev-region.evolution.test";
constexpr world::WorldIdentity world_id{7, 3};
constexpr std::uint64_t region = 12;
@@ -97,7 +102,9 @@ client::EnvironmentCell cell(std::int64_t x, std::int64_t y, std::uint64_t quant
// A region on loopback with a 21 x 21 slice (x, y in -10..10 at z -7), one snapshot per tick.
struct Region {
explicit Region(const Files& f) : files{f} {
explicit Region(const Files& f,
const std::function<void(server::RegionSessionsConfig&)>& configure = {})
: files{f} {
server::RegionSessionsConfig c;
c.transport.certificate_pem_file = f.certificate.string();
c.transport.key_pem_file = f.key.string();
@@ -107,13 +114,17 @@ struct Region {
c.control.epoch = epoch;
c.control.max_account_attempts = 16;
c.issuer_keys.push_back({1, *key.public_key()});
if (configure)
configure(c);
const bool cellular = c.accept_cellular_actions;
auto made = server::RegionSessions::create(std::move(c));
CHECK(made.has_value());
sessions = std::move(*made);
sessions->set_default_interest({3, 3, -7, 7});
// Probe markers (ADR-0094) over the slice's cells, spawning in the middle of (3, 3).
CHECK(sessions->set_motion_area({-10'000'000, -10'000'000, 10'999'999, 10'999'999, -7},
3'500'000, 3'500'000));
if (!cellular)
CHECK(sessions->set_motion_area({-10'000'000, -10'000'000, 10'999'999, 10'999'999, -7},
3'500'000, 3'500'000));
}
WireGrant grant(const AccountId& who, std::uint64_t serial,
std::uint64_t in_region = region) const {
@@ -153,11 +164,14 @@ struct Region {
});
}
static_cast<void>(sessions->take_events());
if (after_poll)
after_poll();
}
const Files& files;
GrantSigningKey key = *GrantSigningKey::import(DeploymentEnvironment::dev, 1, scalar());
std::unique_ptr<server::RegionSessions> sessions;
std::uint64_t epoch{3}, tick{100}, replicated{};
std::function<void()> after_poll;
};
struct Client {
@@ -488,6 +502,145 @@ void crossing_regions(const Files& f) {
CHECK(a.phase() == LaunchPhase::failed && world.probes.at(dana).owner == 2);
CHECK(db1.claims == region1_claims && db2.claims == region2_claims + 1);
}
// Real RemoteSession over QUIC; the fixture records authority answers without simulating biology.
void cellular_v10(const Files& files) {
using namespace evo::client_app;
struct Ledger final : ActionLedger {
std::map<std::uint64_t, DurableActionRecord> records;
std::expected<std::optional<ActionOutcome>, ActionLedgerError>
find(const AccountId&, std::uint64_t id) override {
return records.contains(id) ? std::optional{records.at(id).outcome} : std::nullopt;
}
std::expected<std::optional<DurableActionRecord>, ActionLedgerError>
find_record(const AccountId&, std::uint64_t id) override {
return records.contains(id) ? std::optional{records.at(id)} : std::nullopt;
}
} ledger;
test::WorldDb world;
test::RegionDb control{world, region};
std::vector<CellularMutationAction> mutations;
std::vector<std::uint64_t> births;
std::uint64_t life = 0, next_life = 901;
bool resolve_mutation = false;
const auto owner = account(0xD0);
Region r{files, [&](server::RegionSessionsConfig& config) {
config.ledger = &control;
config.actions = &ledger;
config.accept_cellular_actions = true;
config.create_primitive_life = [&](const AccountId& a, std::uint64_t generation,
std::uint64_t id) {
CHECK(a == owner && generation != 0);
births.push_back(id);
life = next_life;
return PrimitiveLifeOutcome{id, PrimitiveLifeResult::born, life, 1};
};
config.query_primitive_life = config.create_primitive_life;
config.select_cellular_mutation = [&](const AccountId& a, std::uint64_t generation,
const CellularMutationAction& m) {
CHECK(a == owner && generation != 0);
mutations.push_back(m);
return server::CellularMutationAnswer{
resolve_mutation ? AdmitStatus::duplicate : AdmitStatus::admitted, 102,
resolve_mutation ? std::optional{ActionOutcome{
m.action_id, ActionResult::committed, 102, 3}}
: std::nullopt};
};
}};
std::uint64_t sent_view{}, view_session{}, sent_life{};
bool offer = true;
r.after_poll = [&] {
const auto session = r.sessions->holder(owner);
if (!session || (sent_view == r.tick && view_session == *session && sent_life == life))
return;
sent_view = r.tick;
view_session = *session;
sent_life = life;
CHECK(r.sessions->send_cellular_perception(
owner,
{r.tick, life, {}, life ? std::optional{CellularLifeDiagnostics{}} : std::nullopt}));
if (offer && life != 0)
CHECK(r.sessions->send_mutation_offer(owner,
{r.tick, life, 1, 99, {{3, 2, 0, 50, 20, 30}}}));
};
Client c;
CHECK(c.host.connect(
RemoteSession::open(r.material({r.grant(owner, 1), r.grant(owner, 2)}), true)));
CHECK(c.until(r, [&] { return c.host.session()->cellular_play().offer().has_value(); }));
auto& remote = *c.host.session();
CHECK(!births.empty() && remote.cellular_play().life() == 901);
CHECK(remote.request_cellular(CellAction::mutation, {901, 1, 99, 3}));
CHECK(!remote.request_cellular(CellAction::mutation, {901, 1, 99, 3}));
CHECK(c.until(r, [&] {
return !mutations.empty() &&
required(remote.cellular_play().pending()).state == CellActionState::admitted;
}));
const auto original = mutations.front();
r.sessions->shutdown(Clock::now());
CHECK(c.until(r, [&] { return remote.status().phase == "reconnecting"; }));
CHECK(!remote.request_cellular(CellAction::bud));
resolve_mutation = true;
CHECK(c.until(r, [&] { return !remote.cellular_play().history().empty(); }, 20));
CHECK(mutations.size() >= 2 && mutations.back().action_id == original.action_id &&
mutations.back().life_identity == original.life_identity &&
mutations.back().tick == original.tick &&
mutations.back().operator_id == original.operator_id && births.size() == 1);
CHECK(remote.cellular_play().history().back().state == CellActionState::committed);
// No patch coordinates or intake accompany a bud; one request creates one carried action.
remote.set_cellular_feed_target({{1000, 2000}});
CHECK(remote.request_cellular(CellAction::bud));
CHECK(!remote.cellular_feed_target());
const auto bud_id = required(remote.cellular_play().pending()).id;
std::optional<CarriedAction> bud;
CHECK(c.until(
r,
[&] {
for (const auto& carried : r.sessions->carry(r.tick + 1))
if (carried.action_id == bud_id)
bud = carried;
return bud.has_value();
},
20));
CHECK(required(bud).cellular_input);
const auto input = decode_cellular_action_input(required(required(bud).cellular_input));
CHECK(input && input->bud && !input->engulf && !input->has_intake_target);
ledger.records.emplace(
bud_id, DurableActionRecord{{bud_id, ActionResult::committed, required(bud).tick, 4},
required(bud).cellular_input});
r.sessions->committed(std::span{&required(bud), 1}, 4);
CHECK(c.until(r, [&] { return !remote.cellular_play().pending(); }));
CHECK(remote.cellular_play().history().back().id == bud_id);
CHECK(remote.request_cellular(CellAction::engulf));
const auto engulf_id = required(remote.cellular_play().pending()).id;
std::optional<CarriedAction> engulf;
CHECK(c.until(
r,
[&] {
for (const auto& carried : r.sessions->carry(r.tick + 1))
if (carried.action_id == engulf_id)
engulf = carried;
return engulf.has_value();
},
20));
CHECK(required(engulf).cellular_input);
const auto engulf_input =
decode_cellular_action_input(required(required(engulf).cellular_input));
CHECK(engulf_input && engulf_input->engulf && !engulf_input->bud &&
!engulf_input->has_intake_target);
r.sessions->dropped(std::span{&required(engulf), 1}, true);
CHECK(c.until(r, [&] { return !remote.cellular_play().pending(); }));
// Death and a fresh request on the same connection. Repeated UI clicks issue only one.
offer = false;
life = 0;
++r.tick;
CHECK(r.sessions->send_life_ended(owner, {r.tick, 901, CellularDeathReason::starved}));
CHECK(c.until(r, [&] { return remote.cellular_play().can_restart(); }));
CHECK(required(remote.cellular_play().ended()).cause == CellularDeathReason::starved);
CHECK(remote.restart_cellular() && !remote.restart_cellular());
next_life = 902;
++r.tick;
CHECK(c.until(r, [&] { return births.size() == 2 && remote.cellular_play().life() == 902; }));
CHECK(births[0] != births[1] && !remote.cellular_play().ended());
}
} // namespace
int main() try {
@@ -526,6 +679,7 @@ int main() try {
refusals(r);
}
crossing_regions(files);
cellular_v10(files);
std::filesystem::remove_all(files.dir);
std::puts("client remote session tests passed");
return 0;
+135
View File
@@ -1,6 +1,9 @@
// 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 "cellular_controls.hpp"
#include "cellular_play.hpp"
#include "cellular_scene.hpp"
#include "evo/client/labels.hpp"
#include "evo/client/launcher.hpp"
#include "evo/client/outcome_log.hpp"
@@ -25,6 +28,11 @@ void check(bool ok, std::source_location at = std::source_location::current()) {
throw std::runtime_error("client UI model line " + std::to_string(at.line()));
}
#define CHECK(...) check(static_cast<bool>(__VA_ARGS__))
template <class T> const T& required(const std::optional<T>& value) {
if (!value)
throw std::runtime_error("missing client model test value");
return *value;
}
constexpr world::WorldIdentity identity{3, 9};
EnvironmentCell cell(std::int64_t x) {
@@ -69,6 +77,56 @@ OrganismPresentation organisms(std::vector<OrganismCell> cells, std::uint64_t ti
return std::move(*p);
}
void cellular_assistance() {
using namespace client_app;
auto own = organism(42, 980);
own.y = {2000};
own.phenotype.movement_speed = 10000;
auto population = organisms({own});
network::CellularPerception view{2, 42, {{1000, 2000, 100, {}}}, {}};
CellularControls controls;
const Intention diagonal{1, 2, 707, -707};
auto steering = steer_cellular(controls, diagonal, &view, &population, {});
CHECK(steering.patch == std::pair<std::uint32_t, std::uint32_t>{1000, 2000});
CHECK(steering.intention.move_x == 35 && steering.intention.move_y == -35);
own.x = {979};
population = organisms({own});
CHECK(!steer_cellular(controls, diagonal, &view, &population, {}).patch);
controls.slow_near_food = false;
controls.precision = true;
controls.speed_percent = 50;
steering = steer_cellular(controls, diagonal, &view, &population, {});
CHECK(steering.intention.move_x == 70 && steering.intention.move_y == -70);
controls.auto_feed = false;
CHECK(steer_cellular(controls, {}, &view, &population, {{9000, 9000}}).patch ==
std::pair<std::uint32_t, std::uint32_t>{9000, 9000});
controls.auto_feed = true;
view.patches[0].energy_pj = 0;
own.x = {1000};
population = organisms({own});
CHECK(!steer_cellular(controls, {}, &view, &population, {}).patch);
view.patches[0].matter_fg[2] = 1;
CHECK(steer_cellular(controls, {}, &view, &population, {}).patch);
view.life_identity = 0;
CHECK(!steer_cellular(controls, {}, &view, &population, {}).patch);
network::CellularOfferedCandidate candidate;
candidate.cost_energy_pj = 10;
candidate.cost_matter_fg = {1, 2, 3, 4};
network::CellularLifeDiagnostics reserve;
reserve.reserve_energy_pj = 10;
reserve.reserve_matter_fg = {1, 2, 3, 4};
CHECK(can_fund(candidate, reserve));
reserve.reserve_matter_fg[3] = 3;
CHECK(!can_fund(candidate, reserve));
reserve.reserve_matter_fg[3] = 4;
reserve.reserve_energy_pj = 9;
CHECK(!can_fund(candidate, reserve));
std::vector<render::Rectangle> scene;
patch_box(scene, {-10, 100}, {100, -10}, true, true, 80, 80);
CHECK(scene.size() == patch_rectangles);
for (const auto& r : scene)
CHECK(r.x >= 0 && r.y >= 0 && r.x + r.width <= 80 && r.y + r.height <= 80);
}
void labels() {
const auto c = cell(0);
const auto water = describe_field(c, world::Field::water);
@@ -332,6 +390,81 @@ void session_host() {
CHECK(!host.connect(FakeSession{server}));
CHECK(server.alive == 0 && host.session() == nullptr);
}
void cellular_play() {
using namespace evo::client_app;
using namespace evo::network;
CellularPlay play;
play.initialize(100);
CHECK(play.birth_request() == 100 && play.birth_pending());
play.connected();
play.observe({101, 900, {}, CellularLifeDiagnostics{}});
CHECK(play.can_act() && !play.can_restart());
CellularLifeDiagnostics feedback;
feedback.has_tick_effects = true;
feedback.bud = CellularBudOutcome::insufficient_funding;
play.observe({101, 900, {}, feedback});
play.observe({102, 900, {}, CellularLifeDiagnostics{}});
CHECK(play.bud_feedback() ==
std::pair{std::uint64_t{101}, CellularBudOutcome::insufficient_funding});
const CellularMutationOffer offer{101, 900, 1, 100, {{3, 2, 0, 50, 20, 30}}};
play.observe_offer(offer);
CHECK(!play.queue(CellAction::mutation, 102, {900, 2, 100, 3}));
CHECK(!play.queue(CellAction::mutation, 100, {900, 1, 100, 3}));
CHECK(!play.queue(CellAction::mutation, 102, {900, 1, 100, 8}));
CHECK(play.queue(CellAction::mutation, 102, {900, 1, 100, 3}));
const auto id = required(play.pending()).id;
CHECK(!play.queue(CellAction::bud, 102)); // Double clicks cannot create another action.
play.sent();
play.receipt({id, AdmitStatus::not_ready, 101, 0});
CHECK(required(play.pending()).state == CellActionState::unresolved);
play.disconnected();
CHECK(!play.can_act() && !play.offer());
play.connected();
CHECK(!play.can_act());
play.observe({103, 900, {}, CellularLifeDiagnostics{}});
play.receipt({id, AdmitStatus::invalid_action, 103, 0});
CHECK(required(play.pending()).state ==
CellActionState::unresolved); // Refused retry != failed original.
play.outcome({id, ActionResult::committed, 102, 1});
CHECK(!play.pending() && play.history().back().state == CellActionState::committed);
CHECK(play.queue(CellAction::bud, 104));
const auto bud = required(play.pending()).id;
play.sent();
play.observe_end({104, 900, CellularDeathReason::starved});
play.observe({103, 900, {}, CellularLifeDiagnostics{}}); // Retained view is older than death.
CHECK(play.life() == 0 && play.can_restart() && !play.can_act());
CHECK(play.restart());
const auto request = play.birth_request();
CHECK(request != 100 && !play.restart());
play.birth({100, PrimitiveLifeResult::born, 900, 1}); // Old request cannot finish this birth.
CHECK(play.birth_pending());
play.birth({request, PrimitiveLifeResult::born, 901, 3});
CHECK(!play.can_restart()); // Birth reply may precede the first new-life view.
play.observe({105, 901, {}, CellularLifeDiagnostics{}});
play.observe_end({104, 900, CellularDeathReason::starved});
CHECK(play.life() == 901 && !play.ended() && !play.pending());
play.outcome({bud, ActionResult::not_committed, 0, 0});
CHECK(play.history().back().state == CellActionState::refused);
for (int i = 0; i < 20; ++i) {
CHECK(play.queue(CellAction::engulf, 106));
const auto action = required(play.pending()).id;
play.sent();
play.outcome({action, ActionResult::unknown, 0, 0});
play.keep_unknown();
}
CHECK(play.history().size() == CellularPlay::history_limit);
CHECK(play.history().back().state == CellActionState::unresolved);
play.disconnected();
CHECK(!play.queue(CellAction::engulf, 106) && !play.can_restart());
play.connected();
play.observe({106, 901, {}, CellularLifeDiagnostics{}});
CHECK(play.queue(CellAction::bud, 107));
play.disconnected();
CHECK(!play.pending() && play.history().back().state == CellActionState::refused);
CellularPlay exhausted;
exhausted.initialize(std::numeric_limits<std::uint64_t>::max());
CHECK(exhausted.allocate_id() == 0 && exhausted.allocate_id() == 0);
}
} // namespace
int main() try {
@@ -340,6 +473,8 @@ int main() try {
launcher();
outcome_log();
session_host();
cellular_play();
cellular_assistance();
std::puts("client UI model tests passed");
return 0;
} catch (const std::exception& e) {