feat: Regelwerk als Saisonordner mit Invariantenprüfung

Das ISU-Regelwerk liegt jetzt je Saison in einem eigenen Ordner mit
Manifest. Der Code fragt nach Dokumentarten (sov, levels, adult) statt nach
Dateinamen; eine neue Saison braucht kein GDScript.

- Manifest je Saison mit Quellen, valid_from und deklarativen Policies.
  Fehlt eine Policy, gilt sie in dieser Saison nicht – alte Saisons erben
  keine später erfundenen Regeln.
- RulesLibrary findet die Saisons per Verzeichnis-Scan, löst Vererbung für
  zeitversetzt erscheinende Papiere auf und wählt als Voreinstellung die
  neueste vollständige Saison ab valid_from.
- RulesAudit prüft den Invariantenkatalog A–F (Sprungreihenfolge, Level-
  Schwellen, Adult-Grenzen, Policies) und läuft über tools/check_rules.sh
  sowie in ./tools/test.sh.
- Saison an der Kür (Schema 7): alte Küren werden gegen das Regelwerk ihrer
  eigenen Saison geprüft. Die Statusleiste zeigt und wechselt die Saison;
  ohne Zuordnung prüft die App nichts, statt still gegen die falsche Saison
  zu rechnen.
- Validator läuft pro Regelpaket; ein Saison-Paar-Test sichert die
  dokumentierte Differenz zwischen 2025/26 und 2026/27 ab.
- PDF-Kopf nennt die Saison, docs/manual.md erklärt die Zuordnung,
  docs/isu-rules-structure.md beschreibt Struktur und Migrationsplan.

2025/26 hat noch keine Adult-Regeln; das Manifest markiert das Dokument
als missing, die Prüfung meldet die Kategorie als nicht anwendbar.
This commit is contained in:
torsten 2026-11-13 10:39:49 +01:00
parent e31e78d464
commit 386105aa71
40 changed files with 2716 additions and 77 deletions

View file

@ -0,0 +1,25 @@
extends SceneTree
## Prints the invariant report for all season rule packages.
##
## Run with:
## ./tools/check_rules.sh
##
## Exit code 0 means "no errors"; warnings are printed but do not fail, because
## they are deliberately non-blocking notes (e.g. a missing jump family that
## notes.md explains).
func _init() -> void:
var report := RulesAudit.audit_root()
var lines := report.to_lines()
for line: String in lines:
print(line)
var errors := report.error_count()
var warnings := report.warning_count()
print(
"%d Saison(s) geprüft: %d Fehler, %d Warnung(en)"
% [report.seasons_checked, errors, warnings]
)
quit(1 if errors > 0 else 0)

View file

@ -0,0 +1 @@
uid://db7n7aoih1v6s

View file

@ -5,13 +5,11 @@ extends SceneTree
## Run with:
## godot --headless --path rinkplanner --script res://tests/run_adult_tests.gd
const ElementCatalogScript := preload("res://src/core/rules/element_catalog.gd")
const ElementLevelRulesScript := preload("res://src/core/rules/element_level_rules.gd")
const AdultCategoryRulesScript := preload("res://src/core/rules/adult_category_rules.gd")
const RoutineValidatorScript := preload("res://src/core/rules/routine_validator.gd")
const RoutineModel := preload("res://src/core/model/routine.gd")
const RoutineSectionModel := preload("res://src/core/model/routine_section.gd")
const PathSegmentModel := preload("res://src/core/model/path_segment.gd")
const SEASON := "2026/27"
var _assertions: int = 0
var _failures: PackedStringArray = PackedStringArray()
@ -22,9 +20,15 @@ var _validator: RoutineValidator
func _init() -> void:
_catalog = ElementCatalogScript.load_default()
_rules = ElementLevelRulesScript.load_default()
_adult = AdultCategoryRulesScript.load_default()
var library := RulesLibrary.scan()
var package := library.get_package(SEASON)
_check(package != null, "Saison %s ist ladbar" % SEASON)
if package == null:
_finish()
return
_catalog = package.catalog
_rules = package.levels
_adult = package.adult
_validator = RoutineValidatorScript.new(_catalog, _rules, _adult)
_test_metadata()

View file

@ -72,6 +72,7 @@ func _test_json_roundtrip() -> void:
"second timeline label survives"
)
_check(loaded.adult_category == routine.adult_category, "category survives")
_check(loaded.season == routine.season, "season survives")
_check_approx(
loaded.assumed_pcs_average,
routine.assumed_pcs_average,
@ -212,6 +213,21 @@ func _test_json_rejects() -> void:
RoutineFile.json_path("user://kuer.tres") == "user://kuer.json",
"legacy paths migrate to the JSON extension"
)
# Files written before the season field existed stay loadable and are not
# silently assigned to a season.
var legacy_data: Dictionary = JSON.parse_string(encoded)
legacy_data.erase("season")
var without_season := RoutineFile.decode_json(JSON.stringify(legacy_data))
_check(
str(without_season["error"]).is_empty(),
"a file without a season still loads"
)
var old_routine: Routine = without_season["routine"]
_check(
old_routine != null and old_routine.season.is_empty(),
"a missing season stays unassigned"
)
_check(
RoutineFile.json_path("user://kuer") == "user://kuer.json",
"paths without extension get .json"
@ -363,6 +379,7 @@ func _make_routine() -> Routine:
{"time_seconds": 1.25, "text": "Dreh"},
]
routine.adult_category = "gold"
routine.season = "2026/27"
routine.assumed_pcs_average = 4.75
routine.assumed_falls = 1
routine.rink = RinkDimensions.new()

View file

@ -5,8 +5,8 @@ extends SceneTree
## Run with:
## godot --headless --path rinkplanner --script res://tests/run_level_tests.gd
const ElementLevelRulesScript := preload("res://src/core/rules/element_level_rules.gd")
const PathSegmentModel := preload("res://src/core/model/path_segment.gd")
const SEASON := "2026/27"
var _assertions: int = 0
var _failures: PackedStringArray = PackedStringArray()
@ -14,7 +14,13 @@ var _rules: ElementLevelRules
func _init() -> void:
_rules = ElementLevelRulesScript.load_default()
var library := RulesLibrary.scan()
var package := library.get_package(SEASON)
_check(package != null, "Saison %s ist ladbar" % SEASON)
if package == null:
_finish()
return
_rules = package.levels
_test_rules_metadata()
_test_spin_levels()

View file

@ -0,0 +1,296 @@
extends SceneTree
## Headless tests for the season rule packages and the invariant audit.
##
## Run with:
## godot --headless --path rinkplanner --script res://tests/run_rules_audit_tests.gd
const FIXTURE_ROOT := "user://rules-audit-fixture"
var _assertions: int = 0
var _failures: PackedStringArray = PackedStringArray()
func _init() -> void:
_test_library_discovery()
_test_season_resolution()
_test_package_contents()
_test_real_data_passes_audit()
_test_broken_fixture_is_reported()
_test_season_pair_difference()
_cleanup()
_finish()
func _test_library_discovery() -> void:
var library := RulesLibrary.scan()
_check(library.get_errors().is_empty(), "rule library scans without errors")
var seasons := library.get_seasons()
_check(seasons.has("2025/26"), "library knows 2025/26")
_check(seasons.has("2026/27"), "library knows 2026/27")
_check(seasons.size() == 2, "library finds exactly two seasons")
_check(
seasons[0] == "2025/26" and seasons[1] == "2026/27",
"seasons are sorted oldest first"
)
_check(library.has_season("2026/27"), "has_season finds 2026/27")
_check(not library.has_season("2030/31"), "has_season rejects unknown")
_check(library.get_package("2030/31") == null, "unknown season has no package")
func _test_season_resolution() -> void:
var library := RulesLibrary.scan()
_check(
library.get_default_season("2026-11-13") == "2026/27",
"mid season 2026/27 is the default"
)
_check(
library.get_default_season("2026-06-30") == "2025/26",
"before July 1st the previous season is the default"
)
_check(
library.get_default_season("2025-06-01") == "2026/27",
"without a started season the newest complete season wins"
)
_check(
RulesLibrary.season_to_folder("2026/27") == "2026-27",
"season folder name uses a dash"
)
func _test_package_contents() -> void:
var library := RulesLibrary.scan()
var current := library.get_package("2026/27")
_check(current != null, "2026/27 package loads")
if current == null:
return
_check(current.get_errors().is_empty(), "2026/27 package has no errors")
_check(current.is_complete(), "2026/27 is complete")
_check(current.season == "2026/27", "package carries its season")
_check(current.replaces == "2025/26", "2026/27 replaces 2025/26")
_check(current.catalog != null, "package has a catalog")
_check(current.levels != null, "package has level rules")
_check(current.adult != null, "package has adult categories")
_check(current.get_notes_path().ends_with("notes.md"), "package knows its notes")
var policy: Variant = current.get_policy("axel_required_in_sequence", false)
_check(policy == true, "axel policy is declared for 2026/27")
_check(
current.get_policy("max_features_per_foot", 0) == 0,
"undeclared policy falls back to the caller's off value"
)
_check(
not current.has_policy("feature_position_rules"),
"undeclared policy is reported as absent"
)
var previous := library.get_package("2025/26")
_check(previous != null, "2025/26 package loads")
if previous == null:
return
_check(previous.catalog != null, "2025/26 has a catalog")
_check(previous.levels != null, "2025/26 has level rules")
_check(previous.adult == null, "2025/26 has no adult rules")
_check(previous.is_document_missing("adult"), "2025/26 marks adult as missing")
_check(
not previous.get_warnings().is_empty(),
"2025/26 warns about the missing document"
)
func _test_real_data_passes_audit() -> void:
var report := RulesAudit.audit_root()
_check(report.seasons_checked == 2, "audit checks both seasons")
_check(
report.error_count() == 0,
"real data passes the audit (%s)"
% "; ".join(report.to_lines())
)
func _test_broken_fixture_is_reported() -> void:
_cleanup()
_copy_season("2026/27", FIXTURE_ROOT.path_join("2026-27"))
var manifest_path := FIXTURE_ROOT.path_join("2026-27").path_join("manifest.json")
var manifest := _read_json(manifest_path)
manifest["replaces"] = null
var policies: Dictionary = manifest["policies"]
policies["unknown_policy"] = true
manifest["policies"] = policies
_write_json(manifest_path, manifest)
var sov_path := FIXTURE_ROOT.path_join("2026-27").path_join("sov.json")
var sov := _read_json(sov_path)
for entry: Dictionary in sov["elements"]:
if str(entry.get("code", "")) == "3Lz":
entry["base_value"] = 3.0
_write_json(sov_path, sov)
var levels_path := FIXTURE_ROOT.path_join("2026-27").path_join("levels.json")
var levels := _read_json(levels_path)
var fixed_levels: Dictionary = levels["fixed_levels"]
fixed_levels["9Zz"] = 1
levels["fixed_levels"] = fixed_levels
_write_json(levels_path, levels)
var report := RulesAudit.audit_root(FIXTURE_ROOT)
var codes := PackedStringArray()
for finding: RulesAudit.Finding in report.findings:
if not codes.has(finding.code):
codes.append(finding.code)
_check(codes.has("B7"), "audit reports a broken jump order (B7)")
_check(codes.has("C1"), "audit reports an unknown fixed level code (C1)")
_check(codes.has("F2"), "audit reports an unknown policy (F2)")
_check(report.error_count() >= 3, "fixture has at least three errors")
# A document must not be both a file and an inheritance.
var manifest_broken := _read_json(manifest_path)
var adult: Dictionary = manifest_broken["documents"]["adult"]
adult["inherit_from"] = "2025/26"
manifest_broken["documents"]["adult"] = adult
_write_json(manifest_path, manifest_broken)
var broken := RulesAudit.audit_root(FIXTURE_ROOT)
var broken_codes := PackedStringArray()
for finding: RulesAudit.Finding in broken.findings:
broken_codes.append(finding.code)
_check(broken_codes.has("A4"), "audit rejects file plus inherit_from (A4)")
## E6: a reference routine must pass in one season and fail in the next for
## exactly the documented reason. This is what keeps old rules from being
## "repaired" by accident.
func _test_season_pair_difference() -> void:
var library := RulesLibrary.scan()
var older := library.get_package("2025/26")
var newer := library.get_package("2026/27")
_check(older != null and newer != null, "both seasons load for the pair test")
if older == null or newer == null:
return
var routine := _make_pair_routine()
var old_issues := RoutineValidator.new(
older.catalog,
older.levels,
older.adult
).validate(routine)
var new_issues := RoutineValidator.new(
newer.catalog,
newer.levels,
newer.adult
).validate(routine)
_check(
_has_message(old_issues, "nicht im Katalog"),
"2025/26 does not know ChSp"
)
_check(
not _has_message(new_issues, "nicht im Katalog"),
"2026/27 knows ChSp"
)
_check(older.adult == null, "2025/26 has no adult rules")
_check(newer.adult != null, "2026/27 has adult rules")
func _make_pair_routine() -> Routine:
var routine := Routine.new()
routine.routine_id = "season-pair"
routine.season = "2026/27"
var section := RoutineSection.new()
section.section_id = "section-001"
section.title = "Abschnitt 1"
section.sequence_order = 0
routine.sections = [section]
var marker := PathSegment.new()
marker.segment_id = "seg-chsp"
var curve := Curve2D.new()
curve.add_point(Vector2.ZERO)
marker.curve = curve
marker.element_type = PathSegment.ElementType.SPIN
marker.element_code = "ChSp"
marker.element_level = 1
section.segments.append(marker)
return routine
func _has_message(
issues: Array[ValidationIssue],
fragment: String
) -> bool:
for issue: ValidationIssue in issues:
if issue.message.contains(fragment):
return true
return false
func _copy_season(season: String, target: String) -> void:
var source := RulesLibrary.DATA_ROOT.path_join(season.replace("/", "-"))
DirAccess.make_dir_recursive_absolute(target)
var dir := DirAccess.open(source)
if dir == null:
return
dir.list_dir_begin()
var name := dir.get_next()
while not name.is_empty():
if not dir.current_is_dir():
var data := FileAccess.get_file_as_bytes(source.path_join(name))
var file := FileAccess.open(target.path_join(name), FileAccess.WRITE)
if file != null:
file.store_buffer(data)
name = dir.get_next()
dir.list_dir_end()
func _read_json(path: String) -> Dictionary:
var file := FileAccess.open(path, FileAccess.READ)
if file == null:
return {}
var parsed: Variant = JSON.parse_string(file.get_as_text())
return parsed as Dictionary if typeof(parsed) == TYPE_DICTIONARY else {}
func _write_json(path: String, data: Dictionary) -> void:
var file := FileAccess.open(path, FileAccess.WRITE)
if file == null:
return
file.store_string(JSON.stringify(data, " "))
func _cleanup() -> void:
_remove_dir(FIXTURE_ROOT)
func _remove_dir(path: String) -> void:
var dir := DirAccess.open(path)
if dir == null:
return
dir.list_dir_begin()
var name := dir.get_next()
while not name.is_empty():
if dir.current_is_dir():
_remove_dir(path.path_join(name))
else:
dir.remove(name)
name = dir.get_next()
dir.list_dir_end()
DirAccess.remove_absolute(path)
func _check(condition: bool, message: String) -> void:
_assertions += 1
if not condition:
_failures.append(message)
func _finish() -> void:
if _failures.is_empty():
print("PASS: %d assertions" % _assertions)
quit(0)
return
for failure: String in _failures:
printerr("FAIL: %s" % failure)
printerr("%d of %d assertions failed" % [_failures.size(), _assertions])
quit(1)

View file

@ -0,0 +1 @@
uid://cjl04e7kkgah8

View file

@ -7,6 +7,7 @@ extends SceneTree
const ElementDefinitionScript := preload("res://src/core/rules/element_definition.gd")
const ElementCatalogScript := preload("res://src/core/rules/element_catalog.gd")
const SEASON := "2026/27"
const PathSegmentModel := preload("res://src/core/model/path_segment.gd")
var _assertions: int = 0
@ -15,7 +16,13 @@ var _catalog: ElementCatalog
func _init() -> void:
_catalog = ElementCatalogScript.load_default()
var library := RulesLibrary.scan()
var package := library.get_package(SEASON)
_check(package != null, "Saison %s ist ladbar" % SEASON)
if package == null:
_finish()
return
_catalog = package.catalog
_test_catalog_metadata()
_test_jump_values()

View file

@ -5,13 +5,12 @@ extends SceneTree
## Run with:
## godot --headless --path rinkplanner --script res://tests/run_validation_tests.gd
const ElementCatalogScript := preload("res://src/core/rules/element_catalog.gd")
const ElementLevelRulesScript := preload("res://src/core/rules/element_level_rules.gd")
const RoutineValidatorScript := preload("res://src/core/rules/routine_validator.gd")
const ValidationIssueScript := preload("res://src/core/rules/validation_issue.gd")
const RoutineModel := preload("res://src/core/model/routine.gd")
const RoutineSectionModel := preload("res://src/core/model/routine_section.gd")
const PathSegmentModel := preload("res://src/core/model/path_segment.gd")
const SEASON := "2026/27"
var _assertions: int = 0
var _failures: PackedStringArray = PackedStringArray()
@ -21,8 +20,14 @@ var _validator: RoutineValidator
func _init() -> void:
_catalog = ElementCatalogScript.load_default()
_rules = ElementLevelRulesScript.load_default()
var library := RulesLibrary.scan()
var package := library.get_package(SEASON)
_check(package != null, "Saison %s ist ladbar" % SEASON)
if package == null:
_finish()
return
_catalog = package.catalog
_rules = package.levels
_validator = RoutineValidatorScript.new(_catalog, _rules)
_test_clean_routine()

View file

@ -1675,6 +1675,75 @@ func _run() -> void:
)
controller.validation_dialog.hide()
# Season assignment: the routine carries the rule package it is checked
# against, and a season switch must not silently rewrite its data.
controller.new_routine()
_check(
controller.get_season() == "2026/27",
"a new routine gets the default season"
)
_check(
controller.get_rules_package() != null
and controller.get_rules_package().season == "2026/27",
"the active rule package matches the routine"
)
_check(
controller.set_adult_category("gold"),
"Gold is available in the default season"
)
_check(controller.set_season("2025/26"), "the season can be switched to 2025/26")
_check(
controller.get_rules_package().season == "2025/26",
"the rule package follows the season"
)
_check(
controller.get_routine().adult_category == "gold",
"the category is kept when the target season lacks adult rules"
)
var unavailable_index := -1
for index: int in range(controller.adult_category_option.item_count):
if str(controller.adult_category_option.get_item_metadata(index)) == "gold":
unavailable_index = index
_check(unavailable_index >= 0, "the stored category stays visible")
_check(
controller.adult_category_option.get_item_text(unavailable_index).contains(
"nicht verfügbar"
),
"an unavailable category is labelled instead of hidden"
)
_check(
controller.adult_category_option.selected == unavailable_index,
"the dropdown selects the unavailable category"
)
var selected_season := controller.season_option.selected
_check(
str(controller.season_option.get_item_metadata(selected_season)) == "2025/26",
"the season dropdown reflects the routine"
)
_check(controller.set_season(""), "the season can be cleared")
_check(
controller.get_rules_package() == null,
"without a season there is no rule package"
)
var unassigned_issues := controller.validate_routine()
_check(
not unassigned_issues.is_empty(),
"an unassigned season blocks element validation"
)
controller.open_validation_dialog()
_check(
controller.validation_text.text.contains("Saison nicht festgelegt"),
"the dialog explains the missing season"
)
controller.validation_dialog.hide()
_check(
not controller.set_season("2030/31"),
"an unknown season is rejected"
)
controller.new_routine()
# Structured jump combination in the element dialog.
controller.new_routine()
var combo_marker := controller.add_element_marker(