Files
Diabolo/DoOtboy/do-otboy/scripts/qa.gd
T

258 lines
9.7 KiB
GDScript
Raw Normal View History

extends RefCounted
## Gameplay tests use visible Button.pressed signals, real movement, and strike().
## Only the wall-clock origin is moved to avoid waiting seven minutes per ending.
var game: Node
var errors: Array[String] = []
var completed: Array[String] = []
func check(condition: bool, message: String) -> void:
if not condition:
errors.append(message)
push_error("QA: " + message)
func click(id: String) -> void:
var button: Button = game.ui.action_button(id)
check(button != null, "Missing visible button: " + id)
if button != null:
if game.ui.dialog_scroll.is_ancestor_of(button):
game.ui.dialog_scroll.ensure_control_visible(button)
button.pressed.emit()
func at_time(second: float) -> void:
game.start_tick = Time.get_ticks_msec() - int(second * 1000.0)
game._process(0)
func artifact_dir() -> String:
if OS.has_feature("template"):
return OS.get_executable_path().get_base_dir().path_join("captures")
return ProjectSettings.globalize_path("res://../qa")
func wait_for_impact() -> void:
var deadline := Time.get_ticks_msec() + 8000
while game.striking and Time.get_ticks_msec() < deadline:
await game.get_tree().process_frame
check(not game.striking, "Impact animation did not finish")
func rendered_frame() -> void:
await game.get_tree().process_frame
if DisplayServer.get_name() != "headless":
await RenderingServer.frame_post_draw
func visit(id: String) -> void:
game.ui.close_dialog()
game.go_to_object(id)
var deadline := Time.get_ticks_msec() + 12000
while not game.ui.dialog_open and Time.get_ticks_msec() < deadline:
await game.get_tree().physics_frame
check(game.ui.dialog_open, "Object did not open through movement: " + id)
var target: Vector3 = game.apartment.interactables[id]["approach"]
check(game.hero.position.distance_to(target) < 1.16, "Object out of reach: %s distance=%s title=%s" % [id, game.hero.position.distance_to(target), game.ui.dialog_title.text])
func profile_tests() -> void:
var path := artifact_dir().path_join("profile-test.cfg")
check(game.Profile.write_profile(path, {"child": true}, {"alone": true}, 3) == OK, "Profile write")
var data: Dictionary = game.Profile.read_profile(path, game.Story.FACTS, game.Story.ENDINGS)
check(data["status"] == OK and data["facts"] == {"child": true} and data["endings"] == {"alone": true} and data["loops"] == 3, "Profile disk round trip")
check(game.Profile.write_profile(path, {"route": true}, {}, 4) == OK, "Profile overwrite")
data = game.Profile.read_profile(path, game.Story.FACTS, game.Story.ENDINGS)
check(data["facts"] == {"route": true} and data["loops"] == 4, "Profile atomic replacement")
var cfg := ConfigFile.new()
cfg.set_value("save", "facts", {"child": true, "bogus": true, "route": 1})
cfg.set_value("save", "endings", "broken")
cfg.set_value("save", "loops", -5)
cfg.save(path)
data = game.Profile.read_profile(path, game.Story.FACTS, game.Story.ENDINGS)
check(data["facts"] == {"child": true} and data["endings"].is_empty() and data["loops"] == 0, "Malformed profile values")
DirAccess.remove_absolute(path)
data = game.Profile.read_profile(path, game.Story.FACTS, game.Story.ENDINGS)
check(data["status"] != OK and data["facts"].is_empty(), "Missing profile recovery")
func boundaries() -> void:
click("restart")
game.memory.clear()
for pair in [[game.PHONE_AT, "route"], [game.DISPATCH_AT, "dispatch"], [game.CHILD_AT, "child"]]:
at_time(0)
await visit("phone")
at_time(pair[0] - 0.1)
check(game.ui.action_button("call:" + pair[1]) == null, "Call visible before boundary: " + pair[1])
at_time(pair[0])
check(game.ui.action_button("call:" + pair[1]) != null, "Call absent at boundary: " + pair[1])
at_time(0)
await visit("intercom")
at_time(game.NEIGHBOR_AT - 0.1)
check(game.ui.action_button("tamara") == null, "Tamara arrived early")
at_time(game.NEIGHBOR_AT)
check(game.ui.action_button("tamara") != null, "Open intercom did not update")
# The notebook must close when the power goes down, even if already open.
click("close")
at_time(90)
await visit("laptop")
at_time(109)
check(game.ui.action_button("read:signature") != null, "Notebook unavailable before outage")
at_time(110)
check(game.ui.action_button("read:signature") == null, "Notebook survived outage without power")
await visit("fuse")
click("close")
await visit("laptop")
click("read:signature")
click("read:document")
click("close")
at_time(380)
await visit("phone")
at_time(389)
click("plans")
click("choose:official")
check(game.plan.is_empty(), "Choice bypassed confirmation")
var stale: Button = game.ui.action_button("commit:official")
at_time(390)
if is_instance_valid(stale):
stale.pressed.emit()
check(game.plan.is_empty(), "Stale confirmation bypassed deadline")
await visit("phone")
check(game.ui.action_button("call:dispatch") == null, "Call available after network loss")
# Even direct dispatch cannot bypass the visible UI.
game.action("commit:official")
check(game.plan.is_empty(), "Hidden commit accepted")
at_time(419)
check(game.remaining <= 1.1 and game.running, "Dialogue stopped the clock")
at_time(420.1)
check(game.striking, "Impact did not start")
await wait_for_impact()
check(not game.running and game.ui.action_button("restart") != null, "No-plan loop did not finish")
func ending_route(id: String) -> void:
click("restart")
game.memory.clear()
# Fresh knowledge for every route; no injected facts, items, or plans.
if id != "alone":
await visit("fuse")
click("close")
if id in ["list", "after"]:
await visit("laptop")
click("read:signature")
click("read:document")
click("close")
if id in ["shelter", "after"]:
await visit("drawer")
click("close")
if id == "after":
await visit("mother")
click("close")
if id in ["one_seat", "sister"]:
await visit("radio")
click("close")
if id == "exchange":
await visit("battery")
click("close")
at_time(181)
await visit("intercom")
click("choose:exchange")
else:
at_time(241)
await visit("phone")
click("call:route")
click("call:dispatch")
click("close")
await visit("phone")
click("call:child")
if id == "voice":
click("call:voice")
click("choose:voice")
else:
click("close")
if id == "after":
await visit("door")
click("choose:after")
else:
if id in ["one_seat", "sister"]:
at_time(320)
await visit("phone")
at_time(329)
check(game.ui.action_button("call:driver") == null, "Driver available early")
at_time(330)
check(game.ui.action_button("call:driver") != null, "Driver menu did not update")
click("call:driver")
click("choose:" + id)
elif id == "list":
await visit("phone")
click("call:journalist")
click("choose:list")
else:
await visit("phone")
click("plans")
click("choose:" + id)
else:
await visit("bath")
click("choose:alone")
check(game.plan.is_empty(), "Plan committed without confirmation: " + id)
click("commit:" + id)
check(game.plan == id, "UI failed to commit: " + id)
if id == "exchange":
await visit("battery")
check(not game.battery, "Spent battery was duplicated")
# A second choice must not replace the first.
await visit("phone")
if id == "alone":
check(game.ui.action_button("call:route") == null, "Phone menu survived switching off")
at_time(239)
game.ui.subtitle.text = "quiet"
at_time(241)
check(game.ui.subtitle.text == "quiet", "Switched-off phone delivered message")
if game.audio.has("phone"):
check(not game.audio["phone"].playing, "Switched-off phone is playing")
else:
click("plans")
check(game.ui.action_button("choose:official") == null, "Committed plan can be replaced")
var previous_max_fps := Engine.max_fps
if id == "alone":
Engine.max_fps = 10
at_time(420.1)
await wait_for_impact()
Engine.max_fps = previous_max_fps
check(not game.running and game.endings.has(id), "Impact did not unlock ending: " + id)
check(game.ui.splash_box.get_child(1).text == game.Story.ENDINGS[id]["title"], "Wrong ending screen: " + id)
check(game.ui.action_button("restart") != null, "No replay button: " + id)
await rendered_frame()
game.capture_qa("ending-" + id)
if game.endings.has(id):
completed.append(id)
print("QA_UI_ENDING ", id, " reached=", game.endings.has(id))
func run(target: Node) -> void:
game = target
await rendered_frame()
game.capture_qa("intro")
click("start")
await rendered_frame()
game.capture_qa("apartment")
# First check every approach at the normal player speed.
for id in game.apartment.interactables:
await visit(id)
print("QA_WALK ", id)
# Accelerate walking only, keeping the same collision/path/input handlers.
game.hero.speed = 6.0
profile_tests()
# Obtain a real ending screen so boundaries starts with its replay button.
at_time(420.1)
await wait_for_impact()
await boundaries()
game.endings.clear()
for id in game.Story.ENDINGS:
await ending_route(id)
check(completed.size() == 10, "Expected ten UI ending routes")
check(game.endings.size() == 10, "Discovered endings did not accumulate across loops")
var remembered: Dictionary = game.memory.duplicate()
click("restart")
check(game.memory == remembered and not game.battery and not game.phone_off and not game.battery_taken, "Loop reset lost knowledge or retained items")
var result := {"passed": errors.is_empty(), "errors": errors, "ui_endings": completed, "objects": game.apartment.interactables.size(), "loop_seconds": game.LOOP_SECONDS}
DirAccess.make_dir_recursive_absolute(artifact_dir())
var report := FileAccess.open(artifact_dir().path_join("result.json"), FileAccess.WRITE)
check(report != null, "Could not write QA report")
result["passed"] = errors.is_empty()
if report != null:
report.store_string(JSON.stringify(result, " "))
report.close()
print("QA_RESULT ", JSON.stringify(result))
game.get_tree().quit(0 if errors.is_empty() else 1)