FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: skip blank/whitespace lines in receive loop by aorumbayev · Pull Request #87 · agentclientprotocol/python-sdk · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
3 changes: 3 additions & 0 deletions src/acp/connection.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ async def _receive_loop(self) -> None:
line = await self._reader.readline()
if not line:
break
line = line.strip()
if not line:
continue
try:
message: dict[str, Any] = json.loads(line)
except Exception:
Expand Down
14 changes: 14 additions & 0 deletions tests/test_rpc.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,20 @@ async def test_ignore_invalid_messages(connect, server):
await asyncio.wait_for(server.client_reader.readline(), timeout=0.1)


@pytest.mark.asyncio
async def test_blank_lines_skipped(connect, server):
connect(connect_agent=True, connect_client=False)

for noise in [b"\n", b" \n", b"\r\n"]:
server.client_writer.write(noise)
req = {"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {"protocolVersion": 1}}
server.client_writer.write((json.dumps(req) + "\n").encode())
await server.client_writer.drain()

resp = json.loads(await asyncio.wait_for(server.client_reader.readline(), timeout=1))
assert resp["id"] == 1 and "result" in resp


class _ExampleAgent(Agent):
__test__ = False

Expand Down
Loading

Back | FazBrowse Home | New Git URL