Render typed bilingual news and preserve historical journal scope (by Codex)

This commit is contained in:
Codex authored and Codex committed 2026-10-27 05:46:07 +01:00
1 parent 1eb5e99847
commit 950d79d529
16 files changed
+6858 -81

No files matched your search

+169 -4
View File
@@ -2,10 +2,13 @@
#include "modern/ui/demo_news.hpp"
#include "modern/ui/desktop.hpp"
#include "modern/ui/model.hpp"
#include "modern/ui/news_catalog.hpp"
#include "modern/ui/news_journal.hpp"
#include <chrono>
#include <iostream>
#include <set>
#include <stdexcept>
#include <tuple>
using namespace bmh::modern_ui;
namespace {
void require(bool yes, const char *why) {
@@ -89,12 +92,55 @@ void provider(Fixture &f) {
"Current manager and club not interpolated");
auto changed = s;
changed["managers"][0] = {{"name", "Other Manager"}, {"club", "club:news-1"}};
require(demo_news_view(*f.world, changed).at("items").empty() &&
demo_news_unread(changed) == 0,
"Other manager's club must not inherit or rename old club articles");
changed = s;
changed["managers"][0]["name"] = "Renamed Manager";
require(demo_news_view(*f.world, changed)
.at("items")[0]
.at("body")
.get<std::string>()
.find("Other Manager. Synthetic Club 1") != std::string::npos,
"Manager change retained stale template identity");
.find("Synthetic Manager. Synthetic Club 0") !=
std::string::npos,
"Historical owner text must never be rewritten by the current name");
auto national = s;
national["career"] = {{"role", "national"}, {"surface", "outdoor"}};
require(demo_news_view(*f.world, national).at("items").empty() &&
demo_news_unread(national) == 0 &&
demo_news_view(*f.world, national).at("club_name") ==
"Deutschland",
"National header must never expose club financial stories");
reject(national, {{"kind", "read"}, {"id", "season"}}, *f.world);
const auto national_before = national;
require(edit_demo_news(national, {{"kind", "read-all"}, {"folder", "inbox"}},
*f.world)
.empty() &&
national == national_before,
"National read-all must not alter hidden club rows");
auto legacy = s;
Json raw = Json::array();
for (const auto &item : s.at("news").at("items")) {
auto row = item;
row.erase("scope");
row.erase("owner");
raw.push_back(row);
}
raw[0]["body"] = "Hallo {{manager}}. {{club}}.";
legacy["news"] = {{"version", 1}, {"items", raw}};
const auto legacy_before = legacy;
require(demo_news_view(*f.world, legacy).at("items").empty() &&
legacy == legacy_before,
"Reading unbound v1 cannot guess owner or mutate state");
require(
migrate_demo_news(legacy, *f.world) &&
legacy.at("news").at("items").empty() &&
legacy.at("news").at("unbound") == raw &&
demo_news_view(*f.world, legacy).at("unbound_count") == 12,
"Ownerless old article facts remain intact in separate unbound storage");
const auto migrated = legacy;
require(migrate_demo_news(legacy, *f.world) && legacy == migrated,
"Conservative migration is idempotent");
require(demo_news_view(*f.world, s, "inbox", "FINANZEN").at("items").size() ==
2 &&
demo_news_view(*f.world, s, "inbox", "VERTRAGSGESPRÄCHE")
@@ -196,7 +242,7 @@ void provider(Fixture &f) {
invalid["news"]["query"] = "must-be-local";
bad.push_back(invalid);
invalid = initial;
for (int i = 12; i < 101; ++i) {
for (int i = 12; i < 501; ++i) {
auto m = invalid["news"]["items"][0];
m["id"] = "test-" + std::to_string(i);
invalid["news"]["items"].push_back(m);
@@ -289,12 +335,131 @@ void source(Fixture &f) {
base.erase("news");
require(rest == base, "Mailbox actions modified unrelated presentation data");
}
void accepted_start_identity(Fixture &f) {
DemoSource source(f.world);
Json options = {{"duration", 5}, {"difficulty", 3}, {"players", 1},
{"mode", 3}, {"league", true}, {"world", true}};
Json managers = Json::array({{{"name", "FreshCoach"},
{"club", "club:news-1"},
{"portrait", 4},
{"portrait_style", "painted"},
{"strength_choice", 1}}});
require(source
.apply({source.snapshot().revision,
"start",
{{"setup", options}, {"managers", managers}}})
.ok,
"Actual accepted new career start");
const auto original = source.snapshot().state.at("news");
require(original.at("items").size() == 12,
"Known club demo starts with existing journal fixtures");
for (const auto &row : original.at("items"))
require(row.at("scope").at("id") == "club:news-1" &&
row.at("owner").at("name") == "FreshCoach" &&
row.at("owner").at("id") == "portrait:4",
"New start freezes accepted person and nondefault club, never "
"fresh defaults");
require(original.at("items")[0].at("body").get<std::string>().find(
"FreshCoach. Synthetic Club 1") != std::string::npos,
"Actual start story uses confirmed identity");
managers[0]["name"] = "LaterName";
managers.push_back({{"name", "OtherCoach"},
{"club", "club:news-0"},
{"portrait", 1},
{"portrait_style", "photo"},
{"strength_choice", 1}});
require(source.apply({source.snapshot().revision, "managers", managers}).ok &&
source.snapshot().state.at("news") == original,
"Join/name updates cannot rewrite historical journal");
require(source.apply({source.snapshot().revision,
"career",
{{"kind", "role"}, {"value", "national"}}})
.ok &&
source.snapshot().state.at("news") == original &&
demo_news_unread(source.snapshot().state) == 0,
"Role change retains facts but hides club journal");
options["league"] = false;
managers = Json::array({managers[0]});
require(source.apply({source.snapshot().revision,
"start",
{{"setup", options}, {"managers", managers}}})
.ok &&
source.snapshot().state.at("news").at("items").empty(),
"National-only new start must not receive fresh club stories");
}
void write_fixtures(Fixture &f, const fs::path &out,
const fs::path &catalogue_path) {
fs::create_directories(out);
fs::copy(f.root / "world", out / "world",
fs::copy_options::recursive | fs::copy_options::overwrite_existing);
fs::copy_file(f.root / "manifest.json", out / "manifest.json",
fs::copy_options::overwrite_existing);
DemoSource source(f.world);
auto managers = source.snapshot().state.at("managers");
managers.push_back({{"name", "Mara König"},
{"club", "club:news-1"},
{"portrait", 1},
{"portrait_style", "painted"},
{"strength_choice", 1}});
require(source.apply({source.snapshot().revision, "managers", managers}).ok,
"Two-owner native scope fixture");
auto data = source.snapshot().state;
data["desktop"] = default_desktop();
const auto original = data;
const auto catalog = NewsCatalog::load(catalogue_path);
for (const auto &[template_id, scope, id] :
std::vector<std::tuple<std::string, Json, std::string>>{
{"injury-recovered",
{{"kind", "club"},
{"id", "club:news-0"},
{"name", "Synthetic Club 0"}},
"native:press:own"},
{"sponsor-signed",
{{"kind", "club"},
{"id", "club:news-1"},
{"name", "Synthetic Club 1"}},
"native:press:other"},
{"national-squad",
{{"kind", "national"},
{"id", "national-de"},
{"name", "Deutschland"},
{"names", {{"de", "Deutschland"}, {"en", "Germany"}}}},
"native:press:national"}}) {
const auto example = catalog.example(
template_id, {{"scope", scope}, {"date", data.at("date")}, {"id", id}});
require(example.value("ok", false),
"Explicit native catalogue demo fixture");
const auto built = catalog.from_event(example.at("event"));
require(built.value("ok", false), "Typed catalogue demo renders");
require(publish_news_article(data["news"], catalog, built.at("article"))
.value("ok", false),
"Demo fixture publication");
}
require(source.load_data(data) == default_desktop(), "Native fixture layout");
source.save(out / "scoped.json", default_desktop());
auto legacy = original;
legacy["news"] = {
{"version", 1},
{"items", Json::array({{{"id", "legacy-unknown"},
{"date", legacy.at("date")},
{"kind", "finance"},
{"title", "Altbestand {{club}}"},
{"body", "Unveränderte Meldung für {{manager}}. "
"Historischer Besitzer unbekannt."},
{"read", false},
{"folder", "inbox"}}})}};
// This intentionally old input is consumed by the normal native load path.
bmh::editor::write_atomic(out / "legacy.json", legacy.dump(2));
}
} // namespace
int main() {
int main(int argc, char **argv) {
try {
Fixture f;
provider(f);
source(f);
accepted_start_identity(f);
if (argc == 4 && std::string(argv[1]) == "--write-fixtures")
write_fixtures(f, argv[2], argv[3]);
std::cout << "modern news UI tests passed\n";
return 0;
} catch (const std::exception &e) {