From 82a0efabbc3d0b85e79d9fd1c648b7343fe2d215 Mon Sep 17 00:00:00 2001 From: jochen Date: Mon, 30 Nov 2026 10:20:48 +0100 Subject: [PATCH] Fail the merge check on a point trace for a current race Madring's point trace reached the 2026 poster unnoticed: nothing held that a layout a race draws has a traced line. tests/test_traces.py takes every layout the service picks for a season from 2020 to next season (find_layout_slug_for_year over circuits.json, the data the posters draw from) and fails each whose trace is not a LineString of more than ten points. On master it fails on spain/madrid/madring/2026- alone; here it passes for all 35. Builds: docs/posters.md at 8834df45e657ce0e16ba4c8e4e3b8878e95d922a (Layers: no current race draws a layout without a traced line) Claude-Session: https://claude.ai/code/session_01JG73KFhbaNj3tyJ8tKmE3W --- merge-check.sh | 4 ++-- tests/test_traces.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 tests/test_traces.py diff --git a/merge-check.sh b/merge-check.sh index 9d75e6c..828c819 100644 --- a/merge-check.sh +++ b/merge-check.sh @@ -10,8 +10,8 @@ # What the image ships, compiled before the merge: every Python file the service's image copies, and the # models it imports. Then the tests in tests/, which need the standard library only: every circuit in # circuits/circuits.json carries one unique ergastId, and a race's circuit resolves by that id, never by -# its name; a failed Jolpica fetch is never kept, a season that is over is read from disk, a throttled -# request is asked again; a poster's options, keys, cache headers and store cap, its satellite source, credits and +# its name; every layout a race from 2020 on draws has a traced line, never a point; a failed Jolpica +# fetch is never kept, a season that is over is read from disk, a throttled request is asked again; a poster's options, keys, cache headers and store cap, its satellite source, credits and # licence (poster_options.py and poster_sources.py, standard library only). # # **Said, never passed silently**: the service's dependencies (service/requirements.txt) are the image's to diff --git a/tests/test_traces.py b/tests/test_traces.py new file mode 100644 index 0000000..ffb529c --- /dev/null +++ b/tests/test_traces.py @@ -0,0 +1,43 @@ +"""Every layout a race from 2020 on draws has a traced line: a layout whose trace is a point or empty is drawn without +a track (docs/posters.md, Layers), so such a trace for a current race fails the merge check. + +The layouts are the ones the service picks for a season (CircuitService.find_layout_slug_for_year), read from +circuits.json, never from Jolpica's schedules. Standard library only, so the merge check runs it as it is. +""" +import json +import unittest +from datetime import date +from pathlib import Path + +from circuits_service import CircuitService + +ROOT = Path(__file__).resolve().parent.parent +FIRST_SEASON = 2020 +MIN_POINTS = 10 # more than a few: a point, an empty line or a stub of a line fails + + +class TraceTest(unittest.TestCase): + def test_every_layout_raced_from_2020_on_has_a_traced_line(self): + service = CircuitService(str(ROOT / "circuits" / "circuits.json")) + drawn = set() + # This season and the next: a layout added for next season's calendar is held from the day it is added. + for season in range(FIRST_SEASON, date.today().year + 2): + for country in service.circuit_data.values(): + for locality in country.localities.values(): + for circuit in locality.circuits.values(): + slug = service.find_layout_slug_for_year(circuit, season) + if slug is not None: + drawn.add(circuit.layouts[slug].relative_geojson_filepath) + self.assertIn(Path("spain/madrid/madring/2026-.geo.json"), drawn) # the newest layout is among them + for path in sorted(drawn): + with self.subTest(layout=str(path)): + geometry = json.loads((ROOT / "circuits" / path).read_text(encoding="utf-8"))["features"][0]["geometry"] + line = geometry["type"] == "LineString" + points = len(geometry["coordinates"]) if line else 0 + found = f"a LineString of {points} points" if line else f"a {geometry['type']}" + self.assertGreater(points, MIN_POINTS, f"{path} is {found}, not a traced line of more than " + f"{MIN_POINTS} points") + + +if __name__ == "__main__": + unittest.main()