-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: restructure adapter invocation logic #71
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
Merged
touale
merged 5 commits into
master
from
70-typeerror-deploymenthandle-object-is-not-callable-after-upgrading-framex-kit-to-012b1
Feb 9, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e547ef1
refactor: restructure adapter invocation logic
2903d02
chore: add type ignore for ray imports
7d1c888
test: add comprehensive adapter tests
4226667
chore: update uv sync to include ray extra
29bb840
test: add type ignore for remote function
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
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
Empty file.
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,112 @@ | ||
| """Tests for framex.adapter.__init__ module.""" | ||
|
|
||
| from unittest.mock import MagicMock, patch | ||
|
|
||
| from framex.adapter import get_adapter | ||
| from framex.adapter.base import BaseAdapter | ||
| from framex.adapter.local_adapter import LocalAdapter | ||
|
|
||
|
|
||
| class TestGetAdapter: | ||
| """Tests for the get_adapter factory function.""" | ||
|
|
||
| def setup_method(self): | ||
| """Reset the global adapter before each test.""" | ||
| import framex.adapter as adapter_module | ||
|
|
||
| adapter_module._adapter = None | ||
|
|
||
| def test_get_adapter_returns_local_adapter_when_ray_disabled(self): | ||
| """Test get_adapter returns LocalAdapter when use_ray is False.""" | ||
| with patch("framex.adapter.settings.server.use_ray", False): | ||
| adapter = get_adapter() | ||
| assert isinstance(adapter, LocalAdapter) | ||
| assert isinstance(adapter, BaseAdapter) | ||
|
|
||
| def test_get_adapter_returns_ray_adapter_when_ray_enabled(self): | ||
| """Test get_adapter returns RayAdapter when use_ray is True.""" | ||
| with ( | ||
| patch("framex.adapter.settings.server.use_ray", True), | ||
| patch("framex.adapter.ray_adapter.RayAdapter") as mock_ray_adapter, | ||
| ): | ||
| mock_instance = MagicMock() | ||
| mock_ray_adapter.return_value = mock_instance | ||
|
|
||
| adapter = get_adapter() | ||
| assert adapter == mock_instance | ||
| mock_ray_adapter.assert_called_once() | ||
|
|
||
| def test_get_adapter_returns_same_instance_on_multiple_calls(self): | ||
| """Test get_adapter returns the same singleton instance.""" | ||
| with patch("framex.adapter.settings.server.use_ray", False): | ||
| adapter1 = get_adapter() | ||
| adapter2 = get_adapter() | ||
| assert adapter1 is adapter2 | ||
|
|
||
| def test_get_adapter_caches_local_adapter(self): | ||
| """Test that LocalAdapter is cached after first call.""" | ||
| with patch("framex.adapter.settings.server.use_ray", False): | ||
| adapter1 = get_adapter() | ||
| # Second call should return cached instance | ||
| adapter2 = get_adapter() | ||
| assert adapter1 is adapter2 | ||
| assert isinstance(adapter1, LocalAdapter) | ||
|
|
||
| def test_get_adapter_caches_ray_adapter(self): | ||
| """Test that RayAdapter is cached after first call.""" | ||
| with ( | ||
| patch("framex.adapter.settings.server.use_ray", True), | ||
| patch("framex.adapter.ray_adapter.RayAdapter") as mock_ray_adapter, | ||
| ): | ||
| mock_instance = MagicMock() | ||
| mock_ray_adapter.return_value = mock_instance | ||
|
|
||
| adapter1 = get_adapter() | ||
| adapter2 = get_adapter() | ||
|
|
||
| # Should only instantiate once | ||
| assert adapter1 is adapter2 | ||
| assert mock_ray_adapter.call_count == 1 | ||
|
|
||
| def test_get_adapter_lazy_imports_ray_adapter(self): | ||
| """Test that RayAdapter is only imported when needed.""" | ||
| with patch("framex.adapter.settings.server.use_ray", False): # noqa | ||
| # Import should not happen when use_ray is False | ||
| with patch("framex.adapter.ray_adapter") as mock_ray_module: | ||
| get_adapter() | ||
| # RayAdapter module should not be accessed | ||
| mock_ray_module.RayAdapter.assert_not_called() | ||
|
|
||
| def test_adapter_initially_none(self): | ||
| """Test that _adapter global is None before first call.""" | ||
| import framex.adapter as adapter_module | ||
|
|
||
| adapter_module._adapter = None | ||
| assert adapter_module._adapter is None | ||
|
|
||
| def test_adapter_set_after_first_call(self): | ||
| """Test that _adapter global is set after first call.""" | ||
| import framex.adapter as adapter_module | ||
|
|
||
| adapter_module._adapter = None | ||
| with patch("framex.adapter.settings.server.use_ray", False): | ||
| get_adapter() | ||
| assert adapter_module._adapter is not None | ||
| assert isinstance(adapter_module._adapter, LocalAdapter) | ||
|
|
||
| def test_get_adapter_with_switching_ray_setting(self): | ||
| """Test that once adapter is set, changing ray setting doesn't affect it.""" | ||
| import framex.adapter as adapter_module | ||
|
|
||
| adapter_module._adapter = None | ||
|
|
||
| with patch("framex.adapter.settings.server.use_ray", False): | ||
| adapter1 = get_adapter() | ||
| assert isinstance(adapter1, LocalAdapter) | ||
|
|
||
| # Change setting, but adapter should still be the same | ||
| with patch("framex.adapter.settings.server.use_ray", True): | ||
| adapter2 = get_adapter() | ||
| # Should still be the same LocalAdapter instance | ||
| assert adapter2 is adapter1 | ||
| assert isinstance(adapter2, LocalAdapter) |
Oops, something went wrong.
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.
🧩 Analysis chain
🏁 Script executed:
Repository: touale/FrameX-kit
Length of output: 3356
🏁 Script executed:
Repository: touale/FrameX-kit
Length of output: 394
🏁 Script executed:
Repository: touale/FrameX-kit
Length of output: 860
🏁 Script executed:
Repository: touale/FrameX-kit
Length of output: 43
🏁 Script executed:
Repository: touale/FrameX-kit
Length of output: 2984
🏁 Script executed:
Repository: touale/FrameX-kit
Length of output: 43
🏁 Script executed:
Repository: touale/FrameX-kit
Length of output: 3112
🏁 Script executed:
Repository: touale/FrameX-kit
Length of output: 43
🏁 Script executed:
Repository: touale/FrameX-kit
Length of output: 3419
🏁 Script executed:
Repository: touale/FrameX-kit
Length of output: 43
🏁 Script executed:
Repository: touale/FrameX-kit
Length of output: 45
🏁 Script executed:
Repository: touale/FrameX-kit
Length of output: 43
RayAdapter._call is reachable but broken for sync remote methods.
When
get_handle_funccallsgetattr(deployment_handle, func_name)on a RayDeploymentHandle, it returns a method reference—not anotherDeploymentHandle. For a sync (non-async) method on a Ray deployment:isinstance(func, DeploymentHandle)→ Falseinspect.iscoroutinefunction(func)→ False_callHowever, the current
_callimplementation (return func(**kwargs)) is incorrect for Ray. Ray method references require.remote()to execute remotely (see_acall'sfunc.remote(**kwargs)). Callingfunc(**kwargs)directly will fail at runtime because it attempts local execution instead of remote execution.The
_callpath should either:.remote()like_acalldoes, or🤖 Prompt for AI Agents