|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
5 | 5 | import asyncio |
6 | | -import sys |
7 | | -import types |
8 | 6 | from typing import Any |
9 | 7 | from unittest.mock import AsyncMock, MagicMock, patch |
10 | 8 |
|
@@ -163,59 +161,25 @@ async def test_returns_true_when_all_strategies_succeed() -> None: |
163 | 161 |
|
164 | 162 |
|
165 | 163 | @pytest.mark.asyncio |
166 | | -async def test_serve_command_handler_calls_start_daemon_services() -> None: |
167 | | - """The REST serve path invokes orb_app.start_daemon_services() after initialize |
168 | | - completes successfully.""" |
169 | | - # Build lightweight stand-in modules for all heavy local-import targets |
170 | | - # so the handler never reaches actual DI / file-system code. |
171 | | - fake_uvicorn = types.ModuleType("uvicorn") |
172 | | - fake_server = AsyncMock() |
173 | | - fake_server.serve = AsyncMock(return_value=None) |
174 | | - fake_uvicorn.Server = MagicMock(return_value=fake_server) |
175 | | - fake_uvicorn.Config = MagicMock(return_value=MagicMock()) |
176 | | - |
177 | | - fake_fastapi_app = MagicMock() |
178 | | - |
| 164 | +async def test_server_initialize_application_calls_start_daemon_services() -> None: |
| 165 | + """The REST server initialisation path invokes orb_app.start_daemon_services() |
| 166 | + after Application.initialize() completes successfully.""" |
179 | 167 | fake_app = MagicMock() |
180 | 168 | fake_app.initialize = AsyncMock(return_value=True) |
181 | 169 | fake_app.start_daemon_services = AsyncMock(return_value=True) |
182 | 170 |
|
183 | | - fake_server_config = MagicMock() |
184 | | - fake_server_config.host = "127.0.0.1" |
185 | | - fake_server_config.port = 8000 |
186 | | - fake_server_config.workers = 1 |
187 | | - fake_server_config.log_level = "info" |
188 | | - |
189 | 171 | fake_container = MagicMock() |
190 | 172 | fake_config_manager = MagicMock() |
191 | | - fake_config_manager.get_typed_with_defaults.return_value = fake_server_config |
192 | 173 | fake_config_manager._config_file = None |
193 | 174 | fake_container.get.return_value = fake_config_manager |
194 | 175 |
|
195 | 176 | with ( |
196 | 177 | patch("orb.infrastructure.di.container.get_container", return_value=fake_container), |
197 | | - patch("orb.api.server.create_fastapi_app", return_value=fake_fastapi_app), |
198 | 178 | patch("orb.bootstrap.Application", return_value=fake_app), |
199 | 179 | ): |
200 | | - # Inject uvicorn as a temporary sys.modules entry so the try/import |
201 | | - # inside handle_serve_api succeeds without the real package. |
202 | | - sys.modules.setdefault("uvicorn", fake_uvicorn) |
203 | | - try: |
204 | | - from orb.interface.serve_command_handler import handle_serve_api # noqa: PLC0415 |
205 | | - |
206 | | - args = MagicMock() |
207 | | - args.host = "127.0.0.1" |
208 | | - args.port = 8000 |
209 | | - args.workers = 1 |
210 | | - args.reload = False |
211 | | - args.server_log_level = "info" |
212 | | - args.socket_path = None |
213 | | - args.scheduler = None |
214 | | - |
215 | | - await handle_serve_api(args) |
216 | | - finally: |
217 | | - # Only remove if we added it (it was setdefault above). |
218 | | - pass |
| 180 | + from orb.interface.server_command_handlers import _initialize_application # noqa: PLC0415 |
| 181 | + |
| 182 | + await _initialize_application() |
219 | 183 |
|
220 | 184 | fake_app.start_daemon_services.assert_awaited_once() |
221 | 185 |
|
|
0 commit comments