Skip to content

Fix #395: physics_shape_autofit accepts Godot class names#400

Merged
dsarno merged 2 commits into
betafrom
claude/issue-395-physics-shape-class-name
May 7, 2026
Merged

Fix #395: physics_shape_autofit accepts Godot class names#400
dsarno merged 2 commits into
betafrom
claude/issue-395-physics-shape-class-name

Conversation

@dsarno

@dsarno dsarno commented May 6, 2026

Copy link
Copy Markdown
Contributor

Closes #395.

Summary

physics_shape_autofit now accepts either the short form (box, sphere, …) or the matching Godot class name (BoxShape3D, RectangleShape2D, …) for shape_type. Every other tool in the server takes Godot class names; an AI client introspecting via resource_get_info(type="Shape3D") reaches for the concrete_subclasses it sees and used to hit VALUE_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 forwards shape_type verbatim. Cross-dim class names (e.g. RectangleShape2D for a CollisionShape3D) still error — only short-form↔class-name within the same dimension is interchangeable. The unknown-shape_type error message now lists both forms so the next attempt can pick a valid one.

The physics_shape_autofit op description in resource_manage documents 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.
  • Live editor (headless via 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).
  • No autosave pollution after smoke run (git status clean before commit).

Tests added

  • test_physics_shape.gd:
    • test_autofit_3d_accepts_godot_class_nameBoxShape3D input produces BoxShape3D output, shape_type echoed back as the normalized "box".
    • test_autofit_3d_accepts_sphere_class_name — same for SphereShape3D.
    • test_autofit_2d_accepts_godot_class_nameRectangleShape2D input.
    • test_autofit_3d_rejects_2d_class_nameRectangleShape2D for a 3D shape still errors VALUE_OUT_OF_RANGE; error lists both forms.
    • test_autofit_3d_rejects_unknown_class_nameTotallyMadeUpShape3D errors.
  • 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

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
Copilot AI review requested due to automatic review settings May 6, 2026 23:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_type tokens before sizing/creation logic.
  • Improved the invalid-shape_type error 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

codecov Bot commented May 6, 2026

Copy link
Copy Markdown

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 dsarno merged commit fd09035 into beta May 7, 2026
11 checks passed
@dsarno dsarno deleted the claude/issue-395-physics-shape-class-name branch May 7, 2026 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants