- Live ticker: the paused live state carries both starting elevens; the ticker lists them until the first report. A single match no longer gets an empty strip above the score, repeated status lines are gone, whistles carry no club badge, dates are written out. - Desk: "Die letzten Spiele" and the table place curve are fed by the engine (desktop-widgets read: recent, rankCurve) and belong to the default layout; the own crest widget is bound. - News: the German press templates are rewritten to one plain sentence each (the catalogue accepts a single sentence now); the reference snapshots follow, and the catalogue test can rewrite them with --update. Mailbox texts show world spellings of clubs and players and the euro sign. - Small type raised in advertising, lineup, news, toto, transfer and others; the transfer market column no longer runs under its scrollbar. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
248 lines
11 KiB
C++
248 lines
11 KiB
C++
// SPDX-License-Identifier: GPL-3.0-only
|
|
#include "modern/ui/news_catalog.hpp"
|
|
#include "modern/ui/news_journal.hpp"
|
|
#include <iostream>
|
|
#include <stdexcept>
|
|
#include <tuple>
|
|
#include <type_traits>
|
|
|
|
using namespace bmh::modern_ui;
|
|
namespace {
|
|
void require(bool yes, const std::string &message) {
|
|
if (!yes)
|
|
throw std::runtime_error(message);
|
|
}
|
|
void no(const Json &value, const std::string &code) {
|
|
require(!value.value("ok", false) && value.at("error").at("code") == code,
|
|
"Expected explicit " + code + ": " + value.dump());
|
|
}
|
|
} // namespace
|
|
int main(int argc, char **argv) {
|
|
try {
|
|
// a fourth argument "--update" rewrites the expected snapshots after a deliberate
|
|
// change of the catalogue's wording
|
|
const bool update = argc == 4 && std::string(argv[3]) == "--update";
|
|
require(argc == 3 || update, "Catalogue and synthetic reference paths required");
|
|
const auto catalog = NewsCatalog::load(argv[1]);
|
|
auto reference = Json::parse(bmh::editor::read_file(argv[2]));
|
|
if (update) {
|
|
for (auto &test : reference.at("cases"))
|
|
test["result"] = catalog.from_event(test.at("event"), test.at("context"));
|
|
bmh::editor::write_atomic(argv[2], reference.dump());
|
|
std::cout << "reference updated\n";
|
|
return 0;
|
|
}
|
|
require(catalog.registry().size() == 113,
|
|
"113 own authored templates registered");
|
|
size_t passed = 0, mismatches = 0;
|
|
for (const auto &test : reference.at("cases")) {
|
|
const auto result =
|
|
catalog.from_event(test.at("event"), test.at("context"));
|
|
if (news_canonical(result) != news_canonical(test.at("result"))) {
|
|
++mismatches;
|
|
if (mismatches <= 4)
|
|
std::cerr << "Parity mismatch: " << test.at("name")
|
|
<< "\nActual: " << result.dump()
|
|
<< "\nExpected: " << test.at("result").dump() << '\n';
|
|
if (mismatches > 4)
|
|
std::cerr << "Additional mismatch " << test.at("name") << " actual "
|
|
<< result.value("article", Json::object())
|
|
.value("translations", Json())
|
|
<< "\n";
|
|
continue;
|
|
}
|
|
require(catalog.validate_article(result.at("article")).value("ok", false),
|
|
"Persisted bilingual snapshot validates");
|
|
++passed;
|
|
}
|
|
require(mismatches == 0, "Own HTML/native semantic contract mismatches: " +
|
|
std::to_string(mismatches));
|
|
for (const auto &t : catalog.registry()) {
|
|
auto fixture = catalog.example(t.at("id"));
|
|
require(fixture.value("ok", false),
|
|
"Explicit example available " + t.at("id").get<std::string>());
|
|
require(catalog.from_event(fixture.at("event")).value("ok", false),
|
|
"Explicit demo event validates " + t.at("id").get<std::string>());
|
|
for (const auto &[key, schema] : t.at("parameters").items()) {
|
|
auto absent = fixture.at("event");
|
|
if (schema.value("source", "") == "scope")
|
|
absent.erase("scope");
|
|
else
|
|
absent["data"].erase(key);
|
|
require(!catalog.from_event(absent).value("ok", false),
|
|
"Missing required field cannot invent facts: " + key);
|
|
auto bad = fixture.at("event");
|
|
if (schema.value("source", "") == "scope")
|
|
bad["scope"]["kind"] = "unknown";
|
|
else
|
|
bad["data"][key] = Json::array({"invalid"});
|
|
require(!catalog.from_event(bad).value("ok", false),
|
|
"Typed registry rejects malformed data: " + key);
|
|
}
|
|
}
|
|
auto event = catalog.example("transfer-signed").at("event");
|
|
const auto raw_event = event;
|
|
event["data"]["player"]["name"] = "Zoë Özdemir <img src=x> {{club}}";
|
|
const auto de = catalog.from_event(event),
|
|
en = catalog.from_event(event, {{"language", "en"}});
|
|
require(de.at("article").at("id") == en.at("article").at("id") &&
|
|
de.at("article").at("fingerprint") ==
|
|
en.at("article").at("fingerprint"),
|
|
"Locale cannot change occurrence identity");
|
|
require(de.at("article").at("body").get<std::string>().find(
|
|
"<img src=x> {{club}}") != std::string::npos,
|
|
"Payload is literal text, never markup or a second template");
|
|
auto detached = de.at("article");
|
|
event["data"]["player"]["name"] = "Renamed";
|
|
require(detached.at("body").get<std::string>().find("Zoë Özdemir") !=
|
|
std::string::npos,
|
|
"Article owns immutable original facts");
|
|
event = raw_event;
|
|
event["type"] = "unknown";
|
|
no(catalog.from_event(event), "unknown_news_event");
|
|
event = raw_event;
|
|
event["data"]["unknown"] = 1;
|
|
no(catalog.from_event(event), "unknown_news_parameter");
|
|
event = raw_event;
|
|
event["scope"]["kind"] = "national";
|
|
no(catalog.from_event(event), "unsupported_news_scope");
|
|
no(catalog.from_event(raw_event, {{"language", "xx"}}),
|
|
"invalid_news_context");
|
|
no(catalog.from_event(raw_event, {{"asOf", "2027-01-01"}}),
|
|
"future_news_event");
|
|
auto result = catalog.example("match-win").at("event");
|
|
result["data"]["score"] = {{"for", 0}, {"against", 2}};
|
|
no(catalog.from_event(result), "inconsistent_news_event");
|
|
event = raw_event;
|
|
event["data"]["fee"] = {
|
|
{"minor", "100"}, {"currency", "EUR"}, {"minorUnits", 0}};
|
|
no(catalog.from_event(event), "invalid_news_parameter");
|
|
event = raw_event;
|
|
event["data"]["player"]["name"] = std::string("bad\xc0\xaf");
|
|
no(catalog.from_event(event), "invalid_news_parameter");
|
|
for (const auto *id : {"transfer-fee-undisclosed", "sale-fee-undisclosed",
|
|
"contract-basic", "loan-end-undisclosed"}) {
|
|
event = catalog.example(id).at("event");
|
|
event.erase("variant");
|
|
const auto minimal = catalog.from_event(event);
|
|
require(minimal.value("ok", false) &&
|
|
minimal.at("article").at("templateId") == id,
|
|
"Absent fee/wage/end uses only known facts");
|
|
}
|
|
std::string error;
|
|
for (const auto &[precision, minor, expected] :
|
|
std::vector<std::tuple<int, std::string, int64_t>>{{0, "12", 1200},
|
|
{1, "12", 120},
|
|
{2, "12", 12},
|
|
{3, "120", 12},
|
|
{4, "1200", 12}}) {
|
|
auto money = news_money_from_dto(
|
|
{{"minor", minor}, {"currency", "EUR"}, {"minorUnits", precision}},
|
|
error);
|
|
require(money && money->minor == expected && error.empty(),
|
|
"Explicit exact DTO scaling");
|
|
}
|
|
for (const auto &value : Json::array(
|
|
{Json{{"minor", "125"}, {"currency", "EUR"}, {"minorUnits", 3}},
|
|
Json{{"minor", "-12"}, {"currency", "EUR"}, {"minorUnits", 2}},
|
|
Json{{"minor", "12"}, {"currency", "JPY"}, {"minorUnits", 0}},
|
|
Json{{"minor", "900000000000001"},
|
|
{"currency", "EUR"},
|
|
{"minorUnits", 2}},
|
|
Json{{"minor", 12}, {"currency", "EUR"}, {"minorUnits", 2}},
|
|
Json{{"minor", "12"}, {"currency", "EUR"}},
|
|
Json{{"minor", "0012"}, {"currency", "EUR"}, {"minorUnits", 2}}}))
|
|
require(!news_money_from_dto(value, error) && !error.empty(),
|
|
"Unknown/inexact/negative DTO units never silently convert");
|
|
static_assert(!std::is_convertible_v<int64_t, NewsMinorMoney>);
|
|
NewsEvent typed;
|
|
typed.id = "typed:arrival";
|
|
typed.type = "transfer.signed";
|
|
typed.date = "2027-07-07";
|
|
typed.scope = {NewsScopeKind::club, {"club:typed", "FC Typed", {}}};
|
|
typed.data = raw_event.at("data");
|
|
require(catalog.from_event(typed).value("ok", false),
|
|
"Typed semantic event API");
|
|
typed.scope.kind = static_cast<NewsScopeKind>(99);
|
|
no(catalog.from_event(typed), "invalid_news_event");
|
|
for (int bad_case = 0; bad_case < 4; ++bad_case) {
|
|
auto broken = catalog.data();
|
|
if (bad_case == 0)
|
|
broken["templates"][0]["parameters"]["score"]["type"] = "guessed";
|
|
if (bad_case == 1)
|
|
broken["templates"][0]["guards"] = Json::array({"unknown_rule"});
|
|
if (bad_case == 2)
|
|
broken["templates"][0]["de"]["headline"] = "{{undeclared}}";
|
|
if (bad_case == 3)
|
|
broken["templates"][1]["id"] = broken["templates"][0]["id"];
|
|
bool rejected = false;
|
|
try {
|
|
NewsCatalog invalid(broken);
|
|
} catch (...) {
|
|
rejected = true;
|
|
}
|
|
require(rejected, "Malformed typed registry rejected before rendering");
|
|
}
|
|
auto journal = empty_news_journal();
|
|
const auto article = catalog.from_event(raw_event).at("article");
|
|
const auto posted = publish_news_article(journal, catalog, article);
|
|
require(posted.value("ok", false) && !posted.at("deduped").get<bool>() &&
|
|
valid_news_journal(journal),
|
|
"Validated explicit publication");
|
|
const auto initial = journal;
|
|
require(
|
|
publish_news_article(
|
|
journal, catalog,
|
|
catalog.from_event(raw_event, {{"language", "en"}}).at("article"))
|
|
.at("deduped") == true &&
|
|
journal == initial,
|
|
"Locale replay cannot rewrite stored bilingual snapshot or create a "
|
|
"row");
|
|
require(publish_news_article(journal, catalog, article).at("deduped") ==
|
|
true &&
|
|
journal == initial,
|
|
"Replay is a write-free dedupe read");
|
|
journal["items"][0]["folder"] = "trash";
|
|
const auto deleted = journal;
|
|
auto restored = Json::parse(journal.dump());
|
|
require(publish_news_article(restored, catalog, article).at("deduped") ==
|
|
true &&
|
|
restored == deleted,
|
|
"Persisted deletion ledger survives reload and suppresses replay");
|
|
require(publish_news_article(journal, catalog, article).at("deduped") ==
|
|
true &&
|
|
journal == deleted,
|
|
"Delete/replay cannot resurrect or duplicate");
|
|
auto conflict = raw_event;
|
|
conflict["data"]["fee"]["minor"] = 1;
|
|
no(publish_news_article(journal, catalog,
|
|
catalog.from_event(conflict).at("article")),
|
|
"news_event_id_conflict");
|
|
require(journal == deleted, "Conflict has no partial publication");
|
|
require(!news_row_visible(initial.at("items")[0],
|
|
{{"kind", "national"}, {"id", "national-de"}}) &&
|
|
!news_row_visible(initial.at("items")[0],
|
|
{{"kind", "club"}, {"id", "other"}}),
|
|
"National/other club cannot see historical club finance/personnel");
|
|
require(news_row_text(initial.at("items")[0], "en").at("body") ==
|
|
article.at("translations").at("en").at("body"),
|
|
"Both immutable language snapshots are directly projected");
|
|
auto changed = catalog.data();
|
|
for (auto &t : changed["templates"])
|
|
if (t.at("id") == detached.at("templateId"))
|
|
t["de"]["headline"] = "Neue Formulierung";
|
|
NewsCatalog newer(changed);
|
|
require(newer.validate_article(detached).value("ok", false) &&
|
|
newer.validate_article(detached).at("article").at("headline") ==
|
|
detached.at("headline"),
|
|
"Wording edits never rewrite archived snapshots");
|
|
std::cout
|
|
<< "native press renderer: " << passed
|
|
<< " full parity cases plus registry/types/money/scope/dedupe passed\n";
|
|
return 0;
|
|
} catch (const std::exception &e) {
|
|
std::cerr << e.what() << '\n';
|
|
return 1;
|
|
}
|
|
}
|