kitbash_assembly.py: a closure check that finds no closure fails by name instead of raising

Mutant J5 (occupant ignores closures) ended the script on an AttributeError
before any check printed; it now dies on the three occupancy refusals.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-12-01 19:17:56 +01:00
commit dc8dcdb0c3

View file

@ -310,6 +310,10 @@ def closure_of(name):
return report["parts"][0]["closure"] if report else {"error": receipt["message"]}
def closure_row(name):
return closure_of(name) or {}
def without_closures(state):
return {name: (*row[:3], {k: v for k, v in row[3].items() if not k.startswith("kit_close")}, *row[4:]) for name, row in state[0].items()}, state[1]
@ -360,14 +364,14 @@ refused("close of a socket the part does not have", "brokkr_kitbash.close", {"ob
"part 'strut' has no socket 'end_c'")
was = np.array(brace.matrix_world)
receipt, report = send("brokkr_kitbash.set_params", object_name="Leg", params="extension=0.3")
found = closure_of("Brace")
found = closure_row("Brace")
check("set_params that moves the leg's rod pin is accepted and moves no brace: the closure reads holds false with the rod's travel, here and in the report's closures",
receipt["status"] == "accepted" and report and report["closures"] == [{"part": "Brace", "to": "Leg", "holds": False}] and report["closure"] is None
and found["holds"] is False and 0.05 < found["residual"] <= 0.15 + 1e-5 and np.array_equal(np.array(brace.matrix_world), was)
and holds("Brace", "Lower", "end_a", "pivot", connection("Brace")["roll"])[0], [receipt["message"], report and report.get("closures"), found])
receipt, report = send("brokkr_kitbash.set_params", object_name="Leg", params="extension=0.15")
check("and with the rod back the closure holds again: it is read from where the parts stand, not stored", receipt["status"] == "accepted"
and report["closures"] == [{"part": "Brace", "to": "Leg", "holds": True}] and closure_of("Brace")["holds"] is True, [report and report.get("closures"), closure_of("Brace")])
and report["closures"] == [{"part": "Brace", "to": "Leg", "holds": True}] and closure_row("Brace").get("holds") is True, [report and report.get("closures"), closure_of("Brace")])
refused("set_params on the part a closure names, to a size its pin no longer mates", "brokkr_kitbash.set_params", {"object_name": "Leg", "params": "body_r=0.07"},
"'Brace' closing on 'Leg': socket 'end_b' (pivot, size 0.054) and parent socket 'rod_end' (pivot, size 0.063)")
refused("set_params on the closing part, to a size its pin no longer mates", "brokkr_kitbash.set_params", {"object_name": "Brace", "params": "width=0.1"},
@ -383,16 +387,16 @@ check("detach clears the brace's closure with its connection, and it stays where
and report["connection"] is None and not [k for k in brace.keys() if k.startswith(("kit_close", "kit_socket", "kit_parent", "kit_roll"))] and brace.parent is None
and reading("kept", np.abs(np.array(brace.matrix_world) - before).max()) < KEPT, [receipt["message"], dict(brace.items())])
receipt, report = send("brokkr_kitbash.close", **CLOSING)
check("a loose part that meets a socket may state a closure too", receipt["status"] == "accepted" and report["closure"]["holds"] is True and report["connection"] is None, receipt["message"])
check("a loose part that meets a socket may state a closure too", receipt["status"] == "accepted" and report and report["closure"]["holds"] is True and report["connection"] is None, receipt["message"])
leg.name = "Shin"
found = closure_of("Brace")
found = closure_row("Brace")
check("a closure follows its other part through a rename", found.get("to") == "Shin" and found.get("holds") is True, found)
leg.name = "Leg"
send("brokkr_kitbash.detach", object_name="Leg")
bpy.data.objects.remove(leg)
found = closure_of("Brace")
found = closure_row("Brace")
receipt, report = send("brokkr_kitbash.set_params", object_name="Brace", params="length=1.0")
check("a closure whose other part is gone reads to null and holds false, and set_params on the closing part still works", found == {**found, "to": None, "residual": None, "holds": False}
check("a closure whose other part is gone reads to null and holds false, and set_params on the closing part still works", found and found == {**found, "to": None, "residual": None, "holds": False}
and found.get("toSocket") == "rod_end" and receipt["status"] == "accepted" and report["closures"] == [{"part": "Brace", "to": None, "holds": False}], [found, receipt["message"]])
before = np.array(brace.matrix_world)
receipt, report = send("brokkr_kitbash.detach", object_name="Brace")