Bind cup reports and linked competition phases to live engine data (by Codex)

This commit is contained in:
Codex committed 2026-10-28 23:03:36 +01:00
1 parent 545e16f153
commit 6b4aa9772d
26 files changed
+402 -33

No files matched your search

+12 -1
View File
@@ -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","verify-reports","verify-fixtures"};
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"};
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)); };
@@ -337,6 +337,17 @@ int main(int argc, char **argv) {
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");
}
if(mode=="verify-other") {
const auto index=link->read({{"kind","other-index"}}),data=engine_other_index(before,index);write("other-index.json",index);Json all=Json::array();
for(const auto &v:data.at("views"))for(int round=1;round<=v.at("rounds").get<int>();++round) {
const Json request={{"kind","other-fixtures"},{"viewId",v.at("id")},{"round",round}};
const auto read=link->read(request);(void)engine_other_projection(before,index,read,v.at("id"),round);
if(link->read(request)!=read)throw std::runtime_error("cup read changed on repetition");all.push_back(read);
}
write("all-rounds.json",all);if(link->snapshot()!=before)throw std::runtime_error("cup reads mutated session");
write("saved.json",link->save_copy(out/"other.obs"));link.reset();link=EngineBridge::open(world,out/"other.obs");
if(link->read({{"kind","other-index"}}).at("data")!=index.at("data"))throw std::runtime_error("cup index changed on restart");
}
if(mode=="verify-fixtures") {
const auto ir=link->read({{"kind","report-index"}}),idx=engine_report_index(before,ir);write("fixture-index.json",ir);Json rounds=Json::array();
for(const auto &l:idx.at("leagues")) {
+8
View File
@@ -379,6 +379,14 @@ int main() {
bad_fixture=fixture_read;bad_fixture["data"]["round"]=2;rejects([&]{engine_fixtures_projection(report_bundle,report_index_read,bad_fixture,"league:live",1);});
bad_fixture=fixture_read;bad_fixture["data"]["matches"][0]["away"]["id"]="club:6";rejects([&]{engine_fixtures_projection(report_bundle,report_index_read,bad_fixture,"league:live",1);});
bad_fixture=fixture_read;bad_fixture["meta"]["stateRevision"]="42";rejects([&]{engine_fixtures_projection(report_bundle,report_index_read,bad_fixture,"league:live",1);});
const auto other_index=report_wrap("other-index",{{"kind","other-index"},{"views",{{{"id","cup-view:0:0"},{"name","Synthetic Cup"},{"entry",0},{"rounds",2},{"currentRound",1},{"knockout",true},{"twoLegs",false}}}},{"defaultViewId","cup-view:0:0"}});
auto other_data=fixture_read_data;other_data["kind"]="other-fixtures";other_data["viewId"]="cup-view:0:0";other_data["entry"]=0;other_data["available"]=true;other_data["heading"]="Round 1";
auto &om=other_data["matches"][0];om["homeHasSquad"]=true;om["awayHasSquad"]=false;om["secondLegVisible"]=false;om["secondLeg"]=nullptr;om["phase"]=nullptr;om["secondLegPhase"]=nullptr;om["date"]=nullptr;
const auto other_read=report_wrap("other-fixtures",other_data);require(engine_other_projection(report_bundle,other_index,other_read,"cup-view:0:0",1).at("matches")[0].at("home_goals").is_null(),"open cup got a score");
auto bad_other=other_read;bad_other["data"]["available"]=false;rejects([&]{engine_other_projection(report_bundle,other_index,bad_other,"cup-view:0:0",1);});
bad_other=other_read;bad_other["data"]["matches"][0]["result"]={1,2};rejects([&]{engine_other_projection(report_bundle,other_index,bad_other,"cup-view:0:0",1);});
bad_other=other_read;bad_other["data"]["entry"]=1;rejects([&]{engine_other_projection(report_bundle,other_index,bad_other,"cup-view:0:0",1);});
bad_other=other_read;bad_other["meta"]["stateRevision"]="42";rejects([&]{engine_other_projection(report_bundle,other_index,bad_other,"cup-view:0:0",1);});
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; }
+51
View File
@@ -0,0 +1,51 @@
// SPDX-License-Identifier: GPL-3.0-only
// Authored cup records exercise the existing Modern overview, without original data.
#include "modern/content/ui_contract.hpp"
#include "modern/content/projections.hpp"
#include "modern/game/cup.hpp"
#include "formats/executable_layout.hpp"
#include "formats/textd.hpp"
#include <iostream>
#include <stdexcept>
using namespace bmh;
namespace {
using J=cli::Json;using O=J::Object;
const J& at(const J& j,const char* k){return j.object()->at(k);}
void check(bool yes,const char* why){if(!yes)throw std::runtime_error(why);}
}
int main() try {
modern::ModernState g;g.manager_teams={0};g.manager_records.resize(0xb0c);g.display_start_year=2026;
g.memory.add_block(layout::CupTable,modern::kCupEntries*modern::kCupEntrySize);
g.memory.add_block(layout::ActiveSelectors,8);
g.memory.add_block(layout::SyntheticCupParticipantsBegin,0x100);
g.memory.add_block(layout::SyntheticCupResultsBegin,0x100);
for(int i=0;i<modern::kCupEntries;++i){g.memory.set16(modern::cup_entry_address(i)+0x18,0xffff);g.memory.set8(modern::cup_entry_address(i)+0x15,0xff);}
for(int i=0;i<8;++i)g.memory.set8(layout::ActiveSelectors+i,0x14);
g.memory.set8(layout::ActiveSelectors,0);g.memory.set8(layout::ActiveSelectors+1,1);
g.club_ids.resize(4);g.club_names.resize(8);g.world_club_id.resize(4);g.world_club_name.resize(4);
for(int i=0;i<4;++i){g.club_ids[i]=i*2;g.club_names[i*2]='A'+i;g.world_club_id[i]="club:"+std::to_string(i);g.world_club_name[i]="Synthetic "+std::to_string(i);g.memory.set16(layout::SyntheticCupParticipantsBegin+i*2,i);}
g.squad_slots.resize(4000,kEmptySlot);g.team_morale.resize(500);
const auto descriptor=[&](int entry,int comp,int teams,int rounds,int flags){auto a=modern::cup_entry_address(entry);g.memory.set_pointer(a,layout::SyntheticCupParticipantsBegin);g.memory.set_pointer(a+0x0c,layout::SyntheticCupResultsBegin+entry*16);g.memory.set16(a+0x18,comp);g.memory.set8(a+0x14,flags);g.memory.set8(a+0x1a,teams);g.memory.set8(a+0x1b,rounds);};
descriptor(0,0,4,2,4);descriptor(1,1,2,1,5);
g.memory.set16(layout::SyntheticCupResultsBegin,0x41);g.memory.set16(layout::SyntheticCupResultsBegin+2,0xcccc);
g.memory.set16(layout::SyntheticCupResultsBegin+16,0x400|0x21);
g.memory.set_pointer(modern::cup_entry_address(1)+0x10,layout::SyntheticCupResultsBegin+32);g.memory.set16(layout::SyntheticCupResultsBegin+32,0x800|0x62);g.memory.set8(modern::cup_entry_address(1)+0x1d,1);
TextDb texts;texts.strings.resize(1200);for(size_t i=567;i<620;++i)texts.strings[i]="Synthetic round";g.texts=&texts;
modern::UiContext c;c.manager=0;c.state_revision=9;
const auto read=[&](const char* view,int round){return modern::ui_read(g,c,O{{"kind","other-fixtures"},{"viewId",view},{"round",round}});};
const auto index=modern::ui_read(g,c,O{{"kind","other-index"}});check(at(at(index,"data"),"views").array()->size()==2,"active cup index differs");
const auto first=read("cup-view:0:0",1);const auto &m=*at(at(first,"data"),"matches").array();check(m.size()==2,"full first round missing");check(*at(m[0],"status").string()=="played"&&*at(m[0],"result").array()->at(0).integer()==2,"score changed");check(std::holds_alternative<std::nullptr_t>(at(m[1],"result").value),"open fixture has invented score");
const auto future=read("cup-view:0:0",2);check(!std::get<bool>(at(at(future,"data"),"available").value)&&at(at(future,"data"),"matches").array()->empty(),"future draw invented");
const auto legs=read("cup-view:1:0",1);const auto &leg=at(at(legs,"data"),"matches").array()->at(0);check(*at(leg,"phase").integer()==1&&*at(leg,"secondLegPhase").integer()==2,"cup phases lost");check(*at(leg,"secondLeg").array()->at(0).integer()==2&&*at(leg,"secondLeg").array()->at(1).integer()==3,"second leg not oriented to displayed sides");
check(*at(read("cup-view:0:0",0),"messageType").string()=="error"&&*at(read("cup-view:0:0",3),"messageType").string()=="error","invalid cup rounds accepted");
check(*at(read("cup-view:99:0",1),"messageType").string()=="error","foreign cup accepted");
g.memory.add_block(layout::CalendarState_FormatError_RuntimeField3,2);g.memory.set16(layout::CalendarState_FormatError_RuntimeField3,10);
descriptor(2,12,2,1,4);g.memory.set8(layout::ActiveSelectors+2,12);
g.memory.set_pointer(modern::cup_entry_address(2),0);g.memory.set_pointer(modern::cup_entry_address(2)+0x0c,0);
const auto metadata=modern::ui_read(g,c,O{{"kind","other-index"}});check(at(at(metadata,"data"),"views").array()->size()==3,"metadata index accessed uninitialised row arrays");
g.memory.set_pointer(modern::cup_entry_address(2),layout::SyntheticCupParticipantsBegin);g.memory.set_pointer(modern::cup_entry_address(2)+0x0c,layout::SyntheticCupResultsBegin+32);g.memory.set16(layout::SyntheticCupResultsBegin+32,5);
const auto scheduled=read("cup-view:12:0",1);const auto &planned=at(at(scheduled,"data"),"matches").array()->at(0);
check(*at(planned,"status").string()=="scheduled"&&std::holds_alternative<std::nullptr_t>(at(planned,"result").value)&&at(planned,"date").string(),"scheduled offset was decoded as score");
check(g.memory.u16(layout::SyntheticCupResultsBegin)==0x41&&g.memory.u8(layout::ActiveSelectors)==0,"pure read changed source bytes");
std::cout<<"cup index, null results, future draws, phases and reversed legs passed\n";return 0;
} catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}