Take a rehearsed kickoff back completely

A rehearsal (and a kickoff refused for a pending question) now also returns
the turn driver and the managers' desks; before, the desk and the matches
played ran one step apart after a rehearsal. The contract tests rehearse
three kickoffs and check that the desk reads as before and that the
announced fixture is the one played; modern_live_dump can rehearse, play
live and report the announced and the played fixture per kickoff.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
MichaelandClaude Fable 5.2 committed 2026-11-14 08:03:41 +01:00
1 parent 29680d659e
commit 6970dfa20a
3 files changed
+83 -8

No files matched your search

+10 -2
View File
@@ -9929,6 +9929,14 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
}
std::string pending_player;
std::array<uint32_t, 4> pending_demands{};
// a run that is taken back returns the turn driver and the managers' desks as well
const TurnDriver saved_driver = turn_driver_;
const auto saved_managers = managers_;
const auto saved_desk_callargs = source_desk_callargs_;
const auto restore_run = [&] {
restore();
turn_driver_ = saved_driver, managers_ = saved_managers, source_desk_callargs_ = saved_desk_callargs;
};
auto previous_hook = g_.contract_screen;
const bool previous_installed = contract_expiry_presenter_installed_;
set_contract_expiry_presenter([&](modern::ModernState& state, WatcomRandom& random, int m, int row) -> int {
@@ -9978,7 +9986,7 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
g_.contract_screen = previous_hook; // the session's own presenter again
contract_expiry_presenter_installed_ = previous_installed;
if (r.kind == TurnDeskKind::Failed || r.kind == TurnDeskKind::WaitingAtDesk) {
restore();
restore_run();
g_.contract_screen = previous_hook;
if (!pending_player.empty()) {
cli::Json pending = refuse("decision_pending", "Ein Vertrag läuft aus: Verlängern oder freigeben?");
@@ -9994,7 +10002,7 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
}
if (const cli::Json* dry = ui_field(*payload, "dryRun"); dry && std::holds_alternative<bool>(dry->value) && std::get<bool>(dry->value)) {
// a rehearsal: everything goes back, the interface only learns that no question is open
restore();
restore_run();
g_.contract_screen = previous_hook;
cli::Json rehearsal = modern::ui_command_result(request_id, previous, previous, {}, "Probelauf ohne offene Rückfrage.");
std::get<cli::Json::Object>(rehearsal.value)["outcome"] = "rehearsed";
+51 -6
View File
@@ -22,29 +22,74 @@ int main(int argc, char **argv) {
const auto write = [&](const std::string &name, const Json &value) {
std::ofstream(out / name, std::ios::binary) << value.dump(1);
};
int found = 0;
int found = 0, decisions = 0;
const bool live = std::getenv("MODERN_DUMP_LIVE") != nullptr, steps = std::getenv("MODERN_DUMP_STEPS") != nullptr,
quiet = std::getenv("MODERN_DUMP_QUIET") != nullptr;
Json expiry = Json::object();
for (int step = 0; step < 400 && found < wanted; ++step) {
const auto bundle = link->snapshot();
const auto &meta = bundle.at("desktop").at("meta");
if (step == 0) write("bundle.json", bundle);
{
// the desk before each kickoff: its date and the fixture it announces
const auto &next = bundle.at("desktop").at("data").at("nextFixture");
std::cout << "desk " << meta.at("date").get<std::string>() << ": next "
<< (next.is_object() ? next.at("home").at("name").get<std::string>() + " - " + next.at("away").at("name").get<std::string>() + " (" + next.at("competition").value("text", std::string()) + ")" : std::string("none"))
<< std::endl;
}
const Json command = {{"messageType", "command"}, {"contractVersion", meta.at("contractVersion")},
{"requestId", "request:dump-" + std::to_string(step)}, {"careerId", meta.at("careerId")},
{"expectedRevision", meta.at("stateRevision")},
{"owner", {{"managerId", meta.at("scope").at("managerId")}}},
{"kind", "session.advance"}, {"payload", {{"contractExpiry", expiry}}}};
const auto reply = link->command(command);
{"kind", "session.advance"}, {"payload", live ? Json{{"contractExpiry", expiry}, {"live", true}} : Json{{"contractExpiry", expiry}}}};
if (std::getenv("MODERN_DUMP_REHEARSE")) {
// as the interface does: a rehearsal that is taken back, then the kickoff itself
Json rehearsal = command;
rehearsal["requestId"] = "request:dump-rehearsal-" + std::to_string(step);
rehearsal["payload"] = {{"contractExpiry", expiry}, {"dryRun", true}};
const auto tried = link->command(rehearsal);
const auto after = link->snapshot();
if (after.at("desktop") != bundle.at("desktop")) std::cout << "REHEARSAL CHANGED THE DESK at step " << step << std::endl;
if (after != bundle) std::cout << "rehearsal changed a read at step " << step << std::endl;
}
auto reply = link->command(command);
write("advance-" + std::to_string(step) + ".json", reply);
if (reply.value("messageType", "") != "command_result") {
if (reply.value("code", "") == "decision_pending") {
expiry[reply.at("message").at("args").at("playerId").get<std::string>()] = {{"action", "release"}};
const auto &args = reply.at("message").at("args");
const auto player = args.at("playerId").get<std::string>();
// extend every second expiring contract at the demand for two years, release the others
const auto demands = args.value("demands", Json::array());
const bool renew = ++decisions % 2 == 1 && demands.size() > 1 && demands[1].is_object();
std::cout << "step " << step << ": contract of " << player << " runs out, demands " << demands.dump() << (renew ? " -> renew" : " -> release") << std::endl;
if (renew) expiry[player] = {{"action", "renew"}, {"years", 2}, {"monthlySalary", demands[1]}};
else expiry[player] = {{"action", "release"}};
continue;
}
std::cerr << "advance refused: " << reply.dump() << "\n";
return 1;
}
const auto fixture = link->read_live({{"kind", "fixture"}});
std::cout << "step " << step << ": " << (fixture.value("ok", false) ? "fixture" : fixture.value("error", "?")) << "\n";
// MODERN_DUMP_LIVE=1: the kickoff is played live and finished with live.finish
auto fixture = link->read_live({{"kind", "fixture"}});
for (int guard = 0; live && fixture.value("ok", false) && fixture.value("live", false) && guard < 300; ++guard) {
const Json finish = {{"messageType", "command"}, {"contractVersion", meta.at("contractVersion")},
{"requestId", "request:dump-live-" + std::to_string(step) + "-" + std::to_string(guard)},
{"careerId", meta.at("careerId")}, {"expectedRevision", reply.at("newRevision")},
{"owner", {{"managerId", meta.at("scope").at("managerId")}}},
{"kind", steps ? "live.step" : "live.finish"}, {"payload", steps ? Json{{"minutes", 1}} : Json::object()}};
reply = link->command(finish);
if (reply.value("messageType", "") != "command_result") { std::cerr << "live refused: " << reply.dump() << "\n"; return 1; }
fixture = link->read_live({{"kind", "fixture"}});
}
std::cout << "step " << step << ": " << (fixture.value("ok", false) ? "fixture" : fixture.value("error", "?"));
if (fixture.value("ok", false) && fixture.contains("matches"))
for (const auto &m : fixture.at("matches"))
std::cout << " | " << fixture.value("date", std::string()) << " " << m.at("home").at("name").get<std::string>() << " - "
<< m.at("away").at("name").get<std::string>() << " (" << m.value("competition", std::string()) << ")";
std::cout << std::endl;
if (quiet) { if (fixture.value("ok", false)) ++found; continue; }
if (!fixture.value("ok", false)) continue;
const std::string tag = std::to_string(found++);
write("fixture-" + tag + ".json", fixture);
+22
View File
@@ -540,6 +540,28 @@ int main(int argc, char** argv) {
const std::string date_after = s(at(at(session.ui_read(O{{"kind", "desktop"}}, rev), "meta"), "date"));
check(date_after > date_before, "the date moved on");
}
// a rehearsal is played and taken back: no revision, and the desk reads as before
for (int k = 0; k < 3; ++k) {
const uint64_t before = rev;
const std::string desk_before = cli::dump_json(session.ui_read(O{{"kind", "desktop"}}, rev));
const std::string lineup_before = cli::dump_json(session.ui_read(O{{"kind", "lineup"}}, rev));
const J tried = session.ui_command(cmd("request:dry" + std::to_string(k), "session.advance", O{{"dryRun", true}}), rev);
check(s(at(tried, "messageType")) == "command_result" && s(at(tried, "outcome")) == "rehearsed" && rev == before,
"rehearsal accepted without a revision");
check(cli::dump_json(session.ui_read(O{{"kind", "desktop"}}, rev)) == desk_before, "rehearsal leaves the desk as it was");
check(cli::dump_json(session.ui_read(O{{"kind", "lineup"}}, rev)) == lineup_before, "rehearsal leaves the line-up as it was");
// the kickoff after a rehearsal plays the fixture the desk announced
const J next = at(at(session.ui_read(O{{"kind", "desktop"}}, rev), "data"), "nextFixture");
const J played = session.ui_command(cmd("request:dry-play" + std::to_string(k), "session.advance", O{}), rev);
check(s(at(played, "messageType")) == "command_result", "kickoff after a rehearsal accepted");
const J recording = session.read_live(O{{"kind", "fixture"}});
if (truth(at(recording, "ok")) && next.object()) {
bool found = false;
for (const J& m : *at(recording, "matches").array())
found = found || s(at(at(m, "home"), "id")) == s(at(at(next, "home"), "id"));
check(found, "the announced fixture was the one played");
}
}
// the live ticker: advance until a kickoff played a match of the human manager, then its recording
{
J fixture;