Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Fix template SDK tests (#918)
Jakub Dobry4b463bd09b75
diff --git a/packages/js-sdk/tests/template/stacktrace.test.ts b/packages/js-sdk/tests/template/stacktrace.test.tsindex d72b94d7e..3782be658 100644--- a/packages/js-sdk/tests/template/stacktrace.test.ts+++ b/packages/js-sdk/tests/template/stacktrace.test.ts@@ -6,11 +6,12 @@ import fs from 'node:fs'const __fileContent = fs.readFileSync(__filename, 'utf8') // read current file contentconst nonExistentPath = '/nonexistent/path'-function buildTemplate(template: TemplateClass) {+function buildTemplate(template: TemplateClass, skipCache?: boolean) {return Template.build(template, {alias: randomUUID(),cpuCount: 1,memoryMB: 1024,+ skipCache: skipCache,})}@@ -65,7 +66,7 @@ test('traces on fromImage', async () => {const templateFrom = Template()const template = templateFrom.fromImage('e2b.dev/this-image-does-not-exist')await expectToThrowAndCheckTrace(async () => {- await buildTemplate(template)+ await buildTemplate(template, true)}, 'fromImage')})@@ -98,7 +99,7 @@ test('traces on fromRegistry', async () => {})await expectToThrowAndCheckTrace(async () => {- await buildTemplate(template)+ await buildTemplate(template, true)}, 'fromRegistry')})@@ -113,7 +114,7 @@ test('traces on fromAWSRegistry', async () => {})await expectToThrowAndCheckTrace(async () => {- await buildTemplate(template)+ await buildTemplate(template, true)}, 'fromAWSRegistry')})@@ -126,13 +127,13 @@ test('traces on fromGCPRegistry', async () => {})await expectToThrowAndCheckTrace(async () => {- await buildTemplate(template)+ await buildTemplate(template, true)}, 'fromGCPRegistry')})test('traces on copy', async () => {let template = Template().fromBaseImage()- template = template.copy(nonExistentPath, nonExistentPath)+ template = template.skipCache().copy(nonExistentPath, nonExistentPath)await expectToThrowAndCheckTrace(async () => {await buildTemplate(template)}, 'copy')@@ -140,7 +141,7 @@ test('traces on copy', async () => {test('traces on remove', async () => {let template = Template().fromBaseImage()- template = template.remove(nonExistentPath)+ template = template.skipCache().remove(nonExistentPath)await expectToThrowAndCheckTrace(async () => {await buildTemplate(template)}, 'remove')@@ -148,7 +149,7 @@ test('traces on remove', async () => {test('traces on rename', async () => {let template = Template().fromBaseImage()- template = template.rename(nonExistentPath, '/tmp/dest.txt')+ template = template.skipCache().rename(nonExistentPath, '/tmp/dest.txt')await expectToThrowAndCheckTrace(async () => {await buildTemplate(template)}, 'rename')@@ -156,7 +157,7 @@ test('traces on rename', async () => {test('traces on makeDir', async () => {let template = Template().fromBaseImage()- template = template.makeDir('.bashrc')+ template = template.skipCache().makeDir('.bashrc')await expectToThrowAndCheckTrace(async () => {await buildTemplate(template)}, 'makeDir')@@ -164,7 +165,7 @@ test('traces on makeDir', async () => {test('traces on makeSymlink', async () => {let template = Template().fromBaseImage()- template = template.makeSymlink('.bashrc', '.bashrc')+ template = template.skipCache().makeSymlink('.bashrc', '.bashrc')await expectToThrowAndCheckTrace(async () => {await buildTemplate(template)}, 'makeSymlink')@@ -172,7 +173,7 @@ test('traces on makeSymlink', async () => {test('traces on runCmd', async () => {let template = Template().fromBaseImage()- template = template.runCmd(`./${nonExistentPath}`)+ template = template.skipCache().runCmd(`./${nonExistentPath}`)await expectToThrowAndCheckTrace(async () => {await buildTemplate(template)}, 'runCmd')@@ -180,7 +181,7 @@ test('traces on runCmd', async () => {test('traces on setWorkdir', async () => {let template = Template().fromBaseImage()- template = template.setWorkdir('.bashrc')+ template = template.skipCache().setWorkdir('.bashrc')await expectToThrowAndCheckTrace(async () => {await buildTemplate(template)}, 'setWorkdir')@@ -188,7 +189,7 @@ test('traces on setWorkdir', async () => {test('traces on setUser', async () => {let template = Template().fromBaseImage()- template = template.setUser(';')+ template = template.skipCache().setUser(';')await expectToThrowAndCheckTrace(async () => {await buildTemplate(template)}, 'setUser')@@ -196,7 +197,7 @@ test('traces on setUser', async () => {test('traces on pipInstall', async () => {let template = Template().fromBaseImage()- template = template.pipInstall('nonexistent-package')+ template = template.skipCache().pipInstall('nonexistent-package')await expectToThrowAndCheckTrace(async () => {await buildTemplate(template)}, 'pipInstall')@@ -204,7 +205,7 @@ test('traces on pipInstall', async () => {test('traces on npmInstall', async () => {let template = Template().fromBaseImage()- template = template.npmInstall('nonexistent-package')+ template = template.skipCache().npmInstall('nonexistent-package')await expectToThrowAndCheckTrace(async () => {await buildTemplate(template)}, 'npmInstall')@@ -212,7 +213,7 @@ test('traces on npmInstall', async () => {test('traces on aptInstall', async () => {let template = Template().fromBaseImage()- template = template.aptInstall('nonexistent-package')+ template = template.skipCache().aptInstall('nonexistent-package')await expectToThrowAndCheckTrace(async () => {await buildTemplate(template)}, 'aptInstall')@@ -220,7 +221,9 @@ test('traces on aptInstall', async () => {test('traces on gitClone', async () => {let template = Template().fromBaseImage()- template = template.gitClone('https://github.com/nonexistent/repo.git')+ template = template+ .skipCache()+ .gitClone('https://github.com/nonexistent/repo.git')await expectToThrowAndCheckTrace(async () => {await buildTemplate(template)}, 'gitClone')diff --git a/packages/python-sdk/tests/async/template_async/test_stacktrace.py b/packages/python-sdk/tests/async/template_async/test_stacktrace.pyindex 20df08825..7b816d02f 100644--- a/packages/python-sdk/tests/async/template_async/test_stacktrace.py+++ b/packages/python-sdk/tests/async/template_async/test_stacktrace.py@@ -40,7 +40,7 @@ async def _expect_to_throw_and_check_trace(func, expected_method: str):@pytest.mark.skip_debug()async def test_traces_on_from_image():template = AsyncTemplate()- template = template.from_image("e2b.dev/this-image-does-not-exist")+ template = template.skip_cache().from_image("e2b.dev/this-image-does-not-exist")await _expect_to_throw_and_check_trace(lambda: build(template), "from_image")@@ -60,7 +60,7 @@ async def test_traces_on_from_dockerfile():@pytest.mark.skip_debug()async def test_traces_on_from_registry():template = AsyncTemplate()- template = template.from_registry(+ template = template.skip_cache().from_registry("registry.example.com/nonexistent:latest",username="test",password="test",@@ -71,7 +71,7 @@ async def test_traces_on_from_registry():@pytest.mark.skip_debug()async def test_traces_on_from_aws_registry():template = AsyncTemplate()- template = template.from_aws_registry(+ template = template.skip_cache().from_aws_registry("123456789.dkr.ecr.us-east-1.amazonaws.com/nonexistent:latest",access_key_id="test",secret_access_key="test",@@ -83,7 +83,7 @@ async def test_traces_on_from_aws_registry():@pytest.mark.skip_debug()async def test_traces_on_from_gcp_registry():template = AsyncTemplate()- template = template.from_gcp_registry(+ template = template.skip_cache().from_gcp_registry("gcr.io/nonexistent-project/nonexistent:latest",service_account_json={"type": "service_account",@@ -96,7 +96,7 @@ async def test_traces_on_from_gcp_registry():async def test_traces_on_copy():template = AsyncTemplate()template = template.from_base_image()- template = template.copy(non_existent_path, non_existent_path)+ template = template.skip_cache().copy(non_existent_path, non_existent_path)await _expect_to_throw_and_check_trace(lambda: build(template), "copy")@@ -104,7 +104,7 @@ async def test_traces_on_copy():async def test_traces_on_remove():template = AsyncTemplate()template = template.from_base_image()- template = template.remove(non_existent_path)+ template = template.skip_cache().remove(non_existent_path)await _expect_to_throw_and_check_trace(lambda: build(template), "remove")@@ -112,7 +112,7 @@ async def test_traces_on_remove():async def test_traces_on_rename():template = AsyncTemplate()template = template.from_base_image()- template = template.rename(non_existent_path, "/tmp/dest.txt")+ template = template.skip_cache().rename(non_existent_path, "/tmp/dest.txt")await _expect_to_throw_and_check_trace(lambda: build(template), "rename")@@ -120,7 +120,7 @@ async def test_traces_on_rename():async def test_traces_on_make_dir():template = AsyncTemplate()template = template.from_base_image()- template = template.make_dir(".bashrc")+ template = template.skip_cache().make_dir(".bashrc")await _expect_to_throw_and_check_trace(lambda: build(template), "make_dir")@@ -128,7 +128,7 @@ async def test_traces_on_make_dir():async def test_traces_on_make_symlink():template = AsyncTemplate()template = template.from_base_image()- template = template.make_symlink(".bashrc", ".bashrc")+ template = template.skip_cache().make_symlink(".bashrc", ".bashrc")await _expect_to_throw_and_check_trace(lambda: build(template), "make_symlink")@@ -136,7 +136,7 @@ async def test_traces_on_make_symlink():async def test_traces_on_run_cmd():template = AsyncTemplate()template = template.from_base_image()- template = template.run_cmd(f"cat {non_existent_path}")+ template = template.skip_cache().run_cmd(f"cat {non_existent_path}")await _expect_to_throw_and_check_trace(lambda: build(template), "run_cmd")@@ -144,7 +144,7 @@ async def test_traces_on_run_cmd():async def test_traces_on_set_workdir():template = AsyncTemplate()template = template.from_base_image()- template = template.set_workdir(".bashrc")+ template = template.skip_cache().set_workdir(".bashrc")await _expect_to_throw_and_check_trace(lambda: build(template), "set_workdir")@@ -152,7 +152,7 @@ async def test_traces_on_set_workdir():async def test_traces_on_set_user():template = AsyncTemplate()template = template.from_base_image()- template = template.set_user(";")+ template = template.skip_cache().set_user(";")await _expect_to_throw_and_check_trace(lambda: build(template), "set_user")@@ -160,7 +160,7 @@ async def test_traces_on_set_user():async def test_traces_on_pip_install():template = AsyncTemplate()template = template.from_base_image()- template = template.pip_install("nonexistent-package")+ template = template.skip_cache().pip_install("nonexistent-package")await _expect_to_throw_and_check_trace(lambda: build(template), "pip_install")@@ -168,7 +168,7 @@ async def test_traces_on_pip_install():async def test_traces_on_npm_install():template = AsyncTemplate()template = template.from_base_image()- template = template.npm_install("nonexistent-package")+ template = template.skip_cache().npm_install("nonexistent-package")await _expect_to_throw_and_check_trace(lambda: build(template), "npm_install")@@ -176,7 +176,7 @@ async def test_traces_on_npm_install():async def test_traces_on_apt_install():template = AsyncTemplate()template = template.from_base_image()- template = template.apt_install("nonexistent-package")+ template = template.skip_cache().apt_install("nonexistent-package")await _expect_to_throw_and_check_trace(lambda: build(template), "apt_install")@@ -184,7 +184,7 @@ async def test_traces_on_apt_install():async def test_traces_on_git_clone():template = AsyncTemplate()template = template.from_base_image()- template = template.git_clone("https://github.com/repo.git")+ template = template.skip_cache().git_clone("https://github.com/repo.git")await _expect_to_throw_and_check_trace(lambda: build(template), "git_clone")diff --git a/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py b/packages/python-sdk/tests/sync/template_sync/test_stacktrace.pyindex a9b40cef8..36afb67ec 100644--- a/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py+++ b/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py@@ -40,7 +40,7 @@ def _expect_to_throw_and_check_trace(func, expected_method: str):@pytest.mark.skip_debug()def test_traces_on_from_image():template = Template()- template = template.from_image("e2b.dev/this-image-does-not-exist")+ template = template.skip_cache().from_image("e2b.dev/this-image-does-not-exist")_expect_to_throw_and_check_trace(lambda: build(template), "from_image")@@ -60,7 +60,7 @@ def test_traces_on_from_dockerfile():@pytest.mark.skip_debug()def test_traces_on_from_registry():template = Template()- template = template.from_registry(+ template = template.skip_cache().from_registry("registry.example.com/nonexistent:latest",username="test",password="test",@@ -71,7 +71,7 @@ def test_traces_on_from_registry():@pytest.mark.skip_debug()def test_traces_on_from_aws_registry():template = Template()- template = template.from_aws_registry(+ template = template.skip_cache().from_aws_registry("123456789.dkr.ecr.us-east-1.amazonaws.com/nonexistent:latest",access_key_id="test",secret_access_key="test",@@ -83,7 +83,7 @@ def test_traces_on_from_aws_registry():@pytest.mark.skip_debug()def test_traces_on_from_gcp_registry():template = Template()- template = template.from_gcp_registry(+ template = template.skip_cache().from_gcp_registry("gcr.io/nonexistent-project/nonexistent:latest",service_account_json={"type": "service_account",@@ -96,7 +96,7 @@ def test_traces_on_from_gcp_registry():def test_traces_on_copy():template = Template()template = template.from_base_image()- template = template.copy(non_existent_path, non_existent_path)+ template = template.skip_cache().copy(non_existent_path, non_existent_path)_expect_to_throw_and_check_trace(lambda: build(template), "copy")@@ -104,7 +104,7 @@ def test_traces_on_copy():def test_traces_on_remove():template = Template()template = template.from_base_image()- template = template.remove(non_existent_path)+ template = template.skip_cache().remove(non_existent_path)_expect_to_throw_and_check_trace(lambda: build(template), "remove")@@ -112,7 +112,7 @@ def test_traces_on_remove():def test_traces_on_rename():template = Template()template = template.from_base_image()- template = template.rename(non_existent_path, "/tmp/dest.txt")+ template = template.skip_cache().rename(non_existent_path, "/tmp/dest.txt")_expect_to_throw_and_check_trace(lambda: build(template), "rename")@@ -120,7 +120,7 @@ def test_traces_on_rename():def test_traces_on_make_dir():template = Template()template = template.from_base_image()- template = template.make_dir(".bashrc")+ template = template.skip_cache().make_dir(".bashrc")_expect_to_throw_and_check_trace(lambda: build(template), "make_dir")@@ -128,7 +128,7 @@ def test_traces_on_make_dir():def test_traces_on_make_symlink():template = Template()template = template.from_base_image()- template = template.make_symlink(".bashrc", ".bashrc")+ template = template.skip_cache().make_symlink(".bashrc", ".bashrc")_expect_to_throw_and_check_trace(lambda: build(template), "make_symlink")@@ -136,7 +136,7 @@ def test_traces_on_make_symlink():def test_traces_on_run_cmd():template = Template()template = template.from_base_image()- template = template.run_cmd(f"cat {non_existent_path}")+ template = template.skip_cache().run_cmd(f"cat {non_existent_path}")_expect_to_throw_and_check_trace(lambda: build(template), "run_cmd")@@ -144,7 +144,7 @@ def test_traces_on_run_cmd():def test_traces_on_set_workdir():template = Template()template = template.from_base_image()- template = template.set_workdir(".bashrc")+ template = template.skip_cache().set_workdir(".bashrc")_expect_to_throw_and_check_trace(lambda: build(template), "set_workdir")@@ -152,7 +152,7 @@ def test_traces_on_set_workdir():def test_traces_on_set_user():template = Template()template = template.from_base_image()- template = template.set_user(";")+ template = template.skip_cache().set_user(";")_expect_to_throw_and_check_trace(lambda: build(template), "set_user")@@ -160,7 +160,7 @@ def test_traces_on_set_user():def test_traces_on_pip_install():template = Template()template = template.from_base_image()- template = template.pip_install("nonexistent-package")+ template = template.skip_cache().pip_install("nonexistent-package")_expect_to_throw_and_check_trace(lambda: build(template), "pip_install")@@ -168,7 +168,7 @@ def test_traces_on_pip_install():def test_traces_on_npm_install():template = Template()template = template.from_base_image()- template = template.npm_install("nonexistent-package")+ template = template.skip_cache().npm_install("nonexistent-package")_expect_to_throw_and_check_trace(lambda: build(template), "npm_install")@@ -176,7 +176,7 @@ def test_traces_on_npm_install():def test_traces_on_apt_install():template = Template()template = template.from_base_image()- template = template.apt_install("nonexistent-package")+ template = template.skip_cache().apt_install("nonexistent-package")_expect_to_throw_and_check_trace(lambda: build(template), "apt_install")@@ -184,7 +184,7 @@ def test_traces_on_apt_install():def test_traces_on_git_clone():template = Template()template = template.from_base_image()- template = template.git_clone("https://github.com/repo.git")+ template = template.skip_cache().git_clone("https://github.com/repo.git")_expect_to_throw_and_check_trace(lambda: build(template), "git_clone")