Bind the six-column Toto coupon to reviewed engine costs and settlement (by Codex)
This commit is contained in:
1 parent
eb140cdb1c
commit
dfb972abbd
27 files changed
+368
-53
No files matched your search
@@ -15,25 +15,26 @@ using namespace bmh::modern_ui;
|
||||
int main(int argc, char **argv) {
|
||||
try {
|
||||
const std::string mode=argc>1?argv[1]:"";
|
||||
const std::set<std::string> modes{"prepare","prepare-two","prepare-national","prepare-almanac","inspect","inspect-friendlies","inspect-almanac","verify","verify-lineup","verify-sports","verify-bank","verify-commerce","verify-contracts","verify-calendar","verify-friendlies","verify-national","verify-almanac","verify-shootouts","verify-reports","verify-fixtures","verify-other","verify-rankings","prepare-rankings-archived","verify-create","inspect-coach-identity","prepare-coach-identity","verify-coach-almanac","verify-files","verify-statistics","prepare-statistics","inspect-statistics"};
|
||||
const std::set<std::string> modes{"prepare","prepare-two","prepare-national","prepare-almanac","inspect","inspect-friendlies","inspect-almanac","verify","verify-lineup","verify-sports","verify-bank","verify-commerce","verify-contracts","verify-calendar","verify-friendlies","verify-national","verify-almanac","verify-shootouts","verify-reports","verify-fixtures","verify-other","verify-rankings","prepare-rankings-archived","verify-create","inspect-coach-identity","prepare-coach-identity","verify-coach-almanac","verify-files","verify-statistics","prepare-statistics","inspect-statistics","prepare-toto","verify-toto","settle-toto"};
|
||||
if(argc!=4||!modes.contains(mode))throw std::runtime_error("usage: modern_engine_bridge_probe <prepare[-two|-national|-almanac]|inspect[-friendlies|-almanac]|verify[-lineup|-sports|-bank|-commerce|-contracts|-calendar|-friendlies|-national|-almanac|-shootouts]> <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 (mode == "prepare-statistics" || mode == "prepare-almanac" || std::string(argv[1]) == "prepare-national" || std::string(argv[1]) == "prepare" || std::string(argv[1]) == "prepare-two") {
|
||||
if (mode == "prepare-toto" || mode == "prepare-statistics" || mode == "prepare-almanac" || std::string(argv[1]) == "prepare-national" || 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; if(mode=="prepare-almanac"||mode=="prepare-statistics") options.world=false; if (std::string(argv[1]) == "prepare-national") options.league = false; options.managers = std::string(argv[1]) == "prepare-two" ? 2 : 1;
|
||||
ui::SetupOptions options; options.mode = 3; if(mode=="prepare-almanac"||mode=="prepare-statistics"||mode=="prepare-toto") options.world=false; if (std::string(argv[1]) == "prepare-national") options.league = false; 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)) 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)) throw std::runtime_error(error);
|
||||
if (mode == "prepare-national" || mode == "prepare-almanac" || mode == "prepare-statistics") {
|
||||
if (mode == "prepare-national" || mode == "prepare-almanac" || mode == "prepare-statistics" || mode == "prepare-toto") {
|
||||
uint64_t rev = 0; bool found = false; Json expiry = Json::object(), log = Json::array();
|
||||
for (int k = 0; k < 200; ++k) {
|
||||
const auto desk = Json::parse(cli::dump_json(session.ui_read(cli::Json::Object{{"kind","desktop"}},rev)));
|
||||
if (mode=="prepare-national" && desk.at("meta").at("scope").at("role") == "national") { found = true; break; }
|
||||
if(mode=="prepare-toto"){const auto value=Json::parse(cli::dump_json(session.ui_read(cli::Json::Object{{"kind","toto"}},rev)));if(value.value("messageType","")=="snapshot"&&value.at("data").at("open")==true){found=true;break;}}
|
||||
if(mode=="prepare-statistics"&&!session.state().almanac.finished.empty()){found=true;break;}
|
||||
if(mode=="prepare-almanac") {const auto index=Json::parse(cli::dump_json(session.read_almanac(cli::Json::Object{{"kind","index"}})));if(index.value("ok",false)&&index.at("years").size()>=2){found=true;break;}}
|
||||
const auto &meta = desk.at("meta");
|
||||
@@ -132,9 +133,22 @@ int main(int argc, char **argv) {
|
||||
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(),1u,out/"input.obs",false);
|
||||
write("winner-records.json",Json::parse(cli::dump_json(session.read_statistics(cli::Json::Object{{"kind","winners"}}))));modern::set_current_world(nullptr);return 0;
|
||||
}
|
||||
if(mode=="settle-toto") {
|
||||
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(),1u,out/"input.obs",false);uint64_t revision=0;Json expiry=Json::object(),log=Json::array();bool settled=false;
|
||||
for(int step=0;step<100;++step){const auto before=Json::parse(cli::dump_json(session.ui_read(cli::Json::Object{{"kind","desktop"}},revision)));const auto &meta=before.at("meta");const Json command={{"messageType","command"},{"contractVersion",meta.at("contractVersion")},{"requestId","request:settle-toto-"+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=Json::parse(cli::dump_json(session.ui_command(cli::parse_json(command.dump()),revision)));log.push_back(reply);if(reply.value("messageType","")!="command_result"){if(reply.value("code","")=="decision_pending"){const auto id=reply.at("message").at("args").at("playerId").get<std::string>();expiry[id]={{"action","release"}};continue;}throw std::runtime_error(reply.dump());}if(!session.state().pools.empty()&&session.state().pools[0].paid>0){settled=true;break;}}
|
||||
if(!settled)throw std::runtime_error("Toto settlement not reached");write("advance.json",log);write("settlement.json",Json::parse(cli::dump_json(session.ui_read(cli::Json::Object{{"kind","toto"}},revision))));std::string error;const int active=session.state().memory.u8(::bmh::layout::ActiveManager);if(!session.save_game(out/"settled.obs",active,false,error))throw std::runtime_error(error);modern::set_current_world(nullptr);std::cout<<"actual Toto settlement saved\n";return 0;
|
||||
}
|
||||
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(mode=="verify-toto") {
|
||||
const auto value=engine_toto_projection(before);if(value.at("programme").at("complete")!=true)throw std::runtime_error("fixture has no eleven-match coupon");Json rows=Json::array();for(int column=0;column<2;++column){auto tips=value.at("suggestions");if(column){tips[0]=tips[0]==0?1:0;}rows.push_back(tips);}const Json payload={{"stake",{{"currency","EUR"},{"minorUnits",2},{"minor","5000000"}}},{"columns",rows}};
|
||||
const auto quote=link->read({{"kind","toto"},{"draft",payload}});write("quote.json",quote);if(link->read({{"kind","toto"},{"draft",payload}})!=quote||link->snapshot()!=before)throw std::runtime_error("Toto quote changed session");const auto &offer=quote.at("data").at("draftQuote");if(offer.at("allowed")!=true||engine_money_minor(offer.at("cost"))!=10500000||engine_money_minor(offer.at("fee"))!=500000)throw std::runtime_error("wrong actual two-column cost");
|
||||
Json invalid=payload;invalid["columns"][1]=invalid["columns"][0];const auto duplicate=link->read({{"kind","toto"},{"draft",invalid}});write("duplicate.json",duplicate);if(duplicate.at("data").at("draftQuote").at("errorCode")!="duplicate_column"||link->snapshot()!=before)throw std::runtime_error("duplicate preview not pure/refused");
|
||||
const auto request=engine_toto_command(before,quote,"request:toto-two");const auto response=link->command(request);write("submit.json",response);if(response.value("messageType","")!="command_result"||link->command(request)!=response)throw std::runtime_error("submission failed or not idempotent");const auto after=link->snapshot();write("queued.json",after);if(after.at("toto").at("data").at("columns")!=rows||engine_money_minor(after.at("toto").at("data").at("cost"))!=10500000||after.at("desktop").at("data").at("accounts")!=before.at("desktop").at("data").at("accounts"))throw std::runtime_error("queue/cost/wrong immediate debit");link->save_copy(out/"queued.obs");
|
||||
const Json clear={{"stake",{{"currency","EUR"},{"minorUnits",2},{"minor","0"}}},{"columns",Json::array()}};const auto clear_quote=link->read({{"kind","toto"},{"draft",clear}});const auto cancel=engine_toto_command(after,clear_quote,"request:toto-clear");write("clear.json",link->command(cancel));const auto cleared=link->snapshot();if(!cleared.at("toto").at("data").at("columns").empty()||engine_money_minor(cleared.at("toto").at("data").at("stake"))!=0)throw std::runtime_error("withdrawal failed");link->save_copy(out/"cleared.obs");
|
||||
auto stale=request;stale["requestId"]="request:toto-stale";const auto refused=link->command(stale);if(refused.value("code","")!="stale_revision"||link->snapshot()!=cleared)throw std::runtime_error("stale coupon changed session");write("receipt.json",{{"status","passed"},{"costMinor","10500000"},{"feeMinor","500000"},{"quoteReadOnly",true},{"deferredSettlement",true},{"withdrawal",true},{"idempotent",true}});std::cout<<"actual Toto preview, two columns, deferred cost, idempotency and withdrawal passed\n";return 0;
|
||||
}
|
||||
if(mode=="verify-statistics") {
|
||||
Json all=Json::array();
|
||||
const auto run=[&](const Json &query){const auto read=link->read({{"kind","statistics"},{"query",query}});auto value=engine_statistics_projection(before,read);if(link->read({{"kind","statistics"},{"query",query}})!=read)throw std::runtime_error("statistics read not repeatable");all.push_back({{"query",query},{"read",read},{"projection",value}});return value;};
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "modern/ui/engine_bridge.hpp"
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
using namespace bmh::modern_ui;
|
||||
namespace {
|
||||
void check(bool yes,const char* why){if(!yes)throw std::runtime_error(why);}
|
||||
template<class F>void rejected(F f){bool caught=false;try{f();}catch(const std::exception&){caught=true;}check(caught,"bad Toto DTO accepted");}
|
||||
Json money(int euros){return {{"currency","EUR"},{"minorUnits",2},{"minor",std::to_string(euros*100)}};}
|
||||
Json fixture(){const Json meta={{"contractVersion","bmh-modern-ui@draft1"},{"careerId","career:test"},{"worldId","world:test"},{"worldRevision","1"},{"stateRevision","3"},{"date","2026-08-22"},{"season",{{"label","2026/27"}}},{"scope",{{"role","club"},{"managerId","manager:test"},{"teamId","club:test"},{"allowedCommands",{"toto.submit"}}}}};Json b;for(const auto*kind:{"session","desktop","camps","toto"})b[kind]={{"messageType","snapshot"},{"meta",meta},{"data",{{"kind",kind}}}};b["desktop"]["data"].update({{"manager",{{"id","manager:test"}}},{"team",{{"id","club:test"}}},{"accounts",{{"cash",money(5000000)}}}});b["camps"]["data"]["camps"]=Json::array();auto &t=b["toto"]["data"];t.update({{"open",true},{"rules",{{"max_columns",6},{"stake_min",10000},{"stake_max",400000}}},{"columns",{{1,0,2,1,0,2,1,0,2,1,0}}},{"stake",money(10000)},{"cost",money(10000)},{"last",{{"paid",money(20000)},{"won",money(0)},{"hits",{8}}}},{"matches",Json::array()}});for(int row=0;row<11;++row)t["matches"].push_back({{"home",{{"id","club:home"},{"name","Recorded Home"}}},{"away",{{"id","club:away"},{"name","Recorded Away"}}},{"league",{{"index",0},{"id","league:test"},{"name","League"}}},{"suggested",1}});return b;}
|
||||
}
|
||||
int main()try{
|
||||
const auto b=fixture(),before=b;const auto v=engine_toto_projection(b);check(b==before&&v.at("columns").size()==6&&v.at("columns")[0][1]==0&&v.at("columns")[1][0]==-1,"saved tips or empty columns lost");check(v.at("programme").at("rows")[0].at("home_ref").at("name")=="Recorded Home"&&v.at("programme").at("caption").get<std::string>().find("22.08.2026")!=std::string::npos,"programme uses guessed teams/date");check(v.at("last").at("paid")==2000000&&v.at("coupon").at("stake")==1000000,"money scaled twice");
|
||||
auto quote=b.at("toto");const Json payload={{"stake",money(10000)},{"columns",b.at("toto").at("data").at("columns")}};quote["data"]["draftQuote"]={{"allowed",true},{"cost",money(10000)},{"payload",payload}};const auto c=engine_toto_command(b,quote,"request:qa");check(c.at("payload")==payload&&c.at("expectedRevision")=="3"&&c.at("owner").at("managerId")=="manager:test","command does not preserve reviewed payload/owner");quote["meta"]["scope"]["managerId"]="manager:other";rejected([&]{engine_toto_command(b,quote,"request:bad");});auto invalid=b;invalid["toto"]["data"]["columns"][0][0]=3;rejected([&]{engine_toto_projection(invalid);});invalid=b;invalid["toto"]["meta"]["stateRevision"]="4";rejected([&]{engine_toto_projection(invalid);});
|
||||
std::cout<<"Toto DTO: actual programme, stored columns, last settlement, exact money and context passed\n";return 0;
|
||||
}catch(const std::exception&e){std::cerr<<e.what()<<'\n';return 1;}
|
||||
@@ -0,0 +1,23 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "modern/content/toto_quote.hpp"
|
||||
#include "modern/content/ui_contract.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
using namespace bmh;using namespace bmh::modern;
|
||||
namespace {
|
||||
using J=cli::Json;using O=J::Object;using A=J::Array;
|
||||
const J& at(const J& v,const char* key){return v.object()->at(key);}
|
||||
void check(bool yes,const char* why){if(!yes)throw std::runtime_error(why);}
|
||||
J draft(int stake,int count){A rows;for(int c=0;c<count;++c){A row;for(int r=0;r<11;++r)row.push_back(r==c?0:1);rows.push_back(row);}return O{{"stake",ui_money(stake)},{"columns",rows}};}
|
||||
std::string error(const J& q){return at(q,"errorCode").string()?*at(q,"errorCode").string():"";}
|
||||
}
|
||||
int main()try{
|
||||
ModernState g;g.manager_teams={0};g.manager_records.assign(0xb0c,0);g.memory.add_block(::bmh::layout::Coupon,5*0x14);g.memory.add_block(::bmh::layout::DeskActions_SubmitPoolsCoupon_RuntimeField,44);g.memory.add_block(::bmh::layout::CareerSession_DispatchToto_RuntimeField,1);g.memory.set8(::bmh::layout::CareerSession_DispatchToto_RuntimeField,11);
|
||||
const auto q=quote_toto_draft(g,0,draft(50000,3));check(at(q,"allowed").boolean()&&*at(q,"allowed").boolean(),"valid three-column quote rejected");check(*at(at(q,"cost"),"minor").string()=="16000000"&&*at(at(q,"fee"),"minor").string()=="1000000","quote does not use existing total/fee rules");check(g.pools.empty()&&g.memory.u32(::bmh::layout::Coupon)==0,"preview registered a coupon");
|
||||
check(error(quote_toto_draft(g,0,draft(9999,1)))=="stake_out_of_range","low stake accepted");check(error(quote_toto_draft(g,0,draft(100000,5)))=="total_stake_too_high","principal limit missed");check(error(quote_toto_draft(g,0,draft(10000,7)))=="too_many_columns","column limit missed");
|
||||
auto duplicate=draft(50000,2);auto &rows=std::get<A>(std::get<O>(duplicate.value).at("columns").value);rows[1]=rows[0];check(error(quote_toto_draft(g,0,duplicate))=="duplicate_column","duplicate columns accepted");
|
||||
auto bad=draft(10000,1);std::get<O>(std::get<O>(bad.value).at("stake").value)["currency"]="USD";check(!parse_toto_draft(bad),"wrong currency accepted");bad=draft(10000,1);std::get<O>(std::get<O>(bad.value).at("stake").value)["minor"]="1000000garbage";check(!parse_toto_draft(bad),"partial money parsed");bad=draft(10000,1);std::get<O>(std::get<O>(bad.value).at("stake").value)["minor"]="1000001";check(!parse_toto_draft(bad),"fractional euro accepted");
|
||||
const auto clear=quote_toto_draft(g,0,draft(0,0));check(*at(clear,"allowed").boolean()&&*at(clear,"clearing").boolean()&&*at(at(clear,"cost"),"minor").string()=="0","withdrawal does not follow existing clear path");check(!parse_toto_draft(draft(0,1)),"zero stake with tips accepted");g.memory.set8(::bmh::layout::CareerSession_DispatchToto_RuntimeField,9);check(error(quote_toto_draft(g,0,draft(10000,1)))=="toto_coupon_requires_eleven_matches","closed programme accepted");
|
||||
std::cout<<"Toto preview: real rules, fee, duplicate columns, strict money, clear and read purity passed\n";return 0;
|
||||
}catch(const std::exception&e){std::cerr<<e.what()<<'\n';return 1;}
|
||||
Reference in new issue
Block a user