Bind confirmed bank and ticket actions to real careers (by Codex)

This commit is contained in:
Codex committed 2026-10-28 11:04:11 +01:00
1 parent f75e0f8e49
commit dcf42f2da7
23 files changed
+535 -56

No files matched your search

+36 -1
View File
@@ -8,7 +8,7 @@ using namespace bmh;
using namespace bmh::modern_ui;
int main(int argc, char **argv) {
try {
if (argc != 4 || (std::string(argv[1]) != "prepare" && std::string(argv[1]) != "verify" && std::string(argv[1]) != "verify-lineup" && std::string(argv[1]) != "verify-sports")) throw std::runtime_error("usage: modern_engine_bridge_probe prepare|verify|verify-lineup|verify-sports <world.obw> <new-output-directory>");
if (argc != 4 || (std::string(argv[1]) != "prepare" && std::string(argv[1]) != "verify" && std::string(argv[1]) != "verify-lineup" && std::string(argv[1]) != "verify-sports" && std::string(argv[1]) != "verify-bank")) throw std::runtime_error("usage: modern_engine_bridge_probe prepare|verify|verify-lineup|verify-sports|verify-bank <world.obw> <new-output-directory>");
const fs::path world = argv[2], out = argv[3]; fs::create_directories(out);
const auto write = [&](const char *file, const Json &j) { editor::write_atomic(out / file, j.dump(2)); };
if (std::string(argv[1]) == "prepare") {
@@ -80,6 +80,41 @@ int main(int argc, char **argv) {
link = EngineBridge::open(world, out / "sports.obs"); const auto loaded = link->snapshot(); write("sports-loaded.json", loaded);
if (engine_tactics_projection(loaded).at("values") != tactics.at("values") || engine_training_projection(loaded).at("types") != training.at("types") || engine_training_projection(loaded).at("areas") != training.at("areas")) throw std::runtime_error("sports lost in OBS round trip");
}
if (std::string(argv[1]) == "verify-bank") {
const auto M = [](int n) { return Json{{"currency","EUR"},{"minorUnits",2},{"minor",std::to_string(int64_t(n)*100)}}; };
const auto run = [&](const Json &payload, const std::string &id) {
const auto request = engine_bank_command(link->snapshot(),payload,id);
const auto response = link->command(request); write((id.substr(8)+"-response.json").c_str(),response);
if (response.value("messageType","") != "command_result" || link->command(request) != response) throw std::runtime_error(response.dump());
};
run({{"action","deposit"},{"amount",M(10000)}},"request:deposit");
run({{"action","withdraw"},{"amount",M(2500)}},"request:withdraw");
const auto deposited = link->snapshot();
if (engine_money_minor(deposited.at("bank").at("data").at("accounts").at("deposit")) != 750000) throw std::runtime_error("deposit arithmetic wrong");
run({{"action","buy"},{"assetId","stock:0"},{"count",10}},"request:stock-buy");
run({{"action","sell"},{"assetId","stock:0"},{"count",3}},"request:stock-sell");
run({{"action","buy"},{"assetId","fund:0"},{"count",1}},"request:property-buy");
run({{"action","sell"},{"assetId","fund:0"},{"count",1}},"request:property-sell");
auto now = link->snapshot();
const auto tc = engine_ticket_command(now,25,"request:ticket");
const auto tr = link->command(tc); write("ticket-response.json",tr);
if (tr.value("messageType","") != "command_result" || link->command(tc) != tr) throw std::runtime_error(tr.dump());
now = link->snapshot();
auto stale = tc; stale["requestId"] = "request:stale-bank";
if (link->command(stale).value("code","") != "stale_revision" || link->snapshot() != now) throw std::runtime_error("stale bank command changed state");
Json edits = Json::array({{{"field",0},{"value",1000000}}});
auto preview = link->read({{"kind","credit"},{"edits",edits}}); write("credit-preview.json",preview);
(void)engine_credit_projection(now,preview);
if (now != link->snapshot()) throw std::runtime_error("credit preview mutated state");
const auto cc = engine_credit_command(now,preview,edits,"request:credit");
auto cr = link->command(cc); write("credit-response.json",cr);
if (cr.value("messageType","") != "command_result" || link->command(cc) != cr) throw std::runtime_error(cr.dump());
const auto after = link->snapshot(); write("bank-after.json",after);
write("bank-saved.json",link->save_copy(out / "bank.obs")); link.reset();
link = EngineBridge::open(world,out / "bank.obs"); const auto loaded = link->snapshot(); write("bank-loaded.json",loaded);
for (const auto *kind : {"bank","credit","stadium"}) if (loaded.at(kind).at("data") != after.at(kind).at("data")) throw std::runtime_error("finance lost during OBS round trip");
}
std::cout << "engine bridge " << argv[1] << " passed\n"; return 0;
} catch (const std::exception &e) { std::cerr << e.what() << '\n'; return 1; }
}