From ac1416bd2e93a950f899ad9e1a41778a25f436bc Mon Sep 17 00:00:00 2001 From: Jeremiah Lowin <153965+jlowin@users.noreply.github.com> Date: Fri, 17 Apr 2026 07:48:46 -0400 Subject: [PATCH] fix tests that relied on task=True returning error results (#3954) --- loq.toml | 2 +- .../client/tasks/test_task_result_caching.py | 2 +- .../tasks/test_server_tasks_parameter.py | 20 +++++++++++++------ tests/server/tasks/test_task_config.py | 4 +++- tests/server/tasks/test_task_mount.py | 9 +++++++-- tests/server/tasks/test_task_proxy.py | 9 +++++++-- tests/server/tasks/test_task_tools.py | 4 +++- 7 files changed, 36 insertions(+), 14 deletions(-) diff --git a/loq.toml b/loq.toml index b7d075845..f1ac457ab 100644 --- a/loq.toml +++ b/loq.toml @@ -48,7 +48,7 @@ max_lines = 1029 [[rules]] path = "tests/server/tasks/test_task_mount.py" -max_lines = 1083 +max_lines = 1088 [[rules]] path = "tests/server/test_dependencies.py" diff --git a/tests/client/tasks/test_task_result_caching.py b/tests/client/tasks/test_task_result_caching.py index e4c5c83d8..ea7c8edaf 100644 --- a/tests/client/tasks/test_task_result_caching.py +++ b/tests/client/tasks/test_task_result_caching.py @@ -142,7 +142,7 @@ async def test_forbidden_mode_tool_caches_error_result(): async with Client(mcp) as client: # Request as task, but mode="forbidden" will reject with error - task = await client.call_tool("non_task_tool", task=True) + task = await client.call_tool("non_task_tool", task=True, raise_on_error=False) # Should be immediate (error returned immediately) assert task.returned_immediately diff --git a/tests/server/tasks/test_server_tasks_parameter.py b/tests/server/tasks/test_server_tasks_parameter.py index af3d16641..54b8a94cb 100644 --- a/tests/server/tasks/test_server_tasks_parameter.py +++ b/tests/server/tasks/test_server_tasks_parameter.py @@ -72,7 +72,7 @@ async def test_server_tasks_false_defaults_all_components(): async with Client(mcp) as client: # Tool with mode="forbidden" returns error when called with task=True - tool_task = await client.call_tool("my_tool", task=True) + tool_task = await client.call_tool("my_tool", task=True, raise_on_error=False) assert tool_task.returned_immediately result = await tool_task.result() assert result.is_error @@ -97,7 +97,7 @@ async def test_server_tasks_none_defaults_to_false(): async with Client(mcp) as client: # Tool should NOT support background execution (mode="forbidden" from default) - tool_task = await client.call_tool("my_tool", task=True) + tool_task = await client.call_tool("my_tool", task=True, raise_on_error=False) assert tool_task.returned_immediately result = await tool_task.result() assert result.is_error @@ -126,7 +126,9 @@ async def test_component_explicit_false_overrides_server_true(): assert "tool:default_tool@" in docket.tasks # Inherits tasks=True # Explicit False (mode="forbidden") returns error when called with task=True - no_task = await client.call_tool("no_task_tool", task=True) + no_task = await client.call_tool( + "no_task_tool", task=True, raise_on_error=False + ) assert no_task.returned_immediately result = await no_task.result() assert result.is_error @@ -161,7 +163,9 @@ async def test_component_explicit_true_overrides_server_false(): assert not task.returned_immediately # Default (mode="forbidden") returns error when called with task=True - default = await client.call_tool("default_tool", task=True) + default = await client.call_tool( + "default_tool", task=True, raise_on_error=False + ) assert default.returned_immediately result = await default.result() assert result.is_error @@ -225,7 +229,9 @@ async def test_mixed_explicit_and_inherited(): assert not explicit_true.returned_immediately # Explicit False (mode="forbidden") returns error - explicit_false = await client.call_tool("explicit_false_tool", task=True) + explicit_false = await client.call_tool( + "explicit_false_tool", task=True, raise_on_error=False + ) assert explicit_false.returned_immediately result = await explicit_false.result() assert result.is_error @@ -272,7 +278,9 @@ async def test_server_tasks_parameter_sets_component_defaults(): async with Client(mcp2) as client: # Tool inherits tasks=False (mode="forbidden") - returns error - tool_task = await client.call_tool("tool_inherits_false", task=True) + tool_task = await client.call_tool( + "tool_inherits_false", task=True, raise_on_error=False + ) assert tool_task.returned_immediately result = await tool_task.result() assert result.is_error diff --git a/tests/server/tasks/test_task_config.py b/tests/server/tasks/test_task_config.py index c94ffec6a..62600d6ca 100644 --- a/tests/server/tasks/test_task_config.py +++ b/tests/server/tasks/test_task_config.py @@ -128,7 +128,9 @@ class TestToolModeEnforcement: """Forbidden mode returns error when called with task metadata.""" async with Client(server) as client: # Call with task=True should fail - task = await client.call_tool("forbidden_tool", {}, task=True) + task = await client.call_tool( + "forbidden_tool", {}, task=True, raise_on_error=False + ) assert task is not None # The task should have returned immediately with an error assert task.returned_immediately diff --git a/tests/server/tasks/test_task_mount.py b/tests/server/tasks/test_task_mount.py index b00653ca3..3a0c134d9 100644 --- a/tests/server/tasks/test_task_mount.py +++ b/tests/server/tasks/test_task_mount.py @@ -176,7 +176,10 @@ class TestMountedToolTasks: """Sync-only mounted tool returns error with task=True.""" async with Client(parent_server) as client: task = await client.call_tool( - "child_sync_child_tool", {"message": "hello"}, task=True + "child_sync_child_tool", + {"message": "hello"}, + task=True, + raise_on_error=False, ) # Should return immediately with an error @@ -663,7 +666,9 @@ class TestMountedTaskConfigModes: async def test_forbidden_mode_with_task_through_mount(self, parent_with_modes): """Forbidden mode tool degrades gracefully with task through mount.""" async with Client(parent_with_modes) as client: - task = await client.call_tool("child_forbidden_tool", {}, task=True) + task = await client.call_tool( + "child_forbidden_tool", {}, task=True, raise_on_error=False + ) # Should return immediately (graceful degradation) assert task.returned_immediately diff --git a/tests/server/tasks/test_task_proxy.py b/tests/server/tasks/test_task_proxy.py index ce20a9a7b..3aa9e7d15 100644 --- a/tests/server/tasks/test_task_proxy.py +++ b/tests/server/tasks/test_task_proxy.py @@ -85,7 +85,9 @@ class TestProxyToolsTaskForbidden: async def test_tool_task_returns_error_immediately(self, proxy_server: FastMCP): """Tool called with task=True through proxy returns error immediately.""" async with Client(proxy_server) as client: - task = await client.call_tool("add_numbers", {"a": 5, "b": 3}, task=True) + task = await client.call_tool( + "add_numbers", {"a": 5, "b": 3}, task=True, raise_on_error=False + ) # Should return immediately (forbidden behavior) assert task.returned_immediately @@ -100,7 +102,10 @@ class TestProxyToolsTaskForbidden: """Sync-only tool with task=True also returns error immediately.""" async with Client(proxy_server) as client: task = await client.call_tool( - "sync_only_tool", {"message": "test"}, task=True + "sync_only_tool", + {"message": "test"}, + task=True, + raise_on_error=False, ) assert task.returned_immediately diff --git a/tests/server/tasks/test_task_tools.py b/tests/server/tasks/test_task_tools.py index 530f6b0e6..282c2b46c 100644 --- a/tests/server/tasks/test_task_tools.py +++ b/tests/server/tasks/test_task_tools.py @@ -91,7 +91,9 @@ async def test_forbidden_mode_tool_rejects_task_calls(tool_server): """Tools with task=False (mode=forbidden) reject task-augmented calls.""" async with Client(tool_server) as client: # Calling with task=True when task=False should return error - task = await client.call_tool("sync_only_tool", {"message": "test"}, task=True) + task = await client.call_tool( + "sync_only_tool", {"message": "test"}, task=True, raise_on_error=False + ) assert task assert task.returned_immediately