Fix #395: physics_shape_autofit accepts Godot class names#400
Merged
Conversation
Closes #395. Normalize shape_type in physics_shape_handler.autofit so callers can pass either the short form ("box") or the matching Godot class name ("BoxShape3D"). This matches every other tool in the server — node_create, resource_manage(op="create"), etc. — and the natural shape an AI client finds via resource_get_info(type="Shape3D").concrete_subclasses. The error message for unknown shape_types now lists both forms so the next attempt picks a valid one. Cross-dim class names (e.g. RectangleShape2D for a CollisionShape3D) still error with VALUE_OUT_OF_RANGE — only short-form↔class-name within the same dimension is interchangeable. Tests: - test_physics_shape.gd: 5 regression tests for class-name input on 3D and 2D, cross-dim rejection, and unknown-class rejection. - test_runtime_handlers.py: contract test that the Python handler forwards class-name shape_type unchanged (normalization is plugin-side only). https://claude.ai/code/session_01RaCiJxQvK6KXtZqtL2t1gS
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the resource_manage(op="physics_shape_autofit") behavior so shape_type can be provided either as the existing short token form (e.g. box) or as the corresponding Godot concrete class name (e.g. BoxShape3D), matching how other tools accept types and aligning with resource_get_info(...).concrete_subclasses.
Changes:
- Added plugin-side normalization that maps Godot class names back to the existing short-form
shape_typetokens before sizing/creation logic. - Improved the invalid-
shape_typeerror message to list both short forms and their corresponding class names. - Added regression tests (GDScript + Python) covering class-name acceptance, cross-dimension rejection, and Python forwarding behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| plugin/addons/godot_ai/handlers/physics_shape_handler.gd | Normalizes shape_type to accept either short forms or matching Godot class names; enhances error output to include both forms. |
| src/godot_ai/tools/resource.py | Documents the expanded shape_type input forms for physics_shape_autofit in the tool description. |
| test_project/tests/test_physics_shape.gd | Adds regression tests for class-name inputs, cross-dimension rejection, and unknown class-name handling. |
| tests/unit/test_runtime_handlers.py | Adds a contract test ensuring the Python handler forwards class-name shape_type unchanged. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
The sphere variant exercises the same 3D class-name lookup branch as the box variant; removing it leaves box (3D) + rectangle (2D) + cross-dim reject + unknown reject, which already covers every distinct branch in the new normalization path. https://claude.ai/code/session_01RaCiJxQvK6KXtZqtL2t1gS
dsarno
added a commit
that referenced
this pull request
May 7, 2026
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #395.
Summary
physics_shape_autofitnow accepts either the short form (box,sphere, …) or the matching Godot class name (BoxShape3D,RectangleShape2D, …) forshape_type. Every other tool in the server takes Godot class names; an AI client introspecting viaresource_get_info(type="Shape3D")reaches for theconcrete_subclassesit sees and used to hitVALUE_OUT_OF_RANGE.Normalization is plugin-side only: in
physics_shape_handler.autofit, the lookup falls through to a values-table search before erroring. The Python handler still forwardsshape_typeverbatim. Cross-dim class names (e.g.RectangleShape2Dfor aCollisionShape3D) still error — only short-form↔class-name within the same dimension is interchangeable. The unknown-shape_typeerror message now lists both forms so the next attempt can pick a valid one.The
physics_shape_autofitop description inresource_managedocuments both forms.Test plan
ruff check src/ tests/clean (the 5 pre-existing format misses on beta are not in files I touched).pytest -q— 893 passed.script/ci-check-gdscript— all GDScript files OK.GODOT_AI_ALLOW_HEADLESS=1):test_run→ 1221/1237 passed, 0 failed;test_run suite=physics_shape→ 26/26 passed (the 5 new class-name regression tests included).git statusclean before commit).Tests added
test_physics_shape.gd:test_autofit_3d_accepts_godot_class_name—BoxShape3Dinput producesBoxShape3Doutput,shape_typeechoed back as the normalized"box".test_autofit_3d_accepts_sphere_class_name— same forSphereShape3D.test_autofit_2d_accepts_godot_class_name—RectangleShape2Dinput.test_autofit_3d_rejects_2d_class_name—RectangleShape2Dfor a 3D shape still errorsVALUE_OUT_OF_RANGE; error lists both forms.test_autofit_3d_rejects_unknown_class_name—TotallyMadeUpShape3Derrors.test_runtime_handlers.py::test_physics_shape_autofit_passes_class_name_unchanged— Python contract test confirming the class-name form forwards verbatim.https://claude.ai/code/session_01RaCiJxQvK6KXtZqtL2t1gS
Generated by Claude Code