Bind environment and advertising to confirmed engine actions (by Codex)
This commit is contained in:
1 parent
dcf42f2da7
commit
e9483048f4
19 files changed
+395
-23
No files matched your search
@@ -4,11 +4,12 @@
|
||||
#include "modern/app/modern_session.hpp"
|
||||
#include "modern/content/world_package.hpp"
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
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" && std::string(argv[1]) != "verify-lineup" && std::string(argv[1]) != "verify-sports" && std::string(argv[1]) != "verify-bank")) throw std::runtime_error("usage: modern_engine_bridge_probe prepare|verify|verify-lineup|verify-sports|verify-bank <world.obw> <new-output-directory>");
|
||||
if (argc != 4 || (std::string(argv[1]) != "inspect" && 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")) throw std::runtime_error("usage: modern_engine_bridge_probe inspect|prepare|verify|verify-lineup|verify-sports|verify-bank|verify-commerce <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") {
|
||||
@@ -115,6 +116,33 @@ int main(int argc, char **argv) {
|
||||
link = EngineBridge::open(world,out / "bank.obs"); const auto loaded = link->snapshot(); write("bank-loaded.json",loaded);
|
||||
for (const auto *kind : {"bank","credit","stadium"}) if (loaded.at(kind).at("data") != after.at(kind).at("data")) throw std::runtime_error("finance lost during OBS round trip");
|
||||
}
|
||||
|
||||
if (std::string(argv[1]) == "verify-commerce") {
|
||||
const auto run = [&](const Json &request, const std::string &name) {
|
||||
const auto response=link->command(request);write((name+"-response.json").c_str(),response);
|
||||
if(response.value("messageType","")!="command_result" || link->command(request)!=response)throw std::runtime_error(response.dump());
|
||||
};
|
||||
run(engine_environment_command(before,"environment:doctor",3,"request:environment"),"environment");
|
||||
const auto env=link->snapshot();write("environment-after.json",env);
|
||||
if(env.at("desktop").at("data").at("accounts")!=before.at("desktop").at("data").at("accounts"))throw std::runtime_error("monthly environment budget debited immediately");
|
||||
for(int slot:{0,14,15}) {
|
||||
const auto now=link->snapshot(),view=engine_advertising_projection(now);
|
||||
const auto &choices=view.at("slots")[size_t(slot)].at("choices");
|
||||
auto chosen=std::find_if(choices.begin(),choices.end(),[](const auto &q){return q.at("can_accept")==true;});
|
||||
if(chosen==choices.end())throw std::runtime_error("no test advertising offer");
|
||||
run(engine_advertising_command(now,chosen->at("offer_id"),"request:ad-"+std::to_string(slot)),"ad-"+std::to_string(slot));
|
||||
}
|
||||
for(const auto *id:{"budget:press","budget:fans","budget:merchandise"}) {
|
||||
run(engine_budget_command(link->snapshot(),id,1000,std::string("request:")+id),std::string(id).substr(7));
|
||||
}
|
||||
const auto after=link->snapshot();write("commerce-after.json",after);
|
||||
auto stale=engine_environment_command(before,"environment:doctor",4,"request:commerce-stale");
|
||||
const auto rejected=link->command(stale);write("stale-rejected.json",rejected);
|
||||
if(rejected.value("code","")!="stale_revision" || link->snapshot()!=after)throw std::runtime_error("stale commerce command mutated state");
|
||||
write("commerce-saved.json",link->save_copy(out/"commerce.obs"));link.reset();link=EngineBridge::open(world,out/"commerce.obs");
|
||||
const auto loaded=link->snapshot();write("commerce-loaded.json",loaded);
|
||||
for(const auto *kind:{"environment","advertising","bank"})if(loaded.at(kind).at("data")!=after.at(kind).at("data"))throw std::runtime_error("commerce OBS round trip lost state");
|
||||
}
|
||||
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