style: apply ruff formatting

This commit is contained in:
Lina Tawfik 2025-06-30 21:58:37 -07:00
parent 24295417ac
commit 977bf6438b
No known key found for this signature in database
2 changed files with 23 additions and 10 deletions

View file

@ -209,7 +209,7 @@ class SubprocessCLITransport(Transport):
json_buffer = "" # Clear buffer to prevent repeated errors json_buffer = "" # Clear buffer to prevent repeated errors
raise SDKJSONDecodeError( raise SDKJSONDecodeError(
f"JSON message exceeded maximum buffer size of {_MAX_BUFFER_SIZE} bytes", f"JSON message exceeded maximum buffer size of {_MAX_BUFFER_SIZE} bytes",
None None,
) )
try: try:

View file

@ -155,9 +155,14 @@ class TestSubprocessBuffering:
"message": { "message": {
"content": [ "content": [
{"type": "text", "text": "x" * 1000}, {"type": "text", "text": "x" * 1000},
{"type": "tool_use", "id": "tool_123", "name": "Read", "input": {"file_path": "/test.txt"}} {
"type": "tool_use",
"id": "tool_123",
"name": "Read",
"input": {"file_path": "/test.txt"},
},
] ]
} },
} }
complete_json = json.dumps(json_obj) complete_json = json.dumps(json_obj)
@ -203,17 +208,20 @@ class TestSubprocessBuffering:
{ {
"tool_use_id": "toolu_016fed1NhiaMLqnEvrj5NUaj", "tool_use_id": "toolu_016fed1NhiaMLqnEvrj5NUaj",
"type": "tool_result", "type": "tool_result",
"content": json.dumps(large_data) "content": json.dumps(large_data),
} }
] ],
} },
} }
complete_json = json.dumps(json_obj) complete_json = json.dumps(json_obj)
# Split into chunks simulating 64KB buffer limit # Split into chunks simulating 64KB buffer limit
chunk_size = 64 * 1024 # 64KB chunk_size = 64 * 1024 # 64KB
chunks = [complete_json[i:i+chunk_size] for i in range(0, len(complete_json), chunk_size)] chunks = [
complete_json[i : i + chunk_size]
for i in range(0, len(complete_json), chunk_size)
]
transport = SubprocessCLITransport( transport = SubprocessCLITransport(
prompt="test", options=ClaudeCodeOptions(), cli_path="/usr/bin/claude" prompt="test", options=ClaudeCodeOptions(), cli_path="/usr/bin/claude"
@ -232,7 +240,10 @@ class TestSubprocessBuffering:
assert len(messages) == 1 assert len(messages) == 1
assert messages[0]["type"] == "user" assert messages[0]["type"] == "user"
assert messages[0]["message"]["content"][0]["tool_use_id"] == "toolu_016fed1NhiaMLqnEvrj5NUaj" assert (
messages[0]["message"]["content"][0]["tool_use_id"]
== "toolu_016fed1NhiaMLqnEvrj5NUaj"
)
anyio.run(_test) anyio.run(_test)
@ -276,7 +287,7 @@ class TestSubprocessBuffering:
# Second: large JSON split across reads # Second: large JSON split across reads
large_msg = { large_msg = {
"type": "assistant", "type": "assistant",
"message": {"content": [{"type": "text", "text": "y" * 5000}]} "message": {"content": [{"type": "text", "text": "y" * 5000}]},
} }
large_json = json.dumps(large_msg) large_json = json.dumps(large_msg)
@ -288,7 +299,9 @@ class TestSubprocessBuffering:
msg1 + "\n", msg1 + "\n",
large_json[:1000], # First part of large message large_json[:1000], # First part of large message
large_json[1000:3000], # Middle part large_json[1000:3000], # Middle part
large_json[3000:] + "\n" + msg3 # End of large message + complete message large_json[3000:]
+ "\n"
+ msg3, # End of large message + complete message
] ]
transport = SubprocessCLITransport( transport = SubprocessCLITransport(