|
9 | 9 | InitializeRequestParams, |
10 | 10 | JSONRPCMessage, |
11 | 11 | JSONRPCRequest, |
| 12 | + Tool, |
12 | 13 | ) |
13 | 14 |
|
14 | 15 |
|
@@ -56,3 +57,37 @@ async def test_method_initialization(): |
56 | 57 | assert initialize_request.method == "initialize", "method should be set to 'initialize'" |
57 | 58 | assert initialize_request.params is not None |
58 | 59 | assert initialize_request.params.protocolVersion == LATEST_PROTOCOL_VERSION |
| 60 | + |
| 61 | + |
| 62 | +@pytest.mark.parametrize( |
| 63 | + "name", |
| 64 | + [ |
| 65 | + "getUser", |
| 66 | + "DATA_EXPORT_v2", |
| 67 | + "admin.tools.list", |
| 68 | + "a", |
| 69 | + "Z9_.-", |
| 70 | + "x" * 128, # max length |
| 71 | + ], |
| 72 | +) |
| 73 | +def test_tool_allows_valid_names(name: str) -> None: |
| 74 | + Tool(name=name, inputSchema={"type": "object"}) |
| 75 | + |
| 76 | + |
| 77 | +@pytest.mark.parametrize( |
| 78 | + ("name", "expected"), |
| 79 | + [ |
| 80 | + ("", "Invalid tool name length: 0. Tool name must be between 1 and 128 characters."), |
| 81 | + ("x" * 129, "Invalid tool name length: 129. Tool name must be between 1 and 128 characters."), |
| 82 | + ("has space", "Invalid tool name characters. Allowed: A-Z, a-z, 0-9, underscore (_), dash (-), dot (.)."), |
| 83 | + ("comma,name", "Invalid tool name characters. Allowed: A-Z, a-z, 0-9, underscore (_), dash (-), dot (.)."), |
| 84 | + ("not/allowed", "Invalid tool name characters. Allowed: A-Z, a-z, 0-9, underscore (_), dash (-), dot (.)."), |
| 85 | + ("name@", "Invalid tool name characters. Allowed: A-Z, a-z, 0-9, underscore (_), dash (-), dot (.)."), |
| 86 | + ("name#", "Invalid tool name characters. Allowed: A-Z, a-z, 0-9, underscore (_), dash (-), dot (.)."), |
| 87 | + ("name$", "Invalid tool name characters. Allowed: A-Z, a-z, 0-9, underscore (_), dash (-), dot (.)."), |
| 88 | + ], |
| 89 | +) |
| 90 | +def test_tool_rejects_invalid_names(name: str, expected: str) -> None: |
| 91 | + with pytest.raises(ValueError) as exc_info: |
| 92 | + Tool(name=name, inputSchema={"type": "object"}) |
| 93 | + assert expected in str(exc_info.value) |
0 commit comments