Bind original settings and automation to atomic native drafts (by Codex)
This commit is contained in:
1 parent
2ce563a4b9
commit
98cff2185d
23 files changed
+959
-189
No files matched your search
@@ -15,7 +15,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","verify-other","verify-rankings","prepare-rankings-archived","verify-create","inspect-coach-identity","prepare-coach-identity","verify-coach-almanac","verify-files","verify-statistics","prepare-statistics","inspect-statistics","prepare-toto","verify-toto","settle-toto","verify-stadium","complete-stadium","verify-transfer","prepare-achievements","verify-balance","verify-balance-warning"};
|
||||
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","verify-rankings","prepare-rankings-archived","verify-create","inspect-coach-identity","prepare-coach-identity","verify-coach-almanac","verify-files","verify-statistics","prepare-statistics","inspect-statistics","prepare-toto","verify-toto","settle-toto","verify-stadium","complete-stadium","verify-transfer","prepare-achievements","verify-balance","verify-balance-warning","verify-settings"};
|
||||
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)); };
|
||||
@@ -285,6 +285,33 @@ int main(int argc, char **argv) {
|
||||
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");
|
||||
}
|
||||
if (mode == "verify-settings") {
|
||||
const auto projected=engine_settings_projection(before);
|
||||
write("read-only-save.json",link->save_copy(out/"read-only.obs"));
|
||||
if(link->snapshot()!=before)throw std::runtime_error("settings read changed source");
|
||||
auto draft=projected.at("local");
|
||||
draft["cells"][0]=draft["cells"][0]==0?1:0;
|
||||
const int i=17;const auto cap=projected.at("cells").at("B9");
|
||||
draft["cells"][i]=draft["cells"][i].get<int>()<cap.at("max").get<int>()?draft["cells"][i].get<int>()+1:draft["cells"][i].get<int>()-1;
|
||||
draft["automation"]["tactics"]=!draft["automation"]["tactics"].get<bool>();
|
||||
draft["automation"]["training"]=!draft["automation"]["training"].get<bool>();
|
||||
auto command=engine_settings_command(before,draft,"request:settings");
|
||||
auto invalid=command;invalid["requestId"]="request:settings-invalid";const auto blocked=projected.at("cells").at("T7").at("value");invalid["payload"]["edits"].push_back({{"code","T7"},{"value",blocked.is_number_integer()?1-blocked.get<int>():0}});
|
||||
const auto refused=link->command(invalid);write("invalid.json",refused);if(refused.value("messageType","")!="error"||link->snapshot()!=before)throw std::runtime_error("settings failed batch did not roll back");
|
||||
const auto response=link->command(command);write("command.json",command);write("response.json",response);
|
||||
if(response.value("messageType","")!="command_result"||response.at("newRevision").get<std::string>()!="1")throw std::runtime_error(response.dump());
|
||||
if(link->command(command)!=response)throw std::runtime_error("settings replay changed outcome");
|
||||
const auto after=link->snapshot();write("after.json",after);const auto value=engine_settings_projection(after);
|
||||
if(value.at("local")!=draft)throw std::runtime_error("settings target differs from canonical read");
|
||||
const auto &raw_before=before.at("settings").at("data"), &raw_after=after.at("settings").at("data");
|
||||
if(raw_after.at("cells")[i].at("raw").get<int>()%2!=raw_before.at("cells")[i].at("raw").get<int>()%2)throw std::runtime_error("settings odd parity lost");
|
||||
if((raw_after.at("automation")[4].at("raw").get<int>()&~1)!=(raw_before.at("automation")[4].at("raw").get<int>()&~1))throw std::runtime_error("automation unowned bits changed");
|
||||
auto stale=command;stale["requestId"]="request:settings-stale";if(link->command(stale).value("code","")!="stale_revision"||link->snapshot()!=after)throw std::runtime_error("stale settings changed source");
|
||||
const auto noop=link->command(engine_settings_command(after,value.at("local"),"request:settings-noop"));write("noop.json",noop);if(noop.value("outcome","")!="no_change"||link->snapshot()!=after)throw std::runtime_error("no-op settings changed source");
|
||||
write("saved.json",link->save_copy(out/"settings.obs"));link->load_same_world(out/"settings.obs");const auto loaded=link->snapshot();write("loaded.json",loaded);
|
||||
if(loaded.at("settings").at("data")!=after.at("settings").at("data"))throw std::runtime_error("settings OBS round trip changed cells/options");
|
||||
write("receipt.json",{{"status","passed"},{"pureRead",true},{"atomicFailure",true},{"oneRevision",true},{"parityAndBitsPreserved",true},{"replayStaleNoop",true},{"saveLoad",true}});
|
||||
}
|
||||
if (std::string(argv[1]) == "verify-sports") {
|
||||
auto tactics = engine_tactics_projection(before); tactics["values"][0] = 1; tactics["values"][7] = 7;
|
||||
const auto tc = engine_tactics_command(before, tactics.at("values"), "request:sports-tactics");
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "modern/ui/engine_bridge.hpp"
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
using namespace bmh::modern_ui;
|
||||
namespace {
|
||||
void check(bool x, const char *s) {
|
||||
if (!x)
|
||||
throw std::runtime_error(s);
|
||||
}
|
||||
template <class F> void rejects(F f) {
|
||||
bool ok = false;
|
||||
try {
|
||||
f();
|
||||
} catch (const std::exception &) {
|
||||
ok = true;
|
||||
}
|
||||
check(ok, "invalid settings accepted");
|
||||
}
|
||||
} // namespace
|
||||
int main() try {
|
||||
const Json meta = {{"contractVersion", "bmh-modern-ui@draft1"},
|
||||
{"careerId", "career:test"},
|
||||
{"worldId", "world:test"},
|
||||
{"worldRevision", "1"},
|
||||
{"stateRevision", "8"},
|
||||
{"scope",
|
||||
{{"managerId", "manager:one"},
|
||||
{"teamId", "club:one"},
|
||||
{"role", "club"},
|
||||
{"allowedCommands", {"settings.commit"}}}}};
|
||||
Json b;
|
||||
for (auto *k : {"session", "desktop", "camps", "settings"})
|
||||
b[k] = {
|
||||
{"messageType", "snapshot"}, {"meta", meta}, {"data", {{"kind", k}}}};
|
||||
b["desktop"]["data"].update(
|
||||
{{"manager", {{"id", "manager:one"}}},
|
||||
{"team", {{"id", "club:one"}}},
|
||||
{"accounts",
|
||||
{{"cash", {{"minor", "0"}, {"currency", "EUR"}, {"minorUnits", 2}}}}}});
|
||||
b["camps"]["data"]["camps"] = Json::array();
|
||||
auto &d = b["settings"]["data"];
|
||||
d.update({{"cells", Json::array()},
|
||||
{"automation", Json::array()},
|
||||
{"formations",
|
||||
Json::array({{{"value", 2}, {"label", "Synthetic slot 2"}},
|
||||
{{"value", 6}, {"label", "Synthetic slot 6"}}})},
|
||||
{"formation", 2}});
|
||||
for (int i = 0; i < 180; ++i)
|
||||
d["cells"].push_back(
|
||||
{{"code", std::string(1, char('A' + i / 9)) + char('1' + i % 9)},
|
||||
{"raw", 0},
|
||||
{"displayRaw", 0},
|
||||
{"value", i % 9 < 7 ? 1 : 0},
|
||||
{"editable", true},
|
||||
{"min", 0},
|
||||
{"max", i % 9 < 7 ? 1
|
||||
: i % 9 == 7 ? 9
|
||||
: 99},
|
||||
{"step", 1},
|
||||
{"reason", ""}});
|
||||
d["cells"][0].update(
|
||||
{{"raw", 128}, {"displayRaw", 128}, {"value", 1}, {"editable", false}});
|
||||
d["cells"][1].update(
|
||||
{{"raw", 2}, {"displayRaw", 2}, {"value", nullptr}, {"editable", false}});
|
||||
d["cells"][8].update({{"raw", 131}, {"value", 65}});
|
||||
for (auto *key :
|
||||
{"lineup", "substitutions", "tactics", "marking", "training"})
|
||||
d["automation"].push_back(
|
||||
{{"id", key}, {"raw", 0}, {"enabled", false}, {"editable", true}});
|
||||
const auto original = b;
|
||||
const auto p = engine_settings_projection(b);
|
||||
check(b == original && p.at("local").at("cells")[1].is_null() &&
|
||||
p.at("local").at("cells")[0] == 1 &&
|
||||
p.at("local").at("cells")[8] == 65,
|
||||
"raw flags became booleans or odd source number lost");
|
||||
auto draft = p.at("local");
|
||||
draft["cells"][2] = 0;
|
||||
draft["cells"][8] = 66;
|
||||
draft["formation"] = 6;
|
||||
for (auto &[key, v] : draft["automation"].items())
|
||||
v = true;
|
||||
auto command = engine_settings_command(b, draft, "request:test");
|
||||
check(command["expectedRevision"] == "8" &&
|
||||
command["payload"]["edits"].size() == 2 &&
|
||||
command["payload"]["automation"].size() == 5 &&
|
||||
command["payload"]["edits"][1]["value"] == 66,
|
||||
"sparse edits scaled or lost");
|
||||
bool explicit_slot = false;
|
||||
for (const auto &a : command["payload"]["automation"])
|
||||
if (a["id"] == "lineup")
|
||||
explicit_slot = a["formation"] == 6;
|
||||
check(explicit_slot, "automatic lineup lacks explicit available slot");
|
||||
auto noop = engine_settings_command(b, p.at("local"), "request:noop");
|
||||
check(noop["payload"]["edits"].empty() &&
|
||||
noop["payload"]["automation"].empty(),
|
||||
"unchanged settings generated edits");
|
||||
auto bad = draft;
|
||||
bad["cells"][0] = 0;
|
||||
rejects([&] { engine_settings_command(b, bad, "request:x"); });
|
||||
bad = draft;
|
||||
bad["cells"][2] = 2;
|
||||
rejects([&] { engine_settings_command(b, bad, "request:x"); });
|
||||
bad = draft;
|
||||
bad["formation"] = 3;
|
||||
rejects([&] { engine_settings_command(b, bad, "request:x"); });
|
||||
auto foreign = b;
|
||||
foreign["settings"]["meta"]["stateRevision"] = "9";
|
||||
rejects([&] { engine_settings_projection(foreign); });
|
||||
foreign = b;
|
||||
foreign["settings"]["data"]["cells"][1]["code"] = "A1";
|
||||
rejects([&] { engine_settings_projection(foreign); });
|
||||
foreign = b;
|
||||
foreign["settings"]["data"]["automation"][4]["editable"] = false;
|
||||
rejects([&] { engine_settings_command(foreign, draft, "request:x"); });
|
||||
std::cout << "settings raw flags, parity display, sparse edits, explicit "
|
||||
"slots, owner and readonly checks passed\n";
|
||||
return 0;
|
||||
} catch (const std::exception &e) {
|
||||
std::cerr << e.what() << '\n';
|
||||
return 1;
|
||||
}
|
||||
Reference in new issue
Block a user