Skip to content

Commit d6e65ef

Browse files
committed
test: add test for function name collision
1 parent de50062 commit d6e65ef

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

nerve/tools/mcp/compiler_test.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,32 @@ async def calculate(operation: Annotated[str, "The operation to perform"], value
116116
'''.strip(),
117117
func_body,
118118
)
119+
120+
async def test_create_function_body_with_string_default_colliding_with_builtin(self) -> None:
121+
client = MagicMock(spec=Client)
122+
123+
mock_tool = Tool(
124+
name="test_state_tool",
125+
description="A tool to test default string handling.",
126+
inputSchema={
127+
"type": "object",
128+
"properties": {
129+
"state": {
130+
"type": "string",
131+
"description": "The state of the entity.",
132+
"default": "open", # This default value could be misinterpreted as the 'open' function.
133+
},
134+
},
135+
},
136+
)
137+
138+
func_body, type_defs = await create_function_body(client, mock_tool)
139+
140+
# Default value to be correctly quoted as a string literal: 'open'
141+
self.assertIn(
142+
"""async def test_state_tool(state: Annotated[str, "The state of the entity."] = 'open') -> Any:""",
143+
func_body,
144+
)
119145

120146
async def test_create_function_body_with_complex_nested_arguments(self) -> None:
121147
# Mock the client

0 commit comments

Comments
 (0)