Bind native desk and training camps to Modern OBS careers (by Codex)

This commit is contained in:
Codex committed 2026-10-27 22:00:10 +01:00
1 parent 1fb6499b15
commit 85a1fe5a95
19 files changed
+733 -46

No files matched your search

+44
View File
@@ -0,0 +1,44 @@
// SPDX-License-Identifier: GPL-3.0-only
// Opt-in private-data probe. Never registered as an unconditional CTest.
#include "modern/ui/engine_bridge.hpp"
#include "modern/app/modern_session.hpp"
#include "modern/content/world_package.hpp"
#include <iostream>
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>");
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") {
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;
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) || !session.finish(result, error) ||
!session.save_game(out / "input.obs", 0, false, error)) throw std::runtime_error(error);
modern::set_current_world(nullptr);
}
auto link = EngineBridge::open(world, out / "input.obs");
const auto before = link->snapshot(); write("before.json", before);
if (before != link->snapshot()) throw std::runtime_error("reads changed the engine projection");
if (std::string(argv[1]) == "verify") {
auto camp = before.at("camps").at("data").at("camps").front();
const auto command = engine_camp_command(before, camp.at("id"), {{"condition", 3}, {"technique", 4}, {"play", 5}}, "request:probe-book");
const auto response = link->command(command); write("command.json", command); write("response.json", response);
if (response.value("messageType", "") != "command_result") throw std::runtime_error(response.dump());
if (link->command(command) != response) throw std::runtime_error("identical request was not idempotent");
const auto after = link->snapshot(); write("after.json", after);
if (!after.at("camps").at("data").at("bookedThisWeek").get<bool>()) throw std::runtime_error("camp not booked");
const auto delta = engine_money_minor(before.at("desktop").at("data").at("accounts").at("cash")) - engine_money_minor(after.at("desktop").at("data").at("accounts").at("cash"));
if (delta != engine_money_minor(camp.at("quote").at("total"))) throw std::runtime_error("wrong actual booking cost");
write("saved.json", link->save_copy(out / "booked.obs")); link.reset();
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");
}
std::cout << "engine bridge " << argv[1] << " passed\n"; return 0;
} catch (const std::exception &e) { std::cerr << e.what() << '\n'; return 1; }
}
+57
View File
@@ -0,0 +1,57 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "modern/ui/engine_bridge.hpp"
#include <iostream>
#include <limits>
#include <stdexcept>
using namespace bmh::modern_ui;
namespace {
void require(bool v, const char *why) { if (!v) throw std::runtime_error(why); }
template<class F> void rejects(F f) { bool rejected = false; try { f(); } catch (const std::exception &) { rejected = true; } require(rejected, "invalid DTO accepted"); }
Json fixture() {
const Json meta = {{"contractVersion", "bmh-modern-ui@draft1"}, {"careerId", "career:synthetic"},
{"worldId", "world:synthetic"}, {"worldRevision", "1"}, {"stateRevision", "18446744073709551615"},
{"scope", {{"role", "club"}, {"managerId", "manager:99"}, {"teamId", "club:6"}, {"scopeId", "scope:test"}, {"allowedCommands", {"camp.book"}}}}};
Json out;
for (const auto *kind : {"session", "desktop", "camps"}) out[kind] = {{"messageType", "snapshot"}, {"meta", meta}, {"data", {{"kind", kind}}}};
out["desktop"]["data"].update({{"manager", {{"id", "manager:99"}}}, {"team", {{"id", "club:6"}}},
{"accounts", {{"cash", {{"minor", "9007199254740993"}, {"currency", "EUR"}, {"minorUnits", 2}}}}}});
out["camps"]["data"]["camps"] = Json::array({{{"id", "resort:16"}, {"quote", {{"allowed", true}, {"expectedRevision", meta.at("stateRevision")},
{"ownerManagerId", "manager:99"}, {"teamId", "club:6"}, {"scopeId", "scope:test"},
{"total", {{"minor", "123400"}, {"currency", "EUR"}, {"minorUnits", 2}}}}}}});
return out;
}
}
int main() {
try {
const auto bundle = fixture(), original = bundle;
validate_engine_desk(bundle);
require(engine_money_minor(bundle.at("desktop").at("data").at("accounts").at("cash")) == 9007199254740993LL, "money rounded through double");
const auto focus = Json{{"condition", 0}, {"technique", 15}, {"play", 5}};
const auto command = engine_camp_command(bundle, "resort:16", focus, "request:stable");
require(command.at("owner").at("managerId") == "manager:99" && command.at("expectedRevision") == "18446744073709551615" &&
command.at("payload").at("focus") == focus && bundle == original, "command lost authoritative identity/revision or changed snapshot");
for (const auto &v : Json::array({Json{{"minor", "9223372036854775808"}, {"currency", "EUR"}, {"minorUnits", 2}},
Json{{"minor", "10.25"}, {"currency", "EUR"}, {"minorUnits", 2}},
Json{{"minor", "1000"}, {"currency", "GBP"}, {"minorUnits", 2}}}))
rejects([&] { engine_money_minor(v); });
for (int fault = 0; fault < 10; ++fault) {
auto bad = bundle;
if (fault == 0) bad["camps"]["meta"]["stateRevision"] = "2";
if (fault == 1) bad["session"]["meta"]["careerId"] = "career:other";
if (fault == 2) bad["desktop"]["data"]["manager"]["id"] = "manager:portrait-0";
if (fault == 3) bad["camps"]["data"]["camps"][0]["quote"]["ownerManagerId"] = "manager:1";
if (fault == 4) bad["camps"]["data"]["camps"][0]["quote"]["expectedRevision"] = "2";
if (fault == 5) bad["camps"]["data"]["camps"][0]["quote"]["allowed"] = false;
if (fault == 6) bad["camps"]["data"]["camps"][0]["quote"] = nullptr;
if (fault == 7) for (auto &item : bad) item["meta"]["scope"]["role"] = "national";
if (fault == 8) bad["camps"]["data"]["camps"].push_back(bad["camps"]["data"]["camps"][0]);
if (fault == 9) for (auto &item : bad) item["meta"]["stateRevision"] = "18446744073709551616";
rejects([&] { engine_camp_command(bad, "resort:16", focus, "request:stable"); });
}
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"); });
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; }
}