Modern UI contract: building in the stadium (periphery and facilities)

The original's stadium dialog in two commands: quote.request opens it and
gets the building firm's offer (periphery) or selects a facility and levels;
stadium.commit builds - facilities with or without the tip for faster
building - or declines, and closes the dialog. The stadium read shows the
open offer; a refused command also restores the dialog.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Opus 5.5 committed 2026-10-27 09:23:06 +01:00
1 parent 6386c891b5
commit e6bc72d3a0
3 files changed
+152 -7

No files matched your search

+44 -5
View File
@@ -304,6 +304,43 @@ int main(int argc, char** argv) {
rev <= before + 1, "ticket price set");
check(s(at(session.ui_command(cmd("request:e2", "ticket.commit", O{{"price", O{{"minor", "3000"}, {"currency", "EUR"}, {"minorUnits", 2}}}}), rev),
"code")) == "invalid_amount", "ticket price above 25 refused");
// building: a periphery object not built yet, then a facility level without the tip
std::string object;
if (const auto* p = at(at(after, "data"), "periphery").array())
for (const auto& o : *p)
if (object.empty() && at(o, "built").value.index() == 1 && !truth(at(o, "built")) && *at(o, "constructionDays").integer() == 0)
object = s(at(o, "id"));
const auto quote_of = [&]() { const J st = session.ui_read(O{{"kind", "stadium"}}, rev); return J(at(at(st, "data"), "quote")); };
if (!object.empty()) {
const uint64_t b0 = rev;
const J q = session.ui_command(cmd("request:e3", "quote.request", O{{"kind", "periphery"}, {"objectId", object}}), rev);
if (s(at(q, "messageType")) != "command_result") std::fprintf(stderr, "periphery quote: %s\n", cli::dump_json(q).c_str());
const J quote = quote_of();
check(s(at(q, "outcome")) == "offer_pending" && s(at(quote, "objectId")) == object && rev == b0 + 1, "periphery quoted");
const J built = session.ui_command(cmd("request:e4", "stadium.commit", O{{"quoteId", at(quote, "id")}, {"accept", true}}), rev);
if (s(at(built, "messageType")) != "command_result") std::fprintf(stderr, "periphery build: %s\n", cli::dump_json(built).c_str());
check(s(at(built, "messageType")) == "command_result" && rev == b0 + 2 && std::holds_alternative<std::nullptr_t>(quote_of().value),
"periphery built, the stadium closed");
}
{
const uint64_t b0 = rev;
const J q = session.ui_command(cmd("request:e5", "quote.request", O{{"kind", "facility"}, {"facilityId", "facility:safety"}, {"increment", 1}}), rev);
const J quote = quote_of();
if (s(at(q, "messageType")) == "command_result") {
check(s(at(quote, "kind")) == "facility" && at(quote, "price").object(), "facility quoted");
const J done = session.ui_command(cmd("request:e6", "stadium.commit", O{{"quoteId", at(quote, "id")}, {"accept", true}, {"tip", false}}), rev);
if (s(at(done, "messageType")) != "command_result") std::fprintf(stderr, "facility build: %s\n", cli::dump_json(done).c_str());
check(s(at(done, "messageType")) == "command_result" && rev == b0 + 2, "facility ordered");
} else {
std::printf("(facility quote: %s)\n", s(at(q, "code")).c_str());
}
const J q2 = session.ui_command(cmd("request:e7", "quote.request", O{{"kind", "facility"}, {"facilityId", "facility:comfort"}, {"increment", 1}}), rev);
if (s(at(q2, "messageType")) == "command_result") {
const J declined = session.ui_command(cmd("request:e8", "stadium.commit", O{{"quoteId", at(quote_of(), "id")}, {"accept", false}}), rev);
check(s(at(declined, "messageType")) == "command_result" && std::holds_alternative<std::nullptr_t>(quote_of().value),
"facility offer declined, the stadium closed");
}
}
}
// session.advance: three kickoffs, each one revision, the date moves on
{
@@ -361,15 +398,17 @@ int main(int argc, char** argv) {
check(s(at(session.read_almanac(O{{"kind", "match"}, {"id", "match:0-0"}}), "error")) == "almanac_match_not_found",
"unknown match");
// the statistics screen: real data (fictional false), unrecorded views say so
// (the club views need a club desk: on an international day the manager sits at the national one)
const J minutes = session.read_statistics_screen(O{{"section", 8}});
check(truth(at(minutes, "ok")) && !truth(at(minutes, "fictional")) && at(minutes, "rows").array() &&
at(minutes, "rows").array()->size() == 4, "minute statistics");
const J transfers = session.read_statistics_screen(O{{"section", 1}});
const bool club_desk = !std::holds_alternative<std::nullptr_t>(at(minutes, "club").value);
check(truth(at(minutes, "ok")) && !truth(at(minutes, "fictional")) &&
(!club_desk || (at(minutes, "rows").array() && at(minutes, "rows").array()->size() == 4)), "minute statistics");
const J transfers = session.read_statistics_screen(O{{"section", 0}});
check(truth(at(transfers, "ok")) && !truth(at(transfers, "available")) && s(at(transfers, "reason")) == "not_recorded",
"transfer history not recorded");
"title chances not recorded");
check(s(at(session.read_statistics_screen(O{{"section", 9}}), "error")) == "invalid_statistics_filter", "bad section");
const J curves = session.read_statistics_screen(O{{"section", 2}});
check(at(curves, "series").array() && at(curves, "series").array()->size() == 6, "the six curves of the original");
check(!club_desk || (at(curves, "series").array() && at(curves, "series").array()->size() == 6), "the six curves of the original");
}
} catch (const std::exception& ex) {
std::fprintf(stderr, "FAIL: %s\n", ex.what());