TDD: Add test for TypeError in infer_resource_slots() with null properties
Added a new Behave BDD feature file:
- features/tdd_mcp_infer_resource_slots_null_properties.feature, containing
a TDD scenario tagged @tdd_issue @tdd_issue_10470 @tdd_expected_fail that
demonstrates the bug where MCPToolAdapter.infer_resource_slots() raises
TypeError when the input schema has {"properties": None}.
Added features/steps/tdd_mcp_infer_resource_slots_null_properties_steps.py:
- Step definitions for the feature file.
ISSUES CLOSED: #10470
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
"""Step definitions for features/tdd_mcp_infer_resource_slots_null_properties.feature.
|
||||
|
||||
TDD issue-capture scenario for #10470: MCPToolAdapter.infer_resource_slots()
|
||||
raises TypeError when the input schema has a null "properties" value.
|
||||
|
||||
The bug: input_schema.get("properties", {}) returns None (not {}) when the
|
||||
key exists with a null value, causing TypeError on iteration.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from behave import given, then, when
|
||||
from behave.runner import Context
|
||||
|
||||
from cleveragents.mcp.adapter import MCPToolAdapter
|
||||
|
||||
|
||||
@given("an MCP tool input schema where properties key is null")
|
||||
def step_given_null_properties_schema(context: Context) -> None:
|
||||
"""Set up an input schema where 'properties' key exists but has a null value."""
|
||||
context.mcp_tool_name = "test_tool"
|
||||
context.mcp_input_schema = {"properties": None}
|
||||
context.infer_type_error = None
|
||||
context.inferred_slots_result = None
|
||||
|
||||
|
||||
@when("I call infer_resource_slots with the null properties schema")
|
||||
def step_when_infer_slots_null_properties(context: Context) -> None:
|
||||
"""Call infer_resource_slots() and capture any TypeError raised."""
|
||||
try:
|
||||
context.inferred_slots_result = MCPToolAdapter.infer_resource_slots(
|
||||
context.mcp_tool_name,
|
||||
context.mcp_input_schema,
|
||||
)
|
||||
except TypeError as exc:
|
||||
context.infer_type_error = exc
|
||||
|
||||
|
||||
@then("no TypeError should have been raised during slot inference")
|
||||
def step_then_no_type_error(context: Context) -> None:
|
||||
"""Assert that no TypeError was raised during infer_resource_slots()."""
|
||||
assert context.infer_type_error is None, (
|
||||
f"Expected no TypeError, but got: {context.infer_type_error!r}\n"
|
||||
"Bug: infer_resource_slots() raises TypeError when 'properties' is None. "
|
||||
"Fix: use `input_schema.get('properties') or {}` instead of "
|
||||
"`input_schema.get('properties', {})`."
|
||||
)
|
||||
|
||||
|
||||
@then("the inferred slots result should be an empty list")
|
||||
def step_then_slots_empty_list(context: Context) -> None:
|
||||
"""Assert that the result of infer_resource_slots() is an empty list."""
|
||||
result = context.inferred_slots_result
|
||||
assert result is not None, (
|
||||
"inferred_slots_result is None — infer_resource_slots() likely raised "
|
||||
"an exception before returning."
|
||||
)
|
||||
assert result == [], (
|
||||
f"Expected infer_resource_slots() to return [], got: {result!r}"
|
||||
)
|
||||
@@ -0,0 +1,12 @@
|
||||
@tdd_issue @tdd_issue_10470
|
||||
Feature: TDD Issue #10470 — MCPToolAdapter.infer_resource_slots() raises TypeError when properties is null
|
||||
MCPToolAdapter.infer_resource_slots() uses input_schema.get("properties", {}) to retrieve
|
||||
the properties dict. When the key exists but has a null value ({"properties": None}),
|
||||
dict.get() returns None instead of the default {}, causing a TypeError when iterating.
|
||||
|
||||
@tdd_issue @tdd_issue_10470 @tdd_expected_fail
|
||||
Scenario: infer_resource_slots() with null properties does not raise TypeError
|
||||
Given an MCP tool input schema where properties key is null
|
||||
When I call infer_resource_slots with the null properties schema
|
||||
Then no TypeError should have been raised during slot inference
|
||||
And the inferred slots result should be an empty list
|
||||
Reference in New Issue
Block a user