Bind squad and lineup views to confirmed engine player swaps (by Codex)
This commit is contained in:
1 parent
94dc5ecbc4
commit
7d3b3f1101
15 files changed
+340
-36
No files matched your search
@@ -8,7 +8,7 @@ using namespace bmh;
|
||||
using namespace bmh::modern_ui;
|
||||
int main(int argc, char **argv) {
|
||||
try {
|
||||
if (argc != 4 || (std::string(argv[1]) != "prepare" && std::string(argv[1]) != "verify")) throw std::runtime_error("usage: modern_engine_bridge_probe prepare|verify <world.obw> <new-output-directory>");
|
||||
if (argc != 4 || (std::string(argv[1]) != "prepare" && std::string(argv[1]) != "verify" && std::string(argv[1]) != "verify-lineup")) throw std::runtime_error("usage: modern_engine_bridge_probe prepare|verify|verify-lineup <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") {
|
||||
@@ -39,6 +39,24 @@ int main(int argc, char **argv) {
|
||||
link = EngineBridge::open(world, out / "booked.obs"); const auto loaded = link->snapshot(); write("loaded.json", loaded);
|
||||
if (loaded.at("desktop").at("data").at("accounts") != after.at("desktop").at("data").at("accounts") || !loaded.at("camps").at("data").at("bookedThisWeek").get<bool>()) throw std::runtime_error("OBS round trip lost booking");
|
||||
}
|
||||
if (std::string(argv[1]) == "verify-lineup") {
|
||||
(void)engine_lineup_projection(before);
|
||||
auto order = before.at("lineup").at("data").at("order");
|
||||
std::swap(order[0], order[11]);
|
||||
const auto request = engine_lineup_command(before, order, "request:lineup-probe");
|
||||
const auto response = link->command(request); write("lineup-command.json", request); write("lineup-response.json", response);
|
||||
if (response.value("messageType", "") != "command_result") throw std::runtime_error(response.dump());
|
||||
if (link->command(request) != response) throw std::runtime_error("lineup request replay changed response");
|
||||
const auto after = link->snapshot(); write("lineup-after.json", after);
|
||||
if (after.at("lineup").at("data").at("order") != order || after.at("desktop").at("data").at("accounts") != before.at("desktop").at("data").at("accounts"))
|
||||
throw std::runtime_error("lineup order not applied exactly or account changed");
|
||||
auto stale = request; stale["requestId"] = "request:stale-lineup";
|
||||
const auto rejected = link->command(stale); write("lineup-rejected.json", rejected);
|
||||
if (rejected.value("code", "") != "stale_revision" || link->snapshot() != after) throw std::runtime_error("stale lineup changed engine state");
|
||||
write("lineup-saved.json", link->save_copy(out / "lineup.obs")); link.reset();
|
||||
link = EngineBridge::open(world, out / "lineup.obs"); const auto loaded = link->snapshot(); write("lineup-loaded.json", loaded);
|
||||
if (loaded.at("lineup").at("data").at("order") != order) throw std::runtime_error("lineup lost during OBS round trip");
|
||||
}
|
||||
std::cout << "engine bridge " << argv[1] << " passed\n"; return 0;
|
||||
} catch (const std::exception &e) { std::cerr << e.what() << '\n'; return 1; }
|
||||
}
|
||||
@@ -51,6 +51,53 @@ int main() {
|
||||
rejects([&] { engine_camp_command(bundle, "resort:unknown", focus, "request:stable"); });
|
||||
auto invalid_focus = focus; invalid_focus["play"] = 16;
|
||||
rejects([&] { engine_camp_command(bundle, "resort:16", invalid_focus, "request:stable"); });
|
||||
auto squad_bundle = fixture();
|
||||
for (auto &item : squad_bundle) item["meta"]["scope"]["allowedCommands"].push_back("lineup.commit");
|
||||
const auto meta = squad_bundle.at("desktop").at("meta");
|
||||
Json players = Json::array(), order = Json::array(), role_rows = Json::array();
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
const auto id = "player:" + std::to_string(i);
|
||||
order.push_back(id); role_rows.push_back({{"playerId", id}, {"role", i < 2 ? "starter" : i == 2 ? "bench" : "reserve"}});
|
||||
players.push_back({{"player", {{"id", id}, {"name", "Engine Name " + std::to_string(i)}, {"positions", {"gk"}}, {"nationIds", {"nation:de"}}}},
|
||||
{"availability", "fit"}, {"age", 37}, {"skills", {{"speed", 2}}},
|
||||
{"metrics", {{"strength", {{"value", 91}, {"availability", {{"status", "available"}}}}},
|
||||
{"condition", {{"value", 0}}}}}});
|
||||
}
|
||||
squad_bundle["squad"] = {{"messageType", "snapshot"}, {"meta", meta},
|
||||
{"data", {{"kind", "squad"}, {"team", {{"id", "club:6"}}}, {"players", players}}}};
|
||||
squad_bundle["lineup"] = {{"messageType", "snapshot"}, {"meta", meta}, {"data", {{"kind", "lineup"}, {"teamId", "club:6"},
|
||||
{"order", order}, {"rows", role_rows}, {"positions", Json::array({{{"playerId", "player:0"}, {"depth", 19}, {"lane", 8}},
|
||||
{{"playerId", "player:1"}, {"depth", 0}, {"lane", 4}}})}, {"depthMax", 19}, {"laneMax", 8}}}};
|
||||
const auto source_bundle = squad_bundle;
|
||||
const auto projected = engine_lineup_projection(squad_bundle);
|
||||
require(projected.at("rows")[0].at("strength") == 91 && projected.at("rows")[0].at("condition") == 0 &&
|
||||
projected.at("rows")[0].at("goals").is_null() && projected.at("rows")[0].at("grade").is_null(),
|
||||
"projection invented catalogue/season values or discarded known zero");
|
||||
require(projected.at("rows")[2].at("status") == "Ersatzbank" && projected.at("rows")[3].at("status") == "—" &&
|
||||
projected.at("board").at("points")[0] == Json::array({19,8}), "roles/coordinate bounds inferred from demo rules");
|
||||
auto changed_order = order; std::swap(changed_order[0], changed_order[2]);
|
||||
const auto lineup_command = engine_lineup_command(squad_bundle, changed_order, "request:lineup");
|
||||
require(lineup_command.at("payload").at("order") == changed_order && lineup_command.at("owner").at("managerId") == "manager:99" &&
|
||||
lineup_command.at("expectedRevision") == "18446744073709551615" && squad_bundle == source_bundle,
|
||||
"lineup command lost complete identities/revision or changed read source");
|
||||
for (int fault = 0; fault < 6; ++fault) {
|
||||
auto bad_order = changed_order;
|
||||
if (fault == 0) bad_order[0] = bad_order[1];
|
||||
if (fault == 1) bad_order.erase(0);
|
||||
if (fault == 2) bad_order[0] = "player:foreign";
|
||||
if (fault == 3) bad_order[0] = 3;
|
||||
if (fault == 4) bad_order.push_back("player:extra");
|
||||
if (fault == 5) bad_order = Json::object();
|
||||
rejects([&] { engine_lineup_command(squad_bundle, bad_order, "request:lineup"); });
|
||||
}
|
||||
auto wrong_context = squad_bundle; wrong_context["squad"]["meta"]["stateRevision"] = "2";
|
||||
rejects([&] { engine_lineup_projection(wrong_context); });
|
||||
wrong_context = squad_bundle; wrong_context["lineup"]["data"]["teamId"] = "club:other";
|
||||
rejects([&] { engine_lineup_command(wrong_context, order, "request:lineup"); });
|
||||
auto hidden_metric = squad_bundle; hidden_metric["squad"]["data"]["players"][0]["metrics"]["strength"]["availability"]["status"] = "unavailable";
|
||||
require(engine_lineup_projection(hidden_metric).at("rows")[0].at("strength").is_null(), "unavailable metric exposed its stale numeric value");
|
||||
auto unknown_point = squad_bundle; unknown_point["lineup"]["data"]["positions"][0]["depth"] = -1;
|
||||
require(engine_lineup_projection(unknown_point).at("board").at("points")[0].is_null(), "unknown pitch position was fabricated");
|
||||
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