// SPDX-License-Identifier: GPL-3.0-only #include "modern/content/ui_contract.hpp" #include "modern/content/projections.hpp" #include "modern/game/modern_state.hpp" #include "game/schedule.hpp" #include "game/table.hpp" #include "fixture_tables.hpp" #include #include #include using namespace bmh; namespace { using J=cli::Json;using O=J::Object; const J& at(const J& j,const char* key){return j.object()->at(key);} void check(bool b,const char* message){if(!b)throw std::runtime_error(message);} int integer(const J& j){return int(*j.integer());} } int main() try { set_fixture_tables(bmh::test::authored_fixture_tables()); modern::ModernState g;g.manager_teams={0};g.manager_records.resize(0xb0c);g.display_start_year=2026; g.world_league_id.resize(kLeagueCount);g.world_league_name.resize(kLeagueCount); g.world_club_id.resize(modern::league_clubs());g.world_club_name.resize(modern::league_clubs()); for(int l=0;lsize()==size_t(kLeagueCount),"active leagues only"); const auto all=read(0),home=read(3),away=read(4),second=read(2); const auto &rows=*at(at(all,"data"),"table").array(); const auto old=modern::query_projection(g,0,O{{"kind","table"},{"league","league:0"}}); for(const auto &r:rows){ const auto id=*at(at(r,"team"),"id").string(); for(const auto &legacy:*at(old,"rows").array())if(*at(at(legacy,"club"),"id").string()==id) { check(integer(at(r,"rank"))==integer(at(legacy,"rank"))&&integer(at(r,"points"))==integer(at(legacy,"points"))&&integer(at(r,"gf"))==integer(at(legacy,"goals_for")),"unfiltered report matches existing engine table"); } for(const auto *key:{"played","wins","draw","loss","gf","ga"}) { int venue=0; for(const auto *part:{&home,&away})for(const auto &p:*at(at(*part,"data"),"table").array())if(*at(at(p,"team"),"id").string()==id)venue+=integer(at(p,key)); check(venue==integer(at(r,key)),"home and away subsets sum to total"); } } std::vector ranks; for(const auto &r:*at(at(second,"data"),"table").array()){check(integer(at(r,"played"))==0,"unplayed second half has no invented matches");ranks.push_back(integer(at(r,"rank")));} std::sort(ranks.begin(),ranks.end());for(size_t i=0;i(at(r,"strength").value),"absent squads do not receive fake strength"); const auto fixtures=[&](int round){return modern::ui_read(g,context,O{{"kind","league-fixtures"},{"leagueId","league:0"},{"round",round}});}; const auto played_fixture=fixtures(1);const auto& first_fixture=at(at(played_fixture,"data"),"matches").array()->at(0); check(*at(first_fixture,"status").string()=="played" && integer(at(first_fixture,"result").array()->at(0))==2,"played fixture keeps its actual score"); for(const auto marker:{0xcc,0xcd,0xce,0xde,0xee,0xcf}) { g.results[0]=uint8_t(marker);const auto r=fixtures(1);const auto& m=at(at(r,"data"),"matches").array()->at(0); const std::string expected=(marker&0xcf)==0xcc?"open":(marker&0xcf)==0xcd?"postponed":(marker&0xcf)==0xce?"rescheduled":"unavailable"; check(*at(m,"status").string()==expected && std::holds_alternative(at(m,"result").value),"unplayed markers cannot become 12:14 scores"); } g.results[0]=0x21; const auto next=modern::ui_read(g,context,O{{"kind","league-fixtures"},{"leagueId","league:0"}}); check(integer(at(at(next,"data"),"round"))==3,"default round is the engine's next matchday"); check(*at(fixtures(0),"messageType").string()=="error"&&*at(fixtures(35),"messageType").string()=="error","round boundaries enforced"); const auto invalid=read(5);check(*at(invalid,"messageType").string()=="error","invalid filter rejected"); const auto foreign=modern::ui_read(g,context,O{{"kind","report-index"},{"managerId","manager:not-active"}});check(*at(foreign,"code").string()=="manager_not_active","foreign manager rejected"); std::cout<<"report subsets, empty halves, engine parity and scope passed\n";return 0; } catch(const std::exception& e){std::cerr<