Fix error handling, resource leaks, and logic bugs across the SDK
Bugs fixed: - files.py: use typed error checking (_raise_for_status) instead of raw raise_for_status(), ensuring WrennNotFoundError etc. are raised correctly - exceptions.py: check both "capsule_ids" and "sandbox_ids" response keys for backwards compatibility - code_interpreter: retry _ensure_kernel on 5xx errors (only fail on 4xx), remove redundant TimeoutError in bare except, clean up non-standard top-level msg_id/msg_type from Jupyter messages Resource leaks fixed: - capsule.py: close WrennClient if capsule creation or init fails - code_interpreter: add close()/__del__ for _proxy_client cleanup when not using context manager Logic fixes: - pty.py: yield exit events to callers instead of silently discarding them - capsule.py: auto-resume paused capsules in wait_ready instead of failing - capsule.py: log warnings on destroy failure in __exit__ instead of silently swallowing errors
This commit is contained in:
@ -23,7 +23,7 @@ def _make_capsule(cap_id: str = "cl-abc") -> Capsule:
|
||||
respx.post(f"{BASE}/v1/capsules").respond(
|
||||
201, json={"id": cap_id, "status": "running"}
|
||||
)
|
||||
return Capsule(api_key="wrn_test1234567890abcdef12345678")
|
||||
return Capsule(api_key="wrn_test1234567890abcdef12345678", base_url=BASE)
|
||||
|
||||
|
||||
class TestFilesRead:
|
||||
@ -311,12 +311,14 @@ class TestPtySessionIteration:
|
||||
ws.receive_text.side_effect = messages
|
||||
session = PtySession(ws, "cl-abc")
|
||||
events = list(session)
|
||||
assert len(events) == 2
|
||||
assert len(events) == 3
|
||||
assert events[0].type == PtyEventType.started
|
||||
assert session.tag == "pty-abc12345"
|
||||
assert session.pid == 1
|
||||
assert events[1].type == PtyEventType.output
|
||||
assert events[1].data == b"hello"
|
||||
assert events[2].type == PtyEventType.exit
|
||||
assert events[2].exit_code == 0
|
||||
|
||||
def test_iter_stops_on_fatal_error(self):
|
||||
ws = MagicMock()
|
||||
@ -461,10 +463,11 @@ class TestAsyncPtySession:
|
||||
events = []
|
||||
async for event in session:
|
||||
events.append(event)
|
||||
assert len(events) == 2
|
||||
assert len(events) == 3
|
||||
assert events[0].type == PtyEventType.started
|
||||
assert session.tag == "pty-xyz"
|
||||
assert session.pid == 5
|
||||
assert events[2].type == PtyEventType.exit
|
||||
|
||||
|
||||
class TestExports:
|
||||
|
||||
Reference in New Issue
Block a user