Self-improving AI Employees for everyone
Python ai-agentsai-employeeai-employeesassistantautonomous-agentsco-employeescompanygrok-botinstinctloop-agentsmuseown-your-datapersonalself-hosted
test(scaling): retarget remaining patch paths for plugin architecture
trohitg2066aa4a1473
diff --git a/server/tests/nodes/test_code_fs_process.py b/server/tests/nodes/test_code_fs_process.pyindex e78bdeca..0b39dd80 100644--- a/server/tests/nodes/test_code_fs_process.py+++ b/server/tests/nodes/test_code_fs_process.py@@ -17,7 +17,7 @@ Mocking strategy:- filesystem nodes (fileRead, fileModify, shell, fsSearch): patchservices.handlers.filesystem._get_backend to return a fake backend withthe methods each mode invokes.- - processManager: patch services.handlers.process.get_process_service to+ - processManager: patch services.process_service.get_process_service toreturn a fake ProcessService with the dispatched method set to anAsyncMock / MagicMock."""@@ -39,14 +39,17 @@ pytestmark = pytest.mark.node_contractdef _reset_nodejs_singleton():- """Clear the module-level client singleton in services.handlers.code.+ """Clear the module-level client singleton in nodes.code._nodejs.- The handler caches its NodeJSClient on first use; tests that patch must+ The plugin caches its NodeJSClient on first use; tests that patch musteither reset this between cases or patch the module attribute directly."""- import services.handlers.code as code_mod+ try:+ import nodes.code._nodejs as code_mod- code_mod._nodejs_client = None+ code_mod._client = None # scaling-branch singleton name+ except (ImportError, AttributeError):+ passclass _FakeWriteResult(SimpleNamespace):@@ -69,9 +72,9 @@ class _FakeFileInfo(dict):def _patch_fs_backend(backend: MagicMock):- """Patch services.handlers.filesystem._get_backend to return a fake."""+ """Patch nodes.filesystem._backend.get_backend (shared by all 4 fs plugins)."""return patch(- "services.handlers.filesystem._get_backend",+ "nodes.filesystem._backend.get_backend",return_value=backend,)@@ -157,7 +160,7 @@ class TestJavascriptExecutor:)with patch(- "services.handlers.code.get_nodejs_client",+ "nodes.code._nodejs.get_nodejs_client",return_value=fake_client,):result = await harness.execute(@@ -200,7 +203,7 @@ class TestJavascriptExecutor:)with patch(- "services.handlers.code.get_nodejs_client",+ "nodes.code._nodejs.get_nodejs_client",return_value=fake_client,):result = await harness.execute(@@ -220,7 +223,7 @@ class TestJavascriptExecutor:)with patch(- "services.handlers.code.get_nodejs_client",+ "nodes.code._nodejs.get_nodejs_client",return_value=fake_client,):result = await harness.execute(@@ -249,7 +252,7 @@ class TestTypescriptExecutor:)with patch(- "services.handlers.code.get_nodejs_client",+ "nodes.code._nodejs.get_nodejs_client",return_value=fake_client,):result = await harness.execute(@@ -282,7 +285,7 @@ class TestTypescriptExecutor:)with patch(- "services.handlers.code.get_nodejs_client",+ "nodes.code._nodejs.get_nodejs_client",return_value=fake_client,):result = await harness.execute(@@ -646,7 +649,7 @@ def _fake_process_service():def _patch_process_service(svc):return patch(- "services.handlers.process.get_process_service",+ "services.process_service.get_process_service",return_value=svc,)diff --git a/server/tests/nodes/test_email.py b/server/tests/nodes/test_email.pyindex ffef913f..0732e0e8 100644--- a/server/tests/nodes/test_email.py+++ b/server/tests/nodes/test_email.py@@ -69,7 +69,7 @@ class TestEmailSend:stdout = json.dumps({"status": "sent"}).encode()with _patch_ensure_binary(), patched_subprocess(stdout=stdout, returncode=0) as proc, \- patched_container(), patched_pricing():+ patched_container(auth_api_keys={"email_address": "[email protected]", "email_password": "sekret", "email_provider": "gmail"}), patched_pricing():result = await harness.execute("emailSend",_base_creds_params(@@ -90,7 +90,7 @@ class TestEmailSend:async def test_html_body_builds_multipart(self, harness):# Return empty JSON so himalaya "succeeds" with no extra fieldswith _patch_ensure_binary(), patched_subprocess(stdout=b"{}", returncode=0), \- patched_container(), patched_pricing(), \+ patched_container(auth_api_keys={"email_address": "[email protected]", "email_password": "sekret", "email_provider": "gmail"}), patched_pricing(), \patch("services.himalaya_service.HimalayaService.execute",new=AsyncMock(return_value={})) as mock_exec:result = await harness.execute(@@ -126,7 +126,7 @@ class TestEmailSend:# Non-zero returncode -> HimalayaService raises RuntimeError -> envelopewith _patch_ensure_binary(), \patched_subprocess(stdout=b"", stderr=b"auth failed", returncode=1), \- patched_container(), patched_pricing():+ patched_container(auth_api_keys={"email_address": "[email protected]", "email_password": "sekret", "email_provider": "gmail"}), patched_pricing():result = await harness.execute("emailSend",_base_creds_params(to="[email protected]", subject="s", body="b"),@@ -151,7 +151,7 @@ class TestEmailRead:with _patch_ensure_binary(), \patch("services.himalaya_service.HimalayaService.execute",new=AsyncMock(return_value=envelopes)), \- patched_container(), patched_pricing():+ patched_container(auth_api_keys={"email_address": "[email protected]", "email_password": "sekret", "email_provider": "gmail"}), patched_pricing():result = await harness.execute("emailRead",_base_creds_params(operation="list", folder="INBOX", page=1, page_size=20),@@ -168,7 +168,7 @@ class TestEmailRead:with _patch_ensure_binary(), \patch("services.himalaya_service.HimalayaService.execute",new=AsyncMock(return_value=message)), \- patched_container(), patched_pricing():+ patched_container(auth_api_keys={"email_address": "[email protected]", "email_password": "sekret", "email_provider": "gmail"}), patched_pricing():result = await harness.execute("emailRead",_base_creds_params(operation="read", message_id="42", folder="INBOX"),@@ -183,7 +183,7 @@ class TestEmailRead:async def test_unknown_operation_returns_error(self, harness):# No subprocess should be spawned; router raises ValueErrorwith _patch_ensure_binary(), patched_subprocess(), \- patched_container(), patched_pricing():+ patched_container(auth_api_keys={"email_address": "[email protected]", "email_password": "sekret", "email_provider": "gmail"}), patched_pricing():result = await harness.execute("emailRead",_base_creds_params(operation="nonsense"),@@ -195,7 +195,7 @@ class TestEmailRead:async def test_subprocess_failure_returns_error(self, harness):with _patch_ensure_binary(), \patched_subprocess(stdout=b"", stderr=b"folder not found", returncode=1), \- patched_container(), patched_pricing():+ patched_container(auth_api_keys={"email_address": "[email protected]", "email_password": "sekret", "email_provider": "gmail"}), patched_pricing():result = await harness.execute("emailRead",_base_creds_params(operation="list", folder="DoesNotExist"),@@ -223,10 +223,10 @@ class TestEmailReceive:**email_detail, "message_id": "2", "folder": "INBOX",})- with patched_container(), patched_pricing(), \+ with patched_container(auth_api_keys={"email_address": "[email protected]", "email_password": "sekret", "email_provider": "gmail"}), patched_pricing(), \patch.object(EmailService, "poll_ids", poll_ids_mock), \patch.object(EmailService, "fetch_detail", fetch_detail_mock), \- patch("services.handlers.email.asyncio.sleep", new=AsyncMock(return_value=None)), \+ patch("nodes.email.email_receive.asyncio.sleep", new=AsyncMock(return_value=None)), \patch("services.status_broadcaster.get_status_broadcaster") as bcast, \patch("services.event_waiter.dispatch") as dispatch_mock:bcast.return_value.update_node_status = AsyncMock(return_value=None)@@ -255,11 +255,11 @@ class TestEmailReceive:fetch_detail_mock = AsyncMock(return_value={"message_id": "42", "folder": "INBOX"})flag_mock = AsyncMock(return_value={})- with patched_container(), patched_pricing(), \+ with patched_container(auth_api_keys={"email_address": "[email protected]", "email_password": "sekret", "email_provider": "gmail"}), patched_pricing(), \patch.object(EmailService, "poll_ids", poll_ids_mock), \patch.object(EmailService, "fetch_detail", fetch_detail_mock), \patch.object(HimalayaService, "flag_message", flag_mock), \- patch("services.handlers.email.asyncio.sleep", new=AsyncMock(return_value=None)), \+ patch("nodes.email.email_receive.asyncio.sleep", new=AsyncMock(return_value=None)), \patch("services.status_broadcaster.get_status_broadcaster") as bcast, \patch("services.event_waiter.dispatch"):bcast.return_value.update_node_status = AsyncMock(return_value=None)@@ -280,7 +280,7 @@ class TestEmailReceive:async def test_missing_credentials_returns_error(self, harness):with patched_container(auth_api_keys={}), patched_pricing(), \- patch("services.handlers.email.asyncio.sleep", new=AsyncMock(return_value=None)):+ patch("nodes.email.email_receive.asyncio.sleep", new=AsyncMock(return_value=None)):result = await harness.execute("emailReceive",{"provider": "gmail", "folder": "INBOX"},@@ -295,9 +295,9 @@ class TestEmailReceive:poll_ids_mock = AsyncMock(side_effect=RuntimeError("himalaya error: connection refused"))- with patched_container(), patched_pricing(), \+ with patched_container(auth_api_keys={"email_address": "[email protected]", "email_password": "sekret", "email_provider": "gmail"}), patched_pricing(), \patch.object(EmailService, "poll_ids", poll_ids_mock), \- patch("services.handlers.email.asyncio.sleep", new=AsyncMock(return_value=None)), \+ patch("nodes.email.email_receive.asyncio.sleep", new=AsyncMock(return_value=None)), \patch("services.status_broadcaster.get_status_broadcaster") as bcast, \patch("services.event_waiter.dispatch"):bcast.return_value.update_node_status = AsyncMock(return_value=None)diff --git a/server/tests/nodes/test_google_workspace.py b/server/tests/nodes/test_google_workspace.pyindex a33fc918..f8718969 100644--- a/server/tests/nodes/test_google_workspace.py+++ b/server/tests/nodes/test_google_workspace.py@@ -42,7 +42,10 @@ def _patch_creds(module_name: str, creds_return=None, side_effect=None):By default returns a MagicMock that stands in for a Credentials instance.Pass `side_effect=ValueError(...)` to simulate missing credentials."""- target = f"services.handlers.{module_name}.get_google_credentials"+ # Scaling-branch: shared helper lives at services.handlers.google_auth.+ # `module_name` is retained for API symmetry but not part of the patch path.+ _ = module_name+ target = "services.handlers.google_auth.get_google_credentials"kwargs = {}if side_effect is not None:kwargs["side_effect"] = side_effect@@ -53,7 +56,10 @@ def _patch_creds(module_name: str, creds_return=None, side_effect=None):def _patch_build(module_name: str, service_mock):"""Patch googleapiclient `build(...)` to return a provided service MagicMock."""- target = f"services.handlers.{module_name}.build"+ # Scaling-branch: googleapiclient.build is imported once in+ # nodes.google._base and all 6 service plugins share it.+ _ = module_name+ target = "nodes.google._base.build"return patch(target, return_value=service_mock)diff --git a/server/tests/nodes/test_http_proxy.py b/server/tests/nodes/test_http_proxy.pyindex 46eb942b..c19b0bff 100644--- a/server/tests/nodes/test_http_proxy.py+++ b/server/tests/nodes/test_http_proxy.py@@ -170,7 +170,7 @@ class TestProxyRequest:pricing = _pricing_with_proxy_config()with patch(- "services.handlers.proxy.get_proxy_service", return_value=proxy_svc+ "services.proxy.service.get_proxy_service", return_value=proxy_svc), patch("services.pricing.get_pricing_service", return_value=pricing), patched_container():@@ -214,7 +214,7 @@ class TestProxyRequest:proxy_svc = _make_proxy_service_mock(enabled=False)with patch(- "services.handlers.proxy.get_proxy_service", return_value=proxy_svc+ "services.proxy.service.get_proxy_service", return_value=proxy_svc), patched_container():result = await harness.execute("proxyRequest", {"method": "GET", "url": "https://x.test"}@@ -227,7 +227,7 @@ class TestProxyRequest:proxy_svc = _make_proxy_service_mock()with patch(- "services.handlers.proxy.get_proxy_service", return_value=proxy_svc+ "services.proxy.service.get_proxy_service", return_value=proxy_svc), patched_container():result = await harness.execute("proxyRequest", {"method": "GET", "url": ""}@@ -240,7 +240,7 @@ class TestProxyRequest:proxy_svc = _make_proxy_service_mock(proxy_url=None)with patch(- "services.handlers.proxy.get_proxy_service", return_value=proxy_svc+ "services.proxy.service.get_proxy_service", return_value=proxy_svc), patched_container():result = await harness.execute("proxyRequest", {"method": "GET", "url": "https://x.test"}@@ -256,7 +256,7 @@ class TestProxyRequest:proxy_svc = _make_proxy_service_mock()with patch(- "services.handlers.proxy.get_proxy_service", return_value=proxy_svc+ "services.proxy.service.get_proxy_service", return_value=proxy_svc), patched_container():result = await harness.execute("proxyRequest",@@ -295,7 +295,7 @@ class TestProxyConfig:# so we must patch it in the handler module too. tools.py re-imports# it inside the function, so patching the source is sufficient there.with patch(- "services.handlers.proxy.get_proxy_service", return_value=proxy_svc+ "services.proxy.service.get_proxy_service", return_value=proxy_svc), patch("services.proxy.service.get_proxy_service", return_value=proxy_svc), patched_container():@@ -317,7 +317,7 @@ class TestProxyConfig:proxy_svc = _make_proxy_service_mock()with patch(- "services.handlers.proxy.get_proxy_service", return_value=proxy_svc+ "services.proxy.service.get_proxy_service", return_value=proxy_svc), patch("services.proxy.service.get_proxy_service", return_value=proxy_svc), patched_container():@@ -338,7 +338,7 @@ class TestProxyConfig:proxy_svc = _make_proxy_service_mock()with patch(- "services.handlers.proxy.get_proxy_service", return_value=proxy_svc+ "services.proxy.service.get_proxy_service", return_value=proxy_svc), patch("services.proxy.service.get_proxy_service", return_value=proxy_svc), patched_container():@@ -367,7 +367,7 @@ class TestProxyStatus:)with patch(- "services.handlers.proxy.get_proxy_service", return_value=proxy_svc+ "services.proxy.service.get_proxy_service", return_value=proxy_svc):result = await harness.execute("proxyStatus", {})@@ -382,7 +382,7 @@ class TestProxyStatus:proxy_svc = _make_proxy_service_mock(enabled=False)with patch(- "services.handlers.proxy.get_proxy_service", return_value=proxy_svc+ "services.proxy.service.get_proxy_service", return_value=proxy_svc):result = await harness.execute("proxyStatus", {})@@ -396,7 +396,7 @@ class TestProxyStatus:proxy_svc.get_stats = MagicMock(side_effect=RuntimeError("kaboom"))with patch(- "services.handlers.proxy.get_proxy_service", return_value=proxy_svc+ "services.proxy.service.get_proxy_service", return_value=proxy_svc):result = await harness.execute("proxyStatus", {})diff --git a/server/tests/nodes/test_twitter.py b/server/tests/nodes/test_twitter.pyindex 3c5d6366..c54eb649 100644--- a/server/tests/nodes/test_twitter.py+++ b/server/tests/nodes/test_twitter.py@@ -74,8 +74,10 @@ def _make_client_class(*, posts=None, users=None):def _patch_client(stub_cls):- """Patch the xdk.Client reference inside the handler module."""- return patch("services.handlers.twitter.Client", stub_cls)+ """Patch xdk.Client at the SDK module. Scaling-branch plugin does+ `from xdk import Client` inside `nodes.twitter._base.get_twitter_client`+ per call, so patching the source module is the correct target."""+ return patch("xdk.Client", stub_cls)# ============================================================================diff --git a/server/tests/nodes/test_web_automation.py b/server/tests/nodes/test_web_automation.pyindex a6f829f9..c94b5581 100644--- a/server/tests/nodes/test_web_automation.py+++ b/server/tests/nodes/test_web_automation.py@@ -50,7 +50,7 @@ class _FakeBrowserService:def _patch_browser_service(svc):"""Patch get_browser_service to return the fake."""- return patch("services.handlers.browser.get_browser_service", return_value=svc)+ return patch("services.browser_service.get_browser_service", return_value=svc)# ============================================================================@@ -140,7 +140,7 @@ class TestBrowser:async def test_service_not_installed(self, harness):with patch(- "services.handlers.browser.get_browser_service", return_value=None+ "services.browser_service.get_browser_service", return_value=None):result = await harness.execute("browser", {"operation": "navigate", "url": "https://x"})@@ -331,7 +331,7 @@ class TestApifyActor:fake_client = _make_fake_apify_client(run_info=run_info, items=items)with patched_container(auth_api_keys={"apify": "tk_apify"}), patch(- "services.handlers.apify.ApifyClientAsync", return_value=fake_client+ "apify_client.ApifyClientAsync", return_value=fake_client):result = await harness.execute("apifyActor",@@ -392,7 +392,7 @@ class TestApifyActor:fake_client = _make_fake_apify_client(run_info={})with patched_container(auth_api_keys={"apify": "tk"}), patch(- "services.handlers.apify.ApifyClientAsync", return_value=fake_client+ "apify_client.ApifyClientAsync", return_value=fake_client):result = await harness.execute("apifyActor", {"actorId": ""})@@ -409,7 +409,7 @@ class TestApifyActor:fake_client = _make_fake_apify_client(run_info=run_info, items=[])with patched_container(auth_api_keys={"apify": "tk"}), patch(- "services.handlers.apify.ApifyClientAsync", return_value=fake_client+ "apify_client.ApifyClientAsync", return_value=fake_client):result = await harness.execute("apifyActor", {"actorId": "apify/some-actor"}@@ -428,7 +428,7 @@ class TestApifyActor:)with patched_container(auth_api_keys={"apify": "tk"}), patch(- "services.handlers.apify.ApifyClientAsync", return_value=fake_client+ "apify_client.ApifyClientAsync", return_value=fake_client):result = await harness.execute("apifyActor", {"actorId": "apify/some-actor"}@@ -449,7 +449,7 @@ class TestApifyActor:fake_client = _make_fake_apify_client(run_info=run_info, items=[])with patched_container(auth_api_keys={"apify": "tk"}), patch(- "services.handlers.apify.ApifyClientAsync", return_value=fake_client+ "apify_client.ApifyClientAsync", return_value=fake_client):result = await harness.execute("apifyActor",diff --git a/server/tests/nodes/test_workflow_triggers.py b/server/tests/nodes/test_workflow_triggers.pyindex 2056478b..0e499887 100644--- a/server/tests/nodes/test_workflow_triggers.py+++ b/server/tests/nodes/test_workflow_triggers.py@@ -37,18 +37,29 @@ def patched_trigger_waiter(*,raise_cancelled: bool = False,) -> Iterator[MagicMock]:- """Patch event_waiter on the triggers handler namespace.-- The generic trigger handler imports `from services import event_waiter`,- so the bound name lives at `services.handlers.triggers.event_waiter`.- Mocks replicate the real module surface used by the handler:- - get_trigger_config(node_type) -> TriggerConfig-like MagicMock- - register(...) -> awaitable that yields a Waiter-like MagicMock- - wait_for_event(waiter) -> awaitable that yields canned_event- - get_backend_mode() -> "memory"+ """Patch event_waiter at its source module for the plugin trigger path.++ Scaling-branch plugin TriggerNode.execute does:+ from services import event_waiter+ waiter = event_waiter.register(...) # sync+ event_data = await waiter.future # awaitable++ So `register` is a sync MagicMock and `waiter.future` is a pre-resolved+ asyncio.Future (or raises CancelledError if `raise_cancelled=True`)."""+ import asyncio as _asyncio+event_data = canned_event if canned_event is not None else {}++ loop = _asyncio.get_event_loop()+ future = loop.create_future()+ if raise_cancelled:+ future.set_exception(_asyncio.CancelledError())+ else:+ future.set_result(event_data)+waiter_obj = MagicMock(name="Waiter", id="waiter-test-id")+ waiter_obj.future = futuremock = MagicMock(name="event_waiter_module")mock.get_trigger_config = MagicMock(@@ -58,21 +69,15 @@ def patched_trigger_waiter(display_name="Test Trigger",))- mock.register = AsyncMock(return_value=waiter_obj)-+ mock.register = MagicMock(return_value=waiter_obj)if raise_cancelled:- import asyncio as _asyncio-mock.wait_for_event = AsyncMock(side_effect=_asyncio.CancelledError())else:mock.wait_for_event = AsyncMock(return_value=event_data)-mock.get_backend_mode = MagicMock(return_value="memory")mock.is_trigger_node = MagicMock(return_value=True)- with patch("services.handlers.triggers.event_waiter", mock), patch(- "services.node_executor.event_waiter", mock- ):+ with patch("services.event_waiter", mock):yield mock