rinkplanner/rinkplanner/tests/run_update_tests.gd
torsten 54e1c5dc34 feat: Update-Prüfung beim Start und Versions-Endpunkt
- App prüft version.json beim Start (nur exportierte Desktop-Builds)
- Dialog, Download mit SHA-256-Prüfung, Installation je Plattform
- manueller Menüpunkt, übersprungene Version in user://update.cfg
- Endpunkt unter rinkplanner.programmschmiede.de/version.json
- tools/publish_version.sh und Doku in docs/updates.md
- Version 0.2.0
2026-11-11 18:26:11 +01:00

227 lines
6.3 KiB
GDScript

extends SceneTree
## Headless tests for the update check: version comparison, endpoint payload
## validation, platform selection, skipped-version state and the dialog wiring.
## No network access is required.
const WhiteboardScene := preload("res://scenes/whiteboard/whiteboard.tscn")
var _assertions: int = 0
var _failures: PackedStringArray = PackedStringArray()
func _init() -> void:
_run.call_deferred()
func _run() -> void:
_test_current_version()
_test_version_comparison()
_test_platform_keys()
_test_payload_parsing()
_test_download_selection()
_test_date_format()
_test_skipped_state()
await _test_controller_wiring()
UpdateInfo.clear_skipped_version()
_finish()
func _test_current_version() -> void:
var configured := str(
ProjectSettings.get_setting("application/config/version", "")
).strip_edges()
_check(not configured.is_empty(), "project.godot setzt eine Version")
_check(
UpdateInfo.current_version() == configured,
"die Laufzeitversion kommt aus project.godot"
)
_check(
not UpdateInfo.parse_version(UpdateInfo.current_version()).is_empty(),
"die Laufzeitversion ist numerisch"
)
func _test_version_comparison() -> void:
_check(UpdateInfo.is_newer("0.2.0", "0.1.0"), "0.2.0 ist neuer als 0.1.0")
_check(
not UpdateInfo.is_newer("0.1.0", "0.1.0"),
"gleiche Versionen sind nicht neuer"
)
_check(
not UpdateInfo.is_newer("0.1.0", "0.2.0"),
"ältere Versionen sind nicht neuer"
)
_check(
UpdateInfo.is_newer("0.10.0", "0.9.9"),
"Versionen werden numerisch und nicht lexikografisch verglichen"
)
_check(
UpdateInfo.compare_versions("1.0", "1.0.0") == 0,
"fehlende Segmente zählen als Null"
)
_check(
UpdateInfo.is_newer("v0.2.0-beta", "0.1.9"),
"v-Präfix und Vorab-Suffix werden ignoriert"
)
_check(
UpdateInfo.parse_version("0.2.0") == PackedInt32Array([0, 2]),
"abschließende Nullen werden entfernt"
)
func _test_platform_keys() -> void:
_check(UpdateInfo.platform_key("macOS") == "macos", "macOS wird erkannt")
_check(UpdateInfo.platform_key("Windows") == "windows", "Windows wird erkannt")
_check(UpdateInfo.platform_key("Linux") == "linux", "Linux wird erkannt")
_check(UpdateInfo.platform_key("Android") == "android", "Android wird erkannt")
func _test_payload_parsing() -> void:
var payload := {
"version": "0.2.0",
"released": "2026-11-11",
"notes": "Neu: Update-Prüfung.",
"downloads": {
"macos": {"url": "https://example.org/rinkplanner.dmg", "size": 100},
},
}
var info := UpdateInfo.parse_payload(payload)
_check(str(info.get("version", "")) == "0.2.0", "die Version wird gelesen")
_check(
str(info.get("notes", "")) == "Neu: Update-Prüfung.",
"die Notizen werden gelesen"
)
_check(
info.get("downloads") is Dictionary,
"die Download-Liste bleibt erhalten"
)
_check(
UpdateInfo.parse_payload({"version": "abc"}).is_empty(),
"eine nicht numerische Version wird abgelehnt"
)
_check(
UpdateInfo.parse_payload({"version": "0.2.0"}).is_empty(),
"eine fehlende Download-Liste wird abgelehnt"
)
_check(UpdateInfo.parse_payload("kaputt").is_empty(), "Text wird abgelehnt")
_check(
UpdateInfo.parse_payload({
"version": "0.2.0",
"downloads": {"macos": {"url": "https://example.org/a.dmg"}},
"notes": ["Zeile 1", "Zeile 2"],
}).get("notes") == "Zeile 1\nZeile 2",
"Notizen dürfen als Liste kommen"
)
func _test_download_selection() -> void:
var info := {
"downloads": {
"macos": {
"url": "https://example.org/rinkplanner.dmg",
"sha256": "ABCDEF",
"size": 123,
},
"windows": {"url": "http://example.org/rinkplanner.exe"},
},
}
var mac := UpdateInfo.download_for(info, "macos")
_check(not mac.is_empty(), "ein HTTPS-Download wird ausgewählt")
_check(str(mac.get("sha256", "")) == "abcdef", "die Prüfsumme wird normalisiert")
_check(int(mac.get("size", 0)) == 123, "die Größe wird übernommen")
_check(
UpdateInfo.download_for(info, "windows").is_empty(),
"HTTP-Downloads werden abgelehnt"
)
_check(
UpdateInfo.download_for(info, "linux").is_empty(),
"fehlende Plattformen liefern keine Datei"
)
func _test_date_format() -> void:
_check(
UpdateInfo.format_date("2026-11-11") == "11.11.2026",
"ISO-Datum wird deutsch formatiert"
)
_check(
UpdateInfo.format_date("11.11.2026") == "11.11.2026",
"unbekannte Formate bleiben unverändert"
)
func _test_skipped_state() -> void:
UpdateInfo.clear_skipped_version()
_check(
UpdateInfo.load_skipped_version().is_empty(),
"ohne Zustand ist keine Version übersprungen"
)
UpdateInfo.remember_skipped_version("0.2.0")
_check(
UpdateInfo.load_skipped_version() == "0.2.0",
"die übersprungene Version wird gespeichert"
)
UpdateInfo.clear_skipped_version()
_check(
UpdateInfo.load_skipped_version().is_empty(),
"der Zustand lässt sich zurücksetzen"
)
func _test_controller_wiring() -> void:
var scene := WhiteboardScene.instantiate()
var controller := scene as WhiteboardController
controller.restore_autosave = false
controller.autosave_enabled = false
controller.check_for_updates = false
root.add_child(scene)
await process_frame
_check(controller.update_dialog != null, "der Update-Dialog ist verdrahtet")
_check(controller.update_text != null, "der Update-Text ist verdrahtet")
var popup := controller.file_menu_button.get_popup()
_check(
_find_menu_item(popup, "Nach Updates suchen…") >= 0,
"das Datei-Menü bietet die manuelle Update-Prüfung"
)
var text := controller._update_dialog_text(
{
"version": "0.3.0",
"released": "2026-12-01",
"notes": "Testnotiz",
"platform": "macos",
},
{"size": 1048576},
"0.2.0"
)
_check(text.contains("Rinkplanner 0.3.0"), "der Dialog nennt die neue Version")
_check(text.contains("0.2.0"), "der Dialog nennt die installierte Version")
_check(text.contains("Testnotiz"), "der Dialog zeigt die Notizen")
scene.queue_free()
await process_frame
func _find_menu_item(popup: PopupMenu, text: String) -> int:
for index: int in range(popup.item_count):
if popup.get_item_text(index) == text:
return index
return -1
func _check(condition: bool, message: String) -> void:
_assertions += 1
if not condition:
_failures.append(message)
func _finish() -> void:
if _failures.is_empty():
print("Update tests: %d checks passed." % _assertions)
quit(0)
return
printerr("Update tests failed (%d/%d):" % [_failures.size(), _assertions])
for failure: String in _failures:
printerr(" - " + failure)
quit(1)