Skip to content

Commit 2c47fc4

Browse files
committed
Guard the no-deref test with a socket tripwire
Patch socket.connect / create_connection to fail on any outbound connection while validating a tool result, proving the network $ref is never fetched.
1 parent 8e255ad commit 2c47fc4

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

tests/client/test_output_schema_validation.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import socket
23
from typing import Any
34

45
import pytest
@@ -166,13 +167,20 @@ async def on_call_tool(ctx: ServerRequestContext, params: CallToolRequestParams)
166167

167168

168169
@pytest.mark.anyio
169-
async def test_client_does_not_dereference_network_ref():
170+
async def test_client_does_not_dereference_network_ref(monkeypatch: pytest.MonkeyPatch):
170171
"""SEP-2106: validating a result must not fetch a network `$ref` in the output schema.
171172
172173
The output schema references a network URI under a property the structured content
173-
never sets, so a compliant client validates without resolving (and therefore without
174-
fetching) the ref.
174+
never sets. A socket guard fails the test if the client opens any connection while
175+
validating, proving the ref is never dereferenced.
175176
"""
177+
178+
def no_network(*args: object, **kwargs: object) -> None:
179+
raise AssertionError("client attempted a network connection while validating a tool result") # pragma: no cover
180+
181+
monkeypatch.setattr(socket.socket, "connect", no_network)
182+
monkeypatch.setattr(socket, "create_connection", no_network)
183+
176184
output_schema = {
177185
"type": "object",
178186
"properties": {

0 commit comments

Comments
 (0)