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; }
|
||||
}
|
||||
Reference in new issue
Block a user