Upgrade cellular client to v10 with readable play and assisted steering
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user