Bind league tables strengths and live profiles to engine reads (by Codex)
This commit is contained in:
1 parent
f9e8719b2d
commit
1c35698dbe
24 files changed
+463
-20
No files matched your search
@@ -11,7 +11,7 @@ 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"};
|
||||
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"};
|
||||
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)); };
|
||||
@@ -313,6 +313,30 @@ int main(int argc, char **argv) {
|
||||
write("saved.json",link->save_copy(out/"reads.obs"));link.reset();link=EngineBridge::open(world,out/"reads.obs");const auto loaded=link->snapshot();write("loaded.json",loaded);
|
||||
if(loaded.at("desktop").at("data")!=before.at("desktop").at("data")||link->read({{"kind","almanac"},{"query",{{"kind","index"}}}}).at("data")!=index_read.at("data"))throw std::runtime_error("archive or desk changed across OBS restart");
|
||||
}
|
||||
if(mode=="verify-reports") {
|
||||
const auto index_read=link->read({{"kind","report-index"}}),index=engine_report_index(before,index_read);write("report-index.json",index_read);
|
||||
Json all=Json::array();
|
||||
for(const auto &league:index.at("leagues")) {
|
||||
const auto id=league.at("id").get<std::string>();std::vector<Json> views;
|
||||
for(int filter=0;filter<5;++filter) {
|
||||
const Json request={{"kind","league-report"},{"leagueId",id},{"filter",filter}};const auto read=link->read(request);const auto value=engine_report_projection(before,index_read,read,id,filter);
|
||||
if(link->read(request)!=read)throw std::runtime_error("report read not repeatable");
|
||||
views.push_back(value);all.push_back(read);
|
||||
}
|
||||
for(int f=1;f<5;++f)if(views[size_t(f)].at("strengths")!=views[0].at("strengths"))throw std::runtime_error("table filter changed squad strengths");
|
||||
for(const auto &r:views[0].at("table"))for(const auto *k:{"played","wins","draw","loss","gf","ga"}) {
|
||||
const auto n=r.at(k).get<int>();int venue=0,halves=0;
|
||||
for(const auto &q:views[3].at("table"))if(q.at("club")==r.at("club"))venue+=q.at(k).get<int>();for(const auto &q:views[4].at("table"))if(q.at("club")==r.at("club"))venue+=q.at(k).get<int>();
|
||||
for(const auto &q:views[1].at("table"))if(q.at("club")==r.at("club"))halves+=q.at(k).get<int>();for(const auto &q:views[2].at("table"))if(q.at("club")==r.at("club"))halves+=q.at(k).get<int>();
|
||||
if(n!=venue||n!=halves)throw std::runtime_error("table subsets do not sum to total");
|
||||
}
|
||||
const auto team=league.at("members")[0].get<std::string>();const auto squad=link->read({{"kind","squad"},{"teamId",team}});(void)engine_report_squad(before,squad,team);write(("squad-"+std::to_string(all.size()/5)+".json").c_str(),squad);
|
||||
}
|
||||
write("reports.json",all);
|
||||
if(link->snapshot()!=before)throw std::runtime_error("report reads changed engine");
|
||||
write("saved.json",link->save_copy(out/"reports.obs"));link.reset();link=EngineBridge::open(world,out/"reports.obs");
|
||||
if(link->read({{"kind","report-index"}}).at("data")!=index_read.at("data"))throw std::runtime_error("report index changed after OBS restart");
|
||||
}
|
||||
std::cout << "engine bridge " << argv[1] << " passed\n"; return 0;
|
||||
} catch (const std::exception &e) { std::cerr << e.what() << '\n'; return 1; }
|
||||
}
|
||||
@@ -355,6 +355,23 @@ int main() {
|
||||
rejects([&]{engine_almanac_key({{"kind","calendar"},{"year",2026.5}});});
|
||||
rejects([&]{engine_almanac_key({{"kind","day"},{"date","2026-02-30"}});});
|
||||
rejects([&]{engine_almanac_key({{"kind","match"},{"id",""}});});
|
||||
auto report_bundle=fixture();
|
||||
const auto report_wrap=[&](const char*,const Json &data){return Json{{"messageType","snapshot"},{"meta",report_bundle.at("desktop").at("meta")},{"data",data}};};
|
||||
const Json report_index_data={{"kind","report-index"},{"leagues",{{{"id","league:live"},{"name","Live League"},{"nationId","nation:test"},{"members",{"club:6","club:7"}},{"clubCount",2},{"matchdays",2},{"played",1},{"own",true}}}}};
|
||||
const auto report_index_read=report_wrap("report-index",report_index_data);
|
||||
Json report_rows=Json::array(),strength_rows=Json::array();
|
||||
for(int n=0;n<2;++n){const auto id=n?"club:7":"club:6";Json team={{"id",id},{"name",n?"Live B":"Live A"}};
|
||||
report_rows.push_back({{"team",team},{"original",n},{"rank",n+1},{"played",1},{"wins",n?0:1},{"draw",0},{"loss",n?1:0},{"gf",n?0:2},{"ga",n?2:0},{"diff",n?-2:2},{"points",n?0:3},{"form",n?0:3},{"form_text",n?"N":"S"}});
|
||||
strength_rows.push_back({{"team",team},{"original",n},{"basis","squad"},{"keeper",nullptr},{"defence",71},{"midfield",72},{"attack",73},{"strength",72}});
|
||||
}
|
||||
const Json report_data={{"kind","league-report"},{"leagueId","league:live"},{"filter",0},{"table",report_rows},{"strengths",strength_rows},{"zones",nullptr}};
|
||||
const auto report_read=report_wrap("league-report",report_data);const auto report_value=engine_report_projection(report_bundle,report_index_read,report_read,"league:live",0);
|
||||
require(report_value.at("table")[0].at("name")=="Live A"&&report_value.at("strengths")[0].at("keeper").is_null(),"live report name/unknown position was fabricated");
|
||||
auto bad_report=report_read;bad_report["meta"]["careerId"]="other";rejects([&]{engine_report_projection(report_bundle,report_index_read,bad_report,"league:live",0);});
|
||||
bad_report=report_read;bad_report["data"]["table"][0]["team"]["id"]="club:other";rejects([&]{engine_report_projection(report_bundle,report_index_read,bad_report,"league:live",0);});
|
||||
bad_report=report_read;bad_report["data"]["table"][1]["rank"]=1;rejects([&]{engine_report_projection(report_bundle,report_index_read,bad_report,"league:live",0);});
|
||||
bad_report=report_read;bad_report["data"]["filter"]=3;rejects([&]{engine_report_projection(report_bundle,report_index_read,bad_report,"league:live",0);});
|
||||
auto bad_index=report_index_read;bad_index["data"]["leagues"][0]["members"][1]="club:6";rejects([&]{engine_report_index(report_bundle,bad_index);});
|
||||
std::cout << "engine DTO, exact money, scope and booking tests passed\n";
|
||||
return 0;
|
||||
} catch (const std::exception &e) { std::cerr << e.what() << '\n'; return 1; }
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
// 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 <algorithm>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
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;l<kLeagueCount;++l){g.world_league_id[l]="league:"+std::to_string(l);g.world_league_name[l]="Synthetic "+std::to_string(l);}
|
||||
for(int t=0;t<modern::league_clubs();++t){g.world_club_id[t]="club:"+std::to_string(t);g.world_club_name[t]="Club "+std::to_string(t);}
|
||||
g.results.resize(kResultsSize,kNotPlayed);g.league_rounds.assign(kLeagueCount,2);
|
||||
g.results[0]=0x21;g.results[10]=0x03;
|
||||
modern::UiContext context;context.manager=0;context.state_revision=7;
|
||||
const auto read=[&](int filter){return modern::ui_read(g,context,O{{"kind","league-report"},{"leagueId","league:0"},{"filter",filter}});};
|
||||
const auto index=modern::ui_read(g,context,O{{"kind","report-index"}});
|
||||
check(at(index,"messageType").string()&&*at(index,"messageType").string()=="snapshot","index available");
|
||||
check(at(at(index,"data"),"leagues").array()->size()==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<int> 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<ranks.size();++i)check(ranks[i]==int(i+1),"unplayed half has unique engine ranks");
|
||||
for(const auto &r:*at(at(all,"data"),"strengths").array())check(std::holds_alternative<std::nullptr_t>(at(r,"strength").value),"absent squads do not receive fake strength");
|
||||
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<<e.what()<<'\n';return 1;}
|
||||
Reference in new issue
Block a user