Connect Almanac UI to revision-bound career history (by Codex)
This commit is contained in:
1 parent
4b6c18f654
commit
959154c3c0
18 files changed
+405
-44
No files matched your search
@@ -10,24 +10,27 @@ using namespace bmh;
|
||||
using namespace bmh::modern_ui;
|
||||
int main(int argc, char **argv) {
|
||||
try {
|
||||
if (argc != 4 || (std::string(argv[1]) != "prepare-national" && std::string(argv[1]) != "verify-national" && 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 prepare-national|verify-national|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 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"};
|
||||
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]> <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-national" || std::string(argv[1]) == "prepare" || std::string(argv[1]) == "prepare-two") {
|
||||
if (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 (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") 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 (std::string(argv[1]) == "prepare-national") {
|
||||
if (mode == "prepare-national" || mode == "prepare-almanac") {
|
||||
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 (desk.at("meta").at("scope").at("role") == "national") { found = true; break; }
|
||||
if (mode=="prepare-national" && desk.at("meta").at("scope").at("role") == "national") { 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");
|
||||
const Json command{{"messageType","command"},{"contractVersion",meta.at("contractVersion")},{"requestId","request:prepare-national-"+std::to_string(k)},{"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()),rev))); log.push_back(reply);
|
||||
@@ -36,7 +39,7 @@ int main(int argc, char **argv) {
|
||||
throw std::runtime_error(reply.dump());
|
||||
}
|
||||
write("preparation-advance.json",log);
|
||||
if (!found) throw std::runtime_error("no national desk reached through session.advance");
|
||||
if (!found) throw std::runtime_error("requested fixture not reached through session.advance: "+mode);
|
||||
}
|
||||
if (!session.save_game(out / "input.obs", 0, false, error)) throw std::runtime_error(error);
|
||||
modern::set_current_world(nullptr);
|
||||
@@ -274,6 +277,34 @@ int main(int argc, char **argv) {
|
||||
for(const auto *kind:{"friendly-plan","calendar"})if(loaded.at(kind).at("data")!=after.at(kind).at("data"))throw std::runtime_error("national plan/calendar lost on restart");
|
||||
if(loaded.at("desktop").at("data").at("accounts")!=after.at("desktop").at("data").at("accounts"))throw std::runtime_error("national funds lost on restart");
|
||||
}
|
||||
if(mode=="inspect-almanac"||mode=="verify-almanac") {
|
||||
const auto run=[&](const Json &q){const auto read=link->read({{"kind","almanac"},{"query",q}});if(link->read({{"kind","almanac"},{"query",q}})!=read)throw std::runtime_error("archive read changed on repeat");return std::pair{read,engine_almanac_projection(before,read,q)};};
|
||||
const auto [index_read,index]=run({{"kind","index"}});write("index-read.json",index_read);
|
||||
Json catalogue=Json::array();int total=0;
|
||||
for(const auto &year:index.at("years")) {
|
||||
const auto [cr,calendar]=run({{"kind","calendar"},{"year",year}});write(("calendar-"+std::to_string(year.get<int>())+".json").c_str(),cr);
|
||||
for(const auto &day:calendar.at("days")) {
|
||||
const auto [dr,d]=run({{"kind","day"},{"date",day.at("date")}});if(d.at("matches").size()!=size_t(day.at("count").get<int>()))throw std::runtime_error("archive day count mismatch");total+=day.at("count").get<int>();
|
||||
for(const auto &m:d.at("matches"))catalogue.push_back({{"id",m.at("id")},{"date",m.at("date")},{"home",m.at("home")},{"away",m.at("away")},{"result",m.at("result")},{"events",m.at("events").size()},{"competition",m.at("competition")}});
|
||||
}
|
||||
}
|
||||
if(total!=index.at("match_count"))throw std::runtime_error("archive index count differs from calendars");write("catalogue.json",catalogue);
|
||||
Json selected=Json::array();std::set<std::string> selected_ids;
|
||||
for(const auto &m:catalogue) {
|
||||
const bool human=!m.at("home").at("manager").is_null()||!m.at("away").at("manager").is_null();
|
||||
if(selected.size()<2 || (human&&std::none_of(selected.begin(),selected.end(),[](const auto &r){return r.value("human",false);})) || (m.at("result").at("extra_played")==true&&std::none_of(selected.begin(),selected.end(),[](const auto &r){return r.value("extra",false);})) || (m.at("result").at("penalties_played")==true&&std::none_of(selected.begin(),selected.end(),[](const auto &r){return r.value("penalties",false);})) || (m.at("date").get<std::string>().substr(0,4)=="2027"&&std::none_of(selected.begin(),selected.end(),[](const auto &r){return r.at("date").template get<std::string>().substr(0,4)=="2027";}))) {
|
||||
if(!selected_ids.insert(m.at("id").get<std::string>()).second)continue;
|
||||
const auto [read,record]=run({{"kind","match"},{"id",m.at("id")}});write(("match-"+std::to_string(selected.size())+".json").c_str(),read);
|
||||
selected.push_back({{"id",m.at("id")},{"date",m.at("date")},{"human",human},{"extra",m.at("result").at("extra_played")},{"penalties",m.at("result").at("penalties_played")}});
|
||||
}
|
||||
}
|
||||
write("selected.json",selected);
|
||||
if(link->snapshot()!=before)throw std::runtime_error("archive browsing changed engine or RNG projection");
|
||||
const auto unknown=link->read({{"kind","almanac"},{"query",{{"kind","match"},{"id","match:unknown"}}}});write("unknown-match.json",unknown);if(unknown.value("messageType","")!="error")throw std::runtime_error("unknown archived match not rejected");
|
||||
const auto foreign=link->read({{"kind","almanac"},{"managerId","manager:not-active"},{"query",{{"kind","index"}}}});write("foreign-owner.json",foreign);if(foreign.value("code","")!="manager_not_active")throw std::runtime_error("foreign archive scope accepted");
|
||||
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");
|
||||
}
|
||||
std::cout << "engine bridge " << argv[1] << " passed\n"; return 0;
|
||||
} catch (const std::exception &e) { std::cerr << e.what() << '\n'; return 1; }
|
||||
}
|
||||
@@ -320,6 +320,41 @@ int main() {
|
||||
bad_nq=nq;bad_nq["data"]["ratings"]={73};rejects([&]{engine_friendly_projection(np,bad_nq,"nt:two",true);});
|
||||
bad_nq=nq;bad_nq["data"]["ratings"]={73,-1};rejects([&]{engine_friendly_projection(np,bad_nq,"nt:two",true);});
|
||||
bad_nq=nq;bad_nq["meta"]["stateRevision"]="0";rejects([&]{engine_friendly_projection(np,bad_nq,"nt:two",true);});
|
||||
// Archive DTOs retain historic names and unknown fields; only their bound
|
||||
// owner/revision/query may supply a record to the existing presenter.
|
||||
auto archive_bundle=cal;for(auto &[kind,r]:archive_bundle.items())r["meta"]["date"]="2027-01-02";
|
||||
const Json archived_person={{"id","player:archived"},{"name","Historical Player"}};
|
||||
const Json archived_record={{"id","match:2026-1"},{"date","2026-08-01"},{"season","2026/27"},{"round",1},
|
||||
{"competition",{{"id","league:old"},{"name","Historical League"},{"type","league"}}},
|
||||
{"home",{{"id","club:old-a"},{"name","Historical Home"},{"crest",nullptr},{"manager",{{"id","manager:old"},{"name","Historical Manager"}}}}},
|
||||
{"away",{{"id","club:old-b"},{"name","Historical Away"},{"crest",nullptr},{"manager",nullptr}}},
|
||||
{"result",{{"final",{2,1}},{"regulation",nullptr},{"extra",nullptr},{"penalties",nullptr},{"extra_played",false},{"penalties_played",false}}},
|
||||
{"referee",nullptr},{"attendance",12000},{"weather",{{"temperature",19},{"rain",2}}},
|
||||
{"lineups",{{"home",{{"starters",{archived_person}},{"bench",Json::array()}}},{"away",nullptr}}},
|
||||
{"events",{{{"kind","goal"},{"minute",82},{"side","home"},{"player",archived_person},{"other",nullptr},{"detail",0}}}}};
|
||||
const auto archived_read=[&](const Json &query,const Json &result){return Json{{"messageType","snapshot"},{"meta",archive_bundle.at("desktop").at("meta")},{"data",{{"kind","almanac"},{"query",query},{"result",result}}}};};
|
||||
const Json archive_match_query={{"kind","match"},{"id","match:2026-1"}};
|
||||
const Json archive_match_result={{"ok",true},{"match",archived_record}};
|
||||
const auto archive_reply=archived_read(archive_match_query,archive_match_result);
|
||||
const auto archive_value=engine_almanac_projection(archive_bundle,archive_reply,archive_match_query);
|
||||
require(archive_value==archive_match_result && archive_value.at("match").at("result").at("regulation").is_null() && !archive_value.at("match").at("lineups").at("home").at("starters")[0].contains("position"),"archive presentation invented phase or current player data");
|
||||
const Json archive_index_query={{"kind","index"}},archive_index={{"ok",true},{"years",{2026}},{"match_count",1},{"first_date","2026-08-01"},{"last_date","2026-08-01"}};
|
||||
require(engine_almanac_projection(archive_bundle,archived_read(archive_index_query,archive_index),archive_index_query)==archive_index,"archive index lost");
|
||||
const Json archive_calendar_query={{"kind","calendar"},{"year",2026}},archive_calendar={{"ok",true},{"year",2026},{"days",{{{"date","2026-08-01"},{"count",1},{"highlights",{"match:2026-1"}}}}}};
|
||||
(void)engine_almanac_projection(archive_bundle,archived_read(archive_calendar_query,archive_calendar),archive_calendar_query);
|
||||
const Json archive_day_query={{"kind","day"},{"date","2026-08-01"}},archive_day={{"ok",true},{"date","2026-08-01"},{"matches",{archived_record}}};
|
||||
(void)engine_almanac_projection(archive_bundle,archived_read(archive_day_query,archive_day),archive_day_query);
|
||||
auto bad_archive=archive_reply;bad_archive["meta"]["careerId"]="other";rejects([&]{engine_almanac_projection(archive_bundle,bad_archive,archive_match_query);});
|
||||
bad_archive=archive_reply;bad_archive["meta"]["stateRevision"]="42";rejects([&]{engine_almanac_projection(archive_bundle,bad_archive,archive_match_query);});
|
||||
bad_archive=archive_reply;bad_archive["data"]["query"]["id"]="match:other";rejects([&]{engine_almanac_projection(archive_bundle,bad_archive,archive_match_query);});
|
||||
bad_archive=archive_reply;bad_archive["data"]["result"]["match"]["id"]="match:other";rejects([&]{engine_almanac_projection(archive_bundle,bad_archive,archive_match_query);});
|
||||
bad_archive=archive_reply;bad_archive["data"]["result"]["match"]["date"]="2028-08-01";rejects([&]{engine_almanac_projection(archive_bundle,bad_archive,archive_match_query);});
|
||||
auto bad_archive_day=archive_day;bad_archive_day["matches"].push_back(archived_record);rejects([&]{engine_almanac_projection(archive_bundle,archived_read(archive_day_query,bad_archive_day),archive_day_query);});
|
||||
bad_archive_day=archive_day;bad_archive_day["matches"][0]["date"]="2026-08-02";rejects([&]{engine_almanac_projection(archive_bundle,archived_read(archive_day_query,bad_archive_day),archive_day_query);});
|
||||
auto bad_archive_calendar=archive_calendar;bad_archive_calendar["year"]=2025;rejects([&]{engine_almanac_projection(archive_bundle,archived_read(archive_calendar_query,bad_archive_calendar),archive_calendar_query);});
|
||||
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",""}});});
|
||||
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; }
|
||||
|
||||
Reference in new issue
Block a user