Files
windroost/p2_godot_sample/scripts/ch_systems_touch_test.gd
T
wushenghua c8074948b6 S1/S2/S8 integration candidate: schema-agnostic probes and clean CH touch teardown
S1/S2/S8 product code is already present in 529cdeb (all three candidate
commits are ancestors). Align the S1/S2 domain probes with the integrated
schema 7 by comparing to ProfileStore.SCHEMA, and make the CH systems touch
probe free its shell synchronously so the representative run exits clean.
All systems in 529cdeb (S3/S4/S5/S6/buoy) are preserved unchanged.
2026-11-29 10:16:01 +08:00

480 lines
20 KiB
GDScript

extends SceneTree
## S5/S6 real mobile-input evidence. Every action below is driven by
## Input.parse_input_event(InputEventScreenTouch) through the live viewport and
## real Buttons -- no callback is invoked directly. Covers 360/390/430 x zh/en x
## normal/reduced so the new Company Affairs rows are reachable and readable.
## Also drives the side/interactions claim rows (partner, record, LowFreq echo)
## through their real Buttons and asserts modal-back, save/live agreement and
## exactly-once claim accounting. The lifecycle regression additionally drives
## the buoy start / partial-tap / completion path through real ScreenTouch,
## re-discovering each row after rebuild so no freed coordinate is reused.
const OUTPUT_PATH := "res://artifacts/ch_systems_touch_test.json"
const SIZES := [Vector2i(360, 800), Vector2i(390, 844), Vector2i(430, 932)]
const LOCALES := ["zh_CN", "en_US"]
const REDUCED := [false, true]
var _problems: Array = []
var _steps: Array = []
var _mode: String = "full"
func _init() -> void:
_run.call_deferred()
func _check(cond: bool, msg: String) -> void:
if not cond:
_problems.append(msg)
func _record(name: String, data: Dictionary) -> void:
var e := data.duplicate()
e["step"] = name
_steps.append(e)
func _run() -> void:
var root_window := get_root()
_mode = OS.get_environment("WN_SIDE_CLAIMS_MODE")
if _mode.is_empty():
_mode = "full"
for size in SIZES:
for locale in LOCALES:
for reduced in REDUCED:
if not _mode_allows(size as Vector2i, str(locale), bool(reduced)):
continue
await _case(root_window, size as Vector2i, str(locale), bool(reduced))
_finish()
func _mode_allows(size: Vector2i, locale: String, reduced: bool) -> bool:
match _mode:
"minimal":
return _is_minimal_case(size, locale, reduced)
"lifecycle":
return size == Vector2i(390, 844) and locale == "zh_CN" and not reduced
_:
return true
func _is_minimal_case(size: Vector2i, locale: String, reduced: bool) -> bool:
return (size == Vector2i(360, 800) and locale == "zh_CN" and not reduced) \
or (size == Vector2i(390, 844) and locale == "en_US" and reduced)
func _case(root_window: Window, size: Vector2i, locale: String, reduced: bool) -> void:
var tag := "%dx%d/%s/%s" % [size.x, size.y, locale, "reduced" if reduced else "normal"]
root_window.content_scale_mode = Window.CONTENT_SCALE_MODE_CANVAS_ITEMS
root_window.content_scale_size = size
root_window.size = size
await _wait_frames(3)
var shell := load("res://scenes/game_root.tscn").instantiate() as GameRoot
root_window.add_child(shell)
await _wait_frames(2)
shell.set_locale_for_test(locale)
shell.set_reduced_motion_for_test(reduced)
shell.reset_profile_for_test()
var gp := shell.get_profile()
gp["gold"] = 5000
gp["crystal"] = 200
gp["revive_charges"] = 2
gp["rebuild_count"] = 1
var click: Dictionary = gp.get("clickable", {})
click["active_uid"] = 7
click["next_uid"] = 8
click["reward_seed"] = 1 # pinned LCG seed: gate draw < ruby_gate, tier 10
gp["clickable"] = click
# Side/interactions fixtures: P01 tier 1, A001 milestone, echo-1 claim.
# These counters do not touch the CH gold/crystal gates asserted above.
gp["highest_node"] = 10
gp["completed_nodes"] = ["R1-C01-N01"]
gp["battle_wins"] = 6
ProfileStore.save_profile(gp)
shell.show_page_for_test("side")
shell.refresh_pages_for_test()
await _wait_frames(4)
# 1. Real touch on the Guild tab opens the mercenary/automation surface.
var guild_rect := await _scroll_and_rect(shell, "side_tab_guild")
_check(guild_rect != Rect2(), "%s: guild tab has no rect" % tag)
await _tap(guild_rect.get_center())
await _wait_frames(2)
var status := shell.ch_status_for_test()
_check(str(status.get("side_tab", "")) == "guild", "%s: guild tab touch did not switch tab" % tag)
var labels := _side_labels(shell)
var guild_word := "Guild" if locale == "en_US" else "佣兵"
_check(_contains(labels, guild_word), "%s: guild plain-language title missing (%s)" % [tag, guild_word])
_check(not _has_raw_key(labels), "%s: raw locale key visible in guild rows" % tag)
_record("guild_tab", {"case": tag, "tab": status.get("side_tab"), "rect": str(guild_rect)})
# 2. Real touch on Hire debits crystal and creates a slot.
var hire_rect := await _scroll_and_rect(shell, "ch_hire")
_check(hire_rect != Rect2(), "%s: hire button has no rect" % tag)
await _tap(hire_rect.get_center())
await _wait_frames(2)
var p := shell.get_profile()
_check((p.get("merc_quests", []) as Array).size() == 1, "%s: hire did not create a slot" % tag)
_check(int(p.get("crystal", 0)) == 160, "%s: hire must debit pinned 40 crystal" % tag)
await _close_modal(shell, tag)
# 3. Real touch on Buy creates an auto-clicker with the pinned gold price.
var buy_rect := await _scroll_and_rect(shell, "ch_buy_clicker")
_check(buy_rect != Rect2(), "%s: buy button has no rect" % tag)
await _tap(buy_rect.get_center())
await _wait_frames(2)
p = shell.get_profile()
var auto: Dictionary = p.get("autoclick", {})
_check(int(auto.get("owned", 0)) == 1, "%s: auto-clicker was not bought" % tag)
_check(int(p.get("gold", 0)) == 4000, "%s: first auto-clicker costs 1000 gold" % tag)
await _close_modal(shell, tag)
# 4. Real touch on Send starts the 300 s quest on the new slot.
var send_rect := await _scroll_and_rect(shell, "ch_quest_1_start")
_check(send_rect != Rect2(), "%s: send button has no rect" % tag)
await _tap(send_rect.get_center())
await _wait_frames(2)
p = shell.get_profile()
var slots: Array = p.get("merc_quests", [])
_check(not slots.is_empty() and not ((slots[0] as Dictionary).get("quest", {}) as Dictionary).is_empty(),
"%s: send did not start a quest" % tag)
await _close_modal(shell, tag)
_record("guild_actions", {"case": tag, "crystal": p.get("crystal"), "gold": p.get("gold"),
"owned": auto.get("owned"), "slots": slots.size()})
# 5. Real touch on the Bounties tab shows the CH achievement line.
var bounty_rect := await _scroll_and_rect(shell, "side_tab_bounties")
_check(bounty_rect != Rect2(), "%s: bounties tab has no rect" % tag)
await _tap(bounty_rect.get_center())
await _wait_frames(2)
status = shell.ch_status_for_test()
_check(str(status.get("side_tab", "")) == "bounties", "%s: bounties tab touch failed" % tag)
labels = _side_labels(shell)
var ach_word := "Rebuild" if locale == "en_US" else "重建"
_check(_contains(labels, ach_word), "%s: achievement plain-language line missing" % tag)
_check(not _has_raw_key(labels), "%s: raw locale key visible in bounties rows" % tag)
# 6. Real touch on the windfall claims the pinned tier and persists it.
var tap_rect := await _scroll_and_rect(shell, "ch_clickable")
_check(tap_rect != Rect2(), "%s: windfall claim button has no rect" % tag)
await _tap(tap_rect.get_center())
await _wait_frames(2)
p = shell.get_profile()
var claimed: Dictionary = p.get("clickable", {})
_check(int(claimed.get("active_uid", -1)) == 0, "%s: windfall was not consumed" % tag)
_check(int(p.get("crystal", 0)) == 170, "%s: tier 10 windfall must pay 10 crystal" % tag)
var reloaded := ProfileStore.load_profile()
_check(int((reloaded.get("clickable", {}) as Dictionary).get("active_uid", -1)) == 0,
"%s: windfall claim must persist" % tag)
_check(int(reloaded.get("crystal", 0)) == 170, "%s: windfall payout must persist" % tag)
await _close_modal(shell, tag)
_record("bounty_actions", {"case": tag, "crystal": p.get("crystal"),
"active_uid": claimed.get("active_uid"), "persisted": reloaded.get("crystal")})
# 7-9. Side/interactions claims through the same real touch path.
await _claim_flow(shell, tag, "partners", "_on_partner_claim", "P01",
"partner:P01", 20, 2, "partner_claim")
await _claim_flow(shell, tag, "records", "_on_record_claim", "A001",
"A001", 20, 1, "record_claim")
await _claim_flow(shell, tag, "interactions", "_on_echo_claim", "",
"echo-1", 30, 0, "lowfreq_echo")
# 10. Buoy lifecycle through the same real touch path (focused regression
# only, so the full 72-step matrix keeps its original claim coverage).
# start -> partial tap -> completion routed via _on_lowfreq_result.
if _mode == "lifecycle":
await _buoy_flow(shell, tag)
root_window.remove_child(shell)
shell.free()
await process_frame
## One claim row, end to end, with no direct callback. Scrolls a real enabled
## Button into view, touches it, checks the result modal, closes it with one
## real back touch, then verifies save/live agreement and exactly-once state
## (one reward entry, claim row no longer enabled).
func _claim_flow(shell: GameRoot, tag: String, tab: String, method: String,
bound_id: String, claim_key: String, gold_gain: int, crystal_gain: int,
label: String) -> void:
shell.set_side_tab_for_test(tab)
await _wait_frames(3)
var rect := await _scroll_and_side_rect(shell, method, bound_id)
_check(rect != Rect2(), "%s: %s claim row has no rect" % [tag, label])
if rect == Rect2():
return
var live0 := shell.get_profile()
var gold0 := int(live0.get("gold", 0))
var crystal0 := int(live0.get("crystal", 0))
var count0 := _claim_count(live0, claim_key)
await _tap(rect.get_center())
await _wait_frames(3)
_check(shell.get_modal_visible_for_test(), "%s: %s claim did not show modal" % [tag, label])
var live1 := shell.get_profile()
_check(int(live1.get("gold", 0)) == gold0 + gold_gain, "%s: %s gold delta" % [tag, label])
_check(int(live1.get("crystal", 0)) == crystal0 + crystal_gain,
"%s: %s crystal delta" % [tag, label])
_check(_claim_count(live1, claim_key) == count0 + 1,
"%s: %s claim recorded once" % [tag, label])
var stored := ProfileStore.load_profile()
_check(int(stored.get("gold", 0)) == int(live1.get("gold", 0)) \
and int(stored.get("crystal", 0)) == int(live1.get("crystal", 0)) \
and _claim_count(stored, claim_key) == _claim_count(live1, claim_key),
"%s: %s save/live mismatch" % [tag, label])
var back := shell.modal_button_center_for_test("side")
_check(back != Vector2.ZERO, "%s: %s modal has no back button" % [tag, label])
await _tap(back)
await _wait_frames(3)
_check(not shell.get_modal_visible_for_test(),
"%s: %s modal not closed by one back touch" % [tag, label])
# No duplicate claim: the claimed tier/milestone is no longer an enabled
# row, and one touch produced exactly one reward entry. Do not tap these
# coordinates again -- neighbouring rows (e.g. buoy) would legitimately
# occupy them after the claimed row is rebuilt.
var after_rect := shell.side_row_rect_for_test(method, bound_id)
_check(after_rect == Rect2(), "%s: %s row still claimable after touch" % [tag, label])
_record(label, {"case": tag, "tab": tab, "rect": str(rect),
"gold_gain": int(live1.get("gold", 0)) - gold0,
"crystal_gain": int(live1.get("crystal", 0)) - crystal0,
"claim_count": _claim_count(live1, claim_key),
"row_after": str(after_rect), "back_touches": 1})
## Buoy lifecycle through real InputEventScreenTouch, three phases:
## (1) start an inactive buoy, (2) one partial tap that saves but keeps it
## active, (3) taps to completion routed through _on_lowfreq_result. Every tap
## re-discovers the live row rect after the deferred rebuild; a freed row's
## coordinates are never reused, matching how a player really taps.
func _buoy_flow(shell: GameRoot, tag: String) -> void:
shell.set_side_tab_for_test("interactions")
await _wait_frames(3)
# (1) Start: fresh profile has buoy inactive with one tier available
# (battle_wins=6 => wins/4 = 1). The pressed row must be rebuilt off the
# emission frame, not freed inside Button.pressed.
var rect := await _scroll_and_side_rect(shell, "_on_buoy", "")
_check(rect != Rect2(), "%s: buoy start row has no rect" % tag)
if rect == Rect2():
return
var live0 := shell.get_profile()
_check(not bool((live0.get("buoy", {}) as Dictionary).get("active", false)),
"%s: buoy must start inactive" % tag)
var crystal0 := int(live0.get("crystal", 0))
await _tap(rect.get_center())
await _wait_frames(3)
var live1 := shell.get_profile()
var buoy1: Dictionary = live1.get("buoy", {})
_check(bool(buoy1.get("active", false)), "%s: buoy start did not activate" % tag)
_check(int(buoy1.get("taps", 0)) == 0, "%s: buoy start taps must be 0" % tag)
_check(not shell.get_modal_visible_for_test(), "%s: buoy start must not open modal" % tag)
_record("buoy_start", {"case": tag, "active": bool(buoy1.get("active", false)),
"taps": int(buoy1.get("taps", 0)), "modal": shell.get_modal_visible_for_test()})
# Do NOT tap rect again: the start refresh freed and rebuilt that row.
# (2) Partial tap: re-discover the row, one real touch, still active,
# save/live agreement, no modal.
rect = await _scroll_and_side_rect(shell, "_on_buoy", "")
_check(rect != Rect2(), "%s: buoy partial row has no rect" % tag)
if rect == Rect2():
return
await _tap(rect.get_center())
await _wait_frames(3)
var live2 := shell.get_profile()
var buoy2: Dictionary = live2.get("buoy", {})
_check(bool(buoy2.get("active", false)), "%s: buoy partial must stay active" % tag)
_check(int(buoy2.get("taps", 0)) == 1, "%s: buoy partial taps must be 1" % tag)
_check(not shell.get_modal_visible_for_test(), "%s: buoy partial must not open modal" % tag)
var stored2 := ProfileStore.load_profile()
_check(int((stored2.get("buoy", {}) as Dictionary).get("taps", 0)) == 1,
"%s: buoy partial tap must persist" % tag)
_record("buoy_partial_tap", {"case": tag, "active": bool(buoy2.get("active", false)),
"taps": int(buoy2.get("taps", 0)),
"persisted_taps": int((stored2.get("buoy", {}) as Dictionary).get("taps", 0))})
# Do NOT tap rect again: the partial tap saved and rebuilt that row.
# (3) Complete: keep re-discovering the row. The fifth tap returns done and
# routes through _on_lowfreq_result, which defers its refresh/modal pair.
var done := false
var liveN := live2
var taps := 0
for _i in range(8):
var r := await _scroll_and_side_rect(shell, "_on_buoy", "")
if r == Rect2():
break
await _tap(r.get_center())
await _wait_frames(3)
liveN = shell.get_profile()
taps += 1
if shell.get_modal_visible_for_test():
done = true
break
_check(done, "%s: buoy completion did not show result modal" % tag)
var buoyN: Dictionary = liveN.get("buoy", {})
_check(not bool(buoyN.get("active", false)), "%s: buoy must reset after completion" % tag)
_check(int(buoyN.get("taps", 0)) == 0, "%s: buoy taps must reset after completion" % tag)
_check(int(liveN.get("crystal", 0)) == crystal0 + 4, "%s: buoy must pay 4 crystal" % tag)
_check(_claim_count(liveN, "buoy-1") == 1, "%s: buoy claim recorded once" % tag)
var storedN := ProfileStore.load_profile()
_check(int(storedN.get("crystal", 0)) == int(liveN.get("crystal", 0)) \
and _claim_count(storedN, "buoy-1") == 1,
"%s: buoy completion save/live mismatch" % tag)
await _close_modal(shell, tag)
_record("buoy_complete", {"case": tag, "taps_after_partial": taps,
"crystal_gain": int(liveN.get("crystal", 0)) - crystal0,
"claim_count": _claim_count(liveN, "buoy-1"),
"active": bool(buoyN.get("active", false))})
func _claim_count(profile: Dictionary, key: String) -> int:
if key.begins_with("partner:"):
var pid := key.substr(key.find(":") + 1)
var raw = profile.get("partner_claims", {})
var claims: Dictionary = raw if raw is Dictionary else {}
return (claims.get(pid, []) as Array).size()
var raw2 = profile.get("claimed_rewards", [])
var list: Array = raw2 if raw2 is Array else []
var n := 0
for item in list:
if str(item) == key:
n += 1
return n
## Scroll a side-row Button into the visible viewport, then return its global
## rect. Mirrors _scroll_and_rect but locates the row by its live callback.
func _scroll_and_side_rect(shell: GameRoot, method: String, bound_id: String) -> Rect2:
var rect := shell.side_row_rect_for_test(method, bound_id)
if rect == Rect2():
return Rect2()
var viewport_size := get_root().get_visible_rect().size
var scroll := shell.find_side_scroll_for_test()
if scroll != null:
scroll.scroll_vertical = int(maxf(0.0, rect.position.y - viewport_size.y * 0.5))
await _wait_frames(2)
rect = shell.side_row_rect_for_test(method, bound_id)
if rect.position.x < 0.0 or rect.position.x + rect.size.x > viewport_size.x:
return Rect2()
if rect.position.y < 0.0 or rect.position.y + rect.size.y > viewport_size.y:
return Rect2()
return rect
func _contains(labels: Array, needle: String) -> bool:
for text in labels:
if str(text).contains(needle):
return true
return false
func _has_raw_key(labels: Array) -> bool:
for text in labels:
var s := str(text)
if s.begins_with("[shell.") or s.begins_with("[hud."):
return true
return false
func _side_labels(shell: GameRoot) -> Array:
var out: Array = []
var node := shell.find_side_scroll_for_test()
if node == null:
return out
_collect_labels(node, out)
return out
func _collect_labels(node: Node, out: Array) -> void:
if out.size() >= 80:
return
if node is Label:
out.append((node as Label).text)
elif node is Button and not str((node as Button).text).is_empty():
out.append((node as Button).text)
for child in node.get_children():
_collect_labels(child, out)
## Scroll a target into the visible viewport the same way a player would, then
## return its global rect. A real tap only lands on a fully visible control.
func _scroll_and_rect(shell: GameRoot, key: String) -> Rect2:
var rect := shell.ch_target_rect_for_test(key)
if rect == Rect2():
return Rect2()
var viewport_size := get_root().get_visible_rect().size
var scroll := shell.find_side_scroll_for_test()
if scroll != null:
scroll.scroll_vertical = int(maxf(0.0, rect.position.y - viewport_size.y * 0.5))
await _wait_frames(2)
rect = shell.ch_target_rect_for_test(key)
if rect.position.x < 0.0 or rect.position.x + rect.size.x > viewport_size.x:
return Rect2()
if rect.position.y < 0.0 or rect.position.y + rect.size.y > viewport_size.y:
return Rect2()
return rect
func _close_modal(shell: GameRoot, tag: String) -> void:
var center := shell.modal_button_center_for_test("side")
_check(center != Vector2.ZERO, "%s: result modal has no back button" % tag)
await _tap(center)
await _wait_frames(2)
_check(not shell.get_modal_visible_for_test(), "%s: modal did not close after touch" % tag)
func _wait_frames(count: int) -> void:
for _i in range(count):
await process_frame
await RenderingServer.frame_post_draw
func _tap(position: Vector2) -> void:
var down := InputEventScreenTouch.new()
down.index = 12
down.position = position
down.pressed = true
Input.parse_input_event(down)
await process_frame
await process_frame
var up := InputEventScreenTouch.new()
up.index = 12
up.position = position
up.pressed = false
Input.parse_input_event(up)
await process_frame
await process_frame
func _finish() -> void:
var passed := _problems.is_empty()
var report := {"schema": 1, "kind": "windroost_ch_systems_touch_test",
"input_method": "Input.parse_input_event(InputEventScreenTouch)",
"mode": _mode,
"matrix": {"sizes": ["360x800", "390x844", "430x932"], "locales": LOCALES, "reduced": REDUCED},
"overall": "PASS" if passed else "FAIL", "problems": _problems, "steps": _steps}
var dir := ProjectSettings.globalize_path("res://artifacts")
var env_dir := OS.get_environment("WN_SIDE_CLAIMS_OUT_DIR")
if not env_dir.is_empty():
dir = env_dir
DirAccess.make_dir_recursive_absolute(dir)
var out := FileAccess.open(dir.path_join("ch_systems_touch_test.json"), FileAccess.WRITE)
if out != null:
out.store_string(JSON.stringify(report, "\t", true))
out.close()
if passed:
print("CH_SYSTEMS_TOUCH_PASS %d real ScreenTouch cases verified" % _steps.size())
if _mode == "lifecycle":
print("SIDE_CLAIM_LIFECYCLE_PASS partner/record/LowFreq/buoy deferral regression")
else:
print("CH_SYSTEMS_TOUCH_FAIL %s" % "; ".join(_problems))
if _mode == "lifecycle":
print("SIDE_CLAIM_LIFECYCLE_FAIL %s" % "; ".join(_problems))
quit(0 if passed else 1)