feat: manuellen FTP-Sync zwischen Desktop und Tablet
- FTP/FTPS-Client (USER/PASS, AUTH TLS + PROT P, EPSV/PASV, MLSD, SIZE, RETR, STOR, DELE, MKD, RNFR/RNTO) ohne externe Bibliothek - Sync-Vergleich pro Kürdatei mit lokalem Sync-Stand: hochladen, herunterladen, überspringen; beidseitige Änderungen bleiben als Kopie mit Server-Zeitstempel erhalten, die lokale Fassung wird nie verworfen - Sync-Einstellungen (Host, Port, Benutzer, Passwort, Verzeichnis, FTPS, Zertifikatsprüfung) unter user://sync.cfg, nicht im Repository - Sync läuft im Thread, Fortschritt in der Statusleiste, Zusammenfassung im Dialog; geöffnete Kür wird nur unverändert neu geladen - Atomare Ersetzung über .part/.bak, Uploads über .uploading + Umbenennen - Tests für Vergleichsregeln, Konfliktnamen, PASV/EPSV/MDTM, Sync-Stand und Einstellungs-Dialog; zusätzlich E2E gegen den echten FTP-Server - docs/sync.md mit Einrichtung, Verhalten und Grenzen
This commit is contained in:
parent
921cf623fd
commit
f553785710
15 changed files with 1554 additions and 7 deletions
|
|
@ -44,6 +44,9 @@ $GODOT --headless --path rinkplanner --script res://tests/run_touch_tests.gd
|
|||
|
||||
# Run canvas performance stress test
|
||||
$GODOT --headless --path rinkplanner --script res://tests/run_perf_tests.gd
|
||||
|
||||
# Run FTP sync planning/parser/settings tests
|
||||
$GODOT --headless --path rinkplanner --script res://tests/run_sync_tests.gd
|
||||
```
|
||||
|
||||
Manueller visueller Smoke-Test (Layout bei einer Fenstergröße prüfen):
|
||||
|
|
|
|||
230
rinkplanner/tests/run_sync_tests.gd
Normal file
230
rinkplanner/tests/run_sync_tests.gd
Normal file
|
|
@ -0,0 +1,230 @@
|
|||
extends SceneTree
|
||||
|
||||
## Headless tests for the manual FTP sync: planning rules, conflict naming,
|
||||
## state persistence, protocol parsing 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")
|
||||
|
||||
var _assertions: int = 0
|
||||
var _failures: PackedStringArray = PackedStringArray()
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
_run.call_deferred()
|
||||
|
||||
|
||||
func _run() -> void:
|
||||
_test_plan()
|
||||
_test_naming()
|
||||
_test_parsers()
|
||||
_test_state_roundtrip()
|
||||
await _test_controller_wiring()
|
||||
_finish()
|
||||
|
||||
|
||||
func _test_plan() -> void:
|
||||
var local := {
|
||||
"neu.tres": {"mtime": 100, "size": 10},
|
||||
"lokal.tres": {"mtime": 200, "size": 10},
|
||||
"server.tres": {"mtime": 300, "size": 10},
|
||||
"beide.tres": {"mtime": 400, "size": 10},
|
||||
"gleich.tres": {"mtime": 500, "size": 10},
|
||||
"entfernt.tres": {"mtime": 600, "size": 10},
|
||||
}
|
||||
var remote := {
|
||||
"server-neu.tres": {"modify": 700, "size": 10},
|
||||
"lokal.tres": {"modify": 200, "size": 10},
|
||||
"server.tres": {"modify": 900, "size": 10},
|
||||
"beide.tres": {"modify": 900, "size": 10},
|
||||
"gleich.tres": {"modify": 500, "size": 10},
|
||||
"entfernt.tres": {"modify": 600, "size": 10},
|
||||
}
|
||||
var state := {
|
||||
"lokal.tres": {"local_mtime": 100, "remote_modify": 200},
|
||||
"server.tres": {"local_mtime": 300, "remote_modify": 300},
|
||||
"beide.tres": {"local_mtime": 401, "remote_modify": 400},
|
||||
"gleich.tres": {"local_mtime": 500, "remote_modify": 500},
|
||||
"entfernt.tres": {"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.tres") == SyncPlan.Action.UPLOAD, "nur lokal wird hochgeladen")
|
||||
_check(actions.get("server-neu.tres") == SyncPlan.Action.DOWNLOAD, "nur Server wird geladen")
|
||||
_check(
|
||||
actions.get("beide.tres") == SyncPlan.Action.CONFLICT,
|
||||
"beidseitige Änderung ist ein Konflikt"
|
||||
)
|
||||
_check(actions.get("lokal.tres") == SyncPlan.Action.UPLOAD, "lokale Änderung wird hochgeladen")
|
||||
_check(actions.get("server.tres") == SyncPlan.Action.DOWNLOAD, "Server-Änderung wird geladen")
|
||||
_check(actions.get("gleich.tres") == SyncPlan.Action.SKIP, "unverändert wird übersprungen")
|
||||
_check(
|
||||
actions.get("entfernt.tres") == SyncPlan.Action.SKIP,
|
||||
"Server-Datei verschwunden: nicht wiederherstellen"
|
||||
)
|
||||
|
||||
var first_sync := SyncPlan.build(
|
||||
{"a.tres": {"mtime": 1, "size": 1}},
|
||||
{"a.tres": {"modify": 2, "size": 1}},
|
||||
{}
|
||||
)
|
||||
_check(
|
||||
first_sync.size() == 1 and first_sync[0]["action"] == SyncPlan.Action.CONFLICT,
|
||||
"erster Abgleich ohne Stand ist ein Konflikt"
|
||||
)
|
||||
|
||||
var local_deleted := SyncPlan.build(
|
||||
{},
|
||||
{"weg.tres": {"modify": 2, "size": 1}},
|
||||
{"weg.tres": {"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_naming() -> void:
|
||||
_check(
|
||||
SyncPlan.conflict_file_name("kuer.tres", "2026-10-30 1050")
|
||||
== "kuer (Server 2026-10-30 1050).tres",
|
||||
"Konfliktname enthält Zeitstempel"
|
||||
)
|
||||
var used := {"kuer (Server 2026-10-30 1050).tres": true}
|
||||
_check(
|
||||
SyncPlan.unique_name("kuer (Server 2026-10-30 1050).tres", used)
|
||||
== "kuer (Server 2026-10-30 1050) 2.tres",
|
||||
"Konfliktname wird bei Bedarf durchnummeriert"
|
||||
)
|
||||
_check(
|
||||
SyncPlan.unique_name("frei.tres", used) == "frei.tres",
|
||||
"freier Name bleibt unverändert"
|
||||
)
|
||||
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_parsers() -> void:
|
||||
var pasv := FtpClient.parse_pasv("227 Entering Passive Mode (10,1,2,3,200,10)")
|
||||
_check(
|
||||
pasv.get("host") == "10.1.2.3" and pasv.get("port") == 200 * 256 + 10,
|
||||
"PASV-Antwort wird geparst"
|
||||
)
|
||||
_check(
|
||||
FtpClient.parse_epsv("229 Entering Extended Passive Mode (|||6446|)") == 6446,
|
||||
"EPSV-Antwort wird geparst"
|
||||
)
|
||||
_check(
|
||||
FtpClient.parse_epsv("229 Entering Extended Passive Mode (|||)") == -1,
|
||||
"ungültige EPSV-Antwort liefert -1"
|
||||
)
|
||||
var expected := int(Time.get_unix_time_from_datetime_string("2026-10-30T09:48:28"))
|
||||
_check(
|
||||
FtpClient.parse_mdtm("20261030094828") == expected,
|
||||
"MDTM wird als Unix-Zeit gelesen"
|
||||
)
|
||||
_check(FtpClient.parse_mdtm("kaputt") == -1, "ungültiges MDTM liefert -1")
|
||||
|
||||
|
||||
func _test_state_roundtrip() -> void:
|
||||
var path := "user://test_sync_state.cfg"
|
||||
var state := {
|
||||
"kuer.tres": {"local_mtime": 111, "remote_modify": 222},
|
||||
"zweite.tres": {"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.tres", {}).get("remote_modify", 0)) == 222,
|
||||
"Sync-Stand behält die Server-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")
|
||||
|
||||
|
||||
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
|
||||
|
||||
controller.save_sync_settings({
|
||||
"host": "ftp.example.org",
|
||||
"port": 2121,
|
||||
"user": "konto",
|
||||
"password": "geheim",
|
||||
"directory": "rinkplanner",
|
||||
"ftps": false,
|
||||
"verify_certificate": false,
|
||||
})
|
||||
var loaded := controller.load_sync_settings()
|
||||
_check(loaded["host"] == "ftp.example.org", "Sync-Einstellungen speichern den Host")
|
||||
_check(int(loaded["port"]) == 2121, "Sync-Einstellungen speichern den Port")
|
||||
_check(loaded["ftps"] == false, "Sync-Einstellungen speichern FTPS")
|
||||
_check(
|
||||
loaded["verify_certificate"] == false,
|
||||
"Sync-Einstellungen speichern die Zertifikatsprüfung"
|
||||
)
|
||||
|
||||
controller._open_sync_settings_dialog()
|
||||
_check(
|
||||
controller.sync_settings_dialog.visible,
|
||||
"Einstellungsdialog öffnet sich"
|
||||
)
|
||||
_check(
|
||||
controller.sync_host_edit.text == "ftp.example.org",
|
||||
"Dialog ist mit den gespeicherten Werten gefüllt"
|
||||
)
|
||||
_check(
|
||||
controller.sync_password_edit.secret,
|
||||
"Passwortfeld ist verdeckt"
|
||||
)
|
||||
controller.sync_settings_dialog.hide()
|
||||
|
||||
# Ohne Host öffnet "Jetzt synchronisieren" die Einstellungen statt zu starten.
|
||||
controller.save_sync_settings({"host": "", "port": 21, "user": "", "password": ""})
|
||||
controller.start_sync()
|
||||
_check(
|
||||
controller.sync_settings_dialog.visible,
|
||||
"Sync ohne Zugangsdaten öffnet die Einstellungen"
|
||||
)
|
||||
_check(not controller._sync_running, "ohne Zugangsdaten startet kein Sync")
|
||||
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)
|
||||
1
rinkplanner/tests/run_sync_tests.gd.uid
Normal file
1
rinkplanner/tests/run_sync_tests.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://6ugjulridrh0
|
||||
Loading…
Add table
Add a link
Reference in a new issue