ef21bf9d69
Two Godot --script-mode-only quirks, neither a bug in ApiClient itself (verified working against a real backend, health_check returns 200): 1. Bare autoload identifiers don't resolve at compile time in --script/ SceneTree runs (the node exists at runtime, root.has_node() is true, but referencing it as a plain global name fails to compile) -- use get_node() instead. 2. A freshly add_child()'d HTTPRequest isn't reliably "inside tree" yet at _initialize() time, since --script mode hasn't processed a frame yet -- one process_frame await fixes it. Verified: full smoke test now passes end-to-end against a live backend (docker compose postgres + alembic migrations + uvicorn), confirming ApiClient.health_check() genuinely round-trips. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
47 lines
1.7 KiB
GDScript
47 lines
1.7 KiB
GDScript
extends SceneTree
|
|
## Headless smoke test for the ApiClient autoload.
|
|
##
|
|
## Run with:
|
|
## godot --headless --path . --script res://scripts/smoke_test_api.gd
|
|
##
|
|
## Requires the backend to be running (default base URL
|
|
## `application/agp/api_base_url` -> http://127.0.0.1:8000).
|
|
##
|
|
## Calls the real autoload's `health_check()` (which exercises the generic
|
|
## `request()` primitive) and exits 0 on a `status == "ok"` response, 1
|
|
## otherwise. This script is intentionally NOT wired into any game scene.
|
|
|
|
|
|
func _initialize() -> void:
|
|
_run()
|
|
|
|
|
|
func _run() -> void:
|
|
# _initialize() fires before the SceneTree has processed its first frame,
|
|
# so a freshly add_child()'d HTTPRequest node isn't reliably considered
|
|
# "inside tree" yet (request_raw fails with !is_inside_tree()). One frame
|
|
# of delay is enough; this only matters for --script mode, not a real
|
|
# running game.
|
|
await process_frame
|
|
|
|
# Godot's --script/SceneTree runner doesn't resolve autoload singletons
|
|
# as bare global identifiers at compile time (the node exists at
|
|
# runtime -- root.has_node("ApiClient") is true -- but referencing it as
|
|
# a plain identifier fails with "Identifier not found: ApiClient" during
|
|
# script compilation). get_node sidesteps compile-time resolution
|
|
# entirely. This only affects --script mode; a real game scene resolves
|
|
# the bare autoload name normally.
|
|
var api_client := root.get_node("ApiClient")
|
|
print("SMOKE: calling ApiClient.health_check() ...")
|
|
var result: Dictionary = await api_client.health_check()
|
|
print("SMOKE: result = ", result)
|
|
|
|
if result.ok \
|
|
and result.data is Dictionary \
|
|
and str((result.data as Dictionary).get("status", "")) == "ok":
|
|
print("SMOKE RESULT: PASS (status=ok)")
|
|
quit(0)
|
|
else:
|
|
printerr("SMOKE RESULT: FAIL")
|
|
quit(1)
|