51 lines
2.2 KiB
GDScript
51 lines
2.2 KiB
GDScript
extends SceneTree
|
|
|
|
const Config = preload("res://testing/playable_config.gd")
|
|
const Report = preload("res://testing/playable_report.gd")
|
|
|
|
var failures := 0
|
|
|
|
func _init() -> void:
|
|
call_deferred("run")
|
|
|
|
func check(ok: bool, message: String) -> void:
|
|
if not ok:
|
|
failures += 1
|
|
printerr("FAIL: " + message)
|
|
|
|
func run() -> void:
|
|
var example_path := ProjectSettings.globalize_path("res://../test/playable/scenario.example.json")
|
|
var example := Config.load_file(example_path)
|
|
check(not example.ok, "empty example configuration is rejected")
|
|
check(example.errors.size() > 0, "invalid configuration has reasons")
|
|
var valid := {
|
|
"schema_version": 1, "scenario_id": "harness", "protocol": "classic",
|
|
"server": {"server_index": 0, "channel_index": 0}, "character_slot": 0,
|
|
"map_key": "OutdoorA1/metin2_map_a1", "waypoints_cm": [[454600, 934000]],
|
|
"allowed_mob_vnums": [101], "allowed_drop_vnums": [19],
|
|
"skill_cases": [{"case_id": "skill-1", "skill_id": 1, "required_evidence": ["damage"]}],
|
|
"resolution": [1280, 720], "loops": 1, "timeout_seconds": 120,
|
|
}
|
|
check(Config.validate(valid).ok, "complete configuration is accepted")
|
|
var secret := valid.duplicate(true)
|
|
secret["password"] = "must-be-rejected"
|
|
check(not Config.validate(secret).ok, "credentials in configuration are rejected")
|
|
|
|
var report := Report.new()
|
|
report.begin("harness-run", "playable", valid)
|
|
report.add_case("CONFIG-01", "PASS", "validated")
|
|
report.add_case("EVENT-01", "PASS", "received")
|
|
var finished := report.finish()
|
|
check(finished.status == "PASS", "all passing cases produce client PASS")
|
|
check(finished.coverage.required == 2 and finished.coverage.passed == 2, "coverage is exact")
|
|
var blocked := Report.new()
|
|
blocked.begin("blocked-run", "playable", valid)
|
|
blocked.add_case("FIXTURE-01", "BLOCKED", "fixture_not_ready")
|
|
check(blocked.finish().status == "BLOCKED", "blocked fixture cannot become PASS")
|
|
var out := "user://playable-harness-report.json"
|
|
check(report.write(out), "report can be serialized")
|
|
var json: Variant = JSON.parse_string(FileAccess.get_file_as_string(out))
|
|
check(json is Dictionary and json.get("run_id", "") == "harness-run", "serialized report is readable")
|
|
print("playable_harness_test: failures=%d" % failures)
|
|
quit(1 if failures else 0)
|