Accept fixture-bound supplied review nominations without deriving match facts (by Codex)
This commit is contained in:
1 parent
2c4b9d2595
commit
925042b559
6 files changed
+344
-5
No files matched your search
@@ -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"}) &&
|
||||
|
||||
Reference in new issue
Block a user