from engine.character import BodyPart, Character def test_get_body_part_falls_back_to_default_when_missing(): character = Character( default_body_parts=[ BodyPart("head", "human_head"), BodyPart("torso", "human_torso"), ], ) assert character.get_body_part("head").part_def_id == "human_head" assert character.get_body_part("torso").part_def_id == "human_torso" def test_get_body_part_prefers_explicit_override_over_default(): character = Character( body_parts=[BodyPart("head", "human_head_hat")], default_body_parts=[ BodyPart("head", "human_head"), BodyPart("torso", "human_torso"), ], ) assert character.get_body_part("head").part_def_id == "human_head_hat" assert character.get_body_part("torso").part_def_id == "human_torso" # still falls back def test_get_body_part_returns_none_for_unknown_slot(): character = Character(default_body_parts=[BodyPart("head", "human_head")]) assert character.get_body_part("left_arm") is None def test_resolved_body_parts_covers_union_of_both_arrays(): character = Character( body_parts=[BodyPart("head", "human_head_hat")], default_body_parts=[ BodyPart("head", "human_head"), BodyPart("torso", "human_torso"), BodyPart("left_arm", "human_left_arm"), ], ) resolved = character.resolved_body_parts() assert resolved["head"].part_def_id == "human_head_hat" assert resolved["torso"].part_def_id == "human_torso" assert resolved["left_arm"].part_def_id == "human_left_arm" assert set(resolved.keys()) == {"head", "torso", "left_arm"}