Skip to content

Self-improving AI Employees for everyone

test(D5) + feat(B11): golden tool_name snapshot + plugin_connection_status FE handler

trohitg899771cbf6a4
diff --git a/client/src/contexts/WebSocketContext.tsx b/client/src/contexts/WebSocketContext.tsx
index 0a908f88..baaebb7a 100644
--- a/client/src/contexts/WebSocketContext.tsx
+++ b/client/src/contexts/WebSocketContext.tsx
@@ -752,6 +752,38 @@ export const WebSocketProvider: React.FC<{ children: React.ReactNode }> = ({ chi
break;
}
+ case 'plugin_connection_status': {
+ // CloudEvents-typed connection-status envelope (Wave 12 B1-B3).
+ // Backend dual-emits today: the legacy raw wire key
+ // (android_status / whatsapp_status / telegram_status) keeps
+ // the existing handlers below alive, while this case reads
+ // from the typed envelope. After Wave 12 D4 drains the raw
+ // siblings, the legacy cases below retire and this one
+ // becomes the only path.
+ //
+ // Routing is by envelope.source substring — each plugin's
+ // _events.py declares source="machinaos://nodes/<plugin>".
+ const event = data as WorkflowEvent<Record<string, unknown>>;
+ const source = event?.source || '';
+ const payload = (event?.data || {}) as Record<string, unknown>;
+ if (source.includes('/android')) {
+ setAndroidStatus({ ...defaultAndroidStatus, ...(payload as Partial<typeof defaultAndroidStatus>) });
+ } else if (source.includes('/whatsapp')) {
+ setWhatsappStatus({ ...defaultWhatsAppStatus, ...(payload as Partial<typeof defaultWhatsAppStatus>) });
+ invalidateCatalogue(queryClient);
+ } else if (source.includes('/telegram')) {
+ setTelegramStatus({
+ connected: Boolean(payload.connected),
+ bot_username: (payload.bot_username as string | null) ?? null,
+ bot_name: (payload.bot_name as string | null) ?? null,
+ bot_id: (payload.bot_id as string | null) ?? null,
+ owner_chat_id: (payload.owner_chat_id as string | null) ?? null,
+ });
+ invalidateCatalogue(queryClient);
+ }
+ break;
+ }
+
case 'android_status':
setAndroidStatus(data || defaultAndroidStatus);
break;
diff --git a/server/tests/fixtures/tool_names_snapshot.json b/server/tests/fixtures/tool_names_snapshot.json
new file mode 100644
index 00000000..fc2de830
--- /dev/null
+++ b/server/tests/fixtures/tool_names_snapshot.json
@@ -0,0 +1,78 @@
+{
+ "_comment": "Wave 12 D5 golden snapshot. Maps plugin type -> expected tool_name (the LLM-visible name resolved via cls.tool_name ClassVar on each plugin class). Generated from the pre-migration DEFAULT_TOOL_NAMES dict in services/ai.py; updated as plugins migrate. The 2 pseudo-types stay in _PSEUDO_TOOL_FALLBACK and aren't in this snapshot.",
+ "calculatorTool": "calculator",
+ "currentTimeTool": "get_current_time",
+ "duckduckgoSearch": "web_search",
+ "pythonExecutor": "python_code",
+ "javascriptExecutor": "javascript_code",
+ "whatsappSend": "whatsapp_send",
+ "whatsappDb": "whatsapp_db",
+ "gmaps_locations": "geocode",
+ "gmaps_nearby_places": "nearby_places",
+ "braveSearch": "brave_search",
+ "serperSearch": "serper_search",
+ "perplexitySearch": "perplexity_search",
+ "taskManager": "task_manager",
+ "writeTodos": "write_todos",
+ "processManager": "process_manager",
+ "timer": "timer",
+ "cronScheduler": "cron_scheduler",
+ "fileRead": "file_read",
+ "fileModify": "file_modify",
+ "shell": "shell_execute",
+ "fsSearch": "fs_search",
+ "aiAgent": "delegate_to_ai_agent",
+ "chatAgent": "delegate_to_chat_agent",
+ "android_agent": "delegate_to_android_agent",
+ "coding_agent": "delegate_to_coding_agent",
+ "web_agent": "delegate_to_web_agent",
+ "task_agent": "delegate_to_task_agent",
+ "social_agent": "delegate_to_social_agent",
+ "travel_agent": "delegate_to_travel_agent",
+ "tool_agent": "delegate_to_tool_agent",
+ "productivity_agent": "delegate_to_productivity_agent",
+ "payments_agent": "delegate_to_payments_agent",
+ "consumer_agent": "delegate_to_consumer_agent",
+ "autonomous_agent": "delegate_to_autonomous_agent",
+ "orchestrator_agent": "delegate_to_orchestrator_agent",
+ "ai_employee": "delegate_to_ai_employee",
+ "rlm_agent": "delegate_to_rlm_agent",
+ "claude_code_agent": "delegate_to_claude_code_agent",
+ "batteryMonitor": "android_battery",
+ "networkMonitor": "android_network",
+ "systemInfo": "android_system_info",
+ "location": "android_location",
+ "appLauncher": "android_app_launcher",
+ "appList": "android_app_list",
+ "wifiAutomation": "android_wifi",
+ "bluetoothAutomation": "android_bluetooth",
+ "audioAutomation": "android_audio",
+ "deviceStateAutomation": "android_device_state",
+ "screenControlAutomation": "android_screen_control",
+ "airplaneModeControl": "android_airplane_mode",
+ "motionDetection": "android_motion_detection",
+ "environmentalSensors": "android_environmental_sensors",
+ "cameraControl": "android_camera",
+ "mediaControl": "android_media",
+ "googleGmail": "google_gmail",
+ "googleCalendar": "google_calendar",
+ "googleDrive": "google_drive",
+ "googleSheets": "google_sheets",
+ "googleTasks": "google_tasks",
+ "googleContacts": "google_contacts",
+ "proxyRequest": "proxy_request",
+ "proxyConfig": "proxy_config",
+ "proxyStatus": "proxy_status",
+ "crawleeScraper": "web_reader",
+ "browser": "browser",
+ "emailSend": "email_send",
+ "emailRead": "email_read",
+ "stripeAction": "stripe_action",
+ "typescriptExecutor": "typescript_code",
+ "apifyActor": "apify_actor",
+ "agentBuilder": "agent_builder",
+ "twitterSend": "twitter_send",
+ "twitterSearch": "twitter_search",
+ "twitterUser": "twitter_user",
+ "httpRequest": "http_request"
+}
diff --git a/server/tests/test_tool_registry.py b/server/tests/test_tool_registry.py
new file mode 100644
index 00000000..860683d5
--- /dev/null
+++ b/server/tests/test_tool_registry.py
@@ -0,0 +1,115 @@
+"""Wave 12 D5 invariants — locks the migration of `DEFAULT_TOOL_NAMES` /
+`DEFAULT_TOOL_DESCRIPTIONS` out of `services/ai.py` into per-plugin
+`tool_name` / `tool_description` ClassVars + a small `_PSEUDO_TOOL_FALLBACK`
+for the two non-class pseudo-types (`_builtin_check_delegated_tasks`,
+`androidTool`).
+
+Three contracts locked:
+
+1. `test_legacy_tool_dicts_removed` — `_build_tool_from_node` no longer
+ carries the two function-local dicts that Wave 12 D5 deleted.
+2. `test_pseudo_tool_fallback_has_two_entries` — `_PSEUDO_TOOL_FALLBACK`
+ covers exactly the two pseudo-types the system has (no plugin class).
+3. `test_tool_name_snapshot` — every plugin in
+ `tests/fixtures/tool_names_snapshot.json` resolves via `cls.tool_name`
+ to the expected value. Catches accidental renames + missing migrations.
+"""
+
+from __future__ import annotations
+
+import json
+from pathlib import Path
+
+import pytest
+
+
+_AI_SOURCE_PATH = Path(__file__).parent.parent / "services" / "ai.py"
+_SNAPSHOT_PATH = Path(__file__).parent / "fixtures" / "tool_names_snapshot.json"
+
+
+def _load_snapshot() -> dict:
+ raw = json.loads(_SNAPSHOT_PATH.read_text(encoding="utf-8"))
+ return {k: v for k, v in raw.items() if not k.startswith("_")}
+
+
+def _ai_source() -> str:
+ """Read ``services/ai.py`` as text.
+
+ Source-introspection instead of ``inspect.getsource`` keeps the test
+ cheap: it doesn't trigger the full ``services.ai`` import chain
+ (LangChain + auth + temporal client + 200+ transitive deps) which
+ would otherwise need every ``core.*`` submodule stubbed in conftest.
+ """
+ return _AI_SOURCE_PATH.read_text(encoding="utf-8")
+
+
+def test_legacy_tool_dicts_removed():
+ """``_build_tool_from_node`` must not reintroduce the function-local
+ ``_LEGACY_TOOL_NAMES`` / ``_LEGACY_TOOL_DESCRIPTIONS`` dicts that
+ Wave 12 D5 drained."""
+ source = _ai_source()
+ assert "_LEGACY_TOOL_NAMES = {" not in source, (
+ "_LEGACY_TOOL_NAMES dict reintroduced into services/ai.py. "
+ "Wave 12 D5 migrated this data to per-plugin ClassVars; the legacy "
+ "compat fallback was deleted."
+ )
+ assert "_LEGACY_TOOL_DESCRIPTIONS = {" not in source, (
+ "_LEGACY_TOOL_DESCRIPTIONS dict reintroduced into services/ai.py."
+ )
+ assert "DEFAULT_TOOL_NAMES = {" not in source, (
+ "Pre-D5 DEFAULT_TOOL_NAMES dict reintroduced into services/ai.py."
+ )
+ assert "DEFAULT_TOOL_DESCRIPTIONS = {" not in source, (
+ "Pre-D5 DEFAULT_TOOL_DESCRIPTIONS dict reintroduced into services/ai.py."
+ )
+
+
+def test_pseudo_tool_fallback_has_two_entries():
+ """``_PSEUDO_TOOL_FALLBACK`` covers exactly the two pseudo-types.
+
+ Pseudo-types are dispatched by name but have no plugin class to
+ declare ClassVars on:
+ - ``_builtin_check_delegated_tasks`` — internal helper for the
+ delegation-tracking surface in ``services/handlers/tools.py``.
+ - ``androidTool`` — toolkit aggregator that fans out to connected
+ android service plugins at LLM-tool call time.
+ """
+ source = _ai_source()
+ assert "'_builtin_check_delegated_tasks'" in source, (
+ "_builtin_check_delegated_tasks missing from _PSEUDO_TOOL_FALLBACK"
+ )
+ assert "'androidTool'" in source, (
+ "androidTool missing from _PSEUDO_TOOL_FALLBACK"
+ )
+
+
[email protected]("node_type,expected_tool_name", list(_load_snapshot().items()))
+def test_tool_name_snapshot(node_type: str, expected_tool_name: str):
+ """Every plugin in the golden fixture resolves to its expected
+ ``tool_name`` ClassVar.
+
+ Catches: silent renames, missed migrations, deletion of ClassVar
+ declarations. To intentionally rename a plugin's tool_name, update
+ the JSON fixture in the same commit.
+
+ Defers ``get_node_class`` import until the test runs so collection
+ works even when conftest's permissive plugin discovery fails for
+ one plugin folder (the failure is logged in stderr).
+ """
+ from services.node_registry import get_node_class
+
+ cls = get_node_class(node_type)
+ if cls is None:
+ pytest.skip(
+ f"Plugin class for type={node_type!r} not registered — likely "
+ f"conftest's plugin discovery skipped its folder. Snapshot "
+ f"entry stays; the ClassVar check just doesn't run for it."
+ )
+ actual = (getattr(cls, "tool_name", "") or "").strip()
+ assert actual == expected_tool_name, (
+ f"tool_name mismatch for type={node_type!r}:\n"
+ f" expected (snapshot): {expected_tool_name!r}\n"
+ f" actual (cls.tool_name): {actual!r}\n"
+ f"If this rename is intentional, update "
+ f"server/tests/fixtures/tool_names_snapshot.json in the same commit."
+ )