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:
@ -73,7 +73,7 @@ def _make_git(respx_mock=None) -> Git:
|
||||
"""Create a Git instance bound to a test capsule."""
|
||||
from wrenn.client import WrennClient
|
||||
|
||||
client = WrennClient(api_key="wrn_test1234567890abcdef12345678")
|
||||
client = WrennClient(api_key="wrn_test1234567890abcdef12345678", base_url=BASE)
|
||||
return Git(CAPSULE_ID, client.http)
|
||||
|
||||
|
||||
@ -81,7 +81,7 @@ def _make_async_git() -> AsyncGit:
|
||||
"""Create an AsyncGit instance bound to a test capsule."""
|
||||
from wrenn.client import AsyncWrennClient
|
||||
|
||||
client = AsyncWrennClient(api_key="wrn_test1234567890abcdef12345678")
|
||||
client = AsyncWrennClient(api_key="wrn_test1234567890abcdef12345678", base_url=BASE)
|
||||
return AsyncGit(CAPSULE_ID, client.http)
|
||||
|
||||
|
||||
@ -926,7 +926,7 @@ class TestCapsuleWiring:
|
||||
respx.post(f"{BASE}/v1/capsules").respond(
|
||||
201, json={"id": "cl-1", "status": "pending"}
|
||||
)
|
||||
cap = Capsule(api_key="wrn_test1234567890abcdef12345678")
|
||||
cap = Capsule(api_key="wrn_test1234567890abcdef12345678", base_url=BASE)
|
||||
assert hasattr(cap, "git")
|
||||
assert isinstance(cap.git, Git)
|
||||
|
||||
@ -1017,7 +1017,7 @@ class TestCommandPayloadWrapping:
|
||||
from wrenn.client import WrennClient
|
||||
from wrenn.commands import Commands
|
||||
|
||||
client = WrennClient(api_key="wrn_test1234567890abcdef12345678")
|
||||
client = WrennClient(api_key="wrn_test1234567890abcdef12345678", base_url=BASE)
|
||||
commands = Commands(CAPSULE_ID, client.http)
|
||||
|
||||
route = respx.post(EXEC_URL).respond(200, json=_exec_response(stdout="3\n"))
|
||||
@ -1031,7 +1031,7 @@ class TestCommandPayloadWrapping:
|
||||
from wrenn.client import WrennClient
|
||||
from wrenn.commands import Commands
|
||||
|
||||
client = WrennClient(api_key="wrn_test1234567890abcdef12345678")
|
||||
client = WrennClient(api_key="wrn_test1234567890abcdef12345678", base_url=BASE)
|
||||
commands = Commands(CAPSULE_ID, client.http)
|
||||
|
||||
route = respx.post(EXEC_URL).respond(200, json=_exec_response())
|
||||
@ -1045,7 +1045,7 @@ class TestCommandPayloadWrapping:
|
||||
from wrenn.client import WrennClient
|
||||
from wrenn.commands import Commands
|
||||
|
||||
client = WrennClient(api_key="wrn_test1234567890abcdef12345678")
|
||||
client = WrennClient(api_key="wrn_test1234567890abcdef12345678", base_url=BASE)
|
||||
commands = Commands(CAPSULE_ID, client.http)
|
||||
|
||||
route = respx.post(EXEC_URL).respond(200, json=_exec_response())
|
||||
@ -1059,7 +1059,7 @@ class TestCommandPayloadWrapping:
|
||||
from wrenn.client import WrennClient
|
||||
from wrenn.commands import Commands
|
||||
|
||||
client = WrennClient(api_key="wrn_test1234567890abcdef12345678")
|
||||
client = WrennClient(api_key="wrn_test1234567890abcdef12345678", base_url=BASE)
|
||||
commands = Commands(CAPSULE_ID, client.http)
|
||||
|
||||
route = respx.post(EXEC_URL).respond(200, json=_exec_response())
|
||||
@ -1073,7 +1073,7 @@ class TestCommandPayloadWrapping:
|
||||
from wrenn.client import WrennClient
|
||||
from wrenn.commands import Commands
|
||||
|
||||
client = WrennClient(api_key="wrn_test1234567890abcdef12345678")
|
||||
client = WrennClient(api_key="wrn_test1234567890abcdef12345678", base_url=BASE)
|
||||
commands = Commands(CAPSULE_ID, client.http)
|
||||
|
||||
route = respx.post(EXEC_URL).respond(200, json=_exec_response())
|
||||
@ -1089,7 +1089,7 @@ class TestCommandPayloadWrapping:
|
||||
from wrenn.client import WrennClient
|
||||
from wrenn.commands import Commands
|
||||
|
||||
client = WrennClient(api_key="wrn_test1234567890abcdef12345678")
|
||||
client = WrennClient(api_key="wrn_test1234567890abcdef12345678", base_url=BASE)
|
||||
commands = Commands(CAPSULE_ID, client.http)
|
||||
|
||||
route = respx.post(EXEC_URL).respond(200, json=_exec_response())
|
||||
@ -1119,7 +1119,7 @@ class TestCommandPayloadWrapping:
|
||||
from wrenn.client import WrennClient
|
||||
from wrenn.commands import Commands
|
||||
|
||||
client = WrennClient(api_key="wrn_test1234567890abcdef12345678")
|
||||
client = WrennClient(api_key="wrn_test1234567890abcdef12345678", base_url=BASE)
|
||||
commands = Commands(CAPSULE_ID, client.http)
|
||||
|
||||
route = respx.post(EXEC_URL).respond(200, json={"pid": 42, "tag": "bg-1"})
|
||||
|
||||
Reference in New Issue
Block a user