Compare commits

...

3 Commits

Author SHA1 Message Date
VinPropane a8cedcbd64 NEO-74: Repopulate recipe panel when item defs load.
Run craft panel refresh before inventory-error guard in
_on_item_definitions_ready so display names resolve even when
inventory GET failed first.
2026-05-24 20:21:37 -04:00
VinPropane d6d95ec438 NEO-74: Fix craft busy flag ordering; drop unused recipe helpers.
Set _busy before HTTP request so sync mock completion cannot leave the
client stuck busy; remove uncalled recipes_snapshot/recipe_by_id; add
GdUnit guard for is_busy after sync response.
2026-05-24 20:14:05 -04:00
VinPropane f939132f38 NEO-74: Fix recipe client HTTP error test signal capture.
Use got-array lambda pattern; GDScript cannot assign outer locals from
signal callbacks, which left failed_reason empty in CI GdUnit runs.
2026-05-24 20:05:22 -04:00
5 changed files with 20 additions and 19 deletions

View File

@ -40,6 +40,7 @@ func request_craft(recipe_id: String, quantity: int = 1) -> bool:
if rid.is_empty():
return false
_current_recipe_id = rid
_busy = true
var payload: Dictionary = {
"schemaVersion": SCHEMA_VERSION,
"recipeId": rid,
@ -49,10 +50,10 @@ func request_craft(recipe_id: String, quantity: int = 1) -> bool:
var headers := PackedStringArray(["Content-Type: application/json"])
var err: Error = _http.request(url, headers, HTTPClient.METHOD_POST, JSON.stringify(payload))
if err != OK:
_busy = false
_current_recipe_id = ""
push_warning("CraftClient: POST failed to start (%s)" % err)
return false
_busy = true
return true

View File

@ -366,11 +366,11 @@ func _apply_authority_http_config_to_client(client: Node) -> void:
func _on_item_definitions_ready(_definitions_by_id: Dictionary) -> void:
_populate_craft_recipe_panel_if_ready()
if not _inventory_error.is_empty():
return
if not _last_inventory_snapshot.is_empty():
_render_inventory_label()
_populate_craft_recipe_panel_if_ready()
func _on_inventory_received(snapshot: Dictionary) -> void:

View File

@ -41,20 +41,6 @@ func request_sync_from_server() -> void:
recipes_sync_failed.emit(reason)
func recipes_snapshot() -> Array:
return _recipes.duplicate(true)
func recipe_by_id(recipe_id: String) -> Dictionary:
for row_variant in _recipes:
if not row_variant is Dictionary:
continue
var row: Dictionary = row_variant
if str(row.get("id", "")) == recipe_id:
return row.duplicate(true)
return {}
func _base_root() -> String:
return base_url.strip_edges().rstrip("/")

View File

@ -130,3 +130,15 @@ func test_http_error_emits_craft_request_failed() -> void:
c.call("request_craft", "refine_scrap_standard")
# Assert
assert_that(_failed_reason).contains("404")
func test_request_craft_clears_busy_after_sync_mock_response() -> void:
# Arrange
var transport := MockHttpTransport.new()
transport.body_json = _success_craft_json()
var c := _make_client(transport)
# Act
var started: bool = bool(c.call("request_craft", "refine_scrap_standard", 1))
# Assert
assert_that(started).is_true()
assert_that(bool(c.call("is_busy"))).is_false()

View File

@ -1,6 +1,7 @@
extends GdUnitTestSuite
## NEO-74: `RecipeDefinitionsClient` GET parse + `recipes_ready` signal.
## `main.gd` repopulates craft panel on item `definitions_ready` even when inventory GET failed.
const RecipeDefinitionsClient := preload("res://scripts/recipe_definitions_client.gd")
@ -102,9 +103,10 @@ func test_http_error_emits_recipes_sync_failed_with_status() -> void:
var transport := MockHttpTransport.new()
transport.response_code = 503
var c := _make_client(transport)
var failed_reason := ""
c.connect("recipes_sync_failed", func(reason: String) -> void: failed_reason = reason)
var got: Array = []
c.connect("recipes_sync_failed", func(reason: String) -> void: got.append(reason))
# Act
c.call("request_sync_from_server")
# Assert
assert_that(failed_reason).contains("503")
assert_that(got.size()).is_equal(1)
assert_that(str(got[0])).contains("503")