`scenes/routine/routine_manager_panel.tscn` mit `RoutineManagerPanel`: Das Panel baut die Zeilen (Öffnen/Umbenennen/Löschen) und meldet die Auswahl über Signale. Die Abläufe bleiben beim Controller, weil sie Dateien, den aktuellen Pfad und den Sync brauchen. - Der Controller füllt das Panel nur noch (`open_for`, `refresh`), prüft `is_open()` und schließt es über `close()`. - `manager_tabs` ist aus dem Controller entfernt: `%Name` gilt nur innerhalb der Szene, die den Knoten besitzt. - Neuer eigener Test `run_routine_manager_panel_tests.gd` (13 Assertions): Zeilen, Signalnutzlast, Neuaufbau, Leerzustand, Öffnen/Schließen. Controller: 8.116 -> 8.082 Zeilen. Suite grün (23 Suiten).
1037 lines
33 KiB
GDScript
1037 lines
33 KiB
GDScript
extends SceneTree
|
|
|
|
## Headless tests for the cloud sync: planning rules, conflict naming, state
|
|
## persistence, OAuth/PKCE helpers, provider path conventions and the settings
|
|
## UI wiring.
|
|
##
|
|
## Run with:
|
|
## godot --headless --path rinkplanner --script res://tests/run_sync_tests.gd
|
|
|
|
const WhiteboardScene := preload("res://scenes/whiteboard/whiteboard.tscn")
|
|
|
|
## Minimal in-memory cloud used to exercise the newest-wins resolution without
|
|
## network access.
|
|
class FakeRemoteStore extends RemoteStore:
|
|
var remote_files: Dictionary = {}
|
|
var uploads: Array[String] = []
|
|
var deleted: Array[String] = []
|
|
var renames: Array[Dictionary] = []
|
|
|
|
func download(remote_name: String, local_path: String) -> String:
|
|
if not remote_files.has(remote_name):
|
|
return "Datei fehlt in der Test-Cloud"
|
|
var file := FileAccess.open(local_path, FileAccess.WRITE)
|
|
if file == null:
|
|
return "Temporäre Datei nicht schreibbar"
|
|
file.store_string(str(remote_files[remote_name]))
|
|
file.close()
|
|
return ""
|
|
|
|
func upload(local_path: String, remote_name: String) -> String:
|
|
var file := FileAccess.open(local_path, FileAccess.READ)
|
|
if file == null:
|
|
return "Lokale Datei nicht lesbar"
|
|
remote_files[remote_name] = file.get_as_text()
|
|
file.close()
|
|
uploads.append(remote_name)
|
|
return ""
|
|
|
|
func delete_file(remote_name: String) -> String:
|
|
deleted.append(remote_name)
|
|
remote_files.erase(remote_name)
|
|
return ""
|
|
|
|
func rename(from_name: String, to_name: String) -> String:
|
|
if not remote_files.has(from_name):
|
|
return "Datei fehlt in der Test-Cloud"
|
|
remote_files[to_name] = remote_files[from_name]
|
|
remote_files.erase(from_name)
|
|
renames.append({"from": from_name, "to": to_name})
|
|
return ""
|
|
|
|
var _assertions: int = 0
|
|
var _failures: PackedStringArray = PackedStringArray()
|
|
|
|
|
|
func _init() -> void:
|
|
_run.call_deferred()
|
|
|
|
|
|
func _run() -> void:
|
|
_test_plan()
|
|
_test_resolution()
|
|
_test_resolution_files()
|
|
_test_cleanup_files()
|
|
_test_delete_files()
|
|
_test_rename_files()
|
|
_test_cloud_helpers()
|
|
_test_http_cancel()
|
|
_test_app_config()
|
|
_test_state_roundtrip()
|
|
await _test_controller_wiring()
|
|
_finish()
|
|
|
|
|
|
func _test_plan() -> void:
|
|
var local := {
|
|
"neu.json": {"mtime": 100, "size": 10},
|
|
"lokal.json": {"mtime": 200, "size": 10},
|
|
"server.json": {"mtime": 300, "size": 10},
|
|
"beide.json": {"mtime": 400, "size": 10},
|
|
"gleich.json": {"mtime": 500, "size": 10},
|
|
"entfernt.json": {"mtime": 600, "size": 10},
|
|
}
|
|
var remote := {
|
|
"server-neu.json": {"modify": 700, "size": 10},
|
|
"lokal.json": {"modify": 200, "size": 10},
|
|
"server.json": {"modify": 900, "size": 10},
|
|
"beide.json": {"modify": 900, "size": 10},
|
|
"gleich.json": {"modify": 500, "size": 10},
|
|
"entfernt.json": {"modify": 600, "size": 10},
|
|
}
|
|
var state := {
|
|
"lokal.json": {"local_mtime": 100, "remote_modify": 200},
|
|
"server.json": {"local_mtime": 300, "remote_modify": 300},
|
|
"beide.json": {"local_mtime": 401, "remote_modify": 400},
|
|
"gleich.json": {"local_mtime": 500, "remote_modify": 500},
|
|
"entfernt.json": {"local_mtime": 600, "remote_modify": 600},
|
|
}
|
|
var plan := SyncPlan.build(local, remote, state)
|
|
var actions := {}
|
|
for entry: Dictionary in plan:
|
|
actions[entry["name"]] = entry["action"]
|
|
|
|
_check(actions.get("neu.json") == SyncPlan.Action.UPLOAD, "nur lokal wird hochgeladen")
|
|
_check(actions.get("server-neu.json") == SyncPlan.Action.DOWNLOAD, "nur Cloud wird geladen")
|
|
_check(
|
|
actions.get("beide.json") == SyncPlan.Action.CONFLICT,
|
|
"beidseitige Änderung ist ein Konflikt"
|
|
)
|
|
_check(actions.get("lokal.json") == SyncPlan.Action.UPLOAD, "lokale Änderung wird hochgeladen")
|
|
_check(actions.get("server.json") == SyncPlan.Action.DOWNLOAD, "Cloud-Änderung wird geladen")
|
|
_check(actions.get("gleich.json") == SyncPlan.Action.SKIP, "unverändert wird übersprungen")
|
|
_check(
|
|
actions.get("entfernt.json") == SyncPlan.Action.SKIP,
|
|
"Cloud-Datei verschwunden: nicht wiederherstellen"
|
|
)
|
|
|
|
var first_sync := SyncPlan.build(
|
|
{"a.json": {"mtime": 1, "size": 1}},
|
|
{"a.json": {"modify": 2, "size": 1}},
|
|
{}
|
|
)
|
|
_check(
|
|
first_sync.size() == 1 and first_sync[0]["action"] == SyncPlan.Action.TAKE_SERVER,
|
|
"erster Abgleich ohne Stand übernimmt die Cloud-Fassung"
|
|
)
|
|
|
|
var local_deleted := SyncPlan.build(
|
|
{},
|
|
{"weg.json": {"modify": 2, "size": 1}},
|
|
{"weg.json": {"local_mtime": 1, "remote_modify": 2}}
|
|
)
|
|
_check(
|
|
local_deleted.size() == 1 and local_deleted[0]["action"] == SyncPlan.Action.SKIP,
|
|
"lokal gelöschte Datei wird nicht zurückgeholt"
|
|
)
|
|
|
|
|
|
func _test_resolution() -> void:
|
|
_check(
|
|
SyncPlan.remote_wins(100, 200, false),
|
|
"die neuere Cloud-Fassung gewinnt"
|
|
)
|
|
_check(
|
|
not SyncPlan.remote_wins(200, 100, true),
|
|
"die neuere lokale Fassung gewinnt"
|
|
)
|
|
_check(
|
|
SyncPlan.remote_wins(100, 100, true),
|
|
"Gleichstand beim ersten Sync übernimmt die Cloud"
|
|
)
|
|
_check(
|
|
not SyncPlan.remote_wins(100, 100, false),
|
|
"Gleichstand im Konflikt behält die lokale Fassung"
|
|
)
|
|
_check(
|
|
SyncPlan.remote_wins(0, 0, true),
|
|
"unbekannte Zeiten fallen beim ersten Sync auf die Cloud zurück"
|
|
)
|
|
_check(
|
|
RoutineSync.archive_path("kuer.json")
|
|
== "user://conflicts/kuer.json",
|
|
"das Konfliktarchiv liegt außerhalb der Kürliste"
|
|
)
|
|
_check(
|
|
RoutineSync.archive_path("kuer.mp3")
|
|
== "user://conflicts/kuer.mp3",
|
|
"Audio-Konflikte behalten ihren Dateinamen im Archiv"
|
|
)
|
|
_check(
|
|
SyncPlan.old_conflict_base("kuer (Server 2026-10-30 1050).json")
|
|
== "kuer.json",
|
|
"alte Server-Kopien werden erkannt"
|
|
)
|
|
_check(
|
|
SyncPlan.old_conflict_base("kuer (Lokal 2026-10-30 1050) 2.mp3")
|
|
== "kuer.mp3",
|
|
"alte Lokal-Kopien mit Nummer werden erkannt"
|
|
)
|
|
_check(
|
|
SyncPlan.old_conflict_base(
|
|
"kuer (Server 2026-10-30 1050) (Lokal 2026-10-31 1200).json"
|
|
) == "kuer.json",
|
|
"mehrfach gestapelte Konfliktkopien werden aufgelöst"
|
|
)
|
|
_check(
|
|
SyncPlan.old_conflict_base("kuer.json").is_empty(),
|
|
"normale Kürnamen gelten nicht als Konfliktkopie"
|
|
)
|
|
|
|
_check(
|
|
RoutineSync.is_routine_file("kuer.json")
|
|
and RoutineSync.is_routine_file("alt.tres")
|
|
and not RoutineSync.is_routine_file("sync.cfg"),
|
|
"der Sync akzeptiert JSON und Legacy-.tres"
|
|
)
|
|
_check(
|
|
RoutineSync.is_synced_file("kuer.mp3")
|
|
and RoutineSync.is_synced_file("kuer.ogg")
|
|
and RoutineSync.is_synced_file("kuer.wav")
|
|
and not RoutineSync.is_synced_file("notizen.txt"),
|
|
"der Sync akzeptiert Musikdateien der Kür"
|
|
)
|
|
var label := SyncPlan.timestamp_label(0)
|
|
_check(
|
|
label.length() == 15 and label.contains("-") and label.contains(" "),
|
|
"Zeitstempel hat das Format YYYY-MM-DD HHMM"
|
|
)
|
|
|
|
|
|
func _test_resolution_files() -> void:
|
|
DirAccess.make_dir_recursive_absolute(
|
|
ProjectSettings.globalize_path(RoutineSync.LOCAL_DIR)
|
|
)
|
|
var names: Array[String] = []
|
|
names.append(_check_resolution(
|
|
"sync-test-local-newer.json", 200, "lokal", 100, "cloud", false,
|
|
"lokal", true
|
|
))
|
|
names.append(_check_resolution(
|
|
"sync-test-cloud-newer.json", 100, "lokal", 200, "cloud", false,
|
|
"cloud", false
|
|
))
|
|
names.append(_check_resolution(
|
|
"sync-test-tie-first.json", 100, "lokal", 100, "cloud", true,
|
|
"cloud", false
|
|
))
|
|
names.append(_check_resolution(
|
|
"sync-test-tie-conflict.json", 100, "lokal", 100, "cloud", false,
|
|
"lokal", true
|
|
))
|
|
for name: String in names:
|
|
for path: String in [
|
|
RoutineSync.LOCAL_DIR.path_join(name),
|
|
RoutineSync.archive_path(name),
|
|
]:
|
|
if FileAccess.file_exists(path):
|
|
DirAccess.remove_absolute(ProjectSettings.globalize_path(path))
|
|
DirAccess.remove_absolute(
|
|
ProjectSettings.globalize_path(RoutineSync.CONFLICT_DIR)
|
|
)
|
|
|
|
|
|
## Runs one resolution case and returns the file name for cleanup.
|
|
func _check_resolution(
|
|
name: String,
|
|
local_saved_at: int,
|
|
local_title: String,
|
|
remote_saved_at: int,
|
|
remote_title: String,
|
|
prefer_server: bool,
|
|
expected_main: String,
|
|
expect_upload: bool
|
|
) -> String:
|
|
var local_path := RoutineSync.LOCAL_DIR.path_join(name)
|
|
_write_text(local_path, _routine_content(local_saved_at, local_title))
|
|
var store := FakeRemoteStore.new()
|
|
store.remote_files[name] = _routine_content(remote_saved_at, remote_title)
|
|
var job := RoutineSync.new()
|
|
job.result = {
|
|
"uploaded": [],
|
|
"downloaded": [],
|
|
"resolved": [],
|
|
}
|
|
var err := job._resolve_newest(store, name, 0, prefer_server)
|
|
_check(err.is_empty(), "%s wird ohne Fehler aufgelöst" % name)
|
|
_check(
|
|
_routine_title(local_path) == expected_main,
|
|
"%s behält die neuere Fassung (%s)" % [name, expected_main]
|
|
)
|
|
_check(
|
|
job.result["uploaded"].has(name) == expect_upload,
|
|
"%s lädt die lokale Fassung genau dann hoch, wenn sie gewinnt" % name
|
|
)
|
|
var archived := RoutineSync.archive_path(name)
|
|
_check(
|
|
FileAccess.file_exists(archived),
|
|
"%s legt die unterlegene Fassung ins Konfliktarchiv" % name
|
|
)
|
|
if FileAccess.file_exists(archived):
|
|
var expected_archive := (
|
|
remote_title if expect_upload else local_title
|
|
)
|
|
_check(
|
|
_routine_title(archived) == expected_archive,
|
|
"%s archiviert die unterlegene Fassung" % name
|
|
)
|
|
return name
|
|
|
|
|
|
func _routine_content(saved_at: int, title: String, music: String = "") -> String:
|
|
var routine := Routine.new()
|
|
routine.routine_id = "sync-test"
|
|
routine.title = title
|
|
routine.saved_at = saved_at
|
|
routine.music_file = music
|
|
return RoutineFile.encode(routine)
|
|
|
|
|
|
func _write_text(path: String, content: String) -> void:
|
|
var file := FileAccess.open(path, FileAccess.WRITE)
|
|
if file == null:
|
|
return
|
|
file.store_string(content)
|
|
file.close()
|
|
|
|
|
|
func _routine_title(path: String) -> String:
|
|
var result := RoutineFile.load_file(path)
|
|
var routine: Routine = result.get("routine", null)
|
|
return routine.title if routine != null else ""
|
|
|
|
|
|
func _test_delete_files() -> void:
|
|
DirAccess.make_dir_recursive_absolute(
|
|
ProjectSettings.globalize_path(RoutineSync.LOCAL_DIR)
|
|
)
|
|
var routine_name := "sync-test-delete.json"
|
|
var music_name := "sync-test-delete.mp3"
|
|
_write_text(
|
|
RoutineSync.LOCAL_DIR.path_join(routine_name),
|
|
_routine_content(300, "delete")
|
|
)
|
|
_write_text(RoutineSync.LOCAL_DIR.path_join(music_name), "ID3")
|
|
var state_path := "user://test_delete_state.cfg"
|
|
RoutineSync.save_state(state_path, {
|
|
routine_name: {"local_mtime": 1, "remote_modify": 2},
|
|
music_name: {"local_mtime": 1, "remote_modify": 2},
|
|
})
|
|
var errors := RoutineSync.delete_local_files(
|
|
PackedStringArray([routine_name, music_name]),
|
|
state_path
|
|
)
|
|
_check(errors.is_empty(), "lokales Löschen meldet keinen Fehler")
|
|
_check(
|
|
not FileAccess.file_exists(RoutineSync.LOCAL_DIR.path_join(routine_name))
|
|
and not FileAccess.file_exists(
|
|
RoutineSync.LOCAL_DIR.path_join(music_name)
|
|
),
|
|
"Kür und Musik werden lokal entfernt"
|
|
)
|
|
_check(
|
|
RoutineSync.load_state(state_path).is_empty(),
|
|
"gelöschte Dateien verschwinden aus dem Sync-Stand"
|
|
)
|
|
DirAccess.remove_absolute(ProjectSettings.globalize_path(state_path))
|
|
|
|
var cloud_name := "sync-test-delete-cloud.json"
|
|
_write_text(
|
|
RoutineSync.LOCAL_DIR.path_join(cloud_name),
|
|
_routine_content(300, "cloud-delete")
|
|
)
|
|
var store := FakeRemoteStore.new()
|
|
store.remote_files[cloud_name] = _routine_content(300, "cloud-delete")
|
|
var job := RoutineSync.new()
|
|
job.result = {"deleted": [], "errors": []}
|
|
job.delete_names = PackedStringArray([cloud_name])
|
|
job._delete_routines(
|
|
store,
|
|
RoutineSync.local_files(),
|
|
{cloud_name: {"modify": 1, "size": 1}}
|
|
)
|
|
_check(
|
|
store.deleted.has(cloud_name),
|
|
"Löschen entfernt die Cloud-Kopie"
|
|
)
|
|
_check(
|
|
job.result["deleted"].has(cloud_name),
|
|
"Löschen meldet die entfernte Kür"
|
|
)
|
|
_check(
|
|
not FileAccess.file_exists(RoutineSync.LOCAL_DIR.path_join(cloud_name)),
|
|
"Löschen entfernt die lokale Kür nach der Cloud-Kopie"
|
|
)
|
|
_check(job.result["errors"].is_empty(), "Cloud-Löschen meldet keinen Fehler")
|
|
if FileAccess.file_exists(RoutineSync.LOCAL_DIR.path_join(cloud_name)):
|
|
DirAccess.remove_absolute(
|
|
ProjectSettings.globalize_path(
|
|
RoutineSync.LOCAL_DIR.path_join(cloud_name)
|
|
)
|
|
)
|
|
|
|
|
|
func _test_rename_files() -> void:
|
|
var old_json := "sync-test-rename-old.json"
|
|
var new_json := "sync-test-rename-new.json"
|
|
var old_tres := "sync-test-rename-old.tres"
|
|
var store := FakeRemoteStore.new()
|
|
store.remote_files[old_json] = _routine_content(1, "old")
|
|
store.remote_files[old_tres] = "legacy"
|
|
DirAccess.make_dir_recursive_absolute(
|
|
ProjectSettings.globalize_path(RoutineSync.LOCAL_DIR)
|
|
)
|
|
_write_text(
|
|
RoutineSync.LOCAL_DIR.path_join(new_json),
|
|
_routine_content(2, "neu")
|
|
)
|
|
var job := RoutineSync.new()
|
|
job.result = {"renamed": [], "errors": []}
|
|
job.rename_from = PackedStringArray([old_json, old_tres])
|
|
job.rename_to = PackedStringArray([
|
|
new_json,
|
|
"sync-test-rename-new.tres",
|
|
])
|
|
job._rename_routines(store, {
|
|
old_json: {"modify": 1, "size": 1},
|
|
old_tres: {"modify": 1, "size": 1},
|
|
})
|
|
_check(
|
|
store.remote_files.has(new_json),
|
|
"Cloud-Umbenennen legt den neuen Namen an"
|
|
)
|
|
_check(
|
|
not store.remote_files.has(old_json),
|
|
"Cloud-Umbenennen entfernt den alten Namen"
|
|
)
|
|
_check(
|
|
not store.remote_files.has(old_tres) and store.deleted.has(old_tres),
|
|
"Legacy-.tres wird in der Cloud entfernt"
|
|
)
|
|
_check(
|
|
job.result["renamed"].has(old_json),
|
|
"Umbenennen meldet die umbenannte Datei"
|
|
)
|
|
_check(
|
|
store.uploads.has(new_json),
|
|
"Umbenennen lädt den neuen Inhalt in die Cloud"
|
|
)
|
|
_check(job.result["errors"].is_empty(), "Cloud-Umbenennen meldet keinen Fehler")
|
|
if FileAccess.file_exists(RoutineSync.LOCAL_DIR.path_join(new_json)):
|
|
DirAccess.remove_absolute(
|
|
ProjectSettings.globalize_path(
|
|
RoutineSync.LOCAL_DIR.path_join(new_json)
|
|
)
|
|
)
|
|
|
|
|
|
func _test_cleanup_files() -> void:
|
|
DirAccess.make_dir_recursive_absolute(
|
|
ProjectSettings.globalize_path(RoutineSync.LOCAL_DIR)
|
|
)
|
|
var base_name := "sync-test-cleanup.json"
|
|
var copy_name := "sync-test-cleanup (Server 2026-10-30 1050).json"
|
|
var orphan_name := "sync-test-orphan (Lokal 2026-10-30 1050).json"
|
|
var unconfirmed := "sync-test-cleanup (Lokal 2026-10-31 1200).json"
|
|
var remote_only := "sync-test-remote (Server 2026-10-30 1050).json"
|
|
_write_text(RoutineSync.LOCAL_DIR.path_join(base_name), _routine_content(300, "base"))
|
|
_write_text(RoutineSync.LOCAL_DIR.path_join(copy_name), _routine_content(100, "old"))
|
|
_write_text(RoutineSync.LOCAL_DIR.path_join(orphan_name), _routine_content(100, "orphan"))
|
|
_write_text(RoutineSync.LOCAL_DIR.path_join(unconfirmed), _routine_content(100, "keep"))
|
|
|
|
var store := FakeRemoteStore.new()
|
|
store.remote_files[copy_name] = _routine_content(100, "old-cloud")
|
|
store.remote_files[remote_only] = _routine_content(100, "remote-only")
|
|
store.remote_files["sync-test-remote.json"] = _routine_content(300, "remote-base")
|
|
var local := RoutineSync.local_files()
|
|
var remote := {
|
|
copy_name: {"modify": 1, "size": 1},
|
|
remote_only: {"modify": 1, "size": 1},
|
|
"sync-test-remote.json": {"modify": 2, "size": 1},
|
|
}
|
|
var job := RoutineSync.new()
|
|
job.result = {
|
|
"cleanup_candidates": [],
|
|
"cleanup_skipped": [],
|
|
"cleanup_done": [],
|
|
"errors": [],
|
|
}
|
|
job.cleanup_names = PackedStringArray([copy_name, remote_only])
|
|
job._clean_old_conflicts(store, local, remote)
|
|
|
|
_check(
|
|
not FileAccess.file_exists(RoutineSync.LOCAL_DIR.path_join(copy_name)),
|
|
"bestätigte lokale Konfliktkopie wird entfernt"
|
|
)
|
|
_check(
|
|
FileAccess.file_exists(RoutineSync.archive_path(copy_name)),
|
|
"entfernte Kopie liegt im Konfliktarchiv"
|
|
)
|
|
_check(store.deleted.has(copy_name), "Cloud-Konfliktkopie wird gelöscht")
|
|
_check(
|
|
FileAccess.file_exists(RoutineSync.LOCAL_DIR.path_join(base_name)),
|
|
"Hauptdatei bleibt beim Aufräumen erhalten"
|
|
)
|
|
_check(
|
|
store.deleted.has(remote_only),
|
|
"nur in der Cloud liegende Kopie wird gelöscht"
|
|
)
|
|
_check(
|
|
FileAccess.file_exists(RoutineSync.archive_path(remote_only))
|
|
and _routine_title(RoutineSync.archive_path(remote_only)) == "remote-only",
|
|
"nur in der Cloud liegende Kopie wird vorher lokal archiviert"
|
|
)
|
|
_check(
|
|
FileAccess.file_exists(RoutineSync.LOCAL_DIR.path_join(unconfirmed)),
|
|
"nicht bestätigte Kopie bleibt erhalten"
|
|
)
|
|
_check(
|
|
job.result["cleanup_done"].size() == 2,
|
|
"Aufräumen meldet beide erledigten Kopien"
|
|
)
|
|
_check(
|
|
job.result["cleanup_skipped"].has(orphan_name),
|
|
"Kopie ohne Hauptdatei wird übersprungen"
|
|
)
|
|
_check(
|
|
FileAccess.file_exists(RoutineSync.LOCAL_DIR.path_join(orphan_name)),
|
|
"verwaiste Kopie bleibt als einzige Fassung erhalten"
|
|
)
|
|
|
|
for name: String in [base_name, orphan_name, unconfirmed, copy_name]:
|
|
var path := RoutineSync.LOCAL_DIR.path_join(name)
|
|
if FileAccess.file_exists(path):
|
|
DirAccess.remove_absolute(ProjectSettings.globalize_path(path))
|
|
if FileAccess.file_exists(RoutineSync.archive_path(copy_name)):
|
|
DirAccess.remove_absolute(
|
|
ProjectSettings.globalize_path(RoutineSync.archive_path(copy_name))
|
|
)
|
|
if FileAccess.file_exists(RoutineSync.archive_path(remote_only)):
|
|
DirAccess.remove_absolute(
|
|
ProjectSettings.globalize_path(RoutineSync.archive_path(remote_only))
|
|
)
|
|
DirAccess.remove_absolute(
|
|
ProjectSettings.globalize_path(RoutineSync.CONFLICT_DIR)
|
|
)
|
|
|
|
|
|
func _test_cloud_helpers() -> void:
|
|
var url := CloudHttp.parse_url(
|
|
"https://api.dropboxapi.com/2/files/list_folder?limit=10"
|
|
)
|
|
_check(
|
|
url.get("scheme") == "https"
|
|
and url.get("host") == "api.dropboxapi.com"
|
|
and int(url.get("port", 0)) == 443
|
|
and url.get("path") == "/2/files/list_folder?limit=10",
|
|
"HTTPS-URL wird zerlegt"
|
|
)
|
|
var loopback := CloudHttp.parse_url("http://127.0.0.1:53682/callback")
|
|
_check(
|
|
loopback.get("host") == "127.0.0.1"
|
|
and int(loopback.get("port", 0)) == 53682,
|
|
"Loopback-URL mit Port wird zerlegt"
|
|
)
|
|
_check(CloudHttp.parse_url("ftp://example.org").is_empty(), "FTP-URL wird abgelehnt")
|
|
_check(
|
|
CloudHttp.resolve_url("https://api.example.org/a/b", "/c/d")
|
|
== "https://api.example.org:443/c/d",
|
|
"absolute Weiterleitung wird aufgelöst"
|
|
)
|
|
_check(
|
|
CloudHttp.resolve_url("https://api.example.org/a/b", "c")
|
|
== "https://api.example.org:443/a/c",
|
|
"relative Weiterleitung wird aufgelöst"
|
|
)
|
|
_check(
|
|
CloudHttp.json_stringify_ascii({"name": "Kür"}).contains("\\u00fc"),
|
|
"Header-JSON escaped Umlaute"
|
|
)
|
|
|
|
# RFC 7636, Appendix B.
|
|
var verifier := "dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk"
|
|
_check(
|
|
CloudOAuthJob.pkce_challenge(verifier)
|
|
== "E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM",
|
|
"PKCE S256 entspricht dem Referenzwert"
|
|
)
|
|
var generated := CloudOAuthJob.new_verifier()
|
|
_check(
|
|
generated.length() >= 43 and not generated.contains("="),
|
|
"PKCE-Verifier ist lang genug und ohne Padding"
|
|
)
|
|
var authorize := CloudOAuthJob.dropbox_authorize_url("app-key", verifier)
|
|
_check(
|
|
authorize.contains("client_id=app-key")
|
|
and authorize.contains("token_access_type=offline")
|
|
and authorize.contains("code_challenge_method=S256")
|
|
and not authorize.contains("redirect_uri"),
|
|
"Dropbox-Autorisierungs-URL nutzt Offline-Zugriff und PKCE"
|
|
)
|
|
|
|
_check(
|
|
DropboxStore.remote_path("", "kuer.json") == "/kuer.json",
|
|
"Dropbox-Pfad im App-Ordner"
|
|
)
|
|
_check(
|
|
DropboxStore.remote_path("/Rinkplanner", "kuer.json")
|
|
== "/Rinkplanner/kuer.json",
|
|
"Dropbox-Pfad im Unterordner"
|
|
)
|
|
var content_headers := DropboxStore.content_headers("token", {"path": "/kuer.json"})
|
|
var content_type_count := 0
|
|
for value: String in content_headers:
|
|
if value.to_lower().begins_with("content-type:"):
|
|
content_type_count += 1
|
|
_check(
|
|
content_type_count == 1,
|
|
"Dropbox-Content-Request hat genau einen Content-Type"
|
|
)
|
|
var dropbox_time := DropboxStore.parse_timestamp("2026-11-09T12:34:56Z")
|
|
_check(dropbox_time > 0, "Dropbox-Zeitstempel wird gelesen")
|
|
_check(DropboxStore.parse_timestamp("kaputt") == -1, "ungültiger Dropbox-Zeitstempel liefert -1")
|
|
|
|
var google_time := GoogleDriveStore.parse_timestamp("2026-11-09T12:34:56.123Z")
|
|
_check(google_time == dropbox_time, "Google-Zeitstempel wird ohne Millisekunden gelesen")
|
|
_check(
|
|
GoogleDriveStore.escape_query("O'Brien") == "O\\'Brien",
|
|
"Google-Drive-Suchtext wird escaped"
|
|
)
|
|
|
|
|
|
## Ein Abbruch (z. B. beim Beenden) beendet die Warteschleife sofort, statt
|
|
## bis zum Timeout zu laufen.
|
|
func _test_http_cancel() -> void:
|
|
CloudHttp.request_cancel()
|
|
var http := CloudHttp.new()
|
|
var started := Time.get_ticks_msec()
|
|
var response := http.request(
|
|
HTTPClient.METHOD_GET,
|
|
"https://127.0.0.1:9/",
|
|
PackedStringArray(),
|
|
PackedByteArray(),
|
|
5000
|
|
)
|
|
var elapsed := Time.get_ticks_msec() - started
|
|
_check(response.is_empty(), "abgebrochene Anfrage liefert keine Antwort")
|
|
_check(http.last_error == "Abgebrochen.", "Abbruch wird als Fehler gemeldet")
|
|
_check(elapsed < 1000, "Abbruch beendet die Anfrage sofort (%d ms)" % elapsed)
|
|
CloudHttp.reset_cancel()
|
|
_check(not CloudHttp.cancel_requested, "Abbruch lässt sich zurücksetzen")
|
|
|
|
|
|
func _test_app_config() -> void:
|
|
var path := "user://test_sync_apps.cfg"
|
|
var config := ConfigFile.new()
|
|
config.set_value("apps", "google_client_id", "gid")
|
|
config.set_value("apps", "google_client_secret", "gsecret")
|
|
config.set_value("apps", "dropbox_app_key", "dkey")
|
|
config.save(path)
|
|
var app := SyncAppConfig.read_file(path)
|
|
_check(app["google_client_id"] == "gid", "App-Konfiguration liest Google-Client-ID")
|
|
_check(app["dropbox_app_key"] == "dkey", "App-Konfiguration liest Dropbox-App-Key")
|
|
_check(SyncAppConfig.is_configured("google_drive", app), "Google gilt als eingerichtet")
|
|
_check(SyncAppConfig.is_configured("dropbox", app), "Dropbox gilt als eingerichtet")
|
|
app["google_client_secret"] = ""
|
|
_check(not SyncAppConfig.is_configured("google_drive", app), "fehlendes Secret blockiert Google")
|
|
DirAccess.remove_absolute(ProjectSettings.globalize_path(path))
|
|
|
|
# ConfigFile erwartet ';' als Kommentar und Strings in Anführungszeichen.
|
|
var literal_path := "user://test_sync_apps_literal.cfg"
|
|
var literal := FileAccess.open(literal_path, FileAccess.WRITE)
|
|
literal.store_string(
|
|
"; Kommentar\n\n[apps]\n"
|
|
+ "google_client_id=\"\"\n"
|
|
+ "dropbox_app_key=\"key123\"\n"
|
|
)
|
|
literal.close()
|
|
var literal_app := SyncAppConfig.read_file(literal_path)
|
|
_check(
|
|
literal_app["dropbox_app_key"] == "key123",
|
|
"App-Konfiguration liest quoted Strings"
|
|
)
|
|
_check(
|
|
literal_app["google_client_id"] == "",
|
|
"leere quoted Strings bleiben leer"
|
|
)
|
|
_check(
|
|
not SyncAppConfig.is_configured("google_drive", literal_app),
|
|
"leere Google-Client-ID bleibt unkonfiguriert"
|
|
)
|
|
DirAccess.remove_absolute(ProjectSettings.globalize_path(literal_path))
|
|
|
|
|
|
func _test_state_roundtrip() -> void:
|
|
var path := "user://test_sync_state.cfg"
|
|
var state := {
|
|
"kuer.json": {"local_mtime": 111, "remote_modify": 222},
|
|
"zweite.json": {"local_mtime": 333, "remote_modify": 444},
|
|
}
|
|
RoutineSync.save_state(path, state)
|
|
var loaded := RoutineSync.load_state(path)
|
|
_check(loaded.size() == 2, "Sync-Stand wird gespeichert und geladen")
|
|
_check(
|
|
int(loaded.get("kuer.json", {}).get("remote_modify", 0)) == 222,
|
|
"Sync-Stand behält die Cloud-Zeit"
|
|
)
|
|
DirAccess.remove_absolute(ProjectSettings.globalize_path(path))
|
|
|
|
var files := RoutineSync.local_files("user://does_not_exist")
|
|
_check(files.is_empty(), "fehlendes Verzeichnis liefert keine Dateien")
|
|
|
|
var local_dir := "user://test_sync_files"
|
|
DirAccess.make_dir_recursive_absolute(ProjectSettings.globalize_path(local_dir))
|
|
for name: String in ["kuer.json", "kuer.mp3", "notizen.txt"]:
|
|
var file := FileAccess.open(local_dir.path_join(name), FileAccess.WRITE)
|
|
file.store_string("x")
|
|
file.close()
|
|
var listed := RoutineSync.local_files(local_dir)
|
|
_check(
|
|
listed.has("kuer.json") and listed.has("kuer.mp3"),
|
|
"lokale Dateiliste enthält Kür und Musik"
|
|
)
|
|
_check(not listed.has("notizen.txt"), "lokale Dateiliste ignoriert Fremddateien")
|
|
for name: String in ["kuer.json", "kuer.mp3", "notizen.txt"]:
|
|
DirAccess.remove_absolute(
|
|
ProjectSettings.globalize_path(local_dir.path_join(name))
|
|
)
|
|
DirAccess.remove_absolute(ProjectSettings.globalize_path(local_dir))
|
|
|
|
|
|
func _test_controller_wiring() -> void:
|
|
var scene := WhiteboardScene.instantiate()
|
|
var controller := scene as WhiteboardController
|
|
controller.restore_autosave = false
|
|
controller.autosave_enabled = false
|
|
root.add_child(scene)
|
|
await process_frame
|
|
|
|
_check(controller != null, "sync scene has a controller")
|
|
if controller == null:
|
|
return
|
|
|
|
var app_config := SyncAppConfig.load_config()
|
|
var provider := "dropbox"
|
|
if (
|
|
not SyncAppConfig.is_configured("dropbox", app_config)
|
|
and SyncAppConfig.is_configured("google_drive", app_config)
|
|
):
|
|
provider = "google_drive"
|
|
var tokens := {
|
|
provider: {
|
|
"refresh_token": "refresh",
|
|
"access_token": "access",
|
|
"expires_at": 9999999999,
|
|
"account": "konto@example.org",
|
|
},
|
|
}
|
|
|
|
controller.save_sync_settings({
|
|
"provider": provider,
|
|
"directory": "Kueren",
|
|
"tokens": tokens,
|
|
})
|
|
var loaded := controller.load_sync_settings()
|
|
_check(loaded["provider"] == provider, "Sync-Einstellungen speichern den Anbieter")
|
|
_check(
|
|
not loaded.has("directory"),
|
|
"Sync-Einstellungen verwerfen den alten Cloud-Unterordner"
|
|
)
|
|
_check(
|
|
RoutineSync.provider_tokens(loaded, provider).get("refresh_token") == "refresh",
|
|
"Sync-Einstellungen speichern den Refresh-Token"
|
|
)
|
|
|
|
controller._open_sync_settings_dialog()
|
|
_check(
|
|
controller.sync_settings_dialog.visible,
|
|
"Einstellungsdialog öffnet sich"
|
|
)
|
|
_check(
|
|
controller._selected_sync_provider() == provider,
|
|
"Dialog wählt den gespeicherten Anbieter"
|
|
)
|
|
var google_items := 0
|
|
for index: int in range(controller.sync_provider_option.item_count):
|
|
if str(controller.sync_provider_option.get_item_metadata(index)) == "google_drive":
|
|
google_items += 1
|
|
_check(
|
|
google_items == (1 if SyncAppConfig.is_configured("google_drive", app_config) else 0),
|
|
"Google Drive erscheint nur mit konfigurierten Zugangsdaten"
|
|
)
|
|
_check(
|
|
controller.sync_account_value.text == "konto@example.org",
|
|
"Dialog zeigt das verbundene Konto"
|
|
)
|
|
_check(
|
|
controller.sync_connect_button.text == "Trennen",
|
|
"Verbundenes Konto bietet Trennen an"
|
|
)
|
|
var manager_item := -1
|
|
var popup := controller.file_menu_button.get_popup()
|
|
for index: int in range(popup.item_count):
|
|
if popup.get_item_text(index) == "Küren verwalten…":
|
|
manager_item = index
|
|
_check(manager_item >= 0, "das Dateimenü bietet die Kürenverwaltung an")
|
|
_check(
|
|
controller.routine_manager_panel.dialog != null
|
|
and controller.delete_routine_dialog != null,
|
|
"Verwaltungs- und Löschdialog sind in der Szene verdrahtet"
|
|
)
|
|
_check(
|
|
controller.cleanup_conflicts_dialog != null,
|
|
"der Aufräumdialog ist in der Szene verdrahtet"
|
|
)
|
|
var summary := SyncSummaryText.format({
|
|
"uploaded": [],
|
|
"downloaded": [],
|
|
"skipped": [],
|
|
"errors": [],
|
|
"resolved": [
|
|
{
|
|
"name": "kuer.json",
|
|
"winner": "cloud",
|
|
"timestamp": 0,
|
|
"archive": "kuer.json",
|
|
},
|
|
],
|
|
})
|
|
_check(
|
|
summary.contains("Automatisch aufgelöste Konflikte: 1")
|
|
and summary.contains("Cloud-Fassung")
|
|
and summary.contains("Konfliktarchiv"),
|
|
"die Sync-Zusammenfassung nennt Gewinner und Konfliktarchiv"
|
|
)
|
|
|
|
# SyncSettingsModel: Anbieterliste hängt an der Build-Konfiguration.
|
|
var only_dropbox := SyncSettingsModel.provider_items({"dropbox_app_key": "key"})
|
|
_check(
|
|
only_dropbox.size() == 1
|
|
and str(only_dropbox[0]["value"]) == "dropbox",
|
|
"without Google credentials only Dropbox is offered"
|
|
)
|
|
var with_google := SyncSettingsModel.provider_items(
|
|
{
|
|
"dropbox_app_key": "key",
|
|
"google_client_id": "id",
|
|
"google_client_secret": "secret",
|
|
}
|
|
)
|
|
_check(with_google.size() == 2, "Google Drive appears when configured")
|
|
_check(
|
|
SyncSettingsModel.index_of(with_google, "google_drive") == 1,
|
|
"the provider list is searchable by id"
|
|
)
|
|
_check(
|
|
SyncSettingsModel.provider_items({}).size() == 1,
|
|
"Dropbox stays visible without credentials"
|
|
)
|
|
|
|
# RoutineManagerModel: eine Zeile pro Kür, JSON vor Legacy, sortiert.
|
|
var model_dir := "user://routine-manager-model"
|
|
DirAccess.make_dir_recursive_absolute(ProjectSettings.globalize_path(model_dir))
|
|
for name: String in ["b.tres", "a.json", "c.json", "c.tres", "notes.txt"]:
|
|
var file := FileAccess.open(model_dir.path_join(name), FileAccess.WRITE)
|
|
if file != null:
|
|
file.store_string("{}")
|
|
file.close()
|
|
var listed := RoutineManagerModel.list_routines(model_dir)
|
|
_check(listed.size() == 3, "one row per routine, ignoring other files (%d)" % listed.size())
|
|
_check(str(listed[0]) == "a.json", "routines are sorted by name")
|
|
_check(listed.has("c.json") and not listed.has("c.tres"), "JSON wins over the legacy format")
|
|
var variants := RoutineManagerModel.variants(model_dir, "c.json")
|
|
_check(
|
|
variants.size() == 2 and variants.has("c.json") and variants.has("c.tres"),
|
|
"both variants of a routine are found"
|
|
)
|
|
_check(
|
|
RoutineManagerModel.variants(model_dir, "missing.json") == PackedStringArray(["missing.json"]),
|
|
"a missing routine falls back to its name"
|
|
)
|
|
for name: String in ["b.tres", "a.json", "c.json", "c.tres", "notes.txt"]:
|
|
DirAccess.remove_absolute(model_dir.path_join(name))
|
|
DirAccess.remove_absolute(model_dir)
|
|
|
|
# "Küren verwalten": rows expose open/delete, the music stay-check works.
|
|
controller.sync_settings_dialog.hide()
|
|
DirAccess.make_dir_recursive_absolute(
|
|
ProjectSettings.globalize_path(RoutineSync.LOCAL_DIR)
|
|
)
|
|
var manager_file := "sync-test-manager.json"
|
|
var manager_file_two := "sync-test-manager-two.json"
|
|
var shared_music := "sync-test-shared.mp3"
|
|
_write_text(
|
|
RoutineSync.LOCAL_DIR.path_join(manager_file),
|
|
_routine_content(1, "manager", shared_music)
|
|
)
|
|
_write_text(
|
|
RoutineSync.LOCAL_DIR.path_join(manager_file_two),
|
|
_routine_content(1, "manager two", shared_music)
|
|
)
|
|
_write_text(
|
|
RoutineSync.LOCAL_DIR.path_join("sync-test-manager.tres"),
|
|
"legacy twin"
|
|
)
|
|
_check(
|
|
controller._routine_variants(manager_file).size() == 2,
|
|
"Löschen erfasst JSON und Legacy-.tres derselben Kür"
|
|
)
|
|
DirAccess.remove_absolute(
|
|
ProjectSettings.globalize_path(
|
|
RoutineSync.LOCAL_DIR.path_join("sync-test-manager.tres")
|
|
)
|
|
)
|
|
controller._refresh_routine_manager()
|
|
controller.routine_manager_panel.dialog.show()
|
|
_check(
|
|
controller.routine_manager_panel.dialog.visible,
|
|
"der Verwaltungsdialog lässt sich öffnen"
|
|
)
|
|
var manager_row: HBoxContainer = null
|
|
for child: Node in controller.routine_manager_panel.list.get_children():
|
|
if child is HBoxContainer:
|
|
var open_button := child.get_child(0) as Button
|
|
if open_button != null and open_button.text == "sync-test-manager":
|
|
manager_row = child
|
|
break
|
|
_check(
|
|
manager_row != null and manager_row.get_child_count() == 3,
|
|
"die Kürenverwaltung zeigt Öffnen, Umbenennen und Löschen je Kür"
|
|
)
|
|
controller._open_rename_routine_dialog(manager_file)
|
|
_check(
|
|
controller.rename_routine_dialog.visible
|
|
and controller.rename_routine_edit.text == "sync-test-manager",
|
|
"der Umbenennen-Dialog ist mit dem aktuellen Namen gefüllt"
|
|
)
|
|
controller.rename_routine_dialog.hide()
|
|
controller._pending_rename_name = ""
|
|
controller._open_delete_routine_dialog(manager_file)
|
|
_check(
|
|
controller.delete_routine_dialog.visible
|
|
and controller.delete_routine_text.text.contains("sync-test-manager"),
|
|
"der Löschdialog nennt die gewählte Kür"
|
|
)
|
|
controller.delete_routine_dialog.hide()
|
|
controller._pending_delete_name = ""
|
|
_check(
|
|
controller._orphan_music_for(manager_file).is_empty(),
|
|
"gemeinsam genutzte Musik wird nicht als verwaist markiert"
|
|
)
|
|
_write_text(
|
|
RoutineSync.LOCAL_DIR.path_join(manager_file_two),
|
|
_routine_content(1, "manager two")
|
|
)
|
|
_check(
|
|
controller._orphan_music_for(manager_file)
|
|
== PackedStringArray([shared_music]),
|
|
"ungenutzte Musik wird beim Löschen erkannt"
|
|
)
|
|
controller.delete_routine_cloud_check.disabled = true
|
|
controller.delete_routine_cloud_check.button_pressed = false
|
|
controller._pending_delete_name = manager_file_two
|
|
controller._on_delete_routine_confirmed()
|
|
_check(
|
|
not FileAccess.file_exists(
|
|
RoutineSync.LOCAL_DIR.path_join(manager_file_two)
|
|
),
|
|
"die Kürenverwaltung löscht eine Kür lokal"
|
|
)
|
|
controller.message_dialog.hide()
|
|
var rename_file := "sync-test-rename-ui.json"
|
|
var rename_tres := "sync-test-rename-ui.tres"
|
|
var renamed_file := "sync-test-rename-ui-neu.json"
|
|
_write_text(
|
|
RoutineSync.LOCAL_DIR.path_join(rename_file),
|
|
_routine_content(1, "Alte Kür")
|
|
)
|
|
_write_text(RoutineSync.LOCAL_DIR.path_join(rename_tres), "legacy")
|
|
var rename_error := controller._rename_local_routine(
|
|
rename_file,
|
|
"sync-test-rename-ui-neu",
|
|
"Neue Kür",
|
|
false
|
|
)
|
|
_check(rename_error.is_empty(), "lokales Umbenennen meldet keinen Fehler")
|
|
_check(
|
|
FileAccess.file_exists(RoutineSync.LOCAL_DIR.path_join(renamed_file)),
|
|
"Umbenennen legt die Kür unter dem neuen Namen ab"
|
|
)
|
|
_check(
|
|
not FileAccess.file_exists(
|
|
RoutineSync.LOCAL_DIR.path_join(rename_file)
|
|
)
|
|
and not FileAccess.file_exists(
|
|
RoutineSync.LOCAL_DIR.path_join(rename_tres)
|
|
),
|
|
"Umbenennen entfernt alten JSON- und Legacy-Namen"
|
|
)
|
|
_check(
|
|
_routine_title(RoutineSync.LOCAL_DIR.path_join(renamed_file))
|
|
== "Neue Kür",
|
|
"Umbenennen schreibt den neuen Titel in die Kür"
|
|
)
|
|
if FileAccess.file_exists(RoutineSync.LOCAL_DIR.path_join(renamed_file)):
|
|
DirAccess.remove_absolute(
|
|
ProjectSettings.globalize_path(
|
|
RoutineSync.LOCAL_DIR.path_join(renamed_file)
|
|
)
|
|
)
|
|
for name: String in [manager_file, manager_file_two]:
|
|
if FileAccess.file_exists(RoutineSync.LOCAL_DIR.path_join(name)):
|
|
DirAccess.remove_absolute(
|
|
ProjectSettings.globalize_path(
|
|
RoutineSync.LOCAL_DIR.path_join(name)
|
|
)
|
|
)
|
|
controller._refresh_routine_manager()
|
|
controller.routine_manager_panel.dialog.hide()
|
|
controller.sync_settings_dialog.hide()
|
|
|
|
# Ohne Refresh-Token öffnet "Jetzt synchronisieren" die Einstellungen.
|
|
controller.save_sync_settings({
|
|
"provider": "dropbox",
|
|
"tokens": {},
|
|
})
|
|
controller.start_sync()
|
|
_check(
|
|
controller.sync_settings_dialog.visible,
|
|
"Sync ohne Cloud-Konto öffnet die Einstellungen"
|
|
)
|
|
_check(not controller._sync_running, "ohne Cloud-Konto startet kein Sync")
|
|
_check(
|
|
controller.sync_account_value.text == "Nicht verbunden",
|
|
"Dialog zeigt den fehlenden Account"
|
|
)
|
|
controller.sync_settings_dialog.hide()
|
|
|
|
scene.queue_free()
|
|
await process_frame
|
|
|
|
|
|
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)
|