Modern UI contract: lineup, tactics and training reads and commands
lineup.commit takes the squad order and swaps rows into place after opening the board as the desk does; tactics.commit sets the eight values through the board's checks; training.commit initializes the plan when needed and applies decreases before increases so every step stays within the limits. Each is one revision and is rolled back as a whole when the engine refuses a step. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
99a48a463d
commit
78b827a0e6
6 files changed
+305
-11
No files matched your search
@@ -146,6 +146,73 @@ int main(int argc, char** argv) {
|
||||
const J after = session.ui_read(O{{"kind", "camps"}}, rev);
|
||||
check(at(at(after, "data"), "staysThisSeason").integer() && *at(at(after, "data"), "staysThisSeason").integer() == 1 &&
|
||||
truth(at(at(after, "data"), "bookedThisWeek")), "camp read shows the stay");
|
||||
// lineup, tactics, training: read, one accepted and one refused command each
|
||||
const auto cmd = [&](const std::string& id, const char* kind, J payload) {
|
||||
return J(O{{"messageType", "command"}, {"requestId", id}, {"expectedRevision", std::to_string(rev)},
|
||||
{"owner", O{{"managerId", "manager:1"}}}, {"kind", kind}, {"payload", std::move(payload)}});
|
||||
};
|
||||
const J lineup = session.ui_read(O{{"kind", "lineup"}}, rev);
|
||||
const auto* order = at(at(lineup, "data"), "order").array();
|
||||
check(order && order->size() >= 12 && at(at(lineup, "data"), "positions").array() &&
|
||||
at(at(lineup, "data"), "positions").array()->size() == 11, "lineup read");
|
||||
if (order && order->size() >= 12) {
|
||||
J::Array wanted = *order;
|
||||
std::swap(wanted[0], wanted[1]);
|
||||
std::swap(wanted[10], wanted[11]);
|
||||
const uint64_t before_lineup = rev;
|
||||
const J done = session.ui_command(cmd("request:l1", "lineup.commit", O{{"order", wanted}}), rev);
|
||||
if (s(at(done, "messageType")) != "command_result") std::fprintf(stderr, "lineup: %s\n", cli::dump_json(done).c_str());
|
||||
const J reread = session.ui_read(O{{"kind", "lineup"}}, rev);
|
||||
const auto* now = at(at(reread, "data"), "order").array();
|
||||
if (now && (s((*now)[0]) != s(wanted[0]) || s((*now)[10]) != s(wanted[10]) || rev != before_lineup + 1))
|
||||
std::fprintf(stderr, "lineup: rev %llu/%llu, now %s %s %s, wanted %s %s %s\n", (unsigned long long)rev,
|
||||
(unsigned long long)before_lineup, s((*now)[0]).c_str(), s((*now)[1]).c_str(), s((*now)[10]).c_str(),
|
||||
s(wanted[0]).c_str(), s(wanted[1]).c_str(), s(wanted[10]).c_str());
|
||||
check(s(at(done, "messageType")) == "command_result" && rev == before_lineup + 1 && now &&
|
||||
s((*now)[0]) == s(wanted[0]) && s((*now)[10]) == s(wanted[10]),
|
||||
"lineup committed");
|
||||
const auto kept = modern::save_stream(session.state());
|
||||
check(s(at(session.ui_command(cmd("request:l2", "lineup.commit", O{{"order", J::Array{J("player:none")}}}), rev),
|
||||
"code")) == "unknown_player" && modern::save_stream(session.state()) == kept && rev == before_lineup + 1,
|
||||
"unknown player refused without change");
|
||||
}
|
||||
const J tactics = session.ui_read(O{{"kind", "tactics"}}, rev);
|
||||
const auto* controls = at(at(tactics, "data"), "controls").array();
|
||||
check(controls && controls->size() == 8, "tactics read");
|
||||
if (controls && controls->size() == 8) {
|
||||
J::Array values;
|
||||
for (const auto& c : *controls) values.push_back(at(c, "value"));
|
||||
const int64_t max7 = *at(at((*controls)[7], "range"), "max").integer();
|
||||
const int64_t v7 = *values[7].integer();
|
||||
values[7] = J(v7 == max7 ? v7 - 1 : v7 + 1);
|
||||
const uint64_t before_tactics = rev;
|
||||
const J done = session.ui_command(cmd("request:t1", "tactics.commit", O{{"values", values}}), rev);
|
||||
const J reread = session.ui_read(O{{"kind", "tactics"}}, rev);
|
||||
const auto* now = at(at(reread, "data"), "controls").array();
|
||||
check(s(at(done, "messageType")) == "command_result" && rev == before_tactics + 1 && now &&
|
||||
*at((*now)[7], "value").integer() == *values[7].integer(), "tactics committed");
|
||||
values[7] = J(max7 + 1);
|
||||
const auto kept = modern::save_stream(session.state());
|
||||
check(s(at(session.ui_command(cmd("request:t2", "tactics.commit", O{{"values", values}}), rev), "code")) ==
|
||||
"invalid_tactic" && modern::save_stream(session.state()) == kept, "tactic above its maximum refused");
|
||||
}
|
||||
const J training = session.ui_read(O{{"kind", "training"}}, rev);
|
||||
check(s(at(training, "messageType")) == "snapshot" && at(at(training, "data"), "areas").array() &&
|
||||
at(at(training, "data"), "areas").array()->size() == 9, "training read");
|
||||
{
|
||||
const uint64_t before_training = rev;
|
||||
const J done = session.ui_command(cmd("request:p1", "training.commit",
|
||||
O{{"types", J::Array{J(2), J(2), J(2), J(2)}},
|
||||
{"areas", J::Array{J(2), J(2), J(2), J(2), J(2), J(2), J(2), J(2), J(2)}}}), rev);
|
||||
const J now = session.ui_read(O{{"kind", "training"}}, rev);
|
||||
const auto* areas = at(at(now, "data"), "areas").array();
|
||||
check(s(at(done, "messageType")) == "command_result" && rev == before_training + 1 && areas &&
|
||||
*at((*areas)[8], "allocation").integer() == 2, "training committed");
|
||||
const auto kept = modern::save_stream(session.state());
|
||||
check(s(at(session.ui_command(cmd("request:p2", "training.commit", O{{"types", J::Array{J(3), J(3), J(3), J(3)}}}), rev),
|
||||
"messageType")) == "error" && modern::save_stream(session.state()) == kept && rev == before_training + 1,
|
||||
"training over the limit refused without change");
|
||||
}
|
||||
} catch (const std::exception& ex) {
|
||||
std::fprintf(stderr, "FAIL: %s\n", ex.what());
|
||||
return 1;
|
||||
|
||||
Reference in new issue
Block a user