Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a comprehensive pytest suite for the Manx plugin, aiming to cover the HTTP terminal API handlers, websocket terminal handler behavior, service initialization, and plugin hook registration.
Changes:
- Add new pytest test modules for
TermApi,Handle,TermService, andhook.enable. - Add a shared
conftest.pywith Caldera/aiohttp stubs and common fixtures/mocks. - Add
pytest.inito configure test discovery and asyncio behavior.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/conftest.py | Shared fixtures plus Caldera/aiohttp stubs and import-path bootstrapping for plugins.manx.*. |
| tests/test_term_api.py | Tests TermApi endpoint handlers and dynamically_compile behavior. |
| tests/test_h_terminal.py | Tests websocket Handle.run behavior: session resolution, report logging, JSON response format. |
| tests/test_term_svc.py | Tests TermService initialization and TCP contact selection behavior. |
| tests/test_hook.py | Tests plugin module attributes and enable() route/handle/payload registration. |
| pytest.ini | Configures pytest to run tests under tests/ with asyncio auto mode. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| auth_svc = AsyncMock() | ||
| file_svc = AsyncMock() | ||
| file_svc.find_file_path = AsyncMock(return_value=('manx', '/tmp/manx-pytest/shells/manx.go')) |
Comment on lines
+86
to
+112
| # aiohttp / aiohttp_jinja2 ------------------------------------------------ | ||
| if 'aiohttp' not in sys.modules: | ||
| aiohttp_mod = MagicMock() | ||
|
|
||
| class _FakeWebResponse: | ||
| def __init__(self, data=None, **kwargs): | ||
| self.data = data | ||
| self.body = json.dumps(data).encode() if data else b'' | ||
| self.content_type = 'application/json' | ||
|
|
||
| aiohttp_mod.web.json_response = lambda d: _FakeWebResponse(data=d) | ||
| aiohttp_mod.web.Response = _FakeWebResponse | ||
| sys.modules['aiohttp'] = aiohttp_mod | ||
| sys.modules['aiohttp.web'] = aiohttp_mod.web | ||
|
|
||
| if 'aiohttp_jinja2' not in sys.modules: | ||
| jinja2_mod = MagicMock() | ||
|
|
||
| def _fake_template(name): | ||
| """Decorator that just passes through the coroutine.""" | ||
| def decorator(fn): | ||
| return fn | ||
| return decorator | ||
|
|
||
| jinja2_mod.template = _fake_template | ||
| sys.modules['aiohttp_jinja2'] = jinja2_mod | ||
|
|
Comment on lines
+16
to
+39
| _repo_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||
| _plugins_root = os.path.dirname(_repo_root) # parent of manx-pytest | ||
|
|
||
| # We need "plugins.manx" to resolve. Create namespace package. | ||
| sys.path.insert(0, _plugins_root) | ||
|
|
||
| # Ensure the 'plugins' package exists as a namespace | ||
| import importlib | ||
| if 'plugins' not in sys.modules: | ||
| # Create a namespace package pointing to the parent dir | ||
| import types | ||
| plugins_pkg = types.ModuleType('plugins') | ||
| plugins_pkg.__path__ = [os.path.join(_plugins_root)] | ||
| plugins_pkg.__package__ = 'plugins' | ||
| sys.modules['plugins'] = plugins_pkg | ||
|
|
||
| # Ensure plugins.manx points to this repo | ||
| if 'plugins.manx' not in sys.modules: | ||
| import types | ||
| manx_pkg = types.ModuleType('plugins.manx') | ||
| manx_pkg.__path__ = [_repo_root] | ||
| manx_pkg.__package__ = 'plugins.manx' | ||
| sys.modules['plugins.manx'] = manx_pkg | ||
|
|
Comment on lines
+101
to
+105
| async def test_returns_json_response(self, api, mock_request): | ||
| resp = await api.get_sessions(mock_request()) | ||
| data = resp.data | ||
| assert 'sessions' in data | ||
|
|
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.
Summary
Test plan
pytest tests/ -vto verify all tests passpytest --cov=app tests/to verify coverage