From 2c4b9d2595f2c8138e9bc3a8e0a9275f7f5b740f Mon Sep 17 00:00:00 2001 From: Codex Date: Tue, 27 Oct 2026 08:12:43 +0100 Subject: [PATCH] Project completed demo live recordings into read-only match reviews (by Codex) --- docs/new_ui/desktop/post-match/PROVIDER.md | 101 ++++++++++++ src/modern/ui/CMakeLists.txt | 4 +- src/modern/ui/demo_post_match.cpp | 151 +++++++++++++++++ src/modern/ui/demo_post_match.hpp | 16 ++ src/modern/ui/model.cpp | 7 + src/modern/ui/model.hpp | 6 + tests/modern_post_match_ui_tests.cpp | 181 +++++++++++++++++++++ 7 files changed, 464 insertions(+), 2 deletions(-) create mode 100644 docs/new_ui/desktop/post-match/PROVIDER.md create mode 100644 src/modern/ui/demo_post_match.cpp create mode 100644 src/modern/ui/demo_post_match.hpp create mode 100644 tests/modern_post_match_ui_tests.cpp diff --git a/docs/new_ui/desktop/post-match/PROVIDER.md b/docs/new_ui/desktop/post-match/PROVIDER.md new file mode 100644 index 0000000..002e0c7 --- /dev/null +++ b/docs/new_ui/desktop/post-match/PROVIDER.md @@ -0,0 +1,101 @@ +# Native post-match provider (by Codex) + +The Modern UI can review its existing finite live recording through +`demo_post_match.hpp`. This is a read-only presentation component, not a match +engine, season driver or authoritative match report. + +`make_demo_post_match(fixture, completed_sequence)` accepts only a validated +`openbmh-live-fixture@1` with `source=ui-demo-fixture`, its last sequence, a +`finished` final phase and the recorded full duration. The explicit sequence +acknowledges that the UI has reached the end of that recording. It cannot prove +that an engine match finished. Existing nine-frame recordings, their outcomes, +event IDs and owner IDs are unchanged. + +The resulting `openbmh-post-match@1` review retains `fixture_id`, +`source_revision`, `completed_sequence`, world, date, role, surface, duration and +the original owner views. Match rows retain their original identities, teams, +owners and competition. Each adds: + +- `final`: the exact final recorded match snapshot, including score, chances, + yellow/red cards, player counts and declared standings; +- `events`: only that match's original events; +- `attendance: null`, `attendance_reason: "not_recorded"`. + +Club/outdoor review tabs are `results`, `report`, `eleven`, `overview`, `table`. +National/outdoor and club/indoor have only `results`, `report`, `overview`. +Durations remain 90/40 and active-player counts remain 11/6. National owners +retain the existing explicit POC club-roster basis; this does not create a +national selection or caps history. + +`overview` sums final goals, chances and cards over the **unique recorded human +matches**, never once per human manager. Its `scope=recorded_human_matches` +distinguishes it from a whole-league matchday. Additional league fixtures and +crowds are not present in this native recording. `tables` deduplicates equal +existing final standings snapshots and retains their rows unchanged. Wins, +draws and losses are unknown; no season-ranking formula is introduced here. +`eleven={available:false,reason:"not_recorded",rows:[]}` explicitly reports the +missing nominations instead of deriving match ratings from catalogue strength. + +For example, two recorded 2:1 matches shared by four human managers produce: + +```json +{ + "overview": { + "games": 2, "goals": 6, "chances": 28, "yellow": 2, "red": 0, + "attendance": null, "attendance_reason": "not_recorded", + "scope": "recorded_human_matches" + }, + "eleven": {"available": false, "reason": "not_recorded", "rows": []} +} +``` + +## Report seeking + +`query_demo_post_match(fixture, request)` takes that same retained live fixture, +not the review DTO. A report request is: + +```json +{ + "kind": "report", "completed_sequence": 8, + "fixture_id": "the-original-fixture-id", "revision": 1, + "match_id": "the-original-match-id", "minute": 61 +} +``` + +`completed_sequence` is required. Optional `fixture_id` and `revision` must +match the recording. A report's `match_id` defaults to the first original +match; `minute` defaults to full duration. Both are local presentation choices. +The report returns `home`, `away`, `match`, `final`, `final_score`, cursor +`minute`, `recorded_minute`, `sequence`, `phase`, `score`, `chances`, `yellow`, +`red`, `players`, `standings`, past `events` and complete `timeline`. + +Seeking picks the last existing frame at or before the cursor. In this +recording a seek to minute 61 therefore shows the recorded 46-minute 1:0; +minute 62 shows its recorded 1:1. No intermediate goal, assist, possession +percentage or ball time is calculated. Future timeline markers remain +available for the view to draw dimmed. Events retain their original fields; +they do not contain a known player actor. Report-level `actor`, `assists`, +`ratings` and `playing_minutes` are null. + +`kind="review"` returns the complete review and rejects report-only fields. +Malformed queries, incomplete sequences, stale revisions/fixture IDs, foreign +match IDs and out-of-range minutes produce explicit `ok:false,error` values. + +## Source boundary and ownership + +`DataSource::read_post_match` defaults to `post_match_unavailable`. A later +authoritative adapter must independently confirm its actual completed state. +`DemoSource` explicitly binds its read to the current fixture and requires both +`revision` and `fixture_id`; a changed source rejects a stale read. The view can +still review its retained immutable completed recording through the pure API, +without rebinding old facts to another current team/person. + +Reads never call `apply`, change revision/dirty state, create a match or save a +review into a career checkpoint. View-local tab, selected manager, match, +report minute and playback state must not modify the live recording cursor, +owner selection, intervention drafts or career owner. + +`modern_post_match_ui_tests` uses a synthetic catalogue to check unique matches, +exact final values, seek boundaries, 5/3 tabs, missing facts, stale/invalid +requests, retained identities and source/checkpoint immutability. Existing +`modern_live_ui_tests` remains unchanged. diff --git a/src/modern/ui/CMakeLists.txt b/src/modern/ui/CMakeLists.txt index 56a535d..63b7f07 100644 --- a/src/modern/ui/CMakeLists.txt +++ b/src/modern/ui/CMakeLists.txt @@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-3.0-only -add_library(bmh_modern_ui_core STATIC catalog.cpp model.cpp demo_career.cpp demo_national_ui.cpp gui_assets.cpp desktop.cpp demo_sports.cpp demo_calendar.cpp demo_reports.cpp demo_almanac.cpp demo_finance.cpp demo_environment.cpp demo_advertising.cpp demo_toto.cpp demo_lineup.cpp demo_live.cpp demo_transfer.cpp demo_career_reports.cpp demo_rankings.cpp demo_stadium.cpp demo_statistics.cpp demo_news.cpp news_catalog.cpp news_journal.cpp demo_settings.cpp ui_preferences.cpp demo_widgets.cpp demo_files.cpp demo_opening.cpp) +add_library(bmh_modern_ui_core STATIC catalog.cpp model.cpp demo_career.cpp demo_national_ui.cpp gui_assets.cpp desktop.cpp demo_sports.cpp demo_calendar.cpp demo_reports.cpp demo_almanac.cpp demo_finance.cpp demo_environment.cpp demo_advertising.cpp demo_toto.cpp demo_lineup.cpp demo_live.cpp demo_post_match.cpp demo_transfer.cpp demo_career_reports.cpp demo_rankings.cpp demo_stadium.cpp demo_statistics.cpp demo_news.cpp news_catalog.cpp news_journal.cpp demo_settings.cpp ui_preferences.cpp demo_widgets.cpp demo_files.cpp demo_opening.cpp) target_include_directories(bmh_modern_ui_core PUBLIC ../..) target_link_libraries(bmh_modern_ui_core PUBLIC bmh_asset_io) add_library(bmh_modern_ui_mods STATIC mod_library.cpp) @@ -124,7 +124,7 @@ foreach(component environment advertising toto lineup transfer stadium) add_test(NAME modern_${component}_ui_tests COMMAND modern_${component}_ui_tests) endforeach() -foreach(component statistics news settings desktop files entry opening career live national) +foreach(component statistics news settings desktop files entry opening career live national post_match) add_executable(modern_${component}_ui_tests ../../../tests/modern_${component}_ui_tests.cpp) target_link_libraries(modern_${component}_ui_tests PRIVATE bmh_modern_ui_core) if(MSVC) diff --git a/src/modern/ui/demo_post_match.cpp b/src/modern/ui/demo_post_match.cpp new file mode 100644 index 0000000..1978998 --- /dev/null +++ b/src/modern/ui/demo_post_match.cpp @@ -0,0 +1,151 @@ +// SPDX-License-Identifier: GPL-3.0-only +#include "modern/ui/demo_post_match.hpp" +#include "modern/ui/demo_live.hpp" +#include +#include + +namespace bmh::modern_ui { +namespace { +Json failure(const char *error) { return {{"ok", false}, {"error", error}}; } +bool unsigned_value(const Json &v, uint64_t maximum) { + return (v.is_number_unsigned() && v.get() <= maximum) || + (v.is_number_integer() && v.get() >= 0 && + uint64_t(v.get()) <= maximum); +} +Json provenance(const Json &fixture) { + return {{"ok", true}, {"schema", "openbmh-post-match@1"}, + {"source", fixture.at("source")}, + {"review_id", "ui-post:" + fixture.at("fixture_id").get()}, + {"fixture_id", fixture.at("fixture_id")}, + {"source_revision", fixture.at("source_revision")}, + {"completed_sequence", fixture.at("frames").size() - 1}, + {"world", fixture.at("world")}, {"date", fixture.at("date")}, + {"role", fixture.at("role")}, {"surface", fixture.at("surface")}, + {"duration", fixture.at("duration")}, {"field_count", fixture.at("field_count")}, + {"notice", "UI-Demo · Rückblick auf vorgegebene Ergebnisse, keine Spielsimulation"}}; +} +Json match_events(const Json &events, const Json &match_id) { + Json rows = Json::array(); + for (const auto &event : events) + if (event.at("match_id") == match_id) rows.push_back(event); + return rows; +} +const Json &match_snapshot(const Json &frame, const Json &match_id) { + return *std::find_if(frame.at("matches").begin(), frame.at("matches").end(), + [&](const auto &m) { return m.at("match_id") == match_id; }); +} +Json report(const Json &fixture, const Json &match, int minute) { + const auto &frames = fixture.at("frames"); + const Json *frame = &frames.front(); + for (const auto &candidate : frames) { + if (candidate.at("minute").get() > minute) break; + frame = &candidate; + } + const auto ¤t = match_snapshot(*frame, match.at("id")); + const auto &final = match_snapshot(frames.back(), match.at("id")); + auto out = provenance(fixture); + out["kind"] = "report"; + out["match_id"] = match.at("id"); + out["match"] = match; + out["home"] = match.at("home"); out["away"] = match.at("away"); + out["minute"] = minute; out["recorded_minute"] = frame->at("minute"); + out["sequence"] = frame->at("sequence"); out["phase"] = frame->at("phase"); + out["final"] = final; out["final_score"] = final.at("score"); + for (auto key : {"score", "chances", "yellow", "red", "players", "standings"}) + out[key] = current.at(key); + // Raw events retain their original IDs/text/side/score. The recording names + // no player actor, assist or exact playing-time/ratings, so none is inferred. + out["events"] = match_events(frame->at("events"), match.at("id")); + out["timeline"] = match_events(frames.back().at("events"), match.at("id")); + out["attendance"] = nullptr; + out["attendance_reason"] = "not_recorded"; + out["actor"] = nullptr; out["assists"] = nullptr; out["ratings"] = nullptr; + out["playing_minutes"] = nullptr; + return out; +} +} // namespace + +Json make_demo_post_match(const Json &fixture, size_t completed_sequence) { + try { + if (!valid_live_fixture(fixture)) return failure("invalid_post_match_fixture"); + const auto &last = fixture.at("frames").back(); + if (completed_sequence != fixture.at("frames").size() - 1 || + last.at("phase") != "finished" || last.at("minute") != fixture.at("duration")) + return failure("post_match_not_finished"); + auto out = provenance(fixture); + out["kind"] = "review"; + out["owners"] = fixture.at("owners"); + out["tabs"] = fixture.at("role") == "club" && fixture.at("surface") == "outdoor" + ? Json::array({"results", "report", "eleven", "overview", "table"}) + : Json::array({"results", "report", "overview"}); + out["matches"] = Json::array(); out["tables"] = Json::array(); + Json totals = {{"games", fixture.at("matches").size()}, {"goals", 0}, + {"yellow", 0}, {"red", 0}, {"chances", 0}, + {"attendance", nullptr}, {"attendance_reason", "not_recorded"}, + {"scope", "recorded_human_matches"}}; + for (const auto &match : fixture.at("matches")) { + const auto &final = match_snapshot(last, match.at("id")); + auto row = match; + row["final"] = final; + row["events"] = match_events(last.at("events"), match.at("id")); + row["attendance"] = nullptr; row["attendance_reason"] = "not_recorded"; + out["matches"].push_back(std::move(row)); + for (auto key : {"yellow", "red", "chances"}) + totals[key] = totals.at(key).get() + final.at(key)[0].get() + final.at(key)[1].get(); + totals["goals"] = totals.at("goals").get() + final.at("score")[0].get() + final.at("score")[1].get(); + // Preserve declared final table snapshots exactly. Several human matches + // can refer to one recorded table; do not recalculate a season standings. + if (out.at("tabs").back() == "table" && !final.at("standings").empty()) { + auto table = std::find_if(out["tables"].begin(), out["tables"].end(), + [&](const auto &t) { return t.at("rows") == final.at("standings"); }); + if (table != out["tables"].end()) table->at("match_ids").push_back(match.at("id")); + else out["tables"].push_back({{"id", "ui-table:" + match.at("id").get()}, + {"match_ids", Json::array({match.at("id")})}, + {"rows", final.at("standings")}, + {"notice", "Vorgegebener POC-Tabellenstand der Liveaufnahme"}, + {"wins", nullptr}, {"draws", nullptr}, {"losses", nullptr}}); + } + } + out["overview"] = std::move(totals); + out["eleven"] = {{"available", false}, {"reason", "not_recorded"}, {"rows", Json::array()}}; + out["unknown_fields"] = Json::array({"attendance", "actor", "assists", "ratings", "playing_minutes", "eleven", "wins", "draws", "losses"}); + return out; + } catch (const std::exception &) { return failure("invalid_post_match_fixture"); } +} + +Json query_demo_post_match(const Json &fixture, const Json &q) { + try { + if (!q.is_object()) return failure("invalid_post_match_query"); + for (const auto &[key, value] : q.items()) { + (void)value; + if (key != "kind" && key != "completed_sequence" && key != "fixture_id" && + key != "revision" && key != "match_id" && key != "minute") + return failure("invalid_post_match_query"); + } + if (!q.contains("completed_sequence") || + !unsigned_value(q.at("completed_sequence"), std::numeric_limits::max())) + return failure("invalid_post_match_sequence"); + auto review = make_demo_post_match(fixture, q.at("completed_sequence").get()); + if (!review.value("ok", false)) return review; + if (q.contains("revision") && (!unsigned_value(q.at("revision"), UINT64_MAX) || + q.at("revision") != fixture.at("source_revision"))) + return failure("stale_post_match_revision"); + if (q.contains("fixture_id") && (!q.at("fixture_id").is_string() || + q.at("fixture_id") != fixture.at("fixture_id"))) + return failure("stale_post_match_fixture"); + const auto kind = q.value("kind", "review"); + if (kind == "review") + return q.contains("match_id") || q.contains("minute") ? failure("invalid_post_match_query") : review; + if (kind != "report") return failure("invalid_post_match_query"); + const auto id = q.contains("match_id") ? q.at("match_id") : fixture.at("matches").front().at("id"); + if (!id.is_string()) return failure("invalid_post_match_id"); + const auto match = std::find_if(fixture.at("matches").begin(), fixture.at("matches").end(), + [&](const auto &m) { return m.at("id") == id; }); + if (match == fixture.at("matches").end()) return failure("invalid_post_match_id"); + const auto minute = q.contains("minute") ? q.at("minute") : fixture.at("duration"); + if (!unsigned_value(minute, fixture.at("duration").get())) + return failure("invalid_post_match_minute"); + return report(fixture, *match, minute.get()); + } catch (const std::exception &) { return failure("invalid_post_match_query"); } +} +} // namespace bmh::modern_ui diff --git a/src/modern/ui/demo_post_match.hpp b/src/modern/ui/demo_post_match.hpp new file mode 100644 index 0000000..e8083cd --- /dev/null +++ b/src/modern/ui/demo_post_match.hpp @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-3.0-only +#pragma once +#include "modern/ui/catalog.hpp" +#include + +namespace bmh::modern_ui { +// Read-only review of a completed, validated UI recording. Passing its last +// sequence acknowledges UI playback completion, never engine match completion. +// The recording, its identities and every original outcome remain unchanged. +Json make_demo_post_match(const Json &live_fixture, size_t completed_sequence); +// {kind:"review"|"report", completed_sequence:uint, +// fixture_id?:string, revision?:uint, match_id?:string, minute?:uint} +// match_id/minute are report-only. Minute seeking selects an existing recorded +// frame; it does not interpolate scores, calculate ratings or execute actions. +Json query_demo_post_match(const Json &live_fixture, const Json &request); +} // namespace bmh::modern_ui diff --git a/src/modern/ui/model.cpp b/src/modern/ui/model.cpp index 87bbeed..2ca45dd 100644 --- a/src/modern/ui/model.cpp +++ b/src/modern/ui/model.cpp @@ -9,6 +9,7 @@ #include "modern/ui/demo_finance.hpp" #include "modern/ui/demo_lineup.hpp" #include "modern/ui/demo_live.hpp" +#include "modern/ui/demo_post_match.hpp" #include "modern/ui/demo_news.hpp" #include "modern/ui/demo_opening.hpp" #include "modern/ui/demo_reports.hpp" @@ -247,6 +248,12 @@ Json DemoSource::read_statistics(const Json &request) const { Json DemoSource::read_live(const Json &request) const { return query_demo_live(*catalog_, state_, revision_, request); } +Json DemoSource::read_post_match(const Json &request) const { + // This is an explicit UI-fixture path. Do not promote it to engine authority. + if (!request.is_object() || !request.contains("revision") || !request.contains("fixture_id")) + return {{"ok", false}, {"error", "post_match_identity_required"}}; + return query_demo_post_match(make_demo_live(*catalog_, state_, revision_), request); +} ActionResult DemoSource::apply(const Action &action) { if (action.revision != revision_) return {false, revision_, "stale_revision"}; diff --git a/src/modern/ui/model.hpp b/src/modern/ui/model.hpp index aebf62d..6e8089e 100644 --- a/src/modern/ui/model.hpp +++ b/src/modern/ui/model.hpp @@ -41,6 +41,11 @@ public: virtual Json read_live(const Json &) const { return {{"ok", false}, {"error", "live_unavailable"}}; } + // An authoritative adapter must confirm its own completed match state. + // Demo completion only acknowledges the final prerecorded presentation frame. + virtual Json read_post_match(const Json &) const { + return {{"ok", false}, {"error", "post_match_unavailable"}}; + } }; class DemoSource final : public DataSource { public: @@ -53,6 +58,7 @@ public: Json read_almanac(const Json &) const override; Json read_statistics(const Json &) const override; Json read_live(const Json &) const override; + Json read_post_match(const Json &) const override; void save(const fs::path &, const Json &desktop); Json load(const fs::path &); // UI continuation may retain the previous explicit-save clean baseline. diff --git a/tests/modern_post_match_ui_tests.cpp b/tests/modern_post_match_ui_tests.cpp new file mode 100644 index 0000000..6bf9162 --- /dev/null +++ b/tests/modern_post_match_ui_tests.cpp @@ -0,0 +1,181 @@ +// SPDX-License-Identifier: GPL-3.0-only +#include "modern/ui/demo_post_match.hpp" +#include "modern/ui/demo_live.hpp" +#include "modern/ui/desktop.hpp" +#include "modern/ui/model.hpp" +#include +#include + +using namespace bmh::modern_ui; +namespace { +void require(bool yes, const char *message) { + if (!yes) throw std::runtime_error(message); +} +struct Fixture { + fs::path root = fs::temp_directory_path() / bmh::editor::new_id("openbmh-post-test-"); + std::shared_ptr world; + Fixture() { + fs::create_directories(root / "world"); + const auto write = [&](const char *path, const Json &value) { + bmh::editor::write_atomic(root / path, value.dump()); + }; + write("manifest.json", {{"format", "openbmh-world"}, {"kind", "world"}, + {"format_version", "1.1"}, {"id", "world:synthetic-post-match"}, + {"start_date", "2034-07-01"}, {"requires", {"editor:world-v1"}}, + {"x-editor", {{"profile", "editor-world-v1"}}}}); + write("world/nations.json", {{"items", {{{"id", "nation:de"}, {"name", "Deutschland"}}, + {{"id", "nation:fr"}, {"name", "Frankreich"}}}}}); + write("world/competitions.json", {{"items", {{{"id", "competition:post"}, {"name", "POC-Liga"}, + {"nation", "nation:de"}, {"type", "league"}}}}}); + Json clubs = Json::array(), players = Json::array(); + for (int c = 0; c < 8; ++c) { + const auto club = "club:post-" + std::to_string(c); + clubs.push_back({{"id", club}, {"name", "Verein " + std::to_string(c)}, + {"nation", "nation:de"}, {"competition", "competition:post"}}); + for (int i = 0; i < 16; ++i) + players.push_back({{"id", "player:post-" + std::to_string(c) + "-" + std::to_string(i)}, + {"name", "Kaderspieler " + std::to_string(i)}, {"team", club}, + {"nation", "nation:de"}, {"squad_order", i}, + {"positions", Json::array({i == 0 ? "gk" : i < 6 ? "def" : i < 12 ? "mid" : "fwd"})}}); + } + write("world/clubs.json", {{"items", clubs}}); write("world/players.json", {{"items", players}}); + world = Catalog::open(root); + } + ~Fixture() { std::error_code error; fs::remove_all(root, error); } +}; +Json start(std::initializer_list clubs) { + Json managers = Json::array(); + for (const auto club : clubs) + managers.push_back({{"name", "Trainer " + std::to_string(managers.size())}, + {"club", "club:post-" + std::to_string(club)}, + {"portrait", managers.size()}, {"portrait_style", "photo"}, {"strength_choice", 1}}); + return {{"setup", {{"duration", 5}, {"difficulty", 3}, {"players", managers.size()}, + {"mode", 3}, {"league", true}, {"world", true}}}, {"managers", managers}}; +} +Json live(DemoSource &source) { return source.read_live({{"kind", "fixture"}}); } +Json request(const Json &recording, const char *kind = "review") { + return {{"kind", kind}, {"completed_sequence", recording.at("frames").size() - 1}, + {"revision", recording.at("source_revision")}, {"fixture_id", recording.at("fixture_id")}}; +} +} // namespace + +int main() { + try { + struct Unavailable final : DataSource { + Snapshot snapshot() const override { return {}; } + ActionResult apply(const Action &) override { return {false, 0, "unavailable"}; } + } unavailable; + require(unavailable.read_post_match(Json::object()).at("error") == "post_match_unavailable", + "authoritative adapter cannot invent completed results"); + Fixture f; DemoSource source(f.world); + require(source.apply({0, "start", start({0,1,2,3})}).ok, "paired humans start"); + require(source.mark_saved(source.snapshot().revision), "clean baseline"); + const auto before = source.snapshot(); const auto world_before = f.world->summary(); + const auto recording = live(source), original = recording; + const auto review = make_demo_post_match(recording, 8); + require(review.value("ok", false) && review.at("source") == "ui-demo-fixture" && + review.at("fixture_id") == recording.at("fixture_id") && + review.at("source_revision") == before.revision && review.at("completed_sequence") == 8, + "completed review keeps explicit provenance and sequence"); + require(review.at("owners") == recording.at("owners") && review.at("matches").size() == 2 && + review.at("matches")[0].at("owners").size() == 2, + "four owners share exactly two unique human matches"); + require(review.at("tabs") == Json::array({"results", "report", "eleven", "overview", "table"}), + "outdoor club has five review tabs"); + require(review.at("overview").at("games") == 2 && review.at("overview").at("goals") == 6 && + review.at("overview").at("yellow") == 2 && review.at("overview").at("red") == 0 && + review.at("overview").at("chances") == 28 && + review.at("overview").at("scope") == "recorded_human_matches", + "overview aggregates final recorded matches once, not once per human or whole league"); + require(review.at("overview").at("attendance").is_null() && + !review.at("eleven").at("available").get() && review.at("eleven").at("reason") == "not_recorded" && + review.at("eleven").at("rows").empty(), "unrecorded crowd and nominations stay unknown"); + require(review.at("tables").size() == 1 && review.at("tables")[0].at("match_ids").size() == 2 && + review.at("tables")[0].at("rows") == recording.at("frames").back().at("matches")[0].at("standings") && + review.at("tables")[0].at("wins").is_null(), "shared final table is copied verbatim without season formula"); + for (size_t i = 0; i < review.at("matches").size(); ++i) { + const auto &row = review.at("matches")[i]; + require(row.at("final") == recording.at("frames").back().at("matches")[i] && + row.at("id") == recording.at("matches")[i].at("id") && row.at("attendance").is_null(), + "result fields and identities equal exact final snapshot"); + for (const auto &event : row.at("events")) require(event.at("match_id") == row.at("id"), "events cannot leak from another match"); + } + require(source.read_post_match(request(recording)) == review, "DemoSource read hook gives pure final review"); + auto seek = request(recording, "report"); seek["match_id"] = recording.at("matches")[1].at("id"); + for (int minute : {0, 11, 12, 23, 45, 61, 62, 77, 78, 89, 90}) { + seek["minute"] = minute; + const auto report = query_demo_post_match(recording, seek); + require(report.value("ok", false) && report.at("minute") == minute && report.at("recorded_minute") <= minute && + report.at("match_id") == seek.at("match_id"), "seek selects existing frame for selected match"); + require(report.at("score") == (minute < 12 ? Json::array({0,0}) : minute < 62 ? Json::array({1,0}) : + minute < 78 ? Json::array({1,1}) : Json::array({2,1})), + "seek never interpolates or invents a goal between recorded moments"); + require(report.at("final_score") == Json::array({2,1}) && report.at("timeline").size() == 9 && + report.at("actor").is_null() && report.at("assists").is_null() && + report.at("ratings").is_null() && report.at("playing_minutes").is_null(), + "full outcome remains known, absent player facts remain unknown"); + for (const auto &event : report.at("events")) + require(event.at("minute") <= minute && event.at("match_id") == seek.at("match_id"), + "report only reveals that match's recorded past events"); + } + require(source.snapshot().state == before.state && source.snapshot().revision == before.revision && + !source.dirty() && f.world->summary() == world_before && recording == original, + "all review and seek reads preserve source, revision, clean baseline, catalogue and original recording"); + for (size_t sequence = 0; sequence < 8; ++sequence) + require(make_demo_post_match(recording, sequence).at("error") == "post_match_not_finished", + "cannot review incomplete playback"); + require(!make_demo_post_match(recording, 9).at("ok"), "out-of-range completion rejected"); + for (const auto &bad : Json::array({Json(), Json::array(), Json{{"completed_sequence", -1}}, + Json{{"completed_sequence", 8.0}}, Json{{"completed_sequence", 8}, {"kind", "apply"}}, + Json{{"completed_sequence", 8}, {"fixture_id", "wrong"}}, + Json{{"completed_sequence", 8}, {"revision", before.revision + 1}}, + Json{{"completed_sequence", 8}, {"minute", 1}}, + Json{{"completed_sequence", 8}, {"kind", "report"}, {"minute", -1}}, + Json{{"completed_sequence", 8}, {"kind", "report"}, {"minute", 91}}, + Json{{"completed_sequence", 8}, {"kind", "report"}, {"minute", 1.5}}, + Json{{"completed_sequence", 8}, {"kind", "report"}, {"match_id", "foreign"}}, + Json{{"completed_sequence", 8}, {"owner", "manager:0"}}})) + require(!query_demo_post_match(recording, bad).at("ok"), "malformed, stale and unsupported query rejects explicitly"); + require(source.read_post_match({{"completed_sequence", 8}}).at("error") == "post_match_identity_required", + "source hook requires both revision and fixture identity"); + auto invalid = recording; invalid["source"] = "engine"; + require(!make_demo_post_match(invalid, 8).at("ok"), "demo review cannot claim engine authority"); + invalid = recording; invalid["owners"][0]["match_id"] = "wrong"; + require(!make_demo_post_match(invalid, 8).at("ok"), "owner-match consistency required"); + + require(source.apply({source.snapshot().revision, "career", {{"kind", "select_manager"}, {"portrait", 2}}}).ok, + "switch active presentation owner"); + require(!source.read_post_match(request(recording)).at("ok") && make_demo_post_match(recording, 8) == review, + "stale source read fails while retained historical recording remains identical"); + require(source.apply({source.snapshot().revision, "career", {{"kind", "surface"}, {"value", "indoor"}}}).ok, + "switch indoor board"); + const auto hall = live(source); const auto hall_review = make_demo_post_match(hall, 8); + require(hall_review.at("duration") == 40 && hall_review.at("field_count") == 6 && hall_review.at("tables").empty() && + hall_review.at("tabs") == Json::array({"results", "report", "overview"}), "hall has three tabs and no league table"); + auto hall_seek = request(hall, "report"); hall_seek["minute"] = 36; + require(query_demo_post_match(hall, hall_seek).at("score") == Json::array({2,1}), "hall seeks actual36-minute goal"); + hall_seek["minute"] = 41; + require(!query_demo_post_match(hall, hall_seek).at("ok"), "hall cannot seek past40"); + require(source.apply({source.snapshot().revision, "career", {{"kind", "role"}, {"value", "national"}}}).ok, + "switch national role"); + const auto national = live(source); const auto national_review = make_demo_post_match(national, 8); + require(national_review.at("duration") == 90 && national_review.at("role") == "national" && + national_review.at("owners").size() == 1 && national_review.at("tables").empty() && + national_review.at("tabs") == Json::array({"results", "report", "overview"}) && + national_review.at("owners")[0].at("view").at("national_demo_basis") == true, + "national retains own identity and POC squad boundary without club-only tabs"); + for (int count = 1; count <= 4; ++count) { + DemoSource several(f.world); + const auto setup = count == 1 ? start({0}) : count == 2 ? start({0,2}) : count == 3 ? start({0,2,4}) : start({0,2,4,6}); + require(several.apply({0, "start", setup}).ok, "unique human fixtures start"); + const auto view = make_demo_post_match(live(several), 8); + require(view.at("matches").size() == size_t(count) && view.at("overview").at("goals") == count * 3, + "one through four distinct matches retain their own final totals"); + } + source.save(f.root / "checkpoint.json", default_desktop()); + const auto saved = bmh::editor::read_file(f.root / "checkpoint.json"); + require(saved.find("openbmh-post-match@1") == std::string::npos && saved.find("ui-demo-fixture") == std::string::npos, + "read-only review never enters career checkpoint or advances season"); + std::cout << "post-match read-only projection tests passed\n"; return 0; + } catch (const std::exception &error) { std::cerr << error.what() << '\n'; return 1; } +}