Bind friendly planning quotes bookings and explicit hotseat consent (by Codex)
This commit is contained in:
1 parent
cbde7b367e
commit
15d2ac0a4d
20 files changed
+422
-22
No files matched your search
@@ -5,27 +5,37 @@
|
||||
#include "modern/content/world_package.hpp"
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <set>
|
||||
using namespace bmh;
|
||||
using namespace bmh::modern_ui;
|
||||
int main(int argc, char **argv) {
|
||||
try {
|
||||
if (argc != 4 || (std::string(argv[1]) != "inspect" && 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" && std::string(argv[1]) != "verify-commerce" && std::string(argv[1]) != "verify-contracts" && std::string(argv[1]) != "verify-calendar")) throw std::runtime_error("usage: modern_engine_bridge_probe inspect|prepare|verify|verify-lineup|verify-sports|verify-bank|verify-commerce|verify-contracts|verify-calendar <world.obw> <new-output-directory>");
|
||||
if (argc != 4 || (std::string(argv[1]) != "inspect-friendlies" && std::string(argv[1]) != "inspect" && std::string(argv[1]) != "prepare-two" && 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" && std::string(argv[1]) != "verify-commerce" && std::string(argv[1]) != "verify-contracts" && std::string(argv[1]) != "verify-calendar" && std::string(argv[1]) != "verify-friendlies")) throw std::runtime_error("usage: modern_engine_bridge_probe inspect-friendlies|inspect|prepare|prepare-two|verify|verify-lineup|verify-sports|verify-bank|verify-commerce|verify-contracts|verify-calendar|verify-friendlies <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") {
|
||||
if (std::string(argv[1]) == "prepare" || std::string(argv[1]) == "prepare-two") {
|
||||
auto package = modern::open_world_package(world);
|
||||
content::Mount mount(world, package.classic); modern::set_current_world(package.world);
|
||||
modern::app::ModernSession session(mount.root(), 17u);
|
||||
ui::SetupOptions options; options.mode = 3;
|
||||
ui::SetupOptions options; options.mode = 3; options.managers = std::string(argv[1]) == "prepare-two" ? 2 : 1;
|
||||
ui::ManagerChoice manager; manager.name = "Codex Engine QA"; manager.master_club = 0;
|
||||
std::string error; ui::CareerInitializationResult result;
|
||||
if (!session.confirm_manager(options, manager, error) || !session.finish(result, error) ||
|
||||
!session.save_game(out / "input.obs", 0, false, error)) throw std::runtime_error(error);
|
||||
if (!session.confirm_manager(options, manager, error)) throw std::runtime_error(error);
|
||||
if (options.managers == 2) { manager.name = "Codex Opponent QA"; manager.master_club = 1; manager.portrait = 1; if (!session.confirm_manager(options, manager, error)) throw std::runtime_error(error); }
|
||||
if (!session.finish(result, error) || !session.save_game(out / "input.obs", 0, false, error)) throw std::runtime_error(error);
|
||||
modern::set_current_world(nullptr);
|
||||
}
|
||||
auto link = EngineBridge::open(world, out / "input.obs");
|
||||
const auto before = link->snapshot(); write("before.json", before);
|
||||
if (before != link->snapshot()) throw std::runtime_error("reads changed the engine projection");
|
||||
if (std::string(argv[1]) == "inspect-friendlies") {
|
||||
const auto &opponents=before.at("friendly-plan").at("data").at("opponents");
|
||||
if(opponents.empty())throw std::runtime_error("no friendly opponents");
|
||||
const auto id=opponents[0].at("team").at("id");
|
||||
write("home-quote.json",link->read({{"kind","friendly"},{"opponentId",id},{"home",true}}));
|
||||
write("away-quote.json",link->read({{"kind","friendly"},{"opponentId",id},{"home",false}}));
|
||||
if(link->snapshot()!=before)throw std::runtime_error("friendly previews mutated session");
|
||||
}
|
||||
if (std::string(argv[1]) == "verify") {
|
||||
auto camp = before.at("camps").at("data").at("camps").front();
|
||||
const auto command = engine_camp_command(before, camp.at("id"), {{"condition", 3}, {"technique", 4}, {"play", 5}}, "request:probe-book");
|
||||
@@ -179,9 +189,30 @@ int main(int argc, char **argv) {
|
||||
const auto after_schedule=engine_scheduling_projection(moved);if(!after_schedule.at("movable").empty()){auto bad=request;bad["requestId"]="request:invalid-target";bad["expectedRevision"]=moved.at("desktop").at("meta").at("stateRevision");bad["payload"]={{"matchId",after_schedule.at("movable")[0].at("id")},{"date",after_schedule.at("movable")[0].at("date")}};const auto rejected=link->command(bad);write("invalid-target.json",rejected);if(rejected.value("messageType","")!="error"||link->snapshot()!=moved)throw std::runtime_error("invalid target changed state");}
|
||||
write("moved-saved.json",link->save_copy(out/"moved.obs"));link.reset();link=EngineBridge::open(world,out/"moved.obs");const auto loaded=link->snapshot();write("loaded-move.json",loaded);if(loaded.at("calendar").at("data")!=moved.at("calendar").at("data")||loaded.at("scheduling").at("data")!=moved.at("scheduling").at("data"))throw std::runtime_error("move lost in OBS round trip");
|
||||
run(engine_reschedule_undo(loaded,target,"request:undo"),"undo");const auto undone=link->snapshot();write("undone.json",undone);
|
||||
if(undone.at("calendar").at("data").at("fixtures")!=before.at("calendar").at("data").at("fixtures")||!undone.at("scheduling").at("data").at("moved").empty()||undone.at("desktop").at("data").at("accounts")!=before.at("desktop").at("data").at("accounts"))throw std::runtime_error("undo did not restore fixture/calendar or changed account");
|
||||
if(undone.at("calendar").at("data").at("fixtures")!=before.at("calendar").at("data").at("fixtures")||!undone.at("scheduling").at("data").at("moved").empty()||undone.at("desktop").at("data").at("accounts")!=before.at("desktop").at("data").at("accounts")||undone.at("scheduling").at("data")!=before.at("scheduling").at("data"))throw std::runtime_error("undo did not restore fixture/calendar or changed account");
|
||||
write("undone-saved.json",link->save_copy(out/"undone.obs"));link.reset();link=EngineBridge::open(world,out/"undone.obs");const auto final=link->snapshot();write("loaded-undo.json",final);if(final.at("calendar").at("data").at("fixtures")!=before.at("calendar").at("data").at("fixtures")||!final.at("scheduling").at("data").at("moved").empty())throw std::runtime_error("undo not persisted");
|
||||
}
|
||||
|
||||
if(std::string(argv[1])=="verify-friendlies") {
|
||||
const auto run=[&](const Json &request,const std::string &name){auto response=link->command(request);write((name+"-response.json").c_str(),response);if(response.value("messageType","")!="command_result"||link->command(request)!=response)throw std::runtime_error(response.dump());return response;};
|
||||
const auto plan=engine_friendly_plan(before);std::set<std::string> humans;const auto own=before.at("desktop").at("meta").at("scope").at("teamId");for(const auto &r:before.at("session").at("data").at("humanOwnership"))if(r.at("controller")=="human")humans.insert(r.at("teamId").get<std::string>());
|
||||
std::string ai;for(const auto &r:plan.at("opponents"))if(!humans.contains(r.at("team").at("id").get<std::string>())){ai=r.at("team").at("id");break;}if(ai.empty())throw std::runtime_error("no AI opponent");
|
||||
for(bool home:{true,false}) {
|
||||
const auto now=link->snapshot(),read=link->read({{"kind","friendly"},{"opponentId",ai},{"home",home}});write(home?"home-quote.json":"away-quote.json",read);const auto quote=engine_friendly_projection(now,read,ai,home);
|
||||
if(link->snapshot()!=now||link->read({{"kind","friendly"},{"opponentId",ai},{"home",home}})!=read)throw std::runtime_error("preview mutated source or RNG");
|
||||
if(quote.at("dates").empty())throw std::runtime_error("no actual available date");const auto cmd=engine_friendly_command(now,read,ai,home,quote.at("dates")[0],true,false,home?"request:friendly-home":"request:friendly-away");
|
||||
if(home){auto bad=cmd;bad["requestId"]="request:no-cost-consent";bad["payload"]["acceptCost"]=false;const auto refused=link->command(bad);write("no-cost-consent.json",refused);if(refused.value("messageType","")!="error"||link->snapshot()!=now)throw std::runtime_error("unapproved cost changed state");}
|
||||
run(cmd,home?"home-booked":"away-booked");const auto after=link->snapshot();write(home?"home-after.json":"away-after.json",after);const auto delta=engine_money_minor(now.at("desktop").at("data").at("accounts").at("cash"))-engine_money_minor(after.at("desktop").at("data").at("accounts").at("cash"));if(delta!=(home?quote.at("cost").get<int64_t>():0))throw std::runtime_error("actual payer debit differs from quote");
|
||||
auto stale=cmd;stale["requestId"]=home?"request:stale-home":"request:stale-away";if(link->command(stale).value("code","")!="stale_revision"||link->snapshot()!=after)throw std::runtime_error("stale booking changed state");
|
||||
}
|
||||
for(const auto &r:before.at("session").at("data").at("humanOwnership"))if(r.at("teamId")!=own&&r.at("controller")=="human") {
|
||||
const auto id=r.at("teamId").get<std::string>(); const auto now=link->snapshot();const auto read=link->read({{"kind","friendly"},{"opponentId",id},{"home",false}});const auto quote=engine_friendly_projection(now,read,id,false);write("human-quote.json",read);if(quote.at("dates").empty())throw std::runtime_error("no human date");const auto cmd=engine_friendly_command(now,read,id,false,quote.at("dates")[0],true,true,"request:human-friendly");
|
||||
auto bad=cmd;bad["requestId"]="request:missing-opponent-consent";bad["payload"]["opponentConsent"]=false;const auto refused=link->command(bad);write("missing-opponent-consent.json",refused);if(refused.value("messageType","")!="error"||link->snapshot()!=now)throw std::runtime_error("missing opponent consent mutated source");
|
||||
run(cmd,"human-booked");const auto after=link->snapshot();if(after.at("desktop").at("data").at("accounts")!=now.at("desktop").at("data").at("accounts"))throw std::runtime_error("away human booking charged wrong manager");break;
|
||||
}
|
||||
const auto after=link->snapshot();write("friendlies-after.json",after);write("friendlies-saved.json",link->save_copy(out/"friendlies.obs"));link.reset();link=EngineBridge::open(world,out/"friendlies.obs");const auto loaded=link->snapshot();write("friendlies-loaded.json",loaded);
|
||||
if(loaded.at("friendly-plan").at("data")!=after.at("friendly-plan").at("data")||loaded.at("calendar").at("data")!=after.at("calendar").at("data")||loaded.at("desktop").at("data").at("accounts")!=after.at("desktop").at("data").at("accounts"))throw std::runtime_error("bookings or money lost at OBS restart");
|
||||
}
|
||||
std::cout << "engine bridge " << argv[1] << " passed\n"; return 0;
|
||||
} catch (const std::exception &e) { std::cerr << e.what() << '\n'; return 1; }
|
||||
}
|
||||
Reference in new issue
Block a user