refactor(agent): remove dead lifecycle scaffolding
This commit is contained in:
@@ -380,7 +380,7 @@ def test_write_stdin_reports_missing_session(tmp_path):
|
||||
result = asyncio.run(tool.execute(session_id="missing\nExit code: 0", chars=""))
|
||||
|
||||
assert result == "Error: exec session not found: 'missing\\nExit code: 0'"
|
||||
assert is_tool_error_result("write_stdin", result)
|
||||
assert is_tool_error_result(result)
|
||||
|
||||
|
||||
def test_list_exec_sessions_reports_running_commands(tmp_path):
|
||||
|
||||
@@ -449,7 +449,7 @@ async def test_execute_wraps_mcp_is_error_result() -> None:
|
||||
result = await wrapper.execute()
|
||||
|
||||
assert result == "Error: server-side MCP failure"
|
||||
assert is_tool_error_result(wrapper.name, result)
|
||||
assert is_tool_error_result(result)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -462,7 +462,7 @@ async def test_execute_contains_malformed_success_result() -> None:
|
||||
result = await wrapper.execute()
|
||||
|
||||
assert result == "(MCP tool returned malformed content: TypeError)"
|
||||
assert is_tool_error_result(wrapper.name, result)
|
||||
assert is_tool_error_result(result)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -476,7 +476,7 @@ async def test_registry_adds_retry_hint_to_malformed_mcp_result() -> None:
|
||||
|
||||
result = await registry.execute(wrapper.name, {})
|
||||
|
||||
assert is_tool_error_result(wrapper.name, result)
|
||||
assert is_tool_error_result(result)
|
||||
assert "MCP tool returned malformed content" in result
|
||||
assert "Analyze the error above and try a different approach" in result
|
||||
|
||||
@@ -494,7 +494,7 @@ async def test_execute_preserves_success_text_that_starts_with_error() -> None:
|
||||
result = await wrapper.execute()
|
||||
|
||||
assert result == "Error: generated report successfully"
|
||||
assert not is_tool_error_result(wrapper.name, result)
|
||||
assert not is_tool_error_result(result)
|
||||
|
||||
|
||||
# Smallest valid 1x1 PNG, base64 without the data: prefix.
|
||||
@@ -562,7 +562,7 @@ async def test_execute_returns_timeout_message() -> None:
|
||||
result = await wrapper.execute()
|
||||
|
||||
assert result == "(MCP tool call timed out after 0.01s)"
|
||||
assert is_tool_error_result(wrapper.name, result)
|
||||
assert is_tool_error_result(result)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -575,7 +575,7 @@ async def test_execute_handles_server_cancelled_error() -> None:
|
||||
result = await wrapper.execute()
|
||||
|
||||
assert result == "(MCP tool call was cancelled)"
|
||||
assert is_tool_error_result(wrapper.name, result)
|
||||
assert is_tool_error_result(result)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -607,7 +607,7 @@ async def test_execute_handles_generic_exception() -> None:
|
||||
result = await wrapper.execute()
|
||||
|
||||
assert result == "(MCP tool call failed: RuntimeError)"
|
||||
assert is_tool_error_result(wrapper.name, result)
|
||||
assert is_tool_error_result(result)
|
||||
|
||||
|
||||
def _make_tool_def(name: str) -> SimpleNamespace:
|
||||
@@ -1631,7 +1631,7 @@ def test_long_server_name_tools_are_matched_by_server_name() -> None:
|
||||
assert wrapper._reconnect is not None
|
||||
assert other_wrapper._reconnect is None
|
||||
|
||||
removed = mcp_mod._unregister_server_tools(SimpleNamespace(), registry, server_name)
|
||||
removed = mcp_mod._unregister_server_tools(registry, server_name)
|
||||
|
||||
assert removed == 1
|
||||
assert wrapper.name not in registry.tool_names
|
||||
|
||||
@@ -60,7 +60,7 @@ class SampleTool(Tool):
|
||||
@tool_parameters(
|
||||
tool_parameters_schema(
|
||||
query=StringSchema(min_length=2),
|
||||
count=IntegerSchema(2, minimum=1, maximum=10),
|
||||
count=IntegerSchema(minimum=1, maximum=10),
|
||||
required=["query", "count"],
|
||||
)
|
||||
)
|
||||
@@ -81,12 +81,12 @@ def test_schema_validate_value_matches_tool_validate_params() -> None:
|
||||
"""ObjectSchema.validate_value 与 validate_json_schema_value、Tool.validate_params 一致。"""
|
||||
root = tool_parameters_schema(
|
||||
query=StringSchema(min_length=2),
|
||||
count=IntegerSchema(2, minimum=1, maximum=10),
|
||||
count=IntegerSchema(minimum=1, maximum=10),
|
||||
required=["query", "count"],
|
||||
)
|
||||
obj = ObjectSchema(
|
||||
query=StringSchema(min_length=2),
|
||||
count=IntegerSchema(2, minimum=1, maximum=10),
|
||||
count=IntegerSchema(minimum=1, maximum=10),
|
||||
required=["query", "count"],
|
||||
)
|
||||
params = {"query": "h", "count": 2}
|
||||
@@ -110,14 +110,14 @@ def test_schema_validate_value_matches_tool_validate_params() -> None:
|
||||
expected = _Mini().validate_params(params)
|
||||
assert Schema.validate_json_schema_value(params, root, "") == expected
|
||||
assert obj.validate_value(params, "") == expected
|
||||
assert IntegerSchema(0, minimum=1).validate_value(0, "n") == ["n must be >= 1"]
|
||||
assert IntegerSchema(minimum=1).validate_value(0, "n") == ["n must be >= 1"]
|
||||
|
||||
|
||||
def test_schema_classes_equivalent_to_sample_tool_parameters() -> None:
|
||||
"""Schema 类生成的 JSON Schema 应与手写 dict 一致,便于校验行为一致。"""
|
||||
built = tool_parameters_schema(
|
||||
query=StringSchema(min_length=2),
|
||||
count=IntegerSchema(2, minimum=1, maximum=10),
|
||||
count=IntegerSchema(minimum=1, maximum=10),
|
||||
mode=StringSchema("", enum=["fast", "full"]),
|
||||
meta=ObjectSchema(
|
||||
tag=StringSchema(""),
|
||||
|
||||
@@ -272,7 +272,7 @@ async def test_serper_search_http_error(monkeypatch):
|
||||
tool = _tool(provider="serper", api_key="bad-serper-key")
|
||||
result = await tool.execute(query="serper")
|
||||
assert "Error: Serper search failed (403)" in result
|
||||
assert is_tool_error_result(tool.name, result)
|
||||
assert is_tool_error_result(result)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -284,7 +284,7 @@ async def test_serper_search_rate_limited(monkeypatch):
|
||||
tool = _tool(provider="serper", api_key="serper-key")
|
||||
result = await tool.execute(query="serper")
|
||||
assert "Serper search rate limited" in result
|
||||
assert is_tool_error_result(tool.name, result)
|
||||
assert is_tool_error_result(result)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
Reference in New Issue
Block a user