-
Notifications
You must be signed in to change notification settings - Fork 998
feat: add open prefab stage editor action #947
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| """Tests for the manage_editor tool surface.""" | ||
|
|
||
| import inspect | ||
|
|
||
| import pytest | ||
|
|
||
| import services.tools.manage_editor as manage_editor_mod | ||
| from services.registry import get_registered_tools | ||
| from .integration.test_helpers import DummyContext | ||
|
|
||
|
|
||
| def test_manage_editor_prefab_path_parameters_exist(): | ||
| """open_prefab_stage should expose prefab_path plus path alias parameters.""" | ||
| sig = inspect.signature(manage_editor_mod.manage_editor) | ||
| assert "prefab_path" in sig.parameters | ||
| assert "path" in sig.parameters | ||
| assert sig.parameters["prefab_path"].default is None | ||
| assert sig.parameters["path"].default is None | ||
|
|
||
|
|
||
| def test_manage_editor_description_mentions_open_prefab_stage(): | ||
| """The tool description should advertise the new prefab stage action.""" | ||
| editor_tool = next( | ||
| (t for t in get_registered_tools() if t["name"] == "manage_editor"), None | ||
| ) | ||
| assert editor_tool is not None | ||
| desc = editor_tool.get("description") or editor_tool.get("kwargs", {}).get("description", "") | ||
| assert "open_prefab_stage" in desc | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_manage_editor_open_prefab_stage_forwards_prefab_path(monkeypatch): | ||
| """prefab_path should map to Unity's prefabPath parameter.""" | ||
| captured = {} | ||
|
|
||
| async def fake_send(cmd, params, **kwargs): | ||
| captured["cmd"] = cmd | ||
| captured["params"] = params | ||
| return {"success": True, "data": {"openedPrefabPath": params["prefabPath"]}} | ||
|
|
||
| monkeypatch.setattr( | ||
| manage_editor_mod, | ||
| "async_send_command_with_retry", | ||
| fake_send, | ||
| ) | ||
|
|
||
| resp = await manage_editor_mod.manage_editor( | ||
| ctx=DummyContext(), | ||
| action="open_prefab_stage", | ||
| prefab_path="Assets/Prefabs/Test.prefab", | ||
| ) | ||
|
|
||
| assert resp.get("success") is True | ||
| assert captured["cmd"] == "manage_editor" | ||
| assert captured["params"]["action"] == "open_prefab_stage" | ||
| assert captured["params"]["prefabPath"] == "Assets/Prefabs/Test.prefab" | ||
| assert "path" not in captured["params"] | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_manage_editor_open_prefab_stage_accepts_path_alias(monkeypatch): | ||
| """path should remain available as a compatibility alias.""" | ||
| captured = {} | ||
|
|
||
| async def fake_send(cmd, params, **kwargs): | ||
| captured["params"] = params | ||
| return {"success": True} | ||
|
|
||
| monkeypatch.setattr( | ||
| manage_editor_mod, | ||
| "async_send_command_with_retry", | ||
| fake_send, | ||
| ) | ||
|
|
||
| resp = await manage_editor_mod.manage_editor( | ||
| ctx=DummyContext(), | ||
| action="open_prefab_stage", | ||
| path="Assets/Prefabs/Alias.prefab", | ||
| ) | ||
|
|
||
| assert resp.get("success") is True | ||
| assert captured["params"]["action"] == "open_prefab_stage" | ||
| assert captured["params"]["path"] == "Assets/Prefabs/Alias.prefab" | ||
| assert "prefabPath" not in captured["params"] | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_manage_editor_open_prefab_stage_rejects_conflicting_path_inputs(monkeypatch): | ||
| """Conflicting aliases should fail fast before sending a Unity command.""" | ||
|
|
||
| async def fake_send(cmd, params, **kwargs): # pragma: no cover - should not be hit | ||
| raise AssertionError("send should not be called for conflicting path inputs") | ||
|
|
||
| monkeypatch.setattr( | ||
| manage_editor_mod, | ||
| "async_send_command_with_retry", | ||
| fake_send, | ||
| ) | ||
|
|
||
| resp = await manage_editor_mod.manage_editor( | ||
| ctx=DummyContext(), | ||
| action="open_prefab_stage", | ||
| prefab_path="Assets/Prefabs/Primary.prefab", | ||
| path="Assets/Prefabs/Alias.prefab", | ||
| ) | ||
|
|
||
| assert resp.get("success") is False | ||
| assert "Provide only one of prefab_path or path" in resp.get("message", "") |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not return success before prefab stage entry is confirmed.
At Line 417, success is returned even when
enteredPrefabStageisfalse(Line 420 message). That can break callers that issue immediate prefab-stage operations after a “successful” open.Suggested fix
As per coding guidelines, "C# async tool handlers must use
EditorApplication.updatepolling withTaskCompletionSourcepattern as shown in RefreshUnity.cs".📝 Committable suggestion
🤖 Prompt for AI Agents