Accept fixture-bound supplied review nominations without deriving match facts (by Codex)

This commit is contained in:
Codex authored and Codex committed 2026-10-27 08:51:30 +01:00
1 parent 2c4b9d2595
commit 925042b559
6 files changed
+344 -5

No files matched your search

@@ -36,6 +36,54 @@ 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.
### Optional supplied nominations
The additive three-argument overloads of both pure functions accept a separate
`records` object. The existing two-argument functions and the source hook retain
their original no-records behaviour. Records do not modify the live fixture:
```json
{
"schema": "openbmh-post-match-records@1",
"fixture_id": "the-original-fixture-id",
"source_revision": 1,
"eleven": {
"available": true,
"source": "supplied-records",
"notice": "Nominations supplied by the presentation data provider",
"formation": "3-4-3",
"rows": []
}
}
```
`rows` must contain exactly eleven unique player identities and a 1/3/4/3 split
of `position: "gk"|"def"|"mid"|"fwd"`. Each row contains exactly
`player:{id,name}`, `team:{id,name,role:"club"}`, `position` and `rating:null`.
The team must retain a known ID and name from the recording's match teams or
final standings. This validates presentation provenance and identity; it does
not independently prove an engine nomination. The supplying adapter is
responsible for that fact. No producer here selects players from their strength,
lineup position or goal events. Until an authoritative rating scale exists,
numeric ratings are rejected, including otherwise plausible values.
Records are accepted only for club/outdoor and must bind exactly to the same
fixture ID and source revision. Unknown fields, malformed UTF-8, foreign teams,
renamed teams, duplicate players, stale references or invalid formations fail
atomically. `source` is either `supplied-records` or
`synthetic-layout-fixture`; neither claims engine authority. National and
indoor remain three-tab reviews and reject nominations from this club-only
path. Available records replace only `eleven` and remove it from
`unknown_fields`. Scores, report events, timeline minutes, tables and all other
review facts remain unchanged. Missing records retain byte-identical defaults.
`tests/fixtures/modern_post_match_eleven.json` is an explicitly synthetic
standalone layout fixture containing `eleven` and its notice. It deliberately
contains no guessed fixture/revision binding. The core test binds it to its
actual synthetic recording; a document renderer test may use the same `eleven`
to cover a filled pitch/list without a product debug option or any change to
the nine-frame recording. These test names are not original game data.
For example, two recorded 2:1 matches shared by four human managers produce:
```json
+5 -1
View File
@@ -130,7 +130,11 @@ foreach(component statistics news settings desktop files entry opening career li
if(MSVC)
target_compile_options(modern_${component}_ui_tests PRIVATE /utf-8)
endif()
add_test(NAME modern_${component}_ui_tests COMMAND modern_${component}_ui_tests)
if(component STREQUAL "post_match")
add_test(NAME modern_${component}_ui_tests COMMAND modern_${component}_ui_tests "${CMAKE_SOURCE_DIR}/tests/fixtures/modern_post_match_eleven.json")
else()
add_test(NAME modern_${component}_ui_tests COMMAND modern_${component}_ui_tests)
endif()
endforeach()
add_executable(modern_news_catalog_tests ../../../tests/modern_news_catalog_tests.cpp)
+75 -3
View File
@@ -3,6 +3,8 @@
#include "modern/ui/demo_live.hpp"
#include <algorithm>
#include <limits>
#include <map>
#include <set>
namespace bmh::modern_ui {
namespace {
@@ -12,6 +14,68 @@ bool unsigned_value(const Json &v, uint64_t maximum) {
(v.is_number_integer() && v.get<int64_t>() >= 0 &&
uint64_t(v.get<int64_t>()) <= maximum);
}
bool text(const Json &v, size_t maximum = 240) {
if (!v.is_string()) return false;
const auto &s = v.get_ref<const std::string &>();
if (s.empty() || s.size() > maximum ||
std::any_of(s.begin(), s.end(), [](unsigned char c) { return c < 32 || c == 127; })) return false;
(void)v.dump(); // The existing JSON serializer rejects malformed UTF-8.
return true;
}
bool keys(const Json &v, std::initializer_list<const char *> names) {
if (!v.is_object() || v.size() != names.size()) return false;
for (const auto *name : names) if (!v.contains(name)) return false;
return true;
}
const char *attach_records(Json &review, const Json &fixture, const Json &records) {
try {
if (records.is_object() && records.empty()) return nullptr;
if (!keys(records, {"schema", "fixture_id", "source_revision", "eleven"}) ||
records.at("schema") != "openbmh-post-match-records@1") return "invalid_post_match_records";
if (!text(records.at("fixture_id")) || !unsigned_value(records.at("source_revision"), UINT64_MAX) ||
records.at("fixture_id") != fixture.at("fixture_id") ||
records.at("source_revision") != fixture.at("source_revision")) return "stale_post_match_records";
if (fixture.at("role") != "club" || fixture.at("surface") != "outdoor")
return "post_match_records_scope_unavailable";
const auto &eleven = records.at("eleven");
if (!keys(eleven, {"available", "source", "notice", "formation", "rows"}) ||
!eleven.at("available").is_boolean() || !eleven.at("available").get<bool>() ||
(eleven.at("source") != "supplied-records" && eleven.at("source") != "synthetic-layout-fixture") ||
!text(eleven.at("notice"), 1000) || eleven.at("formation") != "3-4-3" ||
!eleven.at("rows").is_array() || eleven.at("rows").size() != 11)
return "invalid_post_match_records";
std::map<std::string, Json> teams;
for (const auto &match : fixture.at("matches"))
for (const auto *side : {"home", "away"}) teams.emplace(match.at(side).at("id"), match.at(side));
for (const auto &snapshot : fixture.at("frames").back().at("matches"))
for (const auto &row : snapshot.at("standings")) teams.emplace(row.at("team").at("id"), row.at("team"));
std::set<std::string> players;
std::map<std::string, size_t> positions;
for (const auto &row : eleven.at("rows")) {
if (!keys(row, {"player", "team", "position", "rating"}) ||
!keys(row.at("player"), {"id", "name"}) ||
!keys(row.at("team"), {"id", "name", "role"}) ||
!text(row.at("player").at("id")) || !text(row.at("player").at("name")) ||
!players.insert(row.at("player").at("id")).second ||
!text(row.at("team").at("id")) || !text(row.at("team").at("name")) ||
row.at("team").at("role") != "club" || !row.at("rating").is_null() ||
!row.at("position").is_string()) return "invalid_post_match_records";
const auto team = teams.find(row.at("team").at("id").get<std::string>());
if (team == teams.end() || team->second.at("name") != row.at("team").at("name"))
return "invalid_post_match_records";
const auto position = row.at("position").get<std::string>();
if (position != "gk" && position != "def" && position != "mid" && position != "fwd")
return "invalid_post_match_records";
++positions[position];
}
if (positions["gk"] != 1 || positions["def"] != 3 || positions["mid"] != 4 || positions["fwd"] != 3)
return "invalid_post_match_records";
review["eleven"] = eleven; // Preserve supplied names/identities; never nominate here.
auto &unknown = review["unknown_fields"];
unknown.erase(std::remove(unknown.begin(), unknown.end(), Json("eleven")), unknown.end());
return nullptr;
} catch (const std::exception &) { return "invalid_post_match_records"; }
}
Json provenance(const Json &fixture) {
return {{"ok", true}, {"schema", "openbmh-post-match@1"},
{"source", fixture.at("source")},
@@ -65,7 +129,7 @@ Json report(const Json &fixture, const Json &match, int minute) {
}
} // namespace
Json make_demo_post_match(const Json &fixture, size_t completed_sequence) {
Json make_demo_post_match(const Json &fixture, size_t completed_sequence, const Json &records) {
try {
if (!valid_live_fixture(fixture)) return failure("invalid_post_match_fixture");
const auto &last = fixture.at("frames").back();
@@ -109,11 +173,16 @@ Json make_demo_post_match(const Json &fixture, size_t completed_sequence) {
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"});
if (const auto *error = attach_records(out, fixture, records)) return failure(error);
return out;
} catch (const std::exception &) { return failure("invalid_post_match_fixture"); }
}
Json query_demo_post_match(const Json &fixture, const Json &q) {
Json make_demo_post_match(const Json &fixture, size_t completed_sequence) {
return make_demo_post_match(fixture, completed_sequence, Json::object());
}
Json query_demo_post_match(const Json &fixture, const Json &q, const Json &records) {
try {
if (!q.is_object()) return failure("invalid_post_match_query");
for (const auto &[key, value] : q.items()) {
@@ -125,7 +194,7 @@ Json query_demo_post_match(const Json &fixture, const Json &q) {
if (!q.contains("completed_sequence") ||
!unsigned_value(q.at("completed_sequence"), std::numeric_limits<size_t>::max()))
return failure("invalid_post_match_sequence");
auto review = make_demo_post_match(fixture, q.at("completed_sequence").get<size_t>());
auto review = make_demo_post_match(fixture, q.at("completed_sequence").get<size_t>(), records);
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")))
@@ -148,4 +217,7 @@ Json query_demo_post_match(const Json &fixture, const Json &q) {
return report(fixture, *match, minute.get<int>());
} catch (const std::exception &) { return failure("invalid_post_match_query"); }
}
Json query_demo_post_match(const Json &fixture, const Json &q) {
return query_demo_post_match(fixture, q, Json::object());
}
} // namespace bmh::modern_ui
+6
View File
@@ -8,9 +8,15 @@ namespace bmh::modern_ui {
// 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);
// Optional externally supplied nominations, explicitly bound to this recording.
// No nominations/ratings are derived from catalogue strength or live events.
Json make_demo_post_match(const Json &live_fixture, size_t completed_sequence,
const Json &records);
// {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);
Json query_demo_post_match(const Json &live_fixture, const Json &request,
const Json &records);
} // namespace bmh::modern_ui
+155
View File
@@ -0,0 +1,155 @@
{
"schema": "openbmh-post-match-eleven-layout@1",
"notice": "Ausschließlich synthetische Layout-Testdaten von Codex, keine tatsächlich ermittelten Nominierungen.",
"eleven": {
"available": true,
"source": "synthetic-layout-fixture",
"notice": "Synthetische Layout-Testelf · keine Spielnoten oder Engineauswertung",
"formation": "3-4-3",
"rows": [
{
"player": {
"id": "player:post-0-0",
"name": "Anton Beispiel"
},
"team": {
"id": "club:post-0",
"name": "Verein 0",
"role": "club"
},
"position": "gk",
"rating": null
},
{
"player": {
"id": "player:post-2-1",
"name": "Benedikt Muster"
},
"team": {
"id": "club:post-2",
"name": "Verein 2",
"role": "club"
},
"position": "def",
"rating": null
},
{
"player": {
"id": "player:post-4-2",
"name": "Cem Öztürk-Demo"
},
"team": {
"id": "club:post-4",
"name": "Verein 4",
"role": "club"
},
"position": "def",
"rating": null
},
{
"player": {
"id": "player:post-6-3",
"name": "Daniel Probe"
},
"team": {
"id": "club:post-6",
"name": "Verein 6",
"role": "club"
},
"position": "def",
"rating": null
},
{
"player": {
"id": "player:post-0-4",
"name": "Emil Testspieler"
},
"team": {
"id": "club:post-0",
"name": "Verein 0",
"role": "club"
},
"position": "mid",
"rating": null
},
{
"player": {
"id": "player:post-2-5",
"name": "Felix Beispielmann"
},
"team": {
"id": "club:post-2",
"name": "Verein 2",
"role": "club"
},
"position": "mid",
"rating": null
},
{
"player": {
"id": "player:post-4-6",
"name": "Gabriel Musterfeld"
},
"team": {
"id": "club:post-4",
"name": "Verein 4",
"role": "club"
},
"position": "mid",
"rating": null
},
{
"player": {
"id": "player:post-6-7",
"name": "Hannes Übung"
},
"team": {
"id": "club:post-6",
"name": "Verein 6",
"role": "club"
},
"position": "mid",
"rating": null
},
{
"player": {
"id": "player:post-0-8",
"name": "Ibrahim Demonstrator"
},
"team": {
"id": "club:post-0",
"name": "Verein 0",
"role": "club"
},
"position": "fwd",
"rating": null
},
{
"player": {
"id": "player:post-2-9",
"name": "Jonas Maximilian Beispiel"
},
"team": {
"id": "club:post-2",
"name": "Verein 2",
"role": "club"
},
"position": "fwd",
"rating": null
},
{
"player": {
"id": "player:post-4-10",
"name": "Kilian Testname"
},
"team": {
"id": "club:post-4",
"name": "Verein 4",
"role": "club"
},
"position": "fwd",
"rating": null
}
]
}
}
+55 -1
View File
@@ -3,6 +3,7 @@
#include "modern/ui/demo_live.hpp"
#include "modern/ui/desktop.hpp"
#include "modern/ui/model.hpp"
#include <algorithm>
#include <iostream>
#include <stdexcept>
@@ -59,8 +60,13 @@ Json request(const Json &recording, const char *kind = "review") {
}
} // namespace
int main() {
int main(int argc, char **argv) {
try {
require(argc == 2, "expected separate synthetic nomination layout fixture");
const auto layout = Json::parse(bmh::editor::read_file(argv[1]));
require(layout.at("schema") == "openbmh-post-match-eleven-layout@1" &&
layout.at("eleven").at("source") == "synthetic-layout-fixture",
"filled nomination example is explicitly synthetic and outside product startup");
struct Unavailable final : DataSource {
Snapshot snapshot() const override { return {}; }
ActionResult apply(const Action &) override { return {false, 0, "unavailable"}; }
@@ -101,10 +107,50 @@ int main() {
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");
Json supplied = {{"schema", "openbmh-post-match-records@1"},
{"fixture_id", recording.at("fixture_id")},
{"source_revision", recording.at("source_revision")}, {"eleven", layout.at("eleven")}};
const auto filled = make_demo_post_match(recording, 8, supplied);
require(filled.value("ok", false) && filled.at("eleven") == layout.at("eleven"),
"explicitly supplied synthetic nominations are preserved for filled layout coverage");
auto expected_filled = review; expected_filled["eleven"] = layout.at("eleven");
auto &unknown = expected_filled["unknown_fields"];
unknown.erase(std::remove(unknown.begin(), unknown.end(), Json("eleven")), unknown.end());
require(filled == expected_filled && make_demo_post_match(recording, 8).dump() == review.dump() &&
make_demo_post_match(recording, 8, Json::object()).dump() == review.dump(),
"filled path only supplies its nominations; no-records output remains byte-identical");
require(query_demo_post_match(recording, request(recording), supplied) == filled && recording == original,
"query overload accepts bound records without rewriting recording frames or identity");
auto actual_supplied = supplied; actual_supplied["eleven"]["source"] = "supplied-records";
require(make_demo_post_match(recording, 8, actual_supplied).at("eleven").at("source") == "supplied-records",
"non-layout records retain explicit supplied provenance without claiming engine authority");
for (int fault = 0; fault < 15; ++fault) {
auto bad = supplied;
if (fault == 0) bad["eleven"]["rows"][1]["player"]["id"] = bad["eleven"]["rows"][0]["player"]["id"];
if (fault == 1) bad["eleven"]["rows"][1]["position"] = "gk";
if (fault == 2) bad["eleven"]["rows"].erase(0);
if (fault == 3) bad["eleven"]["rows"][0]["rating"] = 1;
if (fault == 4) bad["source_revision"] = before.revision + 1;
if (fault == 5) bad["fixture_id"] = "foreign";
if (fault == 6) bad["eleven"]["rows"][0]["team"]["id"] = "club:foreign";
if (fault == 7) bad["eleven"]["rows"][0]["team"]["name"] = "Renamed facts";
if (fault == 8) bad["eleven"]["source"] = "engine";
if (fault == 9) bad["eleven"]["formation"] = "4-4-2";
if (fault == 10) bad["generate"] = true;
if (fault == 11) bad["eleven"]["rows"][0]["player"]["name"] = std::string(1, char(0xff));
if (fault == 12) bad["eleven"]["available"] = false;
if (fault == 13) bad["eleven"]["rows"][0]["team"]["role"] = "national";
if (fault == 14) bad = nullptr;
require(!make_demo_post_match(recording, 8, bad).at("ok") &&
!query_demo_post_match(recording, request(recording), bad).at("ok"),
"malformed, stale, unknown-scale, foreign or non-3-4-3 nominations reject atomically");
}
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(query_demo_post_match(recording, seek, supplied) == report,
"optional nominations cannot change report outcomes, events or minutes");
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}) :
@@ -150,6 +196,10 @@ int main() {
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);
auto hall_records = supplied; hall_records["fixture_id"] = hall.at("fixture_id");
hall_records["source_revision"] = hall.at("source_revision");
require(make_demo_post_match(hall, 8, hall_records).at("error") == "post_match_records_scope_unavailable",
"indoor never receives an outdoor eleven tab through supplied records");
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;
@@ -159,6 +209,10 @@ int main() {
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);
auto national_records = supplied; national_records["fixture_id"] = national.at("fixture_id");
national_records["source_revision"] = national.at("source_revision");
require(make_demo_post_match(national, 8, national_records).at("error") == "post_match_records_scope_unavailable",
"national cannot display old club nominations even when rebound to its fixture");
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"}) &&