Skip to content

Self-improving AI Employees for everyone

test: align orchestration regression coverage

trohitg525b8530fb27
diff --git a/server/nodes/tool/task_manager/__init__.py b/server/nodes/tool/task_manager/__init__.py
index d385153a..f839f4ef 100644
--- a/server/nodes/tool/task_manager/__init__.py
+++ b/server/nodes/tool/task_manager/__init__.py
@@ -109,6 +109,12 @@ async def _execute_task_manager(args: Dict[str, Any], config: Dict[str, Any]) ->
service = get_agent_team_service()
operation = str(args.get("operation") or "list_tasks")
+ allowed_operations = {
+ "assign_task", "list_tasks", "get_task", "modify_task", "cancel_task",
+ "retry_task", "reassign_task", "accept_task", "finish_team", "mark_done",
+ }
+ if operation not in allowed_operations:
+ raise ValueError(f"Unknown Task Manager operation: {operation}")
scope = _scope(config)
if operation == "list_tasks":
@@ -122,7 +128,10 @@ async def _execute_task_manager(args: Dict[str, Any], config: Dict[str, Any]) ->
tasks = await service.list_durable_tasks(**scope, status=args.get("status_filter"))
return {"success": True, "operation": operation, "tasks": tasks, "count": len(tasks)}
if operation == "get_task":
- task = await service.get_durable_task(**scope, task_id=str(args.get("task_id") or ""))
+ task_id = str(args.get("task_id") or "")
+ if not task_id:
+ raise ValueError("get_task requires task_id")
+ task = await service.get_durable_task(**scope, task_id=task_id)
return {"success": True, "operation": operation, "task": task}
if operation == "assign_task":
if not args.get("title") or not args.get("mission"):
diff --git a/server/services/workflow_import.py b/server/services/workflow_import.py
index d52d12d6..85ca53ad 100644
--- a/server/services/workflow_import.py
+++ b/server/services/workflow_import.py
@@ -268,6 +268,7 @@ async def import_workflow(
nodes=nodes,
edges=edges,
parameters_by_id=node_parameters,
+ auth_service=auth_service,
)
report.setdefault("warnings", []).extend(
{"code": "LEGACY_ANDROID_TOOLKIT_REMOVED", "message": warning}
diff --git a/server/services/workflow_validator.py b/server/services/workflow_validator.py
index edf2c722..7e824f56 100644
--- a/server/services/workflow_validator.py
+++ b/server/services/workflow_validator.py
@@ -53,6 +53,7 @@ async def validate_workflow(
edges: List[Dict[str, Any]],
*,
parameters_by_id: Optional[Dict[str, Dict[str, Any]]] = None,
+ auth_service: Any = None,
) -> Dict[str, List[Dict[str, Any]]]:
"""Validate a workflow graph + per-node params + credential presence.
@@ -63,6 +64,8 @@ async def validate_workflow(
When omitted, the validator reads ``node["data"]["parameters"]``
(which is usually empty since parameters live in the DB — callers
who want INVALID_PARAM warnings must hydrate from DB and pass them).
+ auth_service: Optional caller-scoped credential service. Supplying it
+ avoids resolving the process-wide dependency container.
Returns:
``{"errors": [...], "warnings": [...]}``. ``errors`` block execution
@@ -199,7 +202,6 @@ async def validate_workflow(
# 4. Missing credentials. Warnings (a workflow can be saved with missing
# credentials and configured later — only at force=True execute does
# it become a runtime error).
- auth_service = None
for n in nodes:
node_id = n.get("id")
node_type = n.get("type", "")
diff --git a/server/tests/nodes/test_ai_tools.py b/server/tests/nodes/test_ai_tools.py
index d4bf39a4..fe093a6c 100644
--- a/server/tests/nodes/test_ai_tools.py
+++ b/server/tests/nodes/test_ai_tools.py
@@ -243,120 +243,84 @@ class TestDuckDuckGoSearch:
class TestTaskManager:
- """In-memory delegation-registry inspector. State lives in module globals
- `_delegated_tasks` and `_delegation_results` in services.handlers.tools."""
+ """Durable execution-scoped team task control."""
@pytest.fixture(autouse=True)
- def _reset_registry(self):
- """Snapshot + restore the module-level dicts around each test."""
- from services.handlers import tools as tools_mod
-
- tasks_backup = dict(tools_mod._delegated_tasks)
- results_backup = dict(tools_mod._delegation_results)
- tools_mod._delegated_tasks.clear()
- tools_mod._delegation_results.clear()
- try:
- yield tools_mod
- finally:
- tools_mod._delegated_tasks.clear()
- tools_mod._delegated_tasks.update(tasks_backup)
- tools_mod._delegation_results.clear()
- tools_mod._delegation_results.update(results_backup)
-
- async def test_list_tasks_reports_running_and_completed_entries(self, _reset_registry):
- tools_mod = _reset_registry
-
- running_task = MagicMock()
- running_task.done.return_value = False
- tools_mod._delegated_tasks["t1"] = running_task
-
- tools_mod._delegation_results["t2"] = {
- "status": "completed",
- "agent_name": "coding_agent",
- "result": "x" * 500, # will be truncated to 200 chars
- }
+ def durable_service(self):
+ service = MagicMock()
+ service.list_durable_tasks = AsyncMock(return_value=[])
+ service.list_durable_task_history = AsyncMock(return_value=[])
+ service.get_durable_task = AsyncMock(return_value={})
+ service.mutate_durable_task = AsyncMock(return_value={})
+ with patch("services.agent_team.get_agent_team_service", return_value=service):
+ yield service
+
+ @staticmethod
+ def _config():
+ return {"workflow_id": "workflow-1", "parent_node_id": "lead-1", "execution_id": "run-1"}
+
+ async def test_list_tasks_reads_durable_execution_scope(self, durable_service):
+ durable_service.list_durable_tasks.return_value = [
+ {"id": "t1", "status": "running"},
+ {"id": "t2", "status": "submitted"},
+ ]
from nodes.tool.task_manager import _execute_task_manager
- result = await _execute_task_manager({"operation": "list_tasks"}, {"parameters": {}})
+ result = await _execute_task_manager({"operation": "list_tasks"}, self._config())
assert result["success"] is True
assert result["operation"] == "list_tasks"
assert result["count"] == 2
- assert result["running"] == 1
- assert result["completed"] == 1
- assert result["errors"] == 0
-
- ids = {t["task_id"] for t in result["tasks"]}
- assert ids == {"t1", "t2"}
- t2 = next(t for t in result["tasks"] if t["task_id"] == "t2")
- assert t2["agent_name"] == "coding_agent"
- assert len(t2["result_summary"]) == 200
-
- async def test_list_tasks_applies_status_filter(self, _reset_registry):
- tools_mod = _reset_registry
+ durable_service.list_durable_tasks.assert_awaited_once_with(
+ workflow_id="workflow-1", team_lead_node_id="lead-1",
+ execution_id="run-1", status=None,
+ )
- running = MagicMock()
- running.done.return_value = False
- tools_mod._delegated_tasks["r1"] = running
- tools_mod._delegation_results["c1"] = {"status": "completed"}
+ async def test_list_tasks_applies_status_filter(self, durable_service):
+ durable_service.list_durable_tasks.return_value = [{"id": "r1", "status": "running"}]
from nodes.tool.task_manager import _execute_task_manager
result = await _execute_task_manager(
{"operation": "list_tasks", "status_filter": "running"},
- {"parameters": {}},
+ self._config(),
)
assert result["count"] == 1
- assert result["tasks"][0]["task_id"] == "r1"
+ assert result["tasks"][0]["id"] == "r1"
+ assert durable_service.list_durable_tasks.await_args.kwargs["status"] == "running"
- async def test_get_task_without_id_errors(self, _reset_registry):
- tools_mod = _reset_registry
+ async def test_get_task_without_id_errors(self, durable_service):
from nodes.tool.task_manager import _execute_task_manager
- result = await _execute_task_manager({"operation": "get_task"}, {"parameters": {}})
- assert result["success"] is False
- assert "task_id is required" in result["error"]
+ with pytest.raises(ValueError, match="get_task requires task_id"):
+ await _execute_task_manager({"operation": "get_task"}, self._config())
- async def test_mark_done_removes_tracked_task(self, _reset_registry):
- tools_mod = _reset_registry
- tools_mod._delegation_results["gone"] = {"status": "completed"}
+ async def test_mark_done_is_non_destructive_accept_alias(self, durable_service):
+ durable_service.get_durable_task.return_value = {"id": "done", "revision": 4}
+ durable_service.mutate_durable_task.return_value = {"id": "done", "status": "accepted", "revision": 5}
from nodes.tool.task_manager import _execute_task_manager
result = await _execute_task_manager(
- {"operation": "mark_done", "task_id": "gone"},
- {"parameters": {}},
+ {"operation": "mark_done", "task_id": "done"}, self._config(),
)
assert result["success"] is True
- assert result["removed"] is True
- assert "gone" not in tools_mod._delegation_results
-
- async def test_mark_done_untracked_id_returns_removed_false(self, _reset_registry):
- tools_mod = _reset_registry
-
- from nodes.tool.task_manager import _execute_task_manager
-
- result = await _execute_task_manager(
- {"operation": "mark_done", "task_id": "never-seen"},
- {"parameters": {}},
+ assert result["task"]["status"] == "accepted"
+ durable_service.mutate_durable_task.assert_awaited_once_with(
+ workflow_id="workflow-1", team_lead_node_id="lead-1", execution_id="run-1",
+ task_id="done", revision=4, operation="accept",
)
- assert result["success"] is True
- assert result["removed"] is False
- assert "was not in active tracking" in result["message"]
-
- async def test_unknown_operation_returns_failure_envelope(self, _reset_registry):
- tools_mod = _reset_registry
+ async def test_unknown_operation_is_rejected(self, durable_service):
from nodes.tool.task_manager import _execute_task_manager
- result = await _execute_task_manager({"operation": "self_destruct"}, {"parameters": {}})
- assert result["success"] is False
- assert "Unknown operation" in result["error"]
+ with pytest.raises(ValueError, match="Unknown Task Manager operation"):
+ await _execute_task_manager({"operation": "self_destruct"}, self._config())
# ============================================================================
diff --git a/server/tests/services/memory/test_runtime_mutations.py b/server/tests/services/memory/test_runtime_mutations.py
index 99877fe8..bb9f02e2 100644
--- a/server/tests/services/memory/test_runtime_mutations.py
+++ b/server/tests/services/memory/test_runtime_mutations.py
@@ -224,7 +224,7 @@ async def test_parallel_team_task_claim_has_one_winner(runtime_database):
assert retry["assigned_to"] == winner
tasks = await db.get_team_tasks("team-1")
- assert tasks[0]["status"] == "in_progress"
+ assert tasks[0]["status"] == "running"
assert tasks[0]["assigned_to"] == winner
@@ -251,4 +251,4 @@ async def test_team_task_transitions_are_atomic_and_retry_safe(runtime_database)
)
task = selected.scalar_one()
assert task.retry_count == 1
- assert task.status == "pending"
+ assert task.status == "queued"
diff --git a/server/tests/services/test_workflow_rename.py b/server/tests/services/test_workflow_rename.py
index 7492c249..1f2e6609 100644
--- a/server/tests/services/test_workflow_rename.py
+++ b/server/tests/services/test_workflow_rename.py
@@ -151,7 +151,7 @@ async def test_save_existing_workflow_same_name_keeps_slug(patched_handler_deps)
)
# Second save with same name — slug stays as _1.
result = await handle_save_workflow(
- {"workflow_id": "uuid-1", "name": "AI Assistant", "data": {"nodes": ["a"]}},
+ {"workflow_id": "uuid-1", "name": "AI Assistant", "data": {"nodes": [], "marker": "a"}},
websocket=None,
)
diff --git a/server/tests/temporal/test_agent_workflow.py b/server/tests/temporal/test_agent_workflow.py
index cef42b6c..35feb64a 100644
--- a/server/tests/temporal/test_agent_workflow.py
+++ b/server/tests/temporal/test_agent_workflow.py
@@ -16,6 +16,8 @@ canary agent migration lands. This file locks the static contracts:
from __future__ import annotations
+from unittest.mock import MagicMock
+
class TestAgentWorkflowDefinition:
"""``AgentWorkflow`` must be a valid Temporal workflow definition
@@ -442,12 +444,15 @@ class TestAutoRebindTools:
assert "agent.refresh_tools.v1" in names
assert refresh_agent_tools in collect_agent_activities()
- async def test_refresh_tools_runs_without_nameerror(self):
+ async def test_refresh_tools_runs_without_nameerror(self, monkeypatch):
"""Smoke test: the activity body must import ``container`` and
``get_node_class`` so it doesn't NameError on first invocation.
Mirrors the rest of the agent_activities.py pattern (lazy import
inside each activity body)."""
from services.temporal.agent_activities import refresh_agent_tools
+ from core.container import container
+
+ monkeypatch.setattr(container, "ai_service", MagicMock(return_value=MagicMock()))
# Pass empty operations so the activity short-circuits before
# any plugin lookup — we just want to confirm the imports + the
diff --git a/server/tests/temporal/test_temporal_identity.py b/server/tests/temporal/test_temporal_identity.py
index 2f6fa083..cf2a319f 100644
--- a/server/tests/temporal/test_temporal_identity.py
+++ b/server/tests/temporal/test_temporal_identity.py
@@ -367,6 +367,7 @@ class TestAgentCallIdentity:
"refresh-tools-todo-1-1-1",
{
"operations": [{"op": "add_node"}],
+ "agent_node_type": "aiAgent",
"invoking_agent_node_id": "agent-1",
"agent_iteration": 1,
"tool_call_index": 1,
diff --git a/server/tests/test_plugin_contract.py b/server/tests/test_plugin_contract.py
index 5b7bc1d0..62d5a08a 100644
--- a/server/tests/test_plugin_contract.py
+++ b/server/tests/test_plugin_contract.py
@@ -324,7 +324,7 @@ class TestNeedsCanvasContract:
for cls in _all_plugin_classes():
if not issubclass(cls, ToolNode):
continue
- if cls.type == "agentBuilder":
+ if cls.type in {"agentBuilder", "taskManager"}:
continue
assert cls.needs_canvas is False, (
f"{cls.__qualname__} declares needs_canvas=True but isn't agentBuilder. "