Skip to content

Commit b17c155

Browse files
tholorclaude
andcommitted
test(e2b): replace stale 'no sandbox' tool tests with warm-up failure tests
_require_sandbox auto-calls warm_up, so the previous tests expecting "E2B sandbox is not running" were silently hitting the live E2B API with a fake key and failing on the 401 response. Mock Sandbox.create to fail and assert each tool wraps the warm_up RuntimeError as ToolInvocationError instead. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 8a01275 commit b17c155

1 file changed

Lines changed: 24 additions & 8 deletions

File tree

integrations/e2b/tests/test_sandbox_toolset.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -378,10 +378,14 @@ def test_passes_custom_timeout(self):
378378

379379
mock.commands.run.assert_called_once_with("sleep 5", timeout=30)
380380

381-
def test_raises_when_no_sandbox(self):
381+
@patch("haystack_integrations.tools.e2b.e2b_sandbox.e2b_import")
382+
@patch("haystack_integrations.tools.e2b.e2b_sandbox.Sandbox.create")
383+
def test_wraps_warm_up_failure(self, mock_sandbox_create, mock_e2b_import):
384+
mock_e2b_import.check.return_value = None
385+
mock_sandbox_create.side_effect = Exception("connection refused")
382386
sb = _make_sandbox()
383387
tool = RunBashCommandTool(sandbox=sb)
384-
with pytest.raises(ToolInvocationError, match="E2B sandbox is not running"):
388+
with pytest.raises(ToolInvocationError, match="Failed to start E2B sandbox"):
385389
tool.invoke(command="ls")
386390

387391
def test_wraps_sandbox_exception(self):
@@ -417,10 +421,14 @@ def test_decodes_bytes(self):
417421

418422
assert result == "binary content"
419423

420-
def test_raises_when_no_sandbox(self):
424+
@patch("haystack_integrations.tools.e2b.e2b_sandbox.e2b_import")
425+
@patch("haystack_integrations.tools.e2b.e2b_sandbox.Sandbox.create")
426+
def test_wraps_warm_up_failure(self, mock_sandbox_create, mock_e2b_import):
427+
mock_e2b_import.check.return_value = None
428+
mock_sandbox_create.side_effect = Exception("connection refused")
421429
sb = _make_sandbox()
422430
tool = ReadFileTool(sandbox=sb)
423-
with pytest.raises(ToolInvocationError, match="E2B sandbox is not running"):
431+
with pytest.raises(ToolInvocationError, match="Failed to start E2B sandbox"):
424432
tool.invoke(path="/some/file.txt")
425433

426434
def test_wraps_sandbox_exception(self):
@@ -446,10 +454,14 @@ def test_returns_confirmation(self):
446454
assert "/output/result.txt" in result
447455
mock.files.write.assert_called_once_with("/output/result.txt", "hello")
448456

449-
def test_raises_when_no_sandbox(self):
457+
@patch("haystack_integrations.tools.e2b.e2b_sandbox.e2b_import")
458+
@patch("haystack_integrations.tools.e2b.e2b_sandbox.Sandbox.create")
459+
def test_wraps_warm_up_failure(self, mock_sandbox_create, mock_e2b_import):
460+
mock_e2b_import.check.return_value = None
461+
mock_sandbox_create.side_effect = Exception("connection refused")
450462
sb = _make_sandbox()
451463
tool = WriteFileTool(sandbox=sb)
452-
with pytest.raises(ToolInvocationError, match="E2B sandbox is not running"):
464+
with pytest.raises(ToolInvocationError, match="Failed to start E2B sandbox"):
453465
tool.invoke(path="/some/path.txt", content="content")
454466

455467
def test_wraps_sandbox_exception(self):
@@ -495,10 +507,14 @@ def test_empty_directory(self):
495507

496508
assert result == "(empty directory)"
497509

498-
def test_raises_when_no_sandbox(self):
510+
@patch("haystack_integrations.tools.e2b.e2b_sandbox.e2b_import")
511+
@patch("haystack_integrations.tools.e2b.e2b_sandbox.Sandbox.create")
512+
def test_wraps_warm_up_failure(self, mock_sandbox_create, mock_e2b_import):
513+
mock_e2b_import.check.return_value = None
514+
mock_sandbox_create.side_effect = Exception("connection refused")
499515
sb = _make_sandbox()
500516
tool = ListDirectoryTool(sandbox=sb)
501-
with pytest.raises(ToolInvocationError, match="E2B sandbox is not running"):
517+
with pytest.raises(ToolInvocationError, match="Failed to start E2B sandbox"):
502518
tool.invoke(path="/home")
503519

504520
def test_wraps_sandbox_exception(self):

0 commit comments

Comments
 (0)