353 lines
12 KiB
Python
Raw Permalink Normal View History

Improve CI/CD speed for template tests (#1035) <!-- CURSOR_SUMMARY --> > [!NOTE] > Caches Playwright binaries in JS CI and refactors JS/Python template tests to use API mocks and aliases, add Dockerfile tests, and update install APIs to single-package calls. > > - **CI**: > - Cache Playwright binaries on `ubuntu-22.04` and `windows-latest` in `.github/workflows/js_sdk_tests.yml` to speed JS SDK tests. > - **JS SDK Tests**: > - Extend `buildTemplate` options to accept `alias` in `tests/setup.ts`. > - Add `fromDockerfile` tests and switch some builds to `fromBaseImage`; add build-from-base-template test. > - Update install method tests to single-package calls for `aptInstall`, `npmInstall`, `bunInstall`, `pipInstall`. > - Tweak `makeSymlink` test order to ensure overwrite behavior. > - Overhaul stacktrace tests to use `msw` server mocks and alias-based failure mapping. > - **Python SDK Tests**: > - `build`/`async_build` fixtures accept optional `alias`. > - Add `from_dockerfile` tests (sync/async); use base image/base template where applicable. > - Update install method tests to single-package calls. > - Rewrite stacktrace tests to monkeypatch API calls with alias-based failure mapping. > - **Dependencies**: > - Add dev dependency `msw` to `packages/js-sdk/package.json`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 1b7f84f4ce692f664c3ce4cdb345f4c3a028b17a. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
2025-11-28 22:34:13 +01:00
import traceback
from types import SimpleNamespace
from typing import List, Optional
Improve CI/CD speed for template tests (#1035) <!-- CURSOR_SUMMARY --> > [!NOTE] > Caches Playwright binaries in JS CI and refactors JS/Python template tests to use API mocks and aliases, add Dockerfile tests, and update install APIs to single-package calls. > > - **CI**: > - Cache Playwright binaries on `ubuntu-22.04` and `windows-latest` in `.github/workflows/js_sdk_tests.yml` to speed JS SDK tests. > - **JS SDK Tests**: > - Extend `buildTemplate` options to accept `alias` in `tests/setup.ts`. > - Add `fromDockerfile` tests and switch some builds to `fromBaseImage`; add build-from-base-template test. > - Update install method tests to single-package calls for `aptInstall`, `npmInstall`, `bunInstall`, `pipInstall`. > - Tweak `makeSymlink` test order to ensure overwrite behavior. > - Overhaul stacktrace tests to use `msw` server mocks and alias-based failure mapping. > - **Python SDK Tests**: > - `build`/`async_build` fixtures accept optional `alias`. > - Add `from_dockerfile` tests (sync/async); use base image/base template where applicable. > - Update install method tests to single-package calls. > - Rewrite stacktrace tests to monkeypatch API calls with alias-based failure mapping. > - **Dependencies**: > - Add dev dependency `msw` to `packages/js-sdk/package.json`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 1b7f84f4ce692f664c3ce4cdb345f4c3a028b17a. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
2025-11-28 22:34:13 +01:00
from uuid import uuid4
Render failed layer stack traces on build error (#901) ### Changelog - Added traces for Python and JavaScript SDK. - Added methods for stack trace collection, stack trace context - Updated file upload mechanism for tracing - Changed API handling to support throwing API errors with traces > **Note** > For functions like `aptInstall`, `fromRegistry` which call `.run` and `.fromImage`, the stack trace has to be replaced so it throws correctly from parent. > **Note** > There are no build logs in the trace, we can add this at later point. ### Examples Keep in mind that the way the traces are rendered entirely depends on environment (Bun, Node, Deno, Vitest, Pytest) **Standard Python** ``` Traceback (most recent call last): File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module> Template.build( ~~~~~~~~~~~~~~^ template, ^^^^^^^^^ ...<2 lines>... memory_mb=1024, ^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build wait_for_build_finish( ~~~~~~~~~~~~~~~~~~~~~^ api_client, ^^^^^^^^^^^ ...<4 lines>... stack_traces=template._template._stack_traces, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module> .run_cmd("cat non_existing_file.txt") ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Pytest** ``` [gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) # try: > Template.build( template, alias=str(uuid4()), cpu_count=1, memory_mb=1024, ) tests/sync/template_sync/test_stacktrace.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ e2b/template_sync/main.py:157: in build wait_for_build_finish( e2b/template_sync/build_api.py:199: in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") > .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) E e2b.template.exceptions.BuildException: failed to run command: exit status 1 tests/sync/template_sync/test_stacktrace.py:12: BuildException ========================================================== short test summary info ========================================================== FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Node** ``` node:internal/modules/run_main:104 triggerUncaughtException( ^ at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4 at ModuleJob.run (node:internal/modules/esm/module_job:274:25) at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) { name: 'BuildError' } Node.js v23.11.0 ``` **Bun** ``` 1 | export class BuildError extends Error { 2 | constructor(message: string, stackTrace?: string) { 3 | super(message) ^ BuildError: failed to run command: exit status 1 at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5 Bun v1.2.4 (macOS arm64) ``` **Vitest** ``` BuildError: failed to run command: exit status 1 ❯ tests/template/trace.test.ts:8:6 6| const template = Template() 7| .fromImage('ubuntu:22.04') 8| .runCmd('cat folder/test.txt') | ^ 9| .setWorkdir('/app') 10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000)) ``` --------- Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
import pytest
import linecache
Improve method naming and consistency (#934) <!-- CURSOR_SUMMARY --> > [!NOTE] > Unifies Template APIs across JS/Python with PathLike support, new copyItems, option/name tweaks, and simpler registry auth via credentials; updates parser, exports, and tests. > > - **Template API (JS + Python)** > - Add PathLike support for paths in `copy`, `remove`, `rename`, `makeDir`, `makeSymlink`, `setWorkdir`, and `gitClone`. > - Introduce `copyItems` and corresponding `CopyItem` typing; adjust Dockerfile parser to use `copyItems` overload. > - Simplify registry auth: `fromImage(baseImage, credentials)` accepts `{username,password}`; remove `fromRegistry`; update `fromAWSRegistry`/`fromGCPRegistry` to take credentials and set config internally. > - Rename options: `ignoreFilePaths` -> `fileIgnorePatterns`; `fileContextPath` can be `PathLike`. > - Ensure internal hashing/upload use stringified paths; minor enum/type tweaks (e.g., `InstructionType` as string enum, `forceUpload?: true`). > - **Exports** > - Export `CopyItem` from JS `index.ts` and Python `__init__.py`. > - **Tests** > - Update stacktrace and build tests to new method names/signatures (e.g., registry via `fromImage` credentials, new `copyItems` tests, optional `skipCache` param). > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 95391030550a340fe99ebaac4494867b3e3e9507. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-10-09 00:51:02 +02:00
from e2b import AsyncTemplate, CopyItem, wait_for_timeout
from e2b.template.types import TemplateBuildStatus
Improve CI/CD speed for template tests (#1035) <!-- CURSOR_SUMMARY --> > [!NOTE] > Caches Playwright binaries in JS CI and refactors JS/Python template tests to use API mocks and aliases, add Dockerfile tests, and update install APIs to single-package calls. > > - **CI**: > - Cache Playwright binaries on `ubuntu-22.04` and `windows-latest` in `.github/workflows/js_sdk_tests.yml` to speed JS SDK tests. > - **JS SDK Tests**: > - Extend `buildTemplate` options to accept `alias` in `tests/setup.ts`. > - Add `fromDockerfile` tests and switch some builds to `fromBaseImage`; add build-from-base-template test. > - Update install method tests to single-package calls for `aptInstall`, `npmInstall`, `bunInstall`, `pipInstall`. > - Tweak `makeSymlink` test order to ensure overwrite behavior. > - Overhaul stacktrace tests to use `msw` server mocks and alias-based failure mapping. > - **Python SDK Tests**: > - `build`/`async_build` fixtures accept optional `alias`. > - Add `from_dockerfile` tests (sync/async); use base image/base template where applicable. > - Update install method tests to single-package calls. > - Rewrite stacktrace tests to monkeypatch API calls with alias-based failure mapping. > - **Dependencies**: > - Add dev dependency `msw` to `packages/js-sdk/package.json`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 1b7f84f4ce692f664c3ce4cdb345f4c3a028b17a. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
2025-11-28 22:34:13 +01:00
import e2b.template_async.main as template_async_main
import e2b.template_async.build_api as build_api_mod
Render failed layer stack traces on build error (#901) ### Changelog - Added traces for Python and JavaScript SDK. - Added methods for stack trace collection, stack trace context - Updated file upload mechanism for tracing - Changed API handling to support throwing API errors with traces > **Note** > For functions like `aptInstall`, `fromRegistry` which call `.run` and `.fromImage`, the stack trace has to be replaced so it throws correctly from parent. > **Note** > There are no build logs in the trace, we can add this at later point. ### Examples Keep in mind that the way the traces are rendered entirely depends on environment (Bun, Node, Deno, Vitest, Pytest) **Standard Python** ``` Traceback (most recent call last): File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module> Template.build( ~~~~~~~~~~~~~~^ template, ^^^^^^^^^ ...<2 lines>... memory_mb=1024, ^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build wait_for_build_finish( ~~~~~~~~~~~~~~~~~~~~~^ api_client, ^^^^^^^^^^^ ...<4 lines>... stack_traces=template._template._stack_traces, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module> .run_cmd("cat non_existing_file.txt") ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Pytest** ``` [gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) # try: > Template.build( template, alias=str(uuid4()), cpu_count=1, memory_mb=1024, ) tests/sync/template_sync/test_stacktrace.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ e2b/template_sync/main.py:157: in build wait_for_build_finish( e2b/template_sync/build_api.py:199: in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") > .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) E e2b.template.exceptions.BuildException: failed to run command: exit status 1 tests/sync/template_sync/test_stacktrace.py:12: BuildException ========================================================== short test summary info ========================================================== FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Node** ``` node:internal/modules/run_main:104 triggerUncaughtException( ^ at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4 at ModuleJob.run (node:internal/modules/esm/module_job:274:25) at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) { name: 'BuildError' } Node.js v23.11.0 ``` **Bun** ``` 1 | export class BuildError extends Error { 2 | constructor(message: string, stackTrace?: string) { 3 | super(message) ^ BuildError: failed to run command: exit status 1 at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5 Bun v1.2.4 (macOS arm64) ``` **Vitest** ``` BuildError: failed to run command: exit status 1 ❯ tests/template/trace.test.ts:8:6 6| const template = Template() 7| .fromImage('ubuntu:22.04') 8| .runCmd('cat folder/test.txt') | ^ 9| .setWorkdir('/app') 10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000)) ``` --------- Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
feat: validate copy src paths are relative and within context directory (#1106) Add path validation to the copy method in both JS and Python SDKs to ensure source paths are always relative and don't escape the context directory. This prevents: - Absolute paths like /absolute/whatever (Unix) or C:\whatever (Windows) - Path traversal attacks like ../whatever or ./foo/../../../bar The validation works cross-platform using Node's path.isAbsolute/normalize and Python's os.path.isabs/normpath plus PureWindowsPath for detecting Windows paths on Unix. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Changes behavior of `copy`/`copy_items` to throw earlier for previously-accepted absolute or escaping paths, which could break some consumers; logic is localized and well-covered by tests. > > **Overview** > Prevents path traversal in template `copy` operations by validating `src` is *relative* and does not escape the context directory (rejects absolute paths and `..`-based escapes) in both the JS and Python SDKs. > > Updates `copyItems`/`copy_items` error handling to preserve the caller’s stack trace when validation fails, adds unit coverage for the new path validator plus new stack-trace tests for absolute-path failures, and ships as patch releases via a changeset. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit c1a8eb978e3fd99fa829d571e811bb7ee18cd40b. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 13:54:54 +01:00
non_existent_path = "nonexistent/path"
Render failed layer stack traces on build error (#901) ### Changelog - Added traces for Python and JavaScript SDK. - Added methods for stack trace collection, stack trace context - Updated file upload mechanism for tracing - Changed API handling to support throwing API errors with traces > **Note** > For functions like `aptInstall`, `fromRegistry` which call `.run` and `.fromImage`, the stack trace has to be replaced so it throws correctly from parent. > **Note** > There are no build logs in the trace, we can add this at later point. ### Examples Keep in mind that the way the traces are rendered entirely depends on environment (Bun, Node, Deno, Vitest, Pytest) **Standard Python** ``` Traceback (most recent call last): File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module> Template.build( ~~~~~~~~~~~~~~^ template, ^^^^^^^^^ ...<2 lines>... memory_mb=1024, ^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build wait_for_build_finish( ~~~~~~~~~~~~~~~~~~~~~^ api_client, ^^^^^^^^^^^ ...<4 lines>... stack_traces=template._template._stack_traces, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module> .run_cmd("cat non_existing_file.txt") ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Pytest** ``` [gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) # try: > Template.build( template, alias=str(uuid4()), cpu_count=1, memory_mb=1024, ) tests/sync/template_sync/test_stacktrace.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ e2b/template_sync/main.py:157: in build wait_for_build_finish( e2b/template_sync/build_api.py:199: in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") > .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) E e2b.template.exceptions.BuildException: failed to run command: exit status 1 tests/sync/template_sync/test_stacktrace.py:12: BuildException ========================================================== short test summary info ========================================================== FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Node** ``` node:internal/modules/run_main:104 triggerUncaughtException( ^ at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4 at ModuleJob.run (node:internal/modules/esm/module_job:274:25) at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) { name: 'BuildError' } Node.js v23.11.0 ``` **Bun** ``` 1 | export class BuildError extends Error { 2 | constructor(message: string, stackTrace?: string) { 3 | super(message) ^ BuildError: failed to run command: exit status 1 at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5 Bun v1.2.4 (macOS arm64) ``` **Vitest** ``` BuildError: failed to run command: exit status 1 ❯ tests/template/trace.test.ts:8:6 6| const template = Template() 7| .fromImage('ubuntu:22.04') 8| .runCmd('cat folder/test.txt') | ^ 9| .setWorkdir('/app') 10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000)) ``` --------- Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
Improve CI/CD speed for template tests (#1035) <!-- CURSOR_SUMMARY --> > [!NOTE] > Caches Playwright binaries in JS CI and refactors JS/Python template tests to use API mocks and aliases, add Dockerfile tests, and update install APIs to single-package calls. > > - **CI**: > - Cache Playwright binaries on `ubuntu-22.04` and `windows-latest` in `.github/workflows/js_sdk_tests.yml` to speed JS SDK tests. > - **JS SDK Tests**: > - Extend `buildTemplate` options to accept `alias` in `tests/setup.ts`. > - Add `fromDockerfile` tests and switch some builds to `fromBaseImage`; add build-from-base-template test. > - Update install method tests to single-package calls for `aptInstall`, `npmInstall`, `bunInstall`, `pipInstall`. > - Tweak `makeSymlink` test order to ensure overwrite behavior. > - Overhaul stacktrace tests to use `msw` server mocks and alias-based failure mapping. > - **Python SDK Tests**: > - `build`/`async_build` fixtures accept optional `alias`. > - Add `from_dockerfile` tests (sync/async); use base image/base template where applicable. > - Update install method tests to single-package calls. > - Rewrite stacktrace tests to monkeypatch API calls with alias-based failure mapping. > - **Dependencies**: > - Add dev dependency `msw` to `packages/js-sdk/package.json`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 1b7f84f4ce692f664c3ce4cdb345f4c3a028b17a. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
2025-11-28 22:34:13 +01:00
# map template alias -> failed step index
failure_map: dict[str, Optional[int]] = {
"from_image": 0,
"from_template": 0,
"from_dockerfile": 0,
"from_image_registry": 0,
"from_aws_registry": 0,
"from_gcp_registry": 0,
"copy": None,
"copy_items": None,
"remove": 1,
"rename": 1,
"make_dir": 1,
"make_symlink": 1,
"run_cmd": 1,
"set_workdir": 1,
"set_user": 1,
"pip_install": 1,
"npm_install": 1,
"apt_install": 1,
"git_clone": 1,
"set_start_cmd": 1,
"add_mcp_server": None,
"beta_dev_container_prebuild": 1,
"beta_set_dev_container_start": 1,
}
@pytest.fixture(autouse=True)
def mock_template_build(monkeypatch):
async def mock_request_build(
client, name: str, tags: Optional[List[str]], cpu_count: int, memory_mb: int
):
return SimpleNamespace(template_id=name, build_id=str(uuid4()), tags=tags or [])
Improve CI/CD speed for template tests (#1035) <!-- CURSOR_SUMMARY --> > [!NOTE] > Caches Playwright binaries in JS CI and refactors JS/Python template tests to use API mocks and aliases, add Dockerfile tests, and update install APIs to single-package calls. > > - **CI**: > - Cache Playwright binaries on `ubuntu-22.04` and `windows-latest` in `.github/workflows/js_sdk_tests.yml` to speed JS SDK tests. > - **JS SDK Tests**: > - Extend `buildTemplate` options to accept `alias` in `tests/setup.ts`. > - Add `fromDockerfile` tests and switch some builds to `fromBaseImage`; add build-from-base-template test. > - Update install method tests to single-package calls for `aptInstall`, `npmInstall`, `bunInstall`, `pipInstall`. > - Tweak `makeSymlink` test order to ensure overwrite behavior. > - Overhaul stacktrace tests to use `msw` server mocks and alias-based failure mapping. > - **Python SDK Tests**: > - `build`/`async_build` fixtures accept optional `alias`. > - Add `from_dockerfile` tests (sync/async); use base image/base template where applicable. > - Update install method tests to single-package calls. > - Rewrite stacktrace tests to monkeypatch API calls with alias-based failure mapping. > - **Dependencies**: > - Add dev dependency `msw` to `packages/js-sdk/package.json`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 1b7f84f4ce692f664c3ce4cdb345f4c3a028b17a. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
2025-11-28 22:34:13 +01:00
async def mock_trigger_build(client, template_id: str, build_id: str, template):
return None
async def mock_get_build_status(
client, template_id: str, build_id: str, logs_offset: int
):
step = failure_map[template_id]
reason = SimpleNamespace(
message="Mocked API build error",
log_entries=[],
step=str(step) if step is not None else None,
)
return SimpleNamespace(
status=TemplateBuildStatus.ERROR,
log_entries=[],
reason=reason,
)
monkeypatch.setattr(template_async_main, "request_build", mock_request_build)
monkeypatch.setattr(template_async_main, "trigger_build", mock_trigger_build)
monkeypatch.setattr(build_api_mod, "get_build_status", mock_get_build_status)
Render failed layer stack traces on build error (#901) ### Changelog - Added traces for Python and JavaScript SDK. - Added methods for stack trace collection, stack trace context - Updated file upload mechanism for tracing - Changed API handling to support throwing API errors with traces > **Note** > For functions like `aptInstall`, `fromRegistry` which call `.run` and `.fromImage`, the stack trace has to be replaced so it throws correctly from parent. > **Note** > There are no build logs in the trace, we can add this at later point. ### Examples Keep in mind that the way the traces are rendered entirely depends on environment (Bun, Node, Deno, Vitest, Pytest) **Standard Python** ``` Traceback (most recent call last): File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module> Template.build( ~~~~~~~~~~~~~~^ template, ^^^^^^^^^ ...<2 lines>... memory_mb=1024, ^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build wait_for_build_finish( ~~~~~~~~~~~~~~~~~~~~~^ api_client, ^^^^^^^^^^^ ...<4 lines>... stack_traces=template._template._stack_traces, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module> .run_cmd("cat non_existing_file.txt") ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Pytest** ``` [gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) # try: > Template.build( template, alias=str(uuid4()), cpu_count=1, memory_mb=1024, ) tests/sync/template_sync/test_stacktrace.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ e2b/template_sync/main.py:157: in build wait_for_build_finish( e2b/template_sync/build_api.py:199: in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") > .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) E e2b.template.exceptions.BuildException: failed to run command: exit status 1 tests/sync/template_sync/test_stacktrace.py:12: BuildException ========================================================== short test summary info ========================================================== FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Node** ``` node:internal/modules/run_main:104 triggerUncaughtException( ^ at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4 at ModuleJob.run (node:internal/modules/esm/module_job:274:25) at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) { name: 'BuildError' } Node.js v23.11.0 ``` **Bun** ``` 1 | export class BuildError extends Error { 2 | constructor(message: string, stackTrace?: string) { 3 | super(message) ^ BuildError: failed to run command: exit status 1 at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5 Bun v1.2.4 (macOS arm64) ``` **Vitest** ``` BuildError: failed to run command: exit status 1 ❯ tests/template/trace.test.ts:8:6 6| const template = Template() 7| .fromImage('ubuntu:22.04') 8| .runCmd('cat folder/test.txt') | ^ 9| .setWorkdir('/app') 10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000)) ``` --------- Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
async def _expect_to_throw_and_check_trace(func, expected_method: str):
try:
await func()
assert False, "Expected AsyncTemplate.build to raise an exception"
except Exception as e: # noqa: BLE001 - we want to assert on the traceback regardless of type
tb = e.__traceback__
saw_this_file = False
saw_expected_method = False
while tb is not None:
traceback_file = tb.tb_frame.f_code.co_filename
if traceback_file == __file__:
saw_this_file = True
caller_line = linecache.getline(traceback_file, tb.tb_lineno)
if caller_line and f".{expected_method}(" in caller_line:
saw_expected_method = True
break
tb = tb.tb_next
Improve CI/CD speed for template tests (#1035) <!-- CURSOR_SUMMARY --> > [!NOTE] > Caches Playwright binaries in JS CI and refactors JS/Python template tests to use API mocks and aliases, add Dockerfile tests, and update install APIs to single-package calls. > > - **CI**: > - Cache Playwright binaries on `ubuntu-22.04` and `windows-latest` in `.github/workflows/js_sdk_tests.yml` to speed JS SDK tests. > - **JS SDK Tests**: > - Extend `buildTemplate` options to accept `alias` in `tests/setup.ts`. > - Add `fromDockerfile` tests and switch some builds to `fromBaseImage`; add build-from-base-template test. > - Update install method tests to single-package calls for `aptInstall`, `npmInstall`, `bunInstall`, `pipInstall`. > - Tweak `makeSymlink` test order to ensure overwrite behavior. > - Overhaul stacktrace tests to use `msw` server mocks and alias-based failure mapping. > - **Python SDK Tests**: > - `build`/`async_build` fixtures accept optional `alias`. > - Add `from_dockerfile` tests (sync/async); use base image/base template where applicable. > - Update install method tests to single-package calls. > - Rewrite stacktrace tests to monkeypatch API calls with alias-based failure mapping. > - **Dependencies**: > - Add dev dependency `msw` to `packages/js-sdk/package.json`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 1b7f84f4ce692f664c3ce4cdb345f4c3a028b17a. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
2025-11-28 22:34:13 +01:00
assert saw_this_file, traceback.format_exc()
assert saw_expected_method, traceback.format_exc()
Render failed layer stack traces on build error (#901) ### Changelog - Added traces for Python and JavaScript SDK. - Added methods for stack trace collection, stack trace context - Updated file upload mechanism for tracing - Changed API handling to support throwing API errors with traces > **Note** > For functions like `aptInstall`, `fromRegistry` which call `.run` and `.fromImage`, the stack trace has to be replaced so it throws correctly from parent. > **Note** > There are no build logs in the trace, we can add this at later point. ### Examples Keep in mind that the way the traces are rendered entirely depends on environment (Bun, Node, Deno, Vitest, Pytest) **Standard Python** ``` Traceback (most recent call last): File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module> Template.build( ~~~~~~~~~~~~~~^ template, ^^^^^^^^^ ...<2 lines>... memory_mb=1024, ^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build wait_for_build_finish( ~~~~~~~~~~~~~~~~~~~~~^ api_client, ^^^^^^^^^^^ ...<4 lines>... stack_traces=template._template._stack_traces, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module> .run_cmd("cat non_existing_file.txt") ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Pytest** ``` [gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) # try: > Template.build( template, alias=str(uuid4()), cpu_count=1, memory_mb=1024, ) tests/sync/template_sync/test_stacktrace.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ e2b/template_sync/main.py:157: in build wait_for_build_finish( e2b/template_sync/build_api.py:199: in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") > .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) E e2b.template.exceptions.BuildException: failed to run command: exit status 1 tests/sync/template_sync/test_stacktrace.py:12: BuildException ========================================================== short test summary info ========================================================== FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Node** ``` node:internal/modules/run_main:104 triggerUncaughtException( ^ at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4 at ModuleJob.run (node:internal/modules/esm/module_job:274:25) at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) { name: 'BuildError' } Node.js v23.11.0 ``` **Bun** ``` 1 | export class BuildError extends Error { 2 | constructor(message: string, stackTrace?: string) { 3 | super(message) ^ BuildError: failed to run command: exit status 1 at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5 Bun v1.2.4 (macOS arm64) ``` **Vitest** ``` BuildError: failed to run command: exit status 1 ❯ tests/template/trace.test.ts:8:6 6| const template = Template() 7| .fromImage('ubuntu:22.04') 8| .runCmd('cat folder/test.txt') | ^ 9| .setWorkdir('/app') 10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000)) ``` --------- Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
@pytest.mark.skip_debug()
async def test_traces_on_from_image(async_build):
template = AsyncTemplate().from_image("e2b.dev/this-image-does-not-exist")
await _expect_to_throw_and_check_trace(
lambda: async_build(template, name="from_image", skip_cache=True), "from_image"
)
Render failed layer stack traces on build error (#901) ### Changelog - Added traces for Python and JavaScript SDK. - Added methods for stack trace collection, stack trace context - Updated file upload mechanism for tracing - Changed API handling to support throwing API errors with traces > **Note** > For functions like `aptInstall`, `fromRegistry` which call `.run` and `.fromImage`, the stack trace has to be replaced so it throws correctly from parent. > **Note** > There are no build logs in the trace, we can add this at later point. ### Examples Keep in mind that the way the traces are rendered entirely depends on environment (Bun, Node, Deno, Vitest, Pytest) **Standard Python** ``` Traceback (most recent call last): File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module> Template.build( ~~~~~~~~~~~~~~^ template, ^^^^^^^^^ ...<2 lines>... memory_mb=1024, ^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build wait_for_build_finish( ~~~~~~~~~~~~~~~~~~~~~^ api_client, ^^^^^^^^^^^ ...<4 lines>... stack_traces=template._template._stack_traces, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module> .run_cmd("cat non_existing_file.txt") ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Pytest** ``` [gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) # try: > Template.build( template, alias=str(uuid4()), cpu_count=1, memory_mb=1024, ) tests/sync/template_sync/test_stacktrace.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ e2b/template_sync/main.py:157: in build wait_for_build_finish( e2b/template_sync/build_api.py:199: in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") > .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) E e2b.template.exceptions.BuildException: failed to run command: exit status 1 tests/sync/template_sync/test_stacktrace.py:12: BuildException ========================================================== short test summary info ========================================================== FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Node** ``` node:internal/modules/run_main:104 triggerUncaughtException( ^ at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4 at ModuleJob.run (node:internal/modules/esm/module_job:274:25) at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) { name: 'BuildError' } Node.js v23.11.0 ``` **Bun** ``` 1 | export class BuildError extends Error { 2 | constructor(message: string, stackTrace?: string) { 3 | super(message) ^ BuildError: failed to run command: exit status 1 at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5 Bun v1.2.4 (macOS arm64) ``` **Vitest** ``` BuildError: failed to run command: exit status 1 ❯ tests/template/trace.test.ts:8:6 6| const template = Template() 7| .fromImage('ubuntu:22.04') 8| .runCmd('cat folder/test.txt') | ^ 9| .setWorkdir('/app') 10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000)) ``` --------- Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
@pytest.mark.skip_debug()
async def test_traces_on_from_template(async_build):
template = AsyncTemplate().from_template("this-template-does-not-exist")
await _expect_to_throw_and_check_trace(
lambda: async_build(template, name="from_template", skip_cache=True),
Improve CI/CD speed for template tests (#1035) <!-- CURSOR_SUMMARY --> > [!NOTE] > Caches Playwright binaries in JS CI and refactors JS/Python template tests to use API mocks and aliases, add Dockerfile tests, and update install APIs to single-package calls. > > - **CI**: > - Cache Playwright binaries on `ubuntu-22.04` and `windows-latest` in `.github/workflows/js_sdk_tests.yml` to speed JS SDK tests. > - **JS SDK Tests**: > - Extend `buildTemplate` options to accept `alias` in `tests/setup.ts`. > - Add `fromDockerfile` tests and switch some builds to `fromBaseImage`; add build-from-base-template test. > - Update install method tests to single-package calls for `aptInstall`, `npmInstall`, `bunInstall`, `pipInstall`. > - Tweak `makeSymlink` test order to ensure overwrite behavior. > - Overhaul stacktrace tests to use `msw` server mocks and alias-based failure mapping. > - **Python SDK Tests**: > - `build`/`async_build` fixtures accept optional `alias`. > - Add `from_dockerfile` tests (sync/async); use base image/base template where applicable. > - Update install method tests to single-package calls. > - Rewrite stacktrace tests to monkeypatch API calls with alias-based failure mapping. > - **Dependencies**: > - Add dev dependency `msw` to `packages/js-sdk/package.json`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 1b7f84f4ce692f664c3ce4cdb345f4c3a028b17a. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
2025-11-28 22:34:13 +01:00
"from_template",
)
Render failed layer stack traces on build error (#901) ### Changelog - Added traces for Python and JavaScript SDK. - Added methods for stack trace collection, stack trace context - Updated file upload mechanism for tracing - Changed API handling to support throwing API errors with traces > **Note** > For functions like `aptInstall`, `fromRegistry` which call `.run` and `.fromImage`, the stack trace has to be replaced so it throws correctly from parent. > **Note** > There are no build logs in the trace, we can add this at later point. ### Examples Keep in mind that the way the traces are rendered entirely depends on environment (Bun, Node, Deno, Vitest, Pytest) **Standard Python** ``` Traceback (most recent call last): File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module> Template.build( ~~~~~~~~~~~~~~^ template, ^^^^^^^^^ ...<2 lines>... memory_mb=1024, ^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build wait_for_build_finish( ~~~~~~~~~~~~~~~~~~~~~^ api_client, ^^^^^^^^^^^ ...<4 lines>... stack_traces=template._template._stack_traces, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module> .run_cmd("cat non_existing_file.txt") ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Pytest** ``` [gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) # try: > Template.build( template, alias=str(uuid4()), cpu_count=1, memory_mb=1024, ) tests/sync/template_sync/test_stacktrace.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ e2b/template_sync/main.py:157: in build wait_for_build_finish( e2b/template_sync/build_api.py:199: in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") > .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) E e2b.template.exceptions.BuildException: failed to run command: exit status 1 tests/sync/template_sync/test_stacktrace.py:12: BuildException ========================================================== short test summary info ========================================================== FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Node** ``` node:internal/modules/run_main:104 triggerUncaughtException( ^ at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4 at ModuleJob.run (node:internal/modules/esm/module_job:274:25) at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) { name: 'BuildError' } Node.js v23.11.0 ``` **Bun** ``` 1 | export class BuildError extends Error { 2 | constructor(message: string, stackTrace?: string) { 3 | super(message) ^ BuildError: failed to run command: exit status 1 at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5 Bun v1.2.4 (macOS arm64) ``` **Vitest** ``` BuildError: failed to run command: exit status 1 ❯ tests/template/trace.test.ts:8:6 6| const template = Template() 7| .fromImage('ubuntu:22.04') 8| .runCmd('cat folder/test.txt') | ^ 9| .setWorkdir('/app') 10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000)) ``` --------- Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
@pytest.mark.skip_debug()
async def test_traces_on_from_dockerfile(async_build):
template = AsyncTemplate().from_dockerfile("FROM ubuntu:22.04\nRUN nonexistent")
await _expect_to_throw_and_check_trace(
lambda: async_build(template, name="from_dockerfile", skip_cache=True),
Improve CI/CD speed for template tests (#1035) <!-- CURSOR_SUMMARY --> > [!NOTE] > Caches Playwright binaries in JS CI and refactors JS/Python template tests to use API mocks and aliases, add Dockerfile tests, and update install APIs to single-package calls. > > - **CI**: > - Cache Playwright binaries on `ubuntu-22.04` and `windows-latest` in `.github/workflows/js_sdk_tests.yml` to speed JS SDK tests. > - **JS SDK Tests**: > - Extend `buildTemplate` options to accept `alias` in `tests/setup.ts`. > - Add `fromDockerfile` tests and switch some builds to `fromBaseImage`; add build-from-base-template test. > - Update install method tests to single-package calls for `aptInstall`, `npmInstall`, `bunInstall`, `pipInstall`. > - Tweak `makeSymlink` test order to ensure overwrite behavior. > - Overhaul stacktrace tests to use `msw` server mocks and alias-based failure mapping. > - **Python SDK Tests**: > - `build`/`async_build` fixtures accept optional `alias`. > - Add `from_dockerfile` tests (sync/async); use base image/base template where applicable. > - Update install method tests to single-package calls. > - Rewrite stacktrace tests to monkeypatch API calls with alias-based failure mapping. > - **Dependencies**: > - Add dev dependency `msw` to `packages/js-sdk/package.json`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 1b7f84f4ce692f664c3ce4cdb345f4c3a028b17a. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
2025-11-28 22:34:13 +01:00
"from_dockerfile",
)
Render failed layer stack traces on build error (#901) ### Changelog - Added traces for Python and JavaScript SDK. - Added methods for stack trace collection, stack trace context - Updated file upload mechanism for tracing - Changed API handling to support throwing API errors with traces > **Note** > For functions like `aptInstall`, `fromRegistry` which call `.run` and `.fromImage`, the stack trace has to be replaced so it throws correctly from parent. > **Note** > There are no build logs in the trace, we can add this at later point. ### Examples Keep in mind that the way the traces are rendered entirely depends on environment (Bun, Node, Deno, Vitest, Pytest) **Standard Python** ``` Traceback (most recent call last): File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module> Template.build( ~~~~~~~~~~~~~~^ template, ^^^^^^^^^ ...<2 lines>... memory_mb=1024, ^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build wait_for_build_finish( ~~~~~~~~~~~~~~~~~~~~~^ api_client, ^^^^^^^^^^^ ...<4 lines>... stack_traces=template._template._stack_traces, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module> .run_cmd("cat non_existing_file.txt") ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Pytest** ``` [gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) # try: > Template.build( template, alias=str(uuid4()), cpu_count=1, memory_mb=1024, ) tests/sync/template_sync/test_stacktrace.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ e2b/template_sync/main.py:157: in build wait_for_build_finish( e2b/template_sync/build_api.py:199: in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") > .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) E e2b.template.exceptions.BuildException: failed to run command: exit status 1 tests/sync/template_sync/test_stacktrace.py:12: BuildException ========================================================== short test summary info ========================================================== FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Node** ``` node:internal/modules/run_main:104 triggerUncaughtException( ^ at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4 at ModuleJob.run (node:internal/modules/esm/module_job:274:25) at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) { name: 'BuildError' } Node.js v23.11.0 ``` **Bun** ``` 1 | export class BuildError extends Error { 2 | constructor(message: string, stackTrace?: string) { 3 | super(message) ^ BuildError: failed to run command: exit status 1 at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5 Bun v1.2.4 (macOS arm64) ``` **Vitest** ``` BuildError: failed to run command: exit status 1 ❯ tests/template/trace.test.ts:8:6 6| const template = Template() 7| .fromImage('ubuntu:22.04') 8| .runCmd('cat folder/test.txt') | ^ 9| .setWorkdir('/app') 10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000)) ``` --------- Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
@pytest.mark.skip_debug()
Improve method naming and consistency (#934) <!-- CURSOR_SUMMARY --> > [!NOTE] > Unifies Template APIs across JS/Python with PathLike support, new copyItems, option/name tweaks, and simpler registry auth via credentials; updates parser, exports, and tests. > > - **Template API (JS + Python)** > - Add PathLike support for paths in `copy`, `remove`, `rename`, `makeDir`, `makeSymlink`, `setWorkdir`, and `gitClone`. > - Introduce `copyItems` and corresponding `CopyItem` typing; adjust Dockerfile parser to use `copyItems` overload. > - Simplify registry auth: `fromImage(baseImage, credentials)` accepts `{username,password}`; remove `fromRegistry`; update `fromAWSRegistry`/`fromGCPRegistry` to take credentials and set config internally. > - Rename options: `ignoreFilePaths` -> `fileIgnorePatterns`; `fileContextPath` can be `PathLike`. > - Ensure internal hashing/upload use stringified paths; minor enum/type tweaks (e.g., `InstructionType` as string enum, `forceUpload?: true`). > - **Exports** > - Export `CopyItem` from JS `index.ts` and Python `__init__.py`. > - **Tests** > - Update stacktrace and build tests to new method names/signatures (e.g., registry via `fromImage` credentials, new `copyItems` tests, optional `skipCache` param). > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 95391030550a340fe99ebaac4494867b3e3e9507. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-10-09 00:51:02 +02:00
async def test_traces_on_from_image_registry(async_build):
template = AsyncTemplate().from_image(
Render failed layer stack traces on build error (#901) ### Changelog - Added traces for Python and JavaScript SDK. - Added methods for stack trace collection, stack trace context - Updated file upload mechanism for tracing - Changed API handling to support throwing API errors with traces > **Note** > For functions like `aptInstall`, `fromRegistry` which call `.run` and `.fromImage`, the stack trace has to be replaced so it throws correctly from parent. > **Note** > There are no build logs in the trace, we can add this at later point. ### Examples Keep in mind that the way the traces are rendered entirely depends on environment (Bun, Node, Deno, Vitest, Pytest) **Standard Python** ``` Traceback (most recent call last): File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module> Template.build( ~~~~~~~~~~~~~~^ template, ^^^^^^^^^ ...<2 lines>... memory_mb=1024, ^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build wait_for_build_finish( ~~~~~~~~~~~~~~~~~~~~~^ api_client, ^^^^^^^^^^^ ...<4 lines>... stack_traces=template._template._stack_traces, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module> .run_cmd("cat non_existing_file.txt") ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Pytest** ``` [gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) # try: > Template.build( template, alias=str(uuid4()), cpu_count=1, memory_mb=1024, ) tests/sync/template_sync/test_stacktrace.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ e2b/template_sync/main.py:157: in build wait_for_build_finish( e2b/template_sync/build_api.py:199: in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") > .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) E e2b.template.exceptions.BuildException: failed to run command: exit status 1 tests/sync/template_sync/test_stacktrace.py:12: BuildException ========================================================== short test summary info ========================================================== FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Node** ``` node:internal/modules/run_main:104 triggerUncaughtException( ^ at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4 at ModuleJob.run (node:internal/modules/esm/module_job:274:25) at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) { name: 'BuildError' } Node.js v23.11.0 ``` **Bun** ``` 1 | export class BuildError extends Error { 2 | constructor(message: string, stackTrace?: string) { 3 | super(message) ^ BuildError: failed to run command: exit status 1 at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5 Bun v1.2.4 (macOS arm64) ``` **Vitest** ``` BuildError: failed to run command: exit status 1 ❯ tests/template/trace.test.ts:8:6 6| const template = Template() 7| .fromImage('ubuntu:22.04') 8| .runCmd('cat folder/test.txt') | ^ 9| .setWorkdir('/app') 10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000)) ``` --------- Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
"registry.example.com/nonexistent:latest",
username="test",
password="test",
)
await _expect_to_throw_and_check_trace(
lambda: async_build(template, name="from_image_registry", skip_cache=True),
Improve CI/CD speed for template tests (#1035) <!-- CURSOR_SUMMARY --> > [!NOTE] > Caches Playwright binaries in JS CI and refactors JS/Python template tests to use API mocks and aliases, add Dockerfile tests, and update install APIs to single-package calls. > > - **CI**: > - Cache Playwright binaries on `ubuntu-22.04` and `windows-latest` in `.github/workflows/js_sdk_tests.yml` to speed JS SDK tests. > - **JS SDK Tests**: > - Extend `buildTemplate` options to accept `alias` in `tests/setup.ts`. > - Add `fromDockerfile` tests and switch some builds to `fromBaseImage`; add build-from-base-template test. > - Update install method tests to single-package calls for `aptInstall`, `npmInstall`, `bunInstall`, `pipInstall`. > - Tweak `makeSymlink` test order to ensure overwrite behavior. > - Overhaul stacktrace tests to use `msw` server mocks and alias-based failure mapping. > - **Python SDK Tests**: > - `build`/`async_build` fixtures accept optional `alias`. > - Add `from_dockerfile` tests (sync/async); use base image/base template where applicable. > - Update install method tests to single-package calls. > - Rewrite stacktrace tests to monkeypatch API calls with alias-based failure mapping. > - **Dependencies**: > - Add dev dependency `msw` to `packages/js-sdk/package.json`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 1b7f84f4ce692f664c3ce4cdb345f4c3a028b17a. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
2025-11-28 22:34:13 +01:00
"from_image",
)
Render failed layer stack traces on build error (#901) ### Changelog - Added traces for Python and JavaScript SDK. - Added methods for stack trace collection, stack trace context - Updated file upload mechanism for tracing - Changed API handling to support throwing API errors with traces > **Note** > For functions like `aptInstall`, `fromRegistry` which call `.run` and `.fromImage`, the stack trace has to be replaced so it throws correctly from parent. > **Note** > There are no build logs in the trace, we can add this at later point. ### Examples Keep in mind that the way the traces are rendered entirely depends on environment (Bun, Node, Deno, Vitest, Pytest) **Standard Python** ``` Traceback (most recent call last): File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module> Template.build( ~~~~~~~~~~~~~~^ template, ^^^^^^^^^ ...<2 lines>... memory_mb=1024, ^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build wait_for_build_finish( ~~~~~~~~~~~~~~~~~~~~~^ api_client, ^^^^^^^^^^^ ...<4 lines>... stack_traces=template._template._stack_traces, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module> .run_cmd("cat non_existing_file.txt") ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Pytest** ``` [gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) # try: > Template.build( template, alias=str(uuid4()), cpu_count=1, memory_mb=1024, ) tests/sync/template_sync/test_stacktrace.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ e2b/template_sync/main.py:157: in build wait_for_build_finish( e2b/template_sync/build_api.py:199: in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") > .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) E e2b.template.exceptions.BuildException: failed to run command: exit status 1 tests/sync/template_sync/test_stacktrace.py:12: BuildException ========================================================== short test summary info ========================================================== FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Node** ``` node:internal/modules/run_main:104 triggerUncaughtException( ^ at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4 at ModuleJob.run (node:internal/modules/esm/module_job:274:25) at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) { name: 'BuildError' } Node.js v23.11.0 ``` **Bun** ``` 1 | export class BuildError extends Error { 2 | constructor(message: string, stackTrace?: string) { 3 | super(message) ^ BuildError: failed to run command: exit status 1 at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5 Bun v1.2.4 (macOS arm64) ``` **Vitest** ``` BuildError: failed to run command: exit status 1 ❯ tests/template/trace.test.ts:8:6 6| const template = Template() 7| .fromImage('ubuntu:22.04') 8| .runCmd('cat folder/test.txt') | ^ 9| .setWorkdir('/app') 10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000)) ``` --------- Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
@pytest.mark.skip_debug()
async def test_traces_on_from_aws_registry(async_build):
template = AsyncTemplate().from_aws_registry(
Render failed layer stack traces on build error (#901) ### Changelog - Added traces for Python and JavaScript SDK. - Added methods for stack trace collection, stack trace context - Updated file upload mechanism for tracing - Changed API handling to support throwing API errors with traces > **Note** > For functions like `aptInstall`, `fromRegistry` which call `.run` and `.fromImage`, the stack trace has to be replaced so it throws correctly from parent. > **Note** > There are no build logs in the trace, we can add this at later point. ### Examples Keep in mind that the way the traces are rendered entirely depends on environment (Bun, Node, Deno, Vitest, Pytest) **Standard Python** ``` Traceback (most recent call last): File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module> Template.build( ~~~~~~~~~~~~~~^ template, ^^^^^^^^^ ...<2 lines>... memory_mb=1024, ^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build wait_for_build_finish( ~~~~~~~~~~~~~~~~~~~~~^ api_client, ^^^^^^^^^^^ ...<4 lines>... stack_traces=template._template._stack_traces, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module> .run_cmd("cat non_existing_file.txt") ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Pytest** ``` [gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) # try: > Template.build( template, alias=str(uuid4()), cpu_count=1, memory_mb=1024, ) tests/sync/template_sync/test_stacktrace.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ e2b/template_sync/main.py:157: in build wait_for_build_finish( e2b/template_sync/build_api.py:199: in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") > .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) E e2b.template.exceptions.BuildException: failed to run command: exit status 1 tests/sync/template_sync/test_stacktrace.py:12: BuildException ========================================================== short test summary info ========================================================== FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Node** ``` node:internal/modules/run_main:104 triggerUncaughtException( ^ at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4 at ModuleJob.run (node:internal/modules/esm/module_job:274:25) at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) { name: 'BuildError' } Node.js v23.11.0 ``` **Bun** ``` 1 | export class BuildError extends Error { 2 | constructor(message: string, stackTrace?: string) { 3 | super(message) ^ BuildError: failed to run command: exit status 1 at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5 Bun v1.2.4 (macOS arm64) ``` **Vitest** ``` BuildError: failed to run command: exit status 1 ❯ tests/template/trace.test.ts:8:6 6| const template = Template() 7| .fromImage('ubuntu:22.04') 8| .runCmd('cat folder/test.txt') | ^ 9| .setWorkdir('/app') 10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000)) ``` --------- Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
"123456789.dkr.ecr.us-east-1.amazonaws.com/nonexistent:latest",
access_key_id="test",
secret_access_key="test",
region="us-east-1",
)
await _expect_to_throw_and_check_trace(
lambda: async_build(template, name="from_aws_registry"), "from_aws_registry"
)
Render failed layer stack traces on build error (#901) ### Changelog - Added traces for Python and JavaScript SDK. - Added methods for stack trace collection, stack trace context - Updated file upload mechanism for tracing - Changed API handling to support throwing API errors with traces > **Note** > For functions like `aptInstall`, `fromRegistry` which call `.run` and `.fromImage`, the stack trace has to be replaced so it throws correctly from parent. > **Note** > There are no build logs in the trace, we can add this at later point. ### Examples Keep in mind that the way the traces are rendered entirely depends on environment (Bun, Node, Deno, Vitest, Pytest) **Standard Python** ``` Traceback (most recent call last): File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module> Template.build( ~~~~~~~~~~~~~~^ template, ^^^^^^^^^ ...<2 lines>... memory_mb=1024, ^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build wait_for_build_finish( ~~~~~~~~~~~~~~~~~~~~~^ api_client, ^^^^^^^^^^^ ...<4 lines>... stack_traces=template._template._stack_traces, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module> .run_cmd("cat non_existing_file.txt") ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Pytest** ``` [gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) # try: > Template.build( template, alias=str(uuid4()), cpu_count=1, memory_mb=1024, ) tests/sync/template_sync/test_stacktrace.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ e2b/template_sync/main.py:157: in build wait_for_build_finish( e2b/template_sync/build_api.py:199: in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") > .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) E e2b.template.exceptions.BuildException: failed to run command: exit status 1 tests/sync/template_sync/test_stacktrace.py:12: BuildException ========================================================== short test summary info ========================================================== FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Node** ``` node:internal/modules/run_main:104 triggerUncaughtException( ^ at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4 at ModuleJob.run (node:internal/modules/esm/module_job:274:25) at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) { name: 'BuildError' } Node.js v23.11.0 ``` **Bun** ``` 1 | export class BuildError extends Error { 2 | constructor(message: string, stackTrace?: string) { 3 | super(message) ^ BuildError: failed to run command: exit status 1 at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5 Bun v1.2.4 (macOS arm64) ``` **Vitest** ``` BuildError: failed to run command: exit status 1 ❯ tests/template/trace.test.ts:8:6 6| const template = Template() 7| .fromImage('ubuntu:22.04') 8| .runCmd('cat folder/test.txt') | ^ 9| .setWorkdir('/app') 10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000)) ``` --------- Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
@pytest.mark.skip_debug()
async def test_traces_on_from_gcp_registry(async_build):
template = AsyncTemplate().from_gcp_registry(
Render failed layer stack traces on build error (#901) ### Changelog - Added traces for Python and JavaScript SDK. - Added methods for stack trace collection, stack trace context - Updated file upload mechanism for tracing - Changed API handling to support throwing API errors with traces > **Note** > For functions like `aptInstall`, `fromRegistry` which call `.run` and `.fromImage`, the stack trace has to be replaced so it throws correctly from parent. > **Note** > There are no build logs in the trace, we can add this at later point. ### Examples Keep in mind that the way the traces are rendered entirely depends on environment (Bun, Node, Deno, Vitest, Pytest) **Standard Python** ``` Traceback (most recent call last): File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module> Template.build( ~~~~~~~~~~~~~~^ template, ^^^^^^^^^ ...<2 lines>... memory_mb=1024, ^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build wait_for_build_finish( ~~~~~~~~~~~~~~~~~~~~~^ api_client, ^^^^^^^^^^^ ...<4 lines>... stack_traces=template._template._stack_traces, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module> .run_cmd("cat non_existing_file.txt") ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Pytest** ``` [gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) # try: > Template.build( template, alias=str(uuid4()), cpu_count=1, memory_mb=1024, ) tests/sync/template_sync/test_stacktrace.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ e2b/template_sync/main.py:157: in build wait_for_build_finish( e2b/template_sync/build_api.py:199: in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") > .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) E e2b.template.exceptions.BuildException: failed to run command: exit status 1 tests/sync/template_sync/test_stacktrace.py:12: BuildException ========================================================== short test summary info ========================================================== FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Node** ``` node:internal/modules/run_main:104 triggerUncaughtException( ^ at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4 at ModuleJob.run (node:internal/modules/esm/module_job:274:25) at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) { name: 'BuildError' } Node.js v23.11.0 ``` **Bun** ``` 1 | export class BuildError extends Error { 2 | constructor(message: string, stackTrace?: string) { 3 | super(message) ^ BuildError: failed to run command: exit status 1 at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5 Bun v1.2.4 (macOS arm64) ``` **Vitest** ``` BuildError: failed to run command: exit status 1 ❯ tests/template/trace.test.ts:8:6 6| const template = Template() 7| .fromImage('ubuntu:22.04') 8| .runCmd('cat folder/test.txt') | ^ 9| .setWorkdir('/app') 10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000)) ``` --------- Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
"gcr.io/nonexistent-project/nonexistent:latest",
service_account_json={
"type": "service_account",
},
)
await _expect_to_throw_and_check_trace(
lambda: async_build(template, name="from_gcp_registry"), "from_gcp_registry"
)
Render failed layer stack traces on build error (#901) ### Changelog - Added traces for Python and JavaScript SDK. - Added methods for stack trace collection, stack trace context - Updated file upload mechanism for tracing - Changed API handling to support throwing API errors with traces > **Note** > For functions like `aptInstall`, `fromRegistry` which call `.run` and `.fromImage`, the stack trace has to be replaced so it throws correctly from parent. > **Note** > There are no build logs in the trace, we can add this at later point. ### Examples Keep in mind that the way the traces are rendered entirely depends on environment (Bun, Node, Deno, Vitest, Pytest) **Standard Python** ``` Traceback (most recent call last): File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module> Template.build( ~~~~~~~~~~~~~~^ template, ^^^^^^^^^ ...<2 lines>... memory_mb=1024, ^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build wait_for_build_finish( ~~~~~~~~~~~~~~~~~~~~~^ api_client, ^^^^^^^^^^^ ...<4 lines>... stack_traces=template._template._stack_traces, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module> .run_cmd("cat non_existing_file.txt") ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Pytest** ``` [gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) # try: > Template.build( template, alias=str(uuid4()), cpu_count=1, memory_mb=1024, ) tests/sync/template_sync/test_stacktrace.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ e2b/template_sync/main.py:157: in build wait_for_build_finish( e2b/template_sync/build_api.py:199: in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") > .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) E e2b.template.exceptions.BuildException: failed to run command: exit status 1 tests/sync/template_sync/test_stacktrace.py:12: BuildException ========================================================== short test summary info ========================================================== FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Node** ``` node:internal/modules/run_main:104 triggerUncaughtException( ^ at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4 at ModuleJob.run (node:internal/modules/esm/module_job:274:25) at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) { name: 'BuildError' } Node.js v23.11.0 ``` **Bun** ``` 1 | export class BuildError extends Error { 2 | constructor(message: string, stackTrace?: string) { 3 | super(message) ^ BuildError: failed to run command: exit status 1 at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5 Bun v1.2.4 (macOS arm64) ``` **Vitest** ``` BuildError: failed to run command: exit status 1 ❯ tests/template/trace.test.ts:8:6 6| const template = Template() 7| .fromImage('ubuntu:22.04') 8| .runCmd('cat folder/test.txt') | ^ 9| .setWorkdir('/app') 10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000)) ``` --------- Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
@pytest.mark.skip_debug()
async def test_traces_on_copy(async_build):
Render failed layer stack traces on build error (#901) ### Changelog - Added traces for Python and JavaScript SDK. - Added methods for stack trace collection, stack trace context - Updated file upload mechanism for tracing - Changed API handling to support throwing API errors with traces > **Note** > For functions like `aptInstall`, `fromRegistry` which call `.run` and `.fromImage`, the stack trace has to be replaced so it throws correctly from parent. > **Note** > There are no build logs in the trace, we can add this at later point. ### Examples Keep in mind that the way the traces are rendered entirely depends on environment (Bun, Node, Deno, Vitest, Pytest) **Standard Python** ``` Traceback (most recent call last): File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module> Template.build( ~~~~~~~~~~~~~~^ template, ^^^^^^^^^ ...<2 lines>... memory_mb=1024, ^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build wait_for_build_finish( ~~~~~~~~~~~~~~~~~~~~~^ api_client, ^^^^^^^^^^^ ...<4 lines>... stack_traces=template._template._stack_traces, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module> .run_cmd("cat non_existing_file.txt") ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Pytest** ``` [gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) # try: > Template.build( template, alias=str(uuid4()), cpu_count=1, memory_mb=1024, ) tests/sync/template_sync/test_stacktrace.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ e2b/template_sync/main.py:157: in build wait_for_build_finish( e2b/template_sync/build_api.py:199: in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") > .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) E e2b.template.exceptions.BuildException: failed to run command: exit status 1 tests/sync/template_sync/test_stacktrace.py:12: BuildException ========================================================== short test summary info ========================================================== FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Node** ``` node:internal/modules/run_main:104 triggerUncaughtException( ^ at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4 at ModuleJob.run (node:internal/modules/esm/module_job:274:25) at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) { name: 'BuildError' } Node.js v23.11.0 ``` **Bun** ``` 1 | export class BuildError extends Error { 2 | constructor(message: string, stackTrace?: string) { 3 | super(message) ^ BuildError: failed to run command: exit status 1 at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5 Bun v1.2.4 (macOS arm64) ``` **Vitest** ``` BuildError: failed to run command: exit status 1 ❯ tests/template/trace.test.ts:8:6 6| const template = Template() 7| .fromImage('ubuntu:22.04') 8| .runCmd('cat folder/test.txt') | ^ 9| .setWorkdir('/app') 10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000)) ``` --------- Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
template = AsyncTemplate()
template = template.from_base_image()
2025-09-26 14:01:41 +02:00
template = template.skip_cache().copy(non_existent_path, non_existent_path)
Improve CI/CD speed for template tests (#1035) <!-- CURSOR_SUMMARY --> > [!NOTE] > Caches Playwright binaries in JS CI and refactors JS/Python template tests to use API mocks and aliases, add Dockerfile tests, and update install APIs to single-package calls. > > - **CI**: > - Cache Playwright binaries on `ubuntu-22.04` and `windows-latest` in `.github/workflows/js_sdk_tests.yml` to speed JS SDK tests. > - **JS SDK Tests**: > - Extend `buildTemplate` options to accept `alias` in `tests/setup.ts`. > - Add `fromDockerfile` tests and switch some builds to `fromBaseImage`; add build-from-base-template test. > - Update install method tests to single-package calls for `aptInstall`, `npmInstall`, `bunInstall`, `pipInstall`. > - Tweak `makeSymlink` test order to ensure overwrite behavior. > - Overhaul stacktrace tests to use `msw` server mocks and alias-based failure mapping. > - **Python SDK Tests**: > - `build`/`async_build` fixtures accept optional `alias`. > - Add `from_dockerfile` tests (sync/async); use base image/base template where applicable. > - Update install method tests to single-package calls. > - Rewrite stacktrace tests to monkeypatch API calls with alias-based failure mapping. > - **Dependencies**: > - Add dev dependency `msw` to `packages/js-sdk/package.json`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 1b7f84f4ce692f664c3ce4cdb345f4c3a028b17a. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
2025-11-28 22:34:13 +01:00
await _expect_to_throw_and_check_trace(
lambda: async_build(template, name="copy"), "copy"
Improve CI/CD speed for template tests (#1035) <!-- CURSOR_SUMMARY --> > [!NOTE] > Caches Playwright binaries in JS CI and refactors JS/Python template tests to use API mocks and aliases, add Dockerfile tests, and update install APIs to single-package calls. > > - **CI**: > - Cache Playwright binaries on `ubuntu-22.04` and `windows-latest` in `.github/workflows/js_sdk_tests.yml` to speed JS SDK tests. > - **JS SDK Tests**: > - Extend `buildTemplate` options to accept `alias` in `tests/setup.ts`. > - Add `fromDockerfile` tests and switch some builds to `fromBaseImage`; add build-from-base-template test. > - Update install method tests to single-package calls for `aptInstall`, `npmInstall`, `bunInstall`, `pipInstall`. > - Tweak `makeSymlink` test order to ensure overwrite behavior. > - Overhaul stacktrace tests to use `msw` server mocks and alias-based failure mapping. > - **Python SDK Tests**: > - `build`/`async_build` fixtures accept optional `alias`. > - Add `from_dockerfile` tests (sync/async); use base image/base template where applicable. > - Update install method tests to single-package calls. > - Rewrite stacktrace tests to monkeypatch API calls with alias-based failure mapping. > - **Dependencies**: > - Add dev dependency `msw` to `packages/js-sdk/package.json`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 1b7f84f4ce692f664c3ce4cdb345f4c3a028b17a. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
2025-11-28 22:34:13 +01:00
)
Render failed layer stack traces on build error (#901) ### Changelog - Added traces for Python and JavaScript SDK. - Added methods for stack trace collection, stack trace context - Updated file upload mechanism for tracing - Changed API handling to support throwing API errors with traces > **Note** > For functions like `aptInstall`, `fromRegistry` which call `.run` and `.fromImage`, the stack trace has to be replaced so it throws correctly from parent. > **Note** > There are no build logs in the trace, we can add this at later point. ### Examples Keep in mind that the way the traces are rendered entirely depends on environment (Bun, Node, Deno, Vitest, Pytest) **Standard Python** ``` Traceback (most recent call last): File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module> Template.build( ~~~~~~~~~~~~~~^ template, ^^^^^^^^^ ...<2 lines>... memory_mb=1024, ^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build wait_for_build_finish( ~~~~~~~~~~~~~~~~~~~~~^ api_client, ^^^^^^^^^^^ ...<4 lines>... stack_traces=template._template._stack_traces, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module> .run_cmd("cat non_existing_file.txt") ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Pytest** ``` [gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) # try: > Template.build( template, alias=str(uuid4()), cpu_count=1, memory_mb=1024, ) tests/sync/template_sync/test_stacktrace.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ e2b/template_sync/main.py:157: in build wait_for_build_finish( e2b/template_sync/build_api.py:199: in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") > .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) E e2b.template.exceptions.BuildException: failed to run command: exit status 1 tests/sync/template_sync/test_stacktrace.py:12: BuildException ========================================================== short test summary info ========================================================== FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Node** ``` node:internal/modules/run_main:104 triggerUncaughtException( ^ at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4 at ModuleJob.run (node:internal/modules/esm/module_job:274:25) at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) { name: 'BuildError' } Node.js v23.11.0 ``` **Bun** ``` 1 | export class BuildError extends Error { 2 | constructor(message: string, stackTrace?: string) { 3 | super(message) ^ BuildError: failed to run command: exit status 1 at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5 Bun v1.2.4 (macOS arm64) ``` **Vitest** ``` BuildError: failed to run command: exit status 1 ❯ tests/template/trace.test.ts:8:6 6| const template = Template() 7| .fromImage('ubuntu:22.04') 8| .runCmd('cat folder/test.txt') | ^ 9| .setWorkdir('/app') 10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000)) ``` --------- Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
Improve method naming and consistency (#934) <!-- CURSOR_SUMMARY --> > [!NOTE] > Unifies Template APIs across JS/Python with PathLike support, new copyItems, option/name tweaks, and simpler registry auth via credentials; updates parser, exports, and tests. > > - **Template API (JS + Python)** > - Add PathLike support for paths in `copy`, `remove`, `rename`, `makeDir`, `makeSymlink`, `setWorkdir`, and `gitClone`. > - Introduce `copyItems` and corresponding `CopyItem` typing; adjust Dockerfile parser to use `copyItems` overload. > - Simplify registry auth: `fromImage(baseImage, credentials)` accepts `{username,password}`; remove `fromRegistry`; update `fromAWSRegistry`/`fromGCPRegistry` to take credentials and set config internally. > - Rename options: `ignoreFilePaths` -> `fileIgnorePatterns`; `fileContextPath` can be `PathLike`. > - Ensure internal hashing/upload use stringified paths; minor enum/type tweaks (e.g., `InstructionType` as string enum, `forceUpload?: true`). > - **Exports** > - Export `CopyItem` from JS `index.ts` and Python `__init__.py`. > - **Tests** > - Update stacktrace and build tests to new method names/signatures (e.g., registry via `fromImage` credentials, new `copyItems` tests, optional `skipCache` param). > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 95391030550a340fe99ebaac4494867b3e3e9507. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-10-09 00:51:02 +02:00
@pytest.mark.skip_debug()
async def test_traces_on_copyItems(async_build):
template = AsyncTemplate()
template = template.from_base_image()
template = template.skip_cache().copy_items(
[CopyItem(src=non_existent_path, dest=non_existent_path)]
)
Improve CI/CD speed for template tests (#1035) <!-- CURSOR_SUMMARY --> > [!NOTE] > Caches Playwright binaries in JS CI and refactors JS/Python template tests to use API mocks and aliases, add Dockerfile tests, and update install APIs to single-package calls. > > - **CI**: > - Cache Playwright binaries on `ubuntu-22.04` and `windows-latest` in `.github/workflows/js_sdk_tests.yml` to speed JS SDK tests. > - **JS SDK Tests**: > - Extend `buildTemplate` options to accept `alias` in `tests/setup.ts`. > - Add `fromDockerfile` tests and switch some builds to `fromBaseImage`; add build-from-base-template test. > - Update install method tests to single-package calls for `aptInstall`, `npmInstall`, `bunInstall`, `pipInstall`. > - Tweak `makeSymlink` test order to ensure overwrite behavior. > - Overhaul stacktrace tests to use `msw` server mocks and alias-based failure mapping. > - **Python SDK Tests**: > - `build`/`async_build` fixtures accept optional `alias`. > - Add `from_dockerfile` tests (sync/async); use base image/base template where applicable. > - Update install method tests to single-package calls. > - Rewrite stacktrace tests to monkeypatch API calls with alias-based failure mapping. > - **Dependencies**: > - Add dev dependency `msw` to `packages/js-sdk/package.json`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 1b7f84f4ce692f664c3ce4cdb345f4c3a028b17a. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
2025-11-28 22:34:13 +01:00
await _expect_to_throw_and_check_trace(
lambda: async_build(template, name="copy_items"), "copy_items"
Improve CI/CD speed for template tests (#1035) <!-- CURSOR_SUMMARY --> > [!NOTE] > Caches Playwright binaries in JS CI and refactors JS/Python template tests to use API mocks and aliases, add Dockerfile tests, and update install APIs to single-package calls. > > - **CI**: > - Cache Playwright binaries on `ubuntu-22.04` and `windows-latest` in `.github/workflows/js_sdk_tests.yml` to speed JS SDK tests. > - **JS SDK Tests**: > - Extend `buildTemplate` options to accept `alias` in `tests/setup.ts`. > - Add `fromDockerfile` tests and switch some builds to `fromBaseImage`; add build-from-base-template test. > - Update install method tests to single-package calls for `aptInstall`, `npmInstall`, `bunInstall`, `pipInstall`. > - Tweak `makeSymlink` test order to ensure overwrite behavior. > - Overhaul stacktrace tests to use `msw` server mocks and alias-based failure mapping. > - **Python SDK Tests**: > - `build`/`async_build` fixtures accept optional `alias`. > - Add `from_dockerfile` tests (sync/async); use base image/base template where applicable. > - Update install method tests to single-package calls. > - Rewrite stacktrace tests to monkeypatch API calls with alias-based failure mapping. > - **Dependencies**: > - Add dev dependency `msw` to `packages/js-sdk/package.json`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 1b7f84f4ce692f664c3ce4cdb345f4c3a028b17a. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
2025-11-28 22:34:13 +01:00
)
Improve method naming and consistency (#934) <!-- CURSOR_SUMMARY --> > [!NOTE] > Unifies Template APIs across JS/Python with PathLike support, new copyItems, option/name tweaks, and simpler registry auth via credentials; updates parser, exports, and tests. > > - **Template API (JS + Python)** > - Add PathLike support for paths in `copy`, `remove`, `rename`, `makeDir`, `makeSymlink`, `setWorkdir`, and `gitClone`. > - Introduce `copyItems` and corresponding `CopyItem` typing; adjust Dockerfile parser to use `copyItems` overload. > - Simplify registry auth: `fromImage(baseImage, credentials)` accepts `{username,password}`; remove `fromRegistry`; update `fromAWSRegistry`/`fromGCPRegistry` to take credentials and set config internally. > - Rename options: `ignoreFilePaths` -> `fileIgnorePatterns`; `fileContextPath` can be `PathLike`. > - Ensure internal hashing/upload use stringified paths; minor enum/type tweaks (e.g., `InstructionType` as string enum, `forceUpload?: true`). > - **Exports** > - Export `CopyItem` from JS `index.ts` and Python `__init__.py`. > - **Tests** > - Update stacktrace and build tests to new method names/signatures (e.g., registry via `fromImage` credentials, new `copyItems` tests, optional `skipCache` param). > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 95391030550a340fe99ebaac4494867b3e3e9507. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-10-09 00:51:02 +02:00
feat: validate copy src paths are relative and within context directory (#1106) Add path validation to the copy method in both JS and Python SDKs to ensure source paths are always relative and don't escape the context directory. This prevents: - Absolute paths like /absolute/whatever (Unix) or C:\whatever (Windows) - Path traversal attacks like ../whatever or ./foo/../../../bar The validation works cross-platform using Node's path.isAbsolute/normalize and Python's os.path.isabs/normpath plus PureWindowsPath for detecting Windows paths on Unix. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Changes behavior of `copy`/`copy_items` to throw earlier for previously-accepted absolute or escaping paths, which could break some consumers; logic is localized and well-covered by tests. > > **Overview** > Prevents path traversal in template `copy` operations by validating `src` is *relative* and does not escape the context directory (rejects absolute paths and `..`-based escapes) in both the JS and Python SDKs. > > Updates `copyItems`/`copy_items` error handling to preserve the caller’s stack trace when validation fails, adds unit coverage for the new path validator plus new stack-trace tests for absolute-path failures, and ships as patch releases via a changeset. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit c1a8eb978e3fd99fa829d571e811bb7ee18cd40b. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 13:54:54 +01:00
@pytest.mark.skip_debug()
async def test_traces_on_copy_absolute_path():
await _expect_to_throw_and_check_trace(
lambda: AsyncTemplate()
.from_base_image()
.copy("/absolute/path", "/absolute/path"),
"copy",
)
@pytest.mark.skip_debug()
async def test_traces_on_copyItems_absolute_path():
await _expect_to_throw_and_check_trace(
lambda: AsyncTemplate()
.from_base_image()
.copy_items([CopyItem(src="/absolute/path", dest="/absolute/path")]),
"copy_items",
)
Render failed layer stack traces on build error (#901) ### Changelog - Added traces for Python and JavaScript SDK. - Added methods for stack trace collection, stack trace context - Updated file upload mechanism for tracing - Changed API handling to support throwing API errors with traces > **Note** > For functions like `aptInstall`, `fromRegistry` which call `.run` and `.fromImage`, the stack trace has to be replaced so it throws correctly from parent. > **Note** > There are no build logs in the trace, we can add this at later point. ### Examples Keep in mind that the way the traces are rendered entirely depends on environment (Bun, Node, Deno, Vitest, Pytest) **Standard Python** ``` Traceback (most recent call last): File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module> Template.build( ~~~~~~~~~~~~~~^ template, ^^^^^^^^^ ...<2 lines>... memory_mb=1024, ^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build wait_for_build_finish( ~~~~~~~~~~~~~~~~~~~~~^ api_client, ^^^^^^^^^^^ ...<4 lines>... stack_traces=template._template._stack_traces, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module> .run_cmd("cat non_existing_file.txt") ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Pytest** ``` [gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) # try: > Template.build( template, alias=str(uuid4()), cpu_count=1, memory_mb=1024, ) tests/sync/template_sync/test_stacktrace.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ e2b/template_sync/main.py:157: in build wait_for_build_finish( e2b/template_sync/build_api.py:199: in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") > .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) E e2b.template.exceptions.BuildException: failed to run command: exit status 1 tests/sync/template_sync/test_stacktrace.py:12: BuildException ========================================================== short test summary info ========================================================== FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Node** ``` node:internal/modules/run_main:104 triggerUncaughtException( ^ at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4 at ModuleJob.run (node:internal/modules/esm/module_job:274:25) at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) { name: 'BuildError' } Node.js v23.11.0 ``` **Bun** ``` 1 | export class BuildError extends Error { 2 | constructor(message: string, stackTrace?: string) { 3 | super(message) ^ BuildError: failed to run command: exit status 1 at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5 Bun v1.2.4 (macOS arm64) ``` **Vitest** ``` BuildError: failed to run command: exit status 1 ❯ tests/template/trace.test.ts:8:6 6| const template = Template() 7| .fromImage('ubuntu:22.04') 8| .runCmd('cat folder/test.txt') | ^ 9| .setWorkdir('/app') 10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000)) ``` --------- Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
@pytest.mark.skip_debug()
async def test_traces_on_remove(async_build):
Render failed layer stack traces on build error (#901) ### Changelog - Added traces for Python and JavaScript SDK. - Added methods for stack trace collection, stack trace context - Updated file upload mechanism for tracing - Changed API handling to support throwing API errors with traces > **Note** > For functions like `aptInstall`, `fromRegistry` which call `.run` and `.fromImage`, the stack trace has to be replaced so it throws correctly from parent. > **Note** > There are no build logs in the trace, we can add this at later point. ### Examples Keep in mind that the way the traces are rendered entirely depends on environment (Bun, Node, Deno, Vitest, Pytest) **Standard Python** ``` Traceback (most recent call last): File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module> Template.build( ~~~~~~~~~~~~~~^ template, ^^^^^^^^^ ...<2 lines>... memory_mb=1024, ^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build wait_for_build_finish( ~~~~~~~~~~~~~~~~~~~~~^ api_client, ^^^^^^^^^^^ ...<4 lines>... stack_traces=template._template._stack_traces, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module> .run_cmd("cat non_existing_file.txt") ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Pytest** ``` [gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) # try: > Template.build( template, alias=str(uuid4()), cpu_count=1, memory_mb=1024, ) tests/sync/template_sync/test_stacktrace.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ e2b/template_sync/main.py:157: in build wait_for_build_finish( e2b/template_sync/build_api.py:199: in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") > .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) E e2b.template.exceptions.BuildException: failed to run command: exit status 1 tests/sync/template_sync/test_stacktrace.py:12: BuildException ========================================================== short test summary info ========================================================== FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Node** ``` node:internal/modules/run_main:104 triggerUncaughtException( ^ at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4 at ModuleJob.run (node:internal/modules/esm/module_job:274:25) at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) { name: 'BuildError' } Node.js v23.11.0 ``` **Bun** ``` 1 | export class BuildError extends Error { 2 | constructor(message: string, stackTrace?: string) { 3 | super(message) ^ BuildError: failed to run command: exit status 1 at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5 Bun v1.2.4 (macOS arm64) ``` **Vitest** ``` BuildError: failed to run command: exit status 1 ❯ tests/template/trace.test.ts:8:6 6| const template = Template() 7| .fromImage('ubuntu:22.04') 8| .runCmd('cat folder/test.txt') | ^ 9| .setWorkdir('/app') 10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000)) ``` --------- Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
template = AsyncTemplate()
template = template.from_base_image()
2025-09-26 14:01:41 +02:00
template = template.skip_cache().remove(non_existent_path)
Improve CI/CD speed for template tests (#1035) <!-- CURSOR_SUMMARY --> > [!NOTE] > Caches Playwright binaries in JS CI and refactors JS/Python template tests to use API mocks and aliases, add Dockerfile tests, and update install APIs to single-package calls. > > - **CI**: > - Cache Playwright binaries on `ubuntu-22.04` and `windows-latest` in `.github/workflows/js_sdk_tests.yml` to speed JS SDK tests. > - **JS SDK Tests**: > - Extend `buildTemplate` options to accept `alias` in `tests/setup.ts`. > - Add `fromDockerfile` tests and switch some builds to `fromBaseImage`; add build-from-base-template test. > - Update install method tests to single-package calls for `aptInstall`, `npmInstall`, `bunInstall`, `pipInstall`. > - Tweak `makeSymlink` test order to ensure overwrite behavior. > - Overhaul stacktrace tests to use `msw` server mocks and alias-based failure mapping. > - **Python SDK Tests**: > - `build`/`async_build` fixtures accept optional `alias`. > - Add `from_dockerfile` tests (sync/async); use base image/base template where applicable. > - Update install method tests to single-package calls. > - Rewrite stacktrace tests to monkeypatch API calls with alias-based failure mapping. > - **Dependencies**: > - Add dev dependency `msw` to `packages/js-sdk/package.json`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 1b7f84f4ce692f664c3ce4cdb345f4c3a028b17a. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
2025-11-28 22:34:13 +01:00
await _expect_to_throw_and_check_trace(
lambda: async_build(template, name="remove"), "remove"
Improve CI/CD speed for template tests (#1035) <!-- CURSOR_SUMMARY --> > [!NOTE] > Caches Playwright binaries in JS CI and refactors JS/Python template tests to use API mocks and aliases, add Dockerfile tests, and update install APIs to single-package calls. > > - **CI**: > - Cache Playwright binaries on `ubuntu-22.04` and `windows-latest` in `.github/workflows/js_sdk_tests.yml` to speed JS SDK tests. > - **JS SDK Tests**: > - Extend `buildTemplate` options to accept `alias` in `tests/setup.ts`. > - Add `fromDockerfile` tests and switch some builds to `fromBaseImage`; add build-from-base-template test. > - Update install method tests to single-package calls for `aptInstall`, `npmInstall`, `bunInstall`, `pipInstall`. > - Tweak `makeSymlink` test order to ensure overwrite behavior. > - Overhaul stacktrace tests to use `msw` server mocks and alias-based failure mapping. > - **Python SDK Tests**: > - `build`/`async_build` fixtures accept optional `alias`. > - Add `from_dockerfile` tests (sync/async); use base image/base template where applicable. > - Update install method tests to single-package calls. > - Rewrite stacktrace tests to monkeypatch API calls with alias-based failure mapping. > - **Dependencies**: > - Add dev dependency `msw` to `packages/js-sdk/package.json`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 1b7f84f4ce692f664c3ce4cdb345f4c3a028b17a. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
2025-11-28 22:34:13 +01:00
)
Render failed layer stack traces on build error (#901) ### Changelog - Added traces for Python and JavaScript SDK. - Added methods for stack trace collection, stack trace context - Updated file upload mechanism for tracing - Changed API handling to support throwing API errors with traces > **Note** > For functions like `aptInstall`, `fromRegistry` which call `.run` and `.fromImage`, the stack trace has to be replaced so it throws correctly from parent. > **Note** > There are no build logs in the trace, we can add this at later point. ### Examples Keep in mind that the way the traces are rendered entirely depends on environment (Bun, Node, Deno, Vitest, Pytest) **Standard Python** ``` Traceback (most recent call last): File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module> Template.build( ~~~~~~~~~~~~~~^ template, ^^^^^^^^^ ...<2 lines>... memory_mb=1024, ^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build wait_for_build_finish( ~~~~~~~~~~~~~~~~~~~~~^ api_client, ^^^^^^^^^^^ ...<4 lines>... stack_traces=template._template._stack_traces, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module> .run_cmd("cat non_existing_file.txt") ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Pytest** ``` [gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) # try: > Template.build( template, alias=str(uuid4()), cpu_count=1, memory_mb=1024, ) tests/sync/template_sync/test_stacktrace.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ e2b/template_sync/main.py:157: in build wait_for_build_finish( e2b/template_sync/build_api.py:199: in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") > .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) E e2b.template.exceptions.BuildException: failed to run command: exit status 1 tests/sync/template_sync/test_stacktrace.py:12: BuildException ========================================================== short test summary info ========================================================== FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Node** ``` node:internal/modules/run_main:104 triggerUncaughtException( ^ at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4 at ModuleJob.run (node:internal/modules/esm/module_job:274:25) at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) { name: 'BuildError' } Node.js v23.11.0 ``` **Bun** ``` 1 | export class BuildError extends Error { 2 | constructor(message: string, stackTrace?: string) { 3 | super(message) ^ BuildError: failed to run command: exit status 1 at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5 Bun v1.2.4 (macOS arm64) ``` **Vitest** ``` BuildError: failed to run command: exit status 1 ❯ tests/template/trace.test.ts:8:6 6| const template = Template() 7| .fromImage('ubuntu:22.04') 8| .runCmd('cat folder/test.txt') | ^ 9| .setWorkdir('/app') 10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000)) ``` --------- Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
@pytest.mark.skip_debug()
async def test_traces_on_rename(async_build):
Render failed layer stack traces on build error (#901) ### Changelog - Added traces for Python and JavaScript SDK. - Added methods for stack trace collection, stack trace context - Updated file upload mechanism for tracing - Changed API handling to support throwing API errors with traces > **Note** > For functions like `aptInstall`, `fromRegistry` which call `.run` and `.fromImage`, the stack trace has to be replaced so it throws correctly from parent. > **Note** > There are no build logs in the trace, we can add this at later point. ### Examples Keep in mind that the way the traces are rendered entirely depends on environment (Bun, Node, Deno, Vitest, Pytest) **Standard Python** ``` Traceback (most recent call last): File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module> Template.build( ~~~~~~~~~~~~~~^ template, ^^^^^^^^^ ...<2 lines>... memory_mb=1024, ^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build wait_for_build_finish( ~~~~~~~~~~~~~~~~~~~~~^ api_client, ^^^^^^^^^^^ ...<4 lines>... stack_traces=template._template._stack_traces, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module> .run_cmd("cat non_existing_file.txt") ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Pytest** ``` [gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) # try: > Template.build( template, alias=str(uuid4()), cpu_count=1, memory_mb=1024, ) tests/sync/template_sync/test_stacktrace.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ e2b/template_sync/main.py:157: in build wait_for_build_finish( e2b/template_sync/build_api.py:199: in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") > .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) E e2b.template.exceptions.BuildException: failed to run command: exit status 1 tests/sync/template_sync/test_stacktrace.py:12: BuildException ========================================================== short test summary info ========================================================== FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Node** ``` node:internal/modules/run_main:104 triggerUncaughtException( ^ at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4 at ModuleJob.run (node:internal/modules/esm/module_job:274:25) at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) { name: 'BuildError' } Node.js v23.11.0 ``` **Bun** ``` 1 | export class BuildError extends Error { 2 | constructor(message: string, stackTrace?: string) { 3 | super(message) ^ BuildError: failed to run command: exit status 1 at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5 Bun v1.2.4 (macOS arm64) ``` **Vitest** ``` BuildError: failed to run command: exit status 1 ❯ tests/template/trace.test.ts:8:6 6| const template = Template() 7| .fromImage('ubuntu:22.04') 8| .runCmd('cat folder/test.txt') | ^ 9| .setWorkdir('/app') 10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000)) ``` --------- Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
template = AsyncTemplate()
template = template.from_base_image()
2025-09-26 14:01:41 +02:00
template = template.skip_cache().rename(non_existent_path, "/tmp/dest.txt")
Improve CI/CD speed for template tests (#1035) <!-- CURSOR_SUMMARY --> > [!NOTE] > Caches Playwright binaries in JS CI and refactors JS/Python template tests to use API mocks and aliases, add Dockerfile tests, and update install APIs to single-package calls. > > - **CI**: > - Cache Playwright binaries on `ubuntu-22.04` and `windows-latest` in `.github/workflows/js_sdk_tests.yml` to speed JS SDK tests. > - **JS SDK Tests**: > - Extend `buildTemplate` options to accept `alias` in `tests/setup.ts`. > - Add `fromDockerfile` tests and switch some builds to `fromBaseImage`; add build-from-base-template test. > - Update install method tests to single-package calls for `aptInstall`, `npmInstall`, `bunInstall`, `pipInstall`. > - Tweak `makeSymlink` test order to ensure overwrite behavior. > - Overhaul stacktrace tests to use `msw` server mocks and alias-based failure mapping. > - **Python SDK Tests**: > - `build`/`async_build` fixtures accept optional `alias`. > - Add `from_dockerfile` tests (sync/async); use base image/base template where applicable. > - Update install method tests to single-package calls. > - Rewrite stacktrace tests to monkeypatch API calls with alias-based failure mapping. > - **Dependencies**: > - Add dev dependency `msw` to `packages/js-sdk/package.json`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 1b7f84f4ce692f664c3ce4cdb345f4c3a028b17a. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
2025-11-28 22:34:13 +01:00
await _expect_to_throw_and_check_trace(
lambda: async_build(template, name="rename"), "rename"
Improve CI/CD speed for template tests (#1035) <!-- CURSOR_SUMMARY --> > [!NOTE] > Caches Playwright binaries in JS CI and refactors JS/Python template tests to use API mocks and aliases, add Dockerfile tests, and update install APIs to single-package calls. > > - **CI**: > - Cache Playwright binaries on `ubuntu-22.04` and `windows-latest` in `.github/workflows/js_sdk_tests.yml` to speed JS SDK tests. > - **JS SDK Tests**: > - Extend `buildTemplate` options to accept `alias` in `tests/setup.ts`. > - Add `fromDockerfile` tests and switch some builds to `fromBaseImage`; add build-from-base-template test. > - Update install method tests to single-package calls for `aptInstall`, `npmInstall`, `bunInstall`, `pipInstall`. > - Tweak `makeSymlink` test order to ensure overwrite behavior. > - Overhaul stacktrace tests to use `msw` server mocks and alias-based failure mapping. > - **Python SDK Tests**: > - `build`/`async_build` fixtures accept optional `alias`. > - Add `from_dockerfile` tests (sync/async); use base image/base template where applicable. > - Update install method tests to single-package calls. > - Rewrite stacktrace tests to monkeypatch API calls with alias-based failure mapping. > - **Dependencies**: > - Add dev dependency `msw` to `packages/js-sdk/package.json`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 1b7f84f4ce692f664c3ce4cdb345f4c3a028b17a. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
2025-11-28 22:34:13 +01:00
)
Render failed layer stack traces on build error (#901) ### Changelog - Added traces for Python and JavaScript SDK. - Added methods for stack trace collection, stack trace context - Updated file upload mechanism for tracing - Changed API handling to support throwing API errors with traces > **Note** > For functions like `aptInstall`, `fromRegistry` which call `.run` and `.fromImage`, the stack trace has to be replaced so it throws correctly from parent. > **Note** > There are no build logs in the trace, we can add this at later point. ### Examples Keep in mind that the way the traces are rendered entirely depends on environment (Bun, Node, Deno, Vitest, Pytest) **Standard Python** ``` Traceback (most recent call last): File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module> Template.build( ~~~~~~~~~~~~~~^ template, ^^^^^^^^^ ...<2 lines>... memory_mb=1024, ^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build wait_for_build_finish( ~~~~~~~~~~~~~~~~~~~~~^ api_client, ^^^^^^^^^^^ ...<4 lines>... stack_traces=template._template._stack_traces, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module> .run_cmd("cat non_existing_file.txt") ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Pytest** ``` [gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) # try: > Template.build( template, alias=str(uuid4()), cpu_count=1, memory_mb=1024, ) tests/sync/template_sync/test_stacktrace.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ e2b/template_sync/main.py:157: in build wait_for_build_finish( e2b/template_sync/build_api.py:199: in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") > .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) E e2b.template.exceptions.BuildException: failed to run command: exit status 1 tests/sync/template_sync/test_stacktrace.py:12: BuildException ========================================================== short test summary info ========================================================== FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Node** ``` node:internal/modules/run_main:104 triggerUncaughtException( ^ at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4 at ModuleJob.run (node:internal/modules/esm/module_job:274:25) at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) { name: 'BuildError' } Node.js v23.11.0 ``` **Bun** ``` 1 | export class BuildError extends Error { 2 | constructor(message: string, stackTrace?: string) { 3 | super(message) ^ BuildError: failed to run command: exit status 1 at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5 Bun v1.2.4 (macOS arm64) ``` **Vitest** ``` BuildError: failed to run command: exit status 1 ❯ tests/template/trace.test.ts:8:6 6| const template = Template() 7| .fromImage('ubuntu:22.04') 8| .runCmd('cat folder/test.txt') | ^ 9| .setWorkdir('/app') 10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000)) ``` --------- Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
@pytest.mark.skip_debug()
async def test_traces_on_make_dir(async_build):
Render failed layer stack traces on build error (#901) ### Changelog - Added traces for Python and JavaScript SDK. - Added methods for stack trace collection, stack trace context - Updated file upload mechanism for tracing - Changed API handling to support throwing API errors with traces > **Note** > For functions like `aptInstall`, `fromRegistry` which call `.run` and `.fromImage`, the stack trace has to be replaced so it throws correctly from parent. > **Note** > There are no build logs in the trace, we can add this at later point. ### Examples Keep in mind that the way the traces are rendered entirely depends on environment (Bun, Node, Deno, Vitest, Pytest) **Standard Python** ``` Traceback (most recent call last): File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module> Template.build( ~~~~~~~~~~~~~~^ template, ^^^^^^^^^ ...<2 lines>... memory_mb=1024, ^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build wait_for_build_finish( ~~~~~~~~~~~~~~~~~~~~~^ api_client, ^^^^^^^^^^^ ...<4 lines>... stack_traces=template._template._stack_traces, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module> .run_cmd("cat non_existing_file.txt") ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Pytest** ``` [gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) # try: > Template.build( template, alias=str(uuid4()), cpu_count=1, memory_mb=1024, ) tests/sync/template_sync/test_stacktrace.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ e2b/template_sync/main.py:157: in build wait_for_build_finish( e2b/template_sync/build_api.py:199: in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") > .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) E e2b.template.exceptions.BuildException: failed to run command: exit status 1 tests/sync/template_sync/test_stacktrace.py:12: BuildException ========================================================== short test summary info ========================================================== FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Node** ``` node:internal/modules/run_main:104 triggerUncaughtException( ^ at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4 at ModuleJob.run (node:internal/modules/esm/module_job:274:25) at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) { name: 'BuildError' } Node.js v23.11.0 ``` **Bun** ``` 1 | export class BuildError extends Error { 2 | constructor(message: string, stackTrace?: string) { 3 | super(message) ^ BuildError: failed to run command: exit status 1 at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5 Bun v1.2.4 (macOS arm64) ``` **Vitest** ``` BuildError: failed to run command: exit status 1 ❯ tests/template/trace.test.ts:8:6 6| const template = Template() 7| .fromImage('ubuntu:22.04') 8| .runCmd('cat folder/test.txt') | ^ 9| .setWorkdir('/app') 10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000)) ``` --------- Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
template = AsyncTemplate()
template = template.from_base_image()
template = template.set_user("root").skip_cache().make_dir("/root/.bashrc")
Improve CI/CD speed for template tests (#1035) <!-- CURSOR_SUMMARY --> > [!NOTE] > Caches Playwright binaries in JS CI and refactors JS/Python template tests to use API mocks and aliases, add Dockerfile tests, and update install APIs to single-package calls. > > - **CI**: > - Cache Playwright binaries on `ubuntu-22.04` and `windows-latest` in `.github/workflows/js_sdk_tests.yml` to speed JS SDK tests. > - **JS SDK Tests**: > - Extend `buildTemplate` options to accept `alias` in `tests/setup.ts`. > - Add `fromDockerfile` tests and switch some builds to `fromBaseImage`; add build-from-base-template test. > - Update install method tests to single-package calls for `aptInstall`, `npmInstall`, `bunInstall`, `pipInstall`. > - Tweak `makeSymlink` test order to ensure overwrite behavior. > - Overhaul stacktrace tests to use `msw` server mocks and alias-based failure mapping. > - **Python SDK Tests**: > - `build`/`async_build` fixtures accept optional `alias`. > - Add `from_dockerfile` tests (sync/async); use base image/base template where applicable. > - Update install method tests to single-package calls. > - Rewrite stacktrace tests to monkeypatch API calls with alias-based failure mapping. > - **Dependencies**: > - Add dev dependency `msw` to `packages/js-sdk/package.json`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 1b7f84f4ce692f664c3ce4cdb345f4c3a028b17a. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
2025-11-28 22:34:13 +01:00
await _expect_to_throw_and_check_trace(
lambda: async_build(template, name="make_dir"), "make_dir"
Improve CI/CD speed for template tests (#1035) <!-- CURSOR_SUMMARY --> > [!NOTE] > Caches Playwright binaries in JS CI and refactors JS/Python template tests to use API mocks and aliases, add Dockerfile tests, and update install APIs to single-package calls. > > - **CI**: > - Cache Playwright binaries on `ubuntu-22.04` and `windows-latest` in `.github/workflows/js_sdk_tests.yml` to speed JS SDK tests. > - **JS SDK Tests**: > - Extend `buildTemplate` options to accept `alias` in `tests/setup.ts`. > - Add `fromDockerfile` tests and switch some builds to `fromBaseImage`; add build-from-base-template test. > - Update install method tests to single-package calls for `aptInstall`, `npmInstall`, `bunInstall`, `pipInstall`. > - Tweak `makeSymlink` test order to ensure overwrite behavior. > - Overhaul stacktrace tests to use `msw` server mocks and alias-based failure mapping. > - **Python SDK Tests**: > - `build`/`async_build` fixtures accept optional `alias`. > - Add `from_dockerfile` tests (sync/async); use base image/base template where applicable. > - Update install method tests to single-package calls. > - Rewrite stacktrace tests to monkeypatch API calls with alias-based failure mapping. > - **Dependencies**: > - Add dev dependency `msw` to `packages/js-sdk/package.json`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 1b7f84f4ce692f664c3ce4cdb345f4c3a028b17a. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
2025-11-28 22:34:13 +01:00
)
Render failed layer stack traces on build error (#901) ### Changelog - Added traces for Python and JavaScript SDK. - Added methods for stack trace collection, stack trace context - Updated file upload mechanism for tracing - Changed API handling to support throwing API errors with traces > **Note** > For functions like `aptInstall`, `fromRegistry` which call `.run` and `.fromImage`, the stack trace has to be replaced so it throws correctly from parent. > **Note** > There are no build logs in the trace, we can add this at later point. ### Examples Keep in mind that the way the traces are rendered entirely depends on environment (Bun, Node, Deno, Vitest, Pytest) **Standard Python** ``` Traceback (most recent call last): File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module> Template.build( ~~~~~~~~~~~~~~^ template, ^^^^^^^^^ ...<2 lines>... memory_mb=1024, ^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build wait_for_build_finish( ~~~~~~~~~~~~~~~~~~~~~^ api_client, ^^^^^^^^^^^ ...<4 lines>... stack_traces=template._template._stack_traces, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module> .run_cmd("cat non_existing_file.txt") ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Pytest** ``` [gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) # try: > Template.build( template, alias=str(uuid4()), cpu_count=1, memory_mb=1024, ) tests/sync/template_sync/test_stacktrace.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ e2b/template_sync/main.py:157: in build wait_for_build_finish( e2b/template_sync/build_api.py:199: in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") > .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) E e2b.template.exceptions.BuildException: failed to run command: exit status 1 tests/sync/template_sync/test_stacktrace.py:12: BuildException ========================================================== short test summary info ========================================================== FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Node** ``` node:internal/modules/run_main:104 triggerUncaughtException( ^ at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4 at ModuleJob.run (node:internal/modules/esm/module_job:274:25) at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) { name: 'BuildError' } Node.js v23.11.0 ``` **Bun** ``` 1 | export class BuildError extends Error { 2 | constructor(message: string, stackTrace?: string) { 3 | super(message) ^ BuildError: failed to run command: exit status 1 at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5 Bun v1.2.4 (macOS arm64) ``` **Vitest** ``` BuildError: failed to run command: exit status 1 ❯ tests/template/trace.test.ts:8:6 6| const template = Template() 7| .fromImage('ubuntu:22.04') 8| .runCmd('cat folder/test.txt') | ^ 9| .setWorkdir('/app') 10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000)) ``` --------- Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
@pytest.mark.skip_debug()
async def test_traces_on_make_symlink(async_build):
Render failed layer stack traces on build error (#901) ### Changelog - Added traces for Python and JavaScript SDK. - Added methods for stack trace collection, stack trace context - Updated file upload mechanism for tracing - Changed API handling to support throwing API errors with traces > **Note** > For functions like `aptInstall`, `fromRegistry` which call `.run` and `.fromImage`, the stack trace has to be replaced so it throws correctly from parent. > **Note** > There are no build logs in the trace, we can add this at later point. ### Examples Keep in mind that the way the traces are rendered entirely depends on environment (Bun, Node, Deno, Vitest, Pytest) **Standard Python** ``` Traceback (most recent call last): File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module> Template.build( ~~~~~~~~~~~~~~^ template, ^^^^^^^^^ ...<2 lines>... memory_mb=1024, ^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build wait_for_build_finish( ~~~~~~~~~~~~~~~~~~~~~^ api_client, ^^^^^^^^^^^ ...<4 lines>... stack_traces=template._template._stack_traces, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module> .run_cmd("cat non_existing_file.txt") ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Pytest** ``` [gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) # try: > Template.build( template, alias=str(uuid4()), cpu_count=1, memory_mb=1024, ) tests/sync/template_sync/test_stacktrace.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ e2b/template_sync/main.py:157: in build wait_for_build_finish( e2b/template_sync/build_api.py:199: in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") > .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) E e2b.template.exceptions.BuildException: failed to run command: exit status 1 tests/sync/template_sync/test_stacktrace.py:12: BuildException ========================================================== short test summary info ========================================================== FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Node** ``` node:internal/modules/run_main:104 triggerUncaughtException( ^ at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4 at ModuleJob.run (node:internal/modules/esm/module_job:274:25) at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) { name: 'BuildError' } Node.js v23.11.0 ``` **Bun** ``` 1 | export class BuildError extends Error { 2 | constructor(message: string, stackTrace?: string) { 3 | super(message) ^ BuildError: failed to run command: exit status 1 at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5 Bun v1.2.4 (macOS arm64) ``` **Vitest** ``` BuildError: failed to run command: exit status 1 ❯ tests/template/trace.test.ts:8:6 6| const template = Template() 7| .fromImage('ubuntu:22.04') 8| .runCmd('cat folder/test.txt') | ^ 9| .setWorkdir('/app') 10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000)) ``` --------- Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
template = AsyncTemplate()
template = template.from_base_image()
2025-09-26 14:01:41 +02:00
template = template.skip_cache().make_symlink(".bashrc", ".bashrc")
await _expect_to_throw_and_check_trace(
lambda: async_build(template, name="make_symlink"), "make_symlink"
)
Render failed layer stack traces on build error (#901) ### Changelog - Added traces for Python and JavaScript SDK. - Added methods for stack trace collection, stack trace context - Updated file upload mechanism for tracing - Changed API handling to support throwing API errors with traces > **Note** > For functions like `aptInstall`, `fromRegistry` which call `.run` and `.fromImage`, the stack trace has to be replaced so it throws correctly from parent. > **Note** > There are no build logs in the trace, we can add this at later point. ### Examples Keep in mind that the way the traces are rendered entirely depends on environment (Bun, Node, Deno, Vitest, Pytest) **Standard Python** ``` Traceback (most recent call last): File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module> Template.build( ~~~~~~~~~~~~~~^ template, ^^^^^^^^^ ...<2 lines>... memory_mb=1024, ^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build wait_for_build_finish( ~~~~~~~~~~~~~~~~~~~~~^ api_client, ^^^^^^^^^^^ ...<4 lines>... stack_traces=template._template._stack_traces, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module> .run_cmd("cat non_existing_file.txt") ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Pytest** ``` [gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) # try: > Template.build( template, alias=str(uuid4()), cpu_count=1, memory_mb=1024, ) tests/sync/template_sync/test_stacktrace.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ e2b/template_sync/main.py:157: in build wait_for_build_finish( e2b/template_sync/build_api.py:199: in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") > .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) E e2b.template.exceptions.BuildException: failed to run command: exit status 1 tests/sync/template_sync/test_stacktrace.py:12: BuildException ========================================================== short test summary info ========================================================== FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Node** ``` node:internal/modules/run_main:104 triggerUncaughtException( ^ at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4 at ModuleJob.run (node:internal/modules/esm/module_job:274:25) at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) { name: 'BuildError' } Node.js v23.11.0 ``` **Bun** ``` 1 | export class BuildError extends Error { 2 | constructor(message: string, stackTrace?: string) { 3 | super(message) ^ BuildError: failed to run command: exit status 1 at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5 Bun v1.2.4 (macOS arm64) ``` **Vitest** ``` BuildError: failed to run command: exit status 1 ❯ tests/template/trace.test.ts:8:6 6| const template = Template() 7| .fromImage('ubuntu:22.04') 8| .runCmd('cat folder/test.txt') | ^ 9| .setWorkdir('/app') 10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000)) ``` --------- Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
@pytest.mark.skip_debug()
async def test_traces_on_run_cmd(async_build):
Render failed layer stack traces on build error (#901) ### Changelog - Added traces for Python and JavaScript SDK. - Added methods for stack trace collection, stack trace context - Updated file upload mechanism for tracing - Changed API handling to support throwing API errors with traces > **Note** > For functions like `aptInstall`, `fromRegistry` which call `.run` and `.fromImage`, the stack trace has to be replaced so it throws correctly from parent. > **Note** > There are no build logs in the trace, we can add this at later point. ### Examples Keep in mind that the way the traces are rendered entirely depends on environment (Bun, Node, Deno, Vitest, Pytest) **Standard Python** ``` Traceback (most recent call last): File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module> Template.build( ~~~~~~~~~~~~~~^ template, ^^^^^^^^^ ...<2 lines>... memory_mb=1024, ^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build wait_for_build_finish( ~~~~~~~~~~~~~~~~~~~~~^ api_client, ^^^^^^^^^^^ ...<4 lines>... stack_traces=template._template._stack_traces, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module> .run_cmd("cat non_existing_file.txt") ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Pytest** ``` [gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) # try: > Template.build( template, alias=str(uuid4()), cpu_count=1, memory_mb=1024, ) tests/sync/template_sync/test_stacktrace.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ e2b/template_sync/main.py:157: in build wait_for_build_finish( e2b/template_sync/build_api.py:199: in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") > .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) E e2b.template.exceptions.BuildException: failed to run command: exit status 1 tests/sync/template_sync/test_stacktrace.py:12: BuildException ========================================================== short test summary info ========================================================== FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Node** ``` node:internal/modules/run_main:104 triggerUncaughtException( ^ at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4 at ModuleJob.run (node:internal/modules/esm/module_job:274:25) at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) { name: 'BuildError' } Node.js v23.11.0 ``` **Bun** ``` 1 | export class BuildError extends Error { 2 | constructor(message: string, stackTrace?: string) { 3 | super(message) ^ BuildError: failed to run command: exit status 1 at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5 Bun v1.2.4 (macOS arm64) ``` **Vitest** ``` BuildError: failed to run command: exit status 1 ❯ tests/template/trace.test.ts:8:6 6| const template = Template() 7| .fromImage('ubuntu:22.04') 8| .runCmd('cat folder/test.txt') | ^ 9| .setWorkdir('/app') 10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000)) ``` --------- Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
template = AsyncTemplate()
template = template.from_base_image()
2025-09-26 14:01:41 +02:00
template = template.skip_cache().run_cmd(f"cat {non_existent_path}")
Improve CI/CD speed for template tests (#1035) <!-- CURSOR_SUMMARY --> > [!NOTE] > Caches Playwright binaries in JS CI and refactors JS/Python template tests to use API mocks and aliases, add Dockerfile tests, and update install APIs to single-package calls. > > - **CI**: > - Cache Playwright binaries on `ubuntu-22.04` and `windows-latest` in `.github/workflows/js_sdk_tests.yml` to speed JS SDK tests. > - **JS SDK Tests**: > - Extend `buildTemplate` options to accept `alias` in `tests/setup.ts`. > - Add `fromDockerfile` tests and switch some builds to `fromBaseImage`; add build-from-base-template test. > - Update install method tests to single-package calls for `aptInstall`, `npmInstall`, `bunInstall`, `pipInstall`. > - Tweak `makeSymlink` test order to ensure overwrite behavior. > - Overhaul stacktrace tests to use `msw` server mocks and alias-based failure mapping. > - **Python SDK Tests**: > - `build`/`async_build` fixtures accept optional `alias`. > - Add `from_dockerfile` tests (sync/async); use base image/base template where applicable. > - Update install method tests to single-package calls. > - Rewrite stacktrace tests to monkeypatch API calls with alias-based failure mapping. > - **Dependencies**: > - Add dev dependency `msw` to `packages/js-sdk/package.json`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 1b7f84f4ce692f664c3ce4cdb345f4c3a028b17a. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
2025-11-28 22:34:13 +01:00
await _expect_to_throw_and_check_trace(
lambda: async_build(template, name="run_cmd"), "run_cmd"
Improve CI/CD speed for template tests (#1035) <!-- CURSOR_SUMMARY --> > [!NOTE] > Caches Playwright binaries in JS CI and refactors JS/Python template tests to use API mocks and aliases, add Dockerfile tests, and update install APIs to single-package calls. > > - **CI**: > - Cache Playwright binaries on `ubuntu-22.04` and `windows-latest` in `.github/workflows/js_sdk_tests.yml` to speed JS SDK tests. > - **JS SDK Tests**: > - Extend `buildTemplate` options to accept `alias` in `tests/setup.ts`. > - Add `fromDockerfile` tests and switch some builds to `fromBaseImage`; add build-from-base-template test. > - Update install method tests to single-package calls for `aptInstall`, `npmInstall`, `bunInstall`, `pipInstall`. > - Tweak `makeSymlink` test order to ensure overwrite behavior. > - Overhaul stacktrace tests to use `msw` server mocks and alias-based failure mapping. > - **Python SDK Tests**: > - `build`/`async_build` fixtures accept optional `alias`. > - Add `from_dockerfile` tests (sync/async); use base image/base template where applicable. > - Update install method tests to single-package calls. > - Rewrite stacktrace tests to monkeypatch API calls with alias-based failure mapping. > - **Dependencies**: > - Add dev dependency `msw` to `packages/js-sdk/package.json`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 1b7f84f4ce692f664c3ce4cdb345f4c3a028b17a. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
2025-11-28 22:34:13 +01:00
)
Render failed layer stack traces on build error (#901) ### Changelog - Added traces for Python and JavaScript SDK. - Added methods for stack trace collection, stack trace context - Updated file upload mechanism for tracing - Changed API handling to support throwing API errors with traces > **Note** > For functions like `aptInstall`, `fromRegistry` which call `.run` and `.fromImage`, the stack trace has to be replaced so it throws correctly from parent. > **Note** > There are no build logs in the trace, we can add this at later point. ### Examples Keep in mind that the way the traces are rendered entirely depends on environment (Bun, Node, Deno, Vitest, Pytest) **Standard Python** ``` Traceback (most recent call last): File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module> Template.build( ~~~~~~~~~~~~~~^ template, ^^^^^^^^^ ...<2 lines>... memory_mb=1024, ^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build wait_for_build_finish( ~~~~~~~~~~~~~~~~~~~~~^ api_client, ^^^^^^^^^^^ ...<4 lines>... stack_traces=template._template._stack_traces, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module> .run_cmd("cat non_existing_file.txt") ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Pytest** ``` [gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) # try: > Template.build( template, alias=str(uuid4()), cpu_count=1, memory_mb=1024, ) tests/sync/template_sync/test_stacktrace.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ e2b/template_sync/main.py:157: in build wait_for_build_finish( e2b/template_sync/build_api.py:199: in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") > .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) E e2b.template.exceptions.BuildException: failed to run command: exit status 1 tests/sync/template_sync/test_stacktrace.py:12: BuildException ========================================================== short test summary info ========================================================== FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Node** ``` node:internal/modules/run_main:104 triggerUncaughtException( ^ at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4 at ModuleJob.run (node:internal/modules/esm/module_job:274:25) at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) { name: 'BuildError' } Node.js v23.11.0 ``` **Bun** ``` 1 | export class BuildError extends Error { 2 | constructor(message: string, stackTrace?: string) { 3 | super(message) ^ BuildError: failed to run command: exit status 1 at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5 Bun v1.2.4 (macOS arm64) ``` **Vitest** ``` BuildError: failed to run command: exit status 1 ❯ tests/template/trace.test.ts:8:6 6| const template = Template() 7| .fromImage('ubuntu:22.04') 8| .runCmd('cat folder/test.txt') | ^ 9| .setWorkdir('/app') 10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000)) ``` --------- Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
@pytest.mark.skip_debug()
async def test_traces_on_set_workdir(async_build):
Render failed layer stack traces on build error (#901) ### Changelog - Added traces for Python and JavaScript SDK. - Added methods for stack trace collection, stack trace context - Updated file upload mechanism for tracing - Changed API handling to support throwing API errors with traces > **Note** > For functions like `aptInstall`, `fromRegistry` which call `.run` and `.fromImage`, the stack trace has to be replaced so it throws correctly from parent. > **Note** > There are no build logs in the trace, we can add this at later point. ### Examples Keep in mind that the way the traces are rendered entirely depends on environment (Bun, Node, Deno, Vitest, Pytest) **Standard Python** ``` Traceback (most recent call last): File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module> Template.build( ~~~~~~~~~~~~~~^ template, ^^^^^^^^^ ...<2 lines>... memory_mb=1024, ^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build wait_for_build_finish( ~~~~~~~~~~~~~~~~~~~~~^ api_client, ^^^^^^^^^^^ ...<4 lines>... stack_traces=template._template._stack_traces, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module> .run_cmd("cat non_existing_file.txt") ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Pytest** ``` [gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) # try: > Template.build( template, alias=str(uuid4()), cpu_count=1, memory_mb=1024, ) tests/sync/template_sync/test_stacktrace.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ e2b/template_sync/main.py:157: in build wait_for_build_finish( e2b/template_sync/build_api.py:199: in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") > .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) E e2b.template.exceptions.BuildException: failed to run command: exit status 1 tests/sync/template_sync/test_stacktrace.py:12: BuildException ========================================================== short test summary info ========================================================== FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Node** ``` node:internal/modules/run_main:104 triggerUncaughtException( ^ at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4 at ModuleJob.run (node:internal/modules/esm/module_job:274:25) at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) { name: 'BuildError' } Node.js v23.11.0 ``` **Bun** ``` 1 | export class BuildError extends Error { 2 | constructor(message: string, stackTrace?: string) { 3 | super(message) ^ BuildError: failed to run command: exit status 1 at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5 Bun v1.2.4 (macOS arm64) ``` **Vitest** ``` BuildError: failed to run command: exit status 1 ❯ tests/template/trace.test.ts:8:6 6| const template = Template() 7| .fromImage('ubuntu:22.04') 8| .runCmd('cat folder/test.txt') | ^ 9| .setWorkdir('/app') 10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000)) ``` --------- Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
template = AsyncTemplate()
template = template.from_base_image()
template = template.set_user("root").skip_cache().set_workdir("/root/.bashrc")
Improve CI/CD speed for template tests (#1035) <!-- CURSOR_SUMMARY --> > [!NOTE] > Caches Playwright binaries in JS CI and refactors JS/Python template tests to use API mocks and aliases, add Dockerfile tests, and update install APIs to single-package calls. > > - **CI**: > - Cache Playwright binaries on `ubuntu-22.04` and `windows-latest` in `.github/workflows/js_sdk_tests.yml` to speed JS SDK tests. > - **JS SDK Tests**: > - Extend `buildTemplate` options to accept `alias` in `tests/setup.ts`. > - Add `fromDockerfile` tests and switch some builds to `fromBaseImage`; add build-from-base-template test. > - Update install method tests to single-package calls for `aptInstall`, `npmInstall`, `bunInstall`, `pipInstall`. > - Tweak `makeSymlink` test order to ensure overwrite behavior. > - Overhaul stacktrace tests to use `msw` server mocks and alias-based failure mapping. > - **Python SDK Tests**: > - `build`/`async_build` fixtures accept optional `alias`. > - Add `from_dockerfile` tests (sync/async); use base image/base template where applicable. > - Update install method tests to single-package calls. > - Rewrite stacktrace tests to monkeypatch API calls with alias-based failure mapping. > - **Dependencies**: > - Add dev dependency `msw` to `packages/js-sdk/package.json`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 1b7f84f4ce692f664c3ce4cdb345f4c3a028b17a. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
2025-11-28 22:34:13 +01:00
await _expect_to_throw_and_check_trace(
lambda: async_build(template, name="set_workdir"), "set_workdir"
Improve CI/CD speed for template tests (#1035) <!-- CURSOR_SUMMARY --> > [!NOTE] > Caches Playwright binaries in JS CI and refactors JS/Python template tests to use API mocks and aliases, add Dockerfile tests, and update install APIs to single-package calls. > > - **CI**: > - Cache Playwright binaries on `ubuntu-22.04` and `windows-latest` in `.github/workflows/js_sdk_tests.yml` to speed JS SDK tests. > - **JS SDK Tests**: > - Extend `buildTemplate` options to accept `alias` in `tests/setup.ts`. > - Add `fromDockerfile` tests and switch some builds to `fromBaseImage`; add build-from-base-template test. > - Update install method tests to single-package calls for `aptInstall`, `npmInstall`, `bunInstall`, `pipInstall`. > - Tweak `makeSymlink` test order to ensure overwrite behavior. > - Overhaul stacktrace tests to use `msw` server mocks and alias-based failure mapping. > - **Python SDK Tests**: > - `build`/`async_build` fixtures accept optional `alias`. > - Add `from_dockerfile` tests (sync/async); use base image/base template where applicable. > - Update install method tests to single-package calls. > - Rewrite stacktrace tests to monkeypatch API calls with alias-based failure mapping. > - **Dependencies**: > - Add dev dependency `msw` to `packages/js-sdk/package.json`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 1b7f84f4ce692f664c3ce4cdb345f4c3a028b17a. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
2025-11-28 22:34:13 +01:00
)
Render failed layer stack traces on build error (#901) ### Changelog - Added traces for Python and JavaScript SDK. - Added methods for stack trace collection, stack trace context - Updated file upload mechanism for tracing - Changed API handling to support throwing API errors with traces > **Note** > For functions like `aptInstall`, `fromRegistry` which call `.run` and `.fromImage`, the stack trace has to be replaced so it throws correctly from parent. > **Note** > There are no build logs in the trace, we can add this at later point. ### Examples Keep in mind that the way the traces are rendered entirely depends on environment (Bun, Node, Deno, Vitest, Pytest) **Standard Python** ``` Traceback (most recent call last): File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module> Template.build( ~~~~~~~~~~~~~~^ template, ^^^^^^^^^ ...<2 lines>... memory_mb=1024, ^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build wait_for_build_finish( ~~~~~~~~~~~~~~~~~~~~~^ api_client, ^^^^^^^^^^^ ...<4 lines>... stack_traces=template._template._stack_traces, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module> .run_cmd("cat non_existing_file.txt") ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Pytest** ``` [gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) # try: > Template.build( template, alias=str(uuid4()), cpu_count=1, memory_mb=1024, ) tests/sync/template_sync/test_stacktrace.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ e2b/template_sync/main.py:157: in build wait_for_build_finish( e2b/template_sync/build_api.py:199: in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") > .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) E e2b.template.exceptions.BuildException: failed to run command: exit status 1 tests/sync/template_sync/test_stacktrace.py:12: BuildException ========================================================== short test summary info ========================================================== FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Node** ``` node:internal/modules/run_main:104 triggerUncaughtException( ^ at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4 at ModuleJob.run (node:internal/modules/esm/module_job:274:25) at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) { name: 'BuildError' } Node.js v23.11.0 ``` **Bun** ``` 1 | export class BuildError extends Error { 2 | constructor(message: string, stackTrace?: string) { 3 | super(message) ^ BuildError: failed to run command: exit status 1 at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5 Bun v1.2.4 (macOS arm64) ``` **Vitest** ``` BuildError: failed to run command: exit status 1 ❯ tests/template/trace.test.ts:8:6 6| const template = Template() 7| .fromImage('ubuntu:22.04') 8| .runCmd('cat folder/test.txt') | ^ 9| .setWorkdir('/app') 10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000)) ``` --------- Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
@pytest.mark.skip_debug()
async def test_traces_on_set_user(async_build):
Render failed layer stack traces on build error (#901) ### Changelog - Added traces for Python and JavaScript SDK. - Added methods for stack trace collection, stack trace context - Updated file upload mechanism for tracing - Changed API handling to support throwing API errors with traces > **Note** > For functions like `aptInstall`, `fromRegistry` which call `.run` and `.fromImage`, the stack trace has to be replaced so it throws correctly from parent. > **Note** > There are no build logs in the trace, we can add this at later point. ### Examples Keep in mind that the way the traces are rendered entirely depends on environment (Bun, Node, Deno, Vitest, Pytest) **Standard Python** ``` Traceback (most recent call last): File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module> Template.build( ~~~~~~~~~~~~~~^ template, ^^^^^^^^^ ...<2 lines>... memory_mb=1024, ^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build wait_for_build_finish( ~~~~~~~~~~~~~~~~~~~~~^ api_client, ^^^^^^^^^^^ ...<4 lines>... stack_traces=template._template._stack_traces, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module> .run_cmd("cat non_existing_file.txt") ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Pytest** ``` [gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) # try: > Template.build( template, alias=str(uuid4()), cpu_count=1, memory_mb=1024, ) tests/sync/template_sync/test_stacktrace.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ e2b/template_sync/main.py:157: in build wait_for_build_finish( e2b/template_sync/build_api.py:199: in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") > .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) E e2b.template.exceptions.BuildException: failed to run command: exit status 1 tests/sync/template_sync/test_stacktrace.py:12: BuildException ========================================================== short test summary info ========================================================== FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Node** ``` node:internal/modules/run_main:104 triggerUncaughtException( ^ at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4 at ModuleJob.run (node:internal/modules/esm/module_job:274:25) at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) { name: 'BuildError' } Node.js v23.11.0 ``` **Bun** ``` 1 | export class BuildError extends Error { 2 | constructor(message: string, stackTrace?: string) { 3 | super(message) ^ BuildError: failed to run command: exit status 1 at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5 Bun v1.2.4 (macOS arm64) ``` **Vitest** ``` BuildError: failed to run command: exit status 1 ❯ tests/template/trace.test.ts:8:6 6| const template = Template() 7| .fromImage('ubuntu:22.04') 8| .runCmd('cat folder/test.txt') | ^ 9| .setWorkdir('/app') 10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000)) ``` --------- Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
template = AsyncTemplate()
template = template.from_base_image()
template = template.skip_cache().set_user("; exit 1")
Improve CI/CD speed for template tests (#1035) <!-- CURSOR_SUMMARY --> > [!NOTE] > Caches Playwright binaries in JS CI and refactors JS/Python template tests to use API mocks and aliases, add Dockerfile tests, and update install APIs to single-package calls. > > - **CI**: > - Cache Playwright binaries on `ubuntu-22.04` and `windows-latest` in `.github/workflows/js_sdk_tests.yml` to speed JS SDK tests. > - **JS SDK Tests**: > - Extend `buildTemplate` options to accept `alias` in `tests/setup.ts`. > - Add `fromDockerfile` tests and switch some builds to `fromBaseImage`; add build-from-base-template test. > - Update install method tests to single-package calls for `aptInstall`, `npmInstall`, `bunInstall`, `pipInstall`. > - Tweak `makeSymlink` test order to ensure overwrite behavior. > - Overhaul stacktrace tests to use `msw` server mocks and alias-based failure mapping. > - **Python SDK Tests**: > - `build`/`async_build` fixtures accept optional `alias`. > - Add `from_dockerfile` tests (sync/async); use base image/base template where applicable. > - Update install method tests to single-package calls. > - Rewrite stacktrace tests to monkeypatch API calls with alias-based failure mapping. > - **Dependencies**: > - Add dev dependency `msw` to `packages/js-sdk/package.json`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 1b7f84f4ce692f664c3ce4cdb345f4c3a028b17a. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
2025-11-28 22:34:13 +01:00
await _expect_to_throw_and_check_trace(
lambda: async_build(template, name="set_user"), "set_user"
Improve CI/CD speed for template tests (#1035) <!-- CURSOR_SUMMARY --> > [!NOTE] > Caches Playwright binaries in JS CI and refactors JS/Python template tests to use API mocks and aliases, add Dockerfile tests, and update install APIs to single-package calls. > > - **CI**: > - Cache Playwright binaries on `ubuntu-22.04` and `windows-latest` in `.github/workflows/js_sdk_tests.yml` to speed JS SDK tests. > - **JS SDK Tests**: > - Extend `buildTemplate` options to accept `alias` in `tests/setup.ts`. > - Add `fromDockerfile` tests and switch some builds to `fromBaseImage`; add build-from-base-template test. > - Update install method tests to single-package calls for `aptInstall`, `npmInstall`, `bunInstall`, `pipInstall`. > - Tweak `makeSymlink` test order to ensure overwrite behavior. > - Overhaul stacktrace tests to use `msw` server mocks and alias-based failure mapping. > - **Python SDK Tests**: > - `build`/`async_build` fixtures accept optional `alias`. > - Add `from_dockerfile` tests (sync/async); use base image/base template where applicable. > - Update install method tests to single-package calls. > - Rewrite stacktrace tests to monkeypatch API calls with alias-based failure mapping. > - **Dependencies**: > - Add dev dependency `msw` to `packages/js-sdk/package.json`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 1b7f84f4ce692f664c3ce4cdb345f4c3a028b17a. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
2025-11-28 22:34:13 +01:00
)
Render failed layer stack traces on build error (#901) ### Changelog - Added traces for Python and JavaScript SDK. - Added methods for stack trace collection, stack trace context - Updated file upload mechanism for tracing - Changed API handling to support throwing API errors with traces > **Note** > For functions like `aptInstall`, `fromRegistry` which call `.run` and `.fromImage`, the stack trace has to be replaced so it throws correctly from parent. > **Note** > There are no build logs in the trace, we can add this at later point. ### Examples Keep in mind that the way the traces are rendered entirely depends on environment (Bun, Node, Deno, Vitest, Pytest) **Standard Python** ``` Traceback (most recent call last): File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module> Template.build( ~~~~~~~~~~~~~~^ template, ^^^^^^^^^ ...<2 lines>... memory_mb=1024, ^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build wait_for_build_finish( ~~~~~~~~~~~~~~~~~~~~~^ api_client, ^^^^^^^^^^^ ...<4 lines>... stack_traces=template._template._stack_traces, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module> .run_cmd("cat non_existing_file.txt") ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Pytest** ``` [gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) # try: > Template.build( template, alias=str(uuid4()), cpu_count=1, memory_mb=1024, ) tests/sync/template_sync/test_stacktrace.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ e2b/template_sync/main.py:157: in build wait_for_build_finish( e2b/template_sync/build_api.py:199: in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") > .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) E e2b.template.exceptions.BuildException: failed to run command: exit status 1 tests/sync/template_sync/test_stacktrace.py:12: BuildException ========================================================== short test summary info ========================================================== FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Node** ``` node:internal/modules/run_main:104 triggerUncaughtException( ^ at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4 at ModuleJob.run (node:internal/modules/esm/module_job:274:25) at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) { name: 'BuildError' } Node.js v23.11.0 ``` **Bun** ``` 1 | export class BuildError extends Error { 2 | constructor(message: string, stackTrace?: string) { 3 | super(message) ^ BuildError: failed to run command: exit status 1 at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5 Bun v1.2.4 (macOS arm64) ``` **Vitest** ``` BuildError: failed to run command: exit status 1 ❯ tests/template/trace.test.ts:8:6 6| const template = Template() 7| .fromImage('ubuntu:22.04') 8| .runCmd('cat folder/test.txt') | ^ 9| .setWorkdir('/app') 10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000)) ``` --------- Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
@pytest.mark.skip_debug()
async def test_traces_on_pip_install(async_build):
Render failed layer stack traces on build error (#901) ### Changelog - Added traces for Python and JavaScript SDK. - Added methods for stack trace collection, stack trace context - Updated file upload mechanism for tracing - Changed API handling to support throwing API errors with traces > **Note** > For functions like `aptInstall`, `fromRegistry` which call `.run` and `.fromImage`, the stack trace has to be replaced so it throws correctly from parent. > **Note** > There are no build logs in the trace, we can add this at later point. ### Examples Keep in mind that the way the traces are rendered entirely depends on environment (Bun, Node, Deno, Vitest, Pytest) **Standard Python** ``` Traceback (most recent call last): File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module> Template.build( ~~~~~~~~~~~~~~^ template, ^^^^^^^^^ ...<2 lines>... memory_mb=1024, ^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build wait_for_build_finish( ~~~~~~~~~~~~~~~~~~~~~^ api_client, ^^^^^^^^^^^ ...<4 lines>... stack_traces=template._template._stack_traces, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module> .run_cmd("cat non_existing_file.txt") ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Pytest** ``` [gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) # try: > Template.build( template, alias=str(uuid4()), cpu_count=1, memory_mb=1024, ) tests/sync/template_sync/test_stacktrace.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ e2b/template_sync/main.py:157: in build wait_for_build_finish( e2b/template_sync/build_api.py:199: in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") > .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) E e2b.template.exceptions.BuildException: failed to run command: exit status 1 tests/sync/template_sync/test_stacktrace.py:12: BuildException ========================================================== short test summary info ========================================================== FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Node** ``` node:internal/modules/run_main:104 triggerUncaughtException( ^ at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4 at ModuleJob.run (node:internal/modules/esm/module_job:274:25) at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) { name: 'BuildError' } Node.js v23.11.0 ``` **Bun** ``` 1 | export class BuildError extends Error { 2 | constructor(message: string, stackTrace?: string) { 3 | super(message) ^ BuildError: failed to run command: exit status 1 at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5 Bun v1.2.4 (macOS arm64) ``` **Vitest** ``` BuildError: failed to run command: exit status 1 ❯ tests/template/trace.test.ts:8:6 6| const template = Template() 7| .fromImage('ubuntu:22.04') 8| .runCmd('cat folder/test.txt') | ^ 9| .setWorkdir('/app') 10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000)) ``` --------- Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
template = AsyncTemplate()
template = template.from_base_image()
2025-09-26 14:01:41 +02:00
template = template.skip_cache().pip_install("nonexistent-package")
Improve CI/CD speed for template tests (#1035) <!-- CURSOR_SUMMARY --> > [!NOTE] > Caches Playwright binaries in JS CI and refactors JS/Python template tests to use API mocks and aliases, add Dockerfile tests, and update install APIs to single-package calls. > > - **CI**: > - Cache Playwright binaries on `ubuntu-22.04` and `windows-latest` in `.github/workflows/js_sdk_tests.yml` to speed JS SDK tests. > - **JS SDK Tests**: > - Extend `buildTemplate` options to accept `alias` in `tests/setup.ts`. > - Add `fromDockerfile` tests and switch some builds to `fromBaseImage`; add build-from-base-template test. > - Update install method tests to single-package calls for `aptInstall`, `npmInstall`, `bunInstall`, `pipInstall`. > - Tweak `makeSymlink` test order to ensure overwrite behavior. > - Overhaul stacktrace tests to use `msw` server mocks and alias-based failure mapping. > - **Python SDK Tests**: > - `build`/`async_build` fixtures accept optional `alias`. > - Add `from_dockerfile` tests (sync/async); use base image/base template where applicable. > - Update install method tests to single-package calls. > - Rewrite stacktrace tests to monkeypatch API calls with alias-based failure mapping. > - **Dependencies**: > - Add dev dependency `msw` to `packages/js-sdk/package.json`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 1b7f84f4ce692f664c3ce4cdb345f4c3a028b17a. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
2025-11-28 22:34:13 +01:00
await _expect_to_throw_and_check_trace(
lambda: async_build(template, name="pip_install"), "pip_install"
Improve CI/CD speed for template tests (#1035) <!-- CURSOR_SUMMARY --> > [!NOTE] > Caches Playwright binaries in JS CI and refactors JS/Python template tests to use API mocks and aliases, add Dockerfile tests, and update install APIs to single-package calls. > > - **CI**: > - Cache Playwright binaries on `ubuntu-22.04` and `windows-latest` in `.github/workflows/js_sdk_tests.yml` to speed JS SDK tests. > - **JS SDK Tests**: > - Extend `buildTemplate` options to accept `alias` in `tests/setup.ts`. > - Add `fromDockerfile` tests and switch some builds to `fromBaseImage`; add build-from-base-template test. > - Update install method tests to single-package calls for `aptInstall`, `npmInstall`, `bunInstall`, `pipInstall`. > - Tweak `makeSymlink` test order to ensure overwrite behavior. > - Overhaul stacktrace tests to use `msw` server mocks and alias-based failure mapping. > - **Python SDK Tests**: > - `build`/`async_build` fixtures accept optional `alias`. > - Add `from_dockerfile` tests (sync/async); use base image/base template where applicable. > - Update install method tests to single-package calls. > - Rewrite stacktrace tests to monkeypatch API calls with alias-based failure mapping. > - **Dependencies**: > - Add dev dependency `msw` to `packages/js-sdk/package.json`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 1b7f84f4ce692f664c3ce4cdb345f4c3a028b17a. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
2025-11-28 22:34:13 +01:00
)
Render failed layer stack traces on build error (#901) ### Changelog - Added traces for Python and JavaScript SDK. - Added methods for stack trace collection, stack trace context - Updated file upload mechanism for tracing - Changed API handling to support throwing API errors with traces > **Note** > For functions like `aptInstall`, `fromRegistry` which call `.run` and `.fromImage`, the stack trace has to be replaced so it throws correctly from parent. > **Note** > There are no build logs in the trace, we can add this at later point. ### Examples Keep in mind that the way the traces are rendered entirely depends on environment (Bun, Node, Deno, Vitest, Pytest) **Standard Python** ``` Traceback (most recent call last): File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module> Template.build( ~~~~~~~~~~~~~~^ template, ^^^^^^^^^ ...<2 lines>... memory_mb=1024, ^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build wait_for_build_finish( ~~~~~~~~~~~~~~~~~~~~~^ api_client, ^^^^^^^^^^^ ...<4 lines>... stack_traces=template._template._stack_traces, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module> .run_cmd("cat non_existing_file.txt") ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Pytest** ``` [gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) # try: > Template.build( template, alias=str(uuid4()), cpu_count=1, memory_mb=1024, ) tests/sync/template_sync/test_stacktrace.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ e2b/template_sync/main.py:157: in build wait_for_build_finish( e2b/template_sync/build_api.py:199: in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") > .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) E e2b.template.exceptions.BuildException: failed to run command: exit status 1 tests/sync/template_sync/test_stacktrace.py:12: BuildException ========================================================== short test summary info ========================================================== FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Node** ``` node:internal/modules/run_main:104 triggerUncaughtException( ^ at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4 at ModuleJob.run (node:internal/modules/esm/module_job:274:25) at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) { name: 'BuildError' } Node.js v23.11.0 ``` **Bun** ``` 1 | export class BuildError extends Error { 2 | constructor(message: string, stackTrace?: string) { 3 | super(message) ^ BuildError: failed to run command: exit status 1 at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5 Bun v1.2.4 (macOS arm64) ``` **Vitest** ``` BuildError: failed to run command: exit status 1 ❯ tests/template/trace.test.ts:8:6 6| const template = Template() 7| .fromImage('ubuntu:22.04') 8| .runCmd('cat folder/test.txt') | ^ 9| .setWorkdir('/app') 10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000)) ``` --------- Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
@pytest.mark.skip_debug()
async def test_traces_on_npm_install(async_build):
Render failed layer stack traces on build error (#901) ### Changelog - Added traces for Python and JavaScript SDK. - Added methods for stack trace collection, stack trace context - Updated file upload mechanism for tracing - Changed API handling to support throwing API errors with traces > **Note** > For functions like `aptInstall`, `fromRegistry` which call `.run` and `.fromImage`, the stack trace has to be replaced so it throws correctly from parent. > **Note** > There are no build logs in the trace, we can add this at later point. ### Examples Keep in mind that the way the traces are rendered entirely depends on environment (Bun, Node, Deno, Vitest, Pytest) **Standard Python** ``` Traceback (most recent call last): File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module> Template.build( ~~~~~~~~~~~~~~^ template, ^^^^^^^^^ ...<2 lines>... memory_mb=1024, ^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build wait_for_build_finish( ~~~~~~~~~~~~~~~~~~~~~^ api_client, ^^^^^^^^^^^ ...<4 lines>... stack_traces=template._template._stack_traces, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module> .run_cmd("cat non_existing_file.txt") ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Pytest** ``` [gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) # try: > Template.build( template, alias=str(uuid4()), cpu_count=1, memory_mb=1024, ) tests/sync/template_sync/test_stacktrace.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ e2b/template_sync/main.py:157: in build wait_for_build_finish( e2b/template_sync/build_api.py:199: in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") > .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) E e2b.template.exceptions.BuildException: failed to run command: exit status 1 tests/sync/template_sync/test_stacktrace.py:12: BuildException ========================================================== short test summary info ========================================================== FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Node** ``` node:internal/modules/run_main:104 triggerUncaughtException( ^ at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4 at ModuleJob.run (node:internal/modules/esm/module_job:274:25) at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) { name: 'BuildError' } Node.js v23.11.0 ``` **Bun** ``` 1 | export class BuildError extends Error { 2 | constructor(message: string, stackTrace?: string) { 3 | super(message) ^ BuildError: failed to run command: exit status 1 at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5 Bun v1.2.4 (macOS arm64) ``` **Vitest** ``` BuildError: failed to run command: exit status 1 ❯ tests/template/trace.test.ts:8:6 6| const template = Template() 7| .fromImage('ubuntu:22.04') 8| .runCmd('cat folder/test.txt') | ^ 9| .setWorkdir('/app') 10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000)) ``` --------- Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
template = AsyncTemplate()
template = template.from_base_image()
2025-09-26 14:01:41 +02:00
template = template.skip_cache().npm_install("nonexistent-package")
Improve CI/CD speed for template tests (#1035) <!-- CURSOR_SUMMARY --> > [!NOTE] > Caches Playwright binaries in JS CI and refactors JS/Python template tests to use API mocks and aliases, add Dockerfile tests, and update install APIs to single-package calls. > > - **CI**: > - Cache Playwright binaries on `ubuntu-22.04` and `windows-latest` in `.github/workflows/js_sdk_tests.yml` to speed JS SDK tests. > - **JS SDK Tests**: > - Extend `buildTemplate` options to accept `alias` in `tests/setup.ts`. > - Add `fromDockerfile` tests and switch some builds to `fromBaseImage`; add build-from-base-template test. > - Update install method tests to single-package calls for `aptInstall`, `npmInstall`, `bunInstall`, `pipInstall`. > - Tweak `makeSymlink` test order to ensure overwrite behavior. > - Overhaul stacktrace tests to use `msw` server mocks and alias-based failure mapping. > - **Python SDK Tests**: > - `build`/`async_build` fixtures accept optional `alias`. > - Add `from_dockerfile` tests (sync/async); use base image/base template where applicable. > - Update install method tests to single-package calls. > - Rewrite stacktrace tests to monkeypatch API calls with alias-based failure mapping. > - **Dependencies**: > - Add dev dependency `msw` to `packages/js-sdk/package.json`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 1b7f84f4ce692f664c3ce4cdb345f4c3a028b17a. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
2025-11-28 22:34:13 +01:00
await _expect_to_throw_and_check_trace(
lambda: async_build(template, name="npm_install"), "npm_install"
Improve CI/CD speed for template tests (#1035) <!-- CURSOR_SUMMARY --> > [!NOTE] > Caches Playwright binaries in JS CI and refactors JS/Python template tests to use API mocks and aliases, add Dockerfile tests, and update install APIs to single-package calls. > > - **CI**: > - Cache Playwright binaries on `ubuntu-22.04` and `windows-latest` in `.github/workflows/js_sdk_tests.yml` to speed JS SDK tests. > - **JS SDK Tests**: > - Extend `buildTemplate` options to accept `alias` in `tests/setup.ts`. > - Add `fromDockerfile` tests and switch some builds to `fromBaseImage`; add build-from-base-template test. > - Update install method tests to single-package calls for `aptInstall`, `npmInstall`, `bunInstall`, `pipInstall`. > - Tweak `makeSymlink` test order to ensure overwrite behavior. > - Overhaul stacktrace tests to use `msw` server mocks and alias-based failure mapping. > - **Python SDK Tests**: > - `build`/`async_build` fixtures accept optional `alias`. > - Add `from_dockerfile` tests (sync/async); use base image/base template where applicable. > - Update install method tests to single-package calls. > - Rewrite stacktrace tests to monkeypatch API calls with alias-based failure mapping. > - **Dependencies**: > - Add dev dependency `msw` to `packages/js-sdk/package.json`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 1b7f84f4ce692f664c3ce4cdb345f4c3a028b17a. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
2025-11-28 22:34:13 +01:00
)
Render failed layer stack traces on build error (#901) ### Changelog - Added traces for Python and JavaScript SDK. - Added methods for stack trace collection, stack trace context - Updated file upload mechanism for tracing - Changed API handling to support throwing API errors with traces > **Note** > For functions like `aptInstall`, `fromRegistry` which call `.run` and `.fromImage`, the stack trace has to be replaced so it throws correctly from parent. > **Note** > There are no build logs in the trace, we can add this at later point. ### Examples Keep in mind that the way the traces are rendered entirely depends on environment (Bun, Node, Deno, Vitest, Pytest) **Standard Python** ``` Traceback (most recent call last): File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module> Template.build( ~~~~~~~~~~~~~~^ template, ^^^^^^^^^ ...<2 lines>... memory_mb=1024, ^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build wait_for_build_finish( ~~~~~~~~~~~~~~~~~~~~~^ api_client, ^^^^^^^^^^^ ...<4 lines>... stack_traces=template._template._stack_traces, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module> .run_cmd("cat non_existing_file.txt") ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Pytest** ``` [gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) # try: > Template.build( template, alias=str(uuid4()), cpu_count=1, memory_mb=1024, ) tests/sync/template_sync/test_stacktrace.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ e2b/template_sync/main.py:157: in build wait_for_build_finish( e2b/template_sync/build_api.py:199: in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") > .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) E e2b.template.exceptions.BuildException: failed to run command: exit status 1 tests/sync/template_sync/test_stacktrace.py:12: BuildException ========================================================== short test summary info ========================================================== FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Node** ``` node:internal/modules/run_main:104 triggerUncaughtException( ^ at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4 at ModuleJob.run (node:internal/modules/esm/module_job:274:25) at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) { name: 'BuildError' } Node.js v23.11.0 ``` **Bun** ``` 1 | export class BuildError extends Error { 2 | constructor(message: string, stackTrace?: string) { 3 | super(message) ^ BuildError: failed to run command: exit status 1 at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5 Bun v1.2.4 (macOS arm64) ``` **Vitest** ``` BuildError: failed to run command: exit status 1 ❯ tests/template/trace.test.ts:8:6 6| const template = Template() 7| .fromImage('ubuntu:22.04') 8| .runCmd('cat folder/test.txt') | ^ 9| .setWorkdir('/app') 10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000)) ``` --------- Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
@pytest.mark.skip_debug()
async def test_traces_on_apt_install(async_build):
Render failed layer stack traces on build error (#901) ### Changelog - Added traces for Python and JavaScript SDK. - Added methods for stack trace collection, stack trace context - Updated file upload mechanism for tracing - Changed API handling to support throwing API errors with traces > **Note** > For functions like `aptInstall`, `fromRegistry` which call `.run` and `.fromImage`, the stack trace has to be replaced so it throws correctly from parent. > **Note** > There are no build logs in the trace, we can add this at later point. ### Examples Keep in mind that the way the traces are rendered entirely depends on environment (Bun, Node, Deno, Vitest, Pytest) **Standard Python** ``` Traceback (most recent call last): File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module> Template.build( ~~~~~~~~~~~~~~^ template, ^^^^^^^^^ ...<2 lines>... memory_mb=1024, ^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build wait_for_build_finish( ~~~~~~~~~~~~~~~~~~~~~^ api_client, ^^^^^^^^^^^ ...<4 lines>... stack_traces=template._template._stack_traces, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module> .run_cmd("cat non_existing_file.txt") ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Pytest** ``` [gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) # try: > Template.build( template, alias=str(uuid4()), cpu_count=1, memory_mb=1024, ) tests/sync/template_sync/test_stacktrace.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ e2b/template_sync/main.py:157: in build wait_for_build_finish( e2b/template_sync/build_api.py:199: in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") > .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) E e2b.template.exceptions.BuildException: failed to run command: exit status 1 tests/sync/template_sync/test_stacktrace.py:12: BuildException ========================================================== short test summary info ========================================================== FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Node** ``` node:internal/modules/run_main:104 triggerUncaughtException( ^ at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4 at ModuleJob.run (node:internal/modules/esm/module_job:274:25) at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) { name: 'BuildError' } Node.js v23.11.0 ``` **Bun** ``` 1 | export class BuildError extends Error { 2 | constructor(message: string, stackTrace?: string) { 3 | super(message) ^ BuildError: failed to run command: exit status 1 at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5 Bun v1.2.4 (macOS arm64) ``` **Vitest** ``` BuildError: failed to run command: exit status 1 ❯ tests/template/trace.test.ts:8:6 6| const template = Template() 7| .fromImage('ubuntu:22.04') 8| .runCmd('cat folder/test.txt') | ^ 9| .setWorkdir('/app') 10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000)) ``` --------- Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
template = AsyncTemplate()
template = template.from_base_image()
2025-09-26 14:01:41 +02:00
template = template.skip_cache().apt_install("nonexistent-package")
Improve CI/CD speed for template tests (#1035) <!-- CURSOR_SUMMARY --> > [!NOTE] > Caches Playwright binaries in JS CI and refactors JS/Python template tests to use API mocks and aliases, add Dockerfile tests, and update install APIs to single-package calls. > > - **CI**: > - Cache Playwright binaries on `ubuntu-22.04` and `windows-latest` in `.github/workflows/js_sdk_tests.yml` to speed JS SDK tests. > - **JS SDK Tests**: > - Extend `buildTemplate` options to accept `alias` in `tests/setup.ts`. > - Add `fromDockerfile` tests and switch some builds to `fromBaseImage`; add build-from-base-template test. > - Update install method tests to single-package calls for `aptInstall`, `npmInstall`, `bunInstall`, `pipInstall`. > - Tweak `makeSymlink` test order to ensure overwrite behavior. > - Overhaul stacktrace tests to use `msw` server mocks and alias-based failure mapping. > - **Python SDK Tests**: > - `build`/`async_build` fixtures accept optional `alias`. > - Add `from_dockerfile` tests (sync/async); use base image/base template where applicable. > - Update install method tests to single-package calls. > - Rewrite stacktrace tests to monkeypatch API calls with alias-based failure mapping. > - **Dependencies**: > - Add dev dependency `msw` to `packages/js-sdk/package.json`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 1b7f84f4ce692f664c3ce4cdb345f4c3a028b17a. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
2025-11-28 22:34:13 +01:00
await _expect_to_throw_and_check_trace(
lambda: async_build(template, name="apt_install"), "apt_install"
Improve CI/CD speed for template tests (#1035) <!-- CURSOR_SUMMARY --> > [!NOTE] > Caches Playwright binaries in JS CI and refactors JS/Python template tests to use API mocks and aliases, add Dockerfile tests, and update install APIs to single-package calls. > > - **CI**: > - Cache Playwright binaries on `ubuntu-22.04` and `windows-latest` in `.github/workflows/js_sdk_tests.yml` to speed JS SDK tests. > - **JS SDK Tests**: > - Extend `buildTemplate` options to accept `alias` in `tests/setup.ts`. > - Add `fromDockerfile` tests and switch some builds to `fromBaseImage`; add build-from-base-template test. > - Update install method tests to single-package calls for `aptInstall`, `npmInstall`, `bunInstall`, `pipInstall`. > - Tweak `makeSymlink` test order to ensure overwrite behavior. > - Overhaul stacktrace tests to use `msw` server mocks and alias-based failure mapping. > - **Python SDK Tests**: > - `build`/`async_build` fixtures accept optional `alias`. > - Add `from_dockerfile` tests (sync/async); use base image/base template where applicable. > - Update install method tests to single-package calls. > - Rewrite stacktrace tests to monkeypatch API calls with alias-based failure mapping. > - **Dependencies**: > - Add dev dependency `msw` to `packages/js-sdk/package.json`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 1b7f84f4ce692f664c3ce4cdb345f4c3a028b17a. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
2025-11-28 22:34:13 +01:00
)
Render failed layer stack traces on build error (#901) ### Changelog - Added traces for Python and JavaScript SDK. - Added methods for stack trace collection, stack trace context - Updated file upload mechanism for tracing - Changed API handling to support throwing API errors with traces > **Note** > For functions like `aptInstall`, `fromRegistry` which call `.run` and `.fromImage`, the stack trace has to be replaced so it throws correctly from parent. > **Note** > There are no build logs in the trace, we can add this at later point. ### Examples Keep in mind that the way the traces are rendered entirely depends on environment (Bun, Node, Deno, Vitest, Pytest) **Standard Python** ``` Traceback (most recent call last): File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module> Template.build( ~~~~~~~~~~~~~~^ template, ^^^^^^^^^ ...<2 lines>... memory_mb=1024, ^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build wait_for_build_finish( ~~~~~~~~~~~~~~~~~~~~~^ api_client, ^^^^^^^^^^^ ...<4 lines>... stack_traces=template._template._stack_traces, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module> .run_cmd("cat non_existing_file.txt") ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Pytest** ``` [gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) # try: > Template.build( template, alias=str(uuid4()), cpu_count=1, memory_mb=1024, ) tests/sync/template_sync/test_stacktrace.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ e2b/template_sync/main.py:157: in build wait_for_build_finish( e2b/template_sync/build_api.py:199: in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") > .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) E e2b.template.exceptions.BuildException: failed to run command: exit status 1 tests/sync/template_sync/test_stacktrace.py:12: BuildException ========================================================== short test summary info ========================================================== FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Node** ``` node:internal/modules/run_main:104 triggerUncaughtException( ^ at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4 at ModuleJob.run (node:internal/modules/esm/module_job:274:25) at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) { name: 'BuildError' } Node.js v23.11.0 ``` **Bun** ``` 1 | export class BuildError extends Error { 2 | constructor(message: string, stackTrace?: string) { 3 | super(message) ^ BuildError: failed to run command: exit status 1 at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5 Bun v1.2.4 (macOS arm64) ``` **Vitest** ``` BuildError: failed to run command: exit status 1 ❯ tests/template/trace.test.ts:8:6 6| const template = Template() 7| .fromImage('ubuntu:22.04') 8| .runCmd('cat folder/test.txt') | ^ 9| .setWorkdir('/app') 10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000)) ``` --------- Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
@pytest.mark.skip_debug()
async def test_traces_on_git_clone(async_build):
Render failed layer stack traces on build error (#901) ### Changelog - Added traces for Python and JavaScript SDK. - Added methods for stack trace collection, stack trace context - Updated file upload mechanism for tracing - Changed API handling to support throwing API errors with traces > **Note** > For functions like `aptInstall`, `fromRegistry` which call `.run` and `.fromImage`, the stack trace has to be replaced so it throws correctly from parent. > **Note** > There are no build logs in the trace, we can add this at later point. ### Examples Keep in mind that the way the traces are rendered entirely depends on environment (Bun, Node, Deno, Vitest, Pytest) **Standard Python** ``` Traceback (most recent call last): File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module> Template.build( ~~~~~~~~~~~~~~^ template, ^^^^^^^^^ ...<2 lines>... memory_mb=1024, ^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build wait_for_build_finish( ~~~~~~~~~~~~~~~~~~~~~^ api_client, ^^^^^^^^^^^ ...<4 lines>... stack_traces=template._template._stack_traces, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module> .run_cmd("cat non_existing_file.txt") ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Pytest** ``` [gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) # try: > Template.build( template, alias=str(uuid4()), cpu_count=1, memory_mb=1024, ) tests/sync/template_sync/test_stacktrace.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ e2b/template_sync/main.py:157: in build wait_for_build_finish( e2b/template_sync/build_api.py:199: in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") > .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) E e2b.template.exceptions.BuildException: failed to run command: exit status 1 tests/sync/template_sync/test_stacktrace.py:12: BuildException ========================================================== short test summary info ========================================================== FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Node** ``` node:internal/modules/run_main:104 triggerUncaughtException( ^ at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4 at ModuleJob.run (node:internal/modules/esm/module_job:274:25) at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) { name: 'BuildError' } Node.js v23.11.0 ``` **Bun** ``` 1 | export class BuildError extends Error { 2 | constructor(message: string, stackTrace?: string) { 3 | super(message) ^ BuildError: failed to run command: exit status 1 at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5 Bun v1.2.4 (macOS arm64) ``` **Vitest** ``` BuildError: failed to run command: exit status 1 ❯ tests/template/trace.test.ts:8:6 6| const template = Template() 7| .fromImage('ubuntu:22.04') 8| .runCmd('cat folder/test.txt') | ^ 9| .setWorkdir('/app') 10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000)) ``` --------- Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
template = AsyncTemplate()
template = template.from_base_image()
2025-09-26 14:01:41 +02:00
template = template.skip_cache().git_clone("https://github.com/repo.git")
Improve CI/CD speed for template tests (#1035) <!-- CURSOR_SUMMARY --> > [!NOTE] > Caches Playwright binaries in JS CI and refactors JS/Python template tests to use API mocks and aliases, add Dockerfile tests, and update install APIs to single-package calls. > > - **CI**: > - Cache Playwright binaries on `ubuntu-22.04` and `windows-latest` in `.github/workflows/js_sdk_tests.yml` to speed JS SDK tests. > - **JS SDK Tests**: > - Extend `buildTemplate` options to accept `alias` in `tests/setup.ts`. > - Add `fromDockerfile` tests and switch some builds to `fromBaseImage`; add build-from-base-template test. > - Update install method tests to single-package calls for `aptInstall`, `npmInstall`, `bunInstall`, `pipInstall`. > - Tweak `makeSymlink` test order to ensure overwrite behavior. > - Overhaul stacktrace tests to use `msw` server mocks and alias-based failure mapping. > - **Python SDK Tests**: > - `build`/`async_build` fixtures accept optional `alias`. > - Add `from_dockerfile` tests (sync/async); use base image/base template where applicable. > - Update install method tests to single-package calls. > - Rewrite stacktrace tests to monkeypatch API calls with alias-based failure mapping. > - **Dependencies**: > - Add dev dependency `msw` to `packages/js-sdk/package.json`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 1b7f84f4ce692f664c3ce4cdb345f4c3a028b17a. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
2025-11-28 22:34:13 +01:00
await _expect_to_throw_and_check_trace(
lambda: async_build(template, name="git_clone"), "git_clone"
Improve CI/CD speed for template tests (#1035) <!-- CURSOR_SUMMARY --> > [!NOTE] > Caches Playwright binaries in JS CI and refactors JS/Python template tests to use API mocks and aliases, add Dockerfile tests, and update install APIs to single-package calls. > > - **CI**: > - Cache Playwright binaries on `ubuntu-22.04` and `windows-latest` in `.github/workflows/js_sdk_tests.yml` to speed JS SDK tests. > - **JS SDK Tests**: > - Extend `buildTemplate` options to accept `alias` in `tests/setup.ts`. > - Add `fromDockerfile` tests and switch some builds to `fromBaseImage`; add build-from-base-template test. > - Update install method tests to single-package calls for `aptInstall`, `npmInstall`, `bunInstall`, `pipInstall`. > - Tweak `makeSymlink` test order to ensure overwrite behavior. > - Overhaul stacktrace tests to use `msw` server mocks and alias-based failure mapping. > - **Python SDK Tests**: > - `build`/`async_build` fixtures accept optional `alias`. > - Add `from_dockerfile` tests (sync/async); use base image/base template where applicable. > - Update install method tests to single-package calls. > - Rewrite stacktrace tests to monkeypatch API calls with alias-based failure mapping. > - **Dependencies**: > - Add dev dependency `msw` to `packages/js-sdk/package.json`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 1b7f84f4ce692f664c3ce4cdb345f4c3a028b17a. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
2025-11-28 22:34:13 +01:00
)
Render failed layer stack traces on build error (#901) ### Changelog - Added traces for Python and JavaScript SDK. - Added methods for stack trace collection, stack trace context - Updated file upload mechanism for tracing - Changed API handling to support throwing API errors with traces > **Note** > For functions like `aptInstall`, `fromRegistry` which call `.run` and `.fromImage`, the stack trace has to be replaced so it throws correctly from parent. > **Note** > There are no build logs in the trace, we can add this at later point. ### Examples Keep in mind that the way the traces are rendered entirely depends on environment (Bun, Node, Deno, Vitest, Pytest) **Standard Python** ``` Traceback (most recent call last): File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module> Template.build( ~~~~~~~~~~~~~~^ template, ^^^^^^^^^ ...<2 lines>... memory_mb=1024, ^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build wait_for_build_finish( ~~~~~~~~~~~~~~~~~~~~~^ api_client, ^^^^^^^^^^^ ...<4 lines>... stack_traces=template._template._stack_traces, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module> .run_cmd("cat non_existing_file.txt") ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Pytest** ``` [gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) # try: > Template.build( template, alias=str(uuid4()), cpu_count=1, memory_mb=1024, ) tests/sync/template_sync/test_stacktrace.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ e2b/template_sync/main.py:157: in build wait_for_build_finish( e2b/template_sync/build_api.py:199: in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") > .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) E e2b.template.exceptions.BuildException: failed to run command: exit status 1 tests/sync/template_sync/test_stacktrace.py:12: BuildException ========================================================== short test summary info ========================================================== FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Node** ``` node:internal/modules/run_main:104 triggerUncaughtException( ^ at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4 at ModuleJob.run (node:internal/modules/esm/module_job:274:25) at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) { name: 'BuildError' } Node.js v23.11.0 ``` **Bun** ``` 1 | export class BuildError extends Error { 2 | constructor(message: string, stackTrace?: string) { 3 | super(message) ^ BuildError: failed to run command: exit status 1 at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5 Bun v1.2.4 (macOS arm64) ``` **Vitest** ``` BuildError: failed to run command: exit status 1 ❯ tests/template/trace.test.ts:8:6 6| const template = Template() 7| .fromImage('ubuntu:22.04') 8| .runCmd('cat folder/test.txt') | ^ 9| .setWorkdir('/app') 10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000)) ``` --------- Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
@pytest.mark.skip_debug()
Improve method naming and consistency (#934) <!-- CURSOR_SUMMARY --> > [!NOTE] > Unifies Template APIs across JS/Python with PathLike support, new copyItems, option/name tweaks, and simpler registry auth via credentials; updates parser, exports, and tests. > > - **Template API (JS + Python)** > - Add PathLike support for paths in `copy`, `remove`, `rename`, `makeDir`, `makeSymlink`, `setWorkdir`, and `gitClone`. > - Introduce `copyItems` and corresponding `CopyItem` typing; adjust Dockerfile parser to use `copyItems` overload. > - Simplify registry auth: `fromImage(baseImage, credentials)` accepts `{username,password}`; remove `fromRegistry`; update `fromAWSRegistry`/`fromGCPRegistry` to take credentials and set config internally. > - Rename options: `ignoreFilePaths` -> `fileIgnorePatterns`; `fileContextPath` can be `PathLike`. > - Ensure internal hashing/upload use stringified paths; minor enum/type tweaks (e.g., `InstructionType` as string enum, `forceUpload?: true`). > - **Exports** > - Export `CopyItem` from JS `index.ts` and Python `__init__.py`. > - **Tests** > - Update stacktrace and build tests to new method names/signatures (e.g., registry via `fromImage` credentials, new `copyItems` tests, optional `skipCache` param). > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 95391030550a340fe99ebaac4494867b3e3e9507. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-10-09 00:51:02 +02:00
async def test_traces_on_start_cmd(async_build):
Render failed layer stack traces on build error (#901) ### Changelog - Added traces for Python and JavaScript SDK. - Added methods for stack trace collection, stack trace context - Updated file upload mechanism for tracing - Changed API handling to support throwing API errors with traces > **Note** > For functions like `aptInstall`, `fromRegistry` which call `.run` and `.fromImage`, the stack trace has to be replaced so it throws correctly from parent. > **Note** > There are no build logs in the trace, we can add this at later point. ### Examples Keep in mind that the way the traces are rendered entirely depends on environment (Bun, Node, Deno, Vitest, Pytest) **Standard Python** ``` Traceback (most recent call last): File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 17, in <module> Template.build( ~~~~~~~~~~~~~~^ template, ^^^^^^^^^ ...<2 lines>... memory_mb=1024, ^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/main.py", line 157, in build wait_for_build_finish( ~~~~~~~~~~~~~~~~~~~~~^ api_client, ^^^^^^^^^^^ ...<4 lines>... stack_traces=template._template._stack_traces, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/e2b/template_sync/build_api.py", line 199, in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) File "/Users/mish/Documents/Projects/E2B/E2B/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py", line 12, in <module> .run_cmd("cat non_existing_file.txt") ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Pytest** ``` [gw0] darwin -- Python 3.13.3 /Users/mish/Library/Caches/pypoetry/virtualenvs/e2b-e6GdLxLZ-py3.13/bin/python @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) # try: > Template.build( template, alias=str(uuid4()), cpu_count=1, memory_mb=1024, ) tests/sync/template_sync/test_stacktrace.py:18: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ e2b/template_sync/main.py:157: in build wait_for_build_finish( e2b/template_sync/build_api.py:199: in wait_for_build_finish raise BuildException(error_message).with_traceback(stack_trace) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ @pytest.mark.skip_debug() def test_build(): template = ( Template() .from_image("ubuntu:22.04") > .run_cmd("cat non_existing_file.txt") .set_workdir("/app") .set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)) ) E e2b.template.exceptions.BuildException: failed to run command: exit status 1 tests/sync/template_sync/test_stacktrace.py:12: BuildException ========================================================== short test summary info ========================================================== FAILED tests/sync/template_sync/test_stacktrace.py::test_build - e2b.template.exceptions.BuildException: failed to run command: exit status 1 ``` **Node** ``` node:internal/modules/run_main:104 triggerUncaughtException( ^ at file:///Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/tests/template/trace.test.mts:8:4 at ModuleJob.run (node:internal/modules/esm/module_job:274:25) at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5) { name: 'BuildError' } Node.js v23.11.0 ``` **Bun** ``` 1 | export class BuildError extends Error { 2 | constructor(message: string, stackTrace?: string) { 3 | super(message) ^ BuildError: failed to run command: exit status 1 at /Users/mish/Documents/Projects/E2B/E2B/packages/js-sdk/src/template/errors.ts:3:5 Bun v1.2.4 (macOS arm64) ``` **Vitest** ``` BuildError: failed to run command: exit status 1 ❯ tests/template/trace.test.ts:8:6 6| const template = Template() 7| .fromImage('ubuntu:22.04') 8| .runCmd('cat folder/test.txt') | ^ 9| .setWorkdir('/app') 10| .setStartCmd('echo "Hello, world!"', waitForTimeout(10_000)) ``` --------- Co-authored-by: Jakub Dobry <jakub.dobry8@gmail.com>
2025-09-19 12:34:08 +02:00
template = AsyncTemplate()
template = template.from_base_image()
template = template.set_start_cmd(
f"./{non_existent_path}", wait_for_timeout(10_000)
)
await _expect_to_throw_and_check_trace(
lambda: async_build(template, name="set_start_cmd"), "set_start_cmd"
)
Add mcp server prepull (#975) Adds prepulling mcp server images to the SDK. ```typescript export const template = Template() .fromTemplate("mcp-gateway") .betaAddMcpServer("arxiv") await Template.build(template, { alias: "arxiv-mcp-gateway", cpuCount: 1, memoryMB: 1024, onBuildLogs: console.log, }); ``` ```python template = Template().from_template("mcp-gateway").beta_add_mcp_server("arxiv") Template.build( template, alias="arxiv-mcp-gateway-v1", cpu_count=1, memory_mb=1024, ) ``` <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Introduce beta methods to prepull MCP servers via mcp-gateway in JS and Python templates, with typing, validation, and stacktrace-tested errors. > > - **Template SDKs** > - **JS**: > - Add `Template.betaAddMcpServer(servers: McpServerName | McpServerName[])` to run `mcp-gateway pull ...`. > - Enforce base template check (`'mcp-gateway'`), throwing `BuildError` with stack trace. > - Introduce and export `McpServerName` type (from `../sandbox/mcp`). > - **Python**: > - Add `Template.beta_add_mcp_server(servers: Union[str, List[str]])` to run `mcp-gateway pull ...`. > - Enforce `'mcp-gateway'` base template; raise `BuildException` with captured traceback. > - **Tests** > - Add stacktrace tests for `betaAddMcpServer` (JS) and `beta_add_mcp_server` (Python async/sync). > - **Release** > - Changeset: patch bumps for `@e2b/python-sdk` and `e2b`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 43b4a01ce3c856dff7def5ba6b706ee00eda0f84. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Joseph Lombrozo <joe.lombrozo@e2b.dev>
2025-10-20 14:52:30 -07:00
@pytest.mark.skip_debug()
Promote beta MCP features to main (#986) <!-- CURSOR_SUMMARY --> > [!NOTE] > Promotes MCP to stable across JS/Python SDKs: add `mcp` config to sandbox creation, auto-select MCP template, start gateway with token, rename beta APIs to stable (`getMcpUrl`/`getMcpToken`, `addMcpServer`). > > - **JS SDK**: > - **Sandbox creation**: `Sandbox.create` now accepts `opts.mcp`; auto-selects `defaultMcpTemplate`, starts `mcp-gateway` with generated token, and returns initialized sandbox. > - **API opts**: Move `mcp` from `SandboxBetaCreateOpts` to `SandboxOpts`; pass `mcp` through `SandboxApi.createSandbox`. > - **Stable MCP APIs**: Rename `betaGetMcpUrl` -> `getMcpUrl`, `betaGetMcpToken` -> `getMcpToken`. > - **Template builder**: Rename `betaAddMcpServer` -> `addMcpServer`. > - **Tests**: Update stacktrace tests to new method names. > - **Python SDK**: > - **Sandbox creation**: `AsyncSandbox.create`/`Sandbox.create` accept `mcp`; auto-select MCP template when unset, start `mcp-gateway`, store token. > - **Stable MCP APIs**: Add `get_mcp_url`; rename `beta_get_mcp_token` -> `get_mcp_token`. > - **Types**: Minor signature tweaks (e.g., `secure` default handling). > - **Tests**: Update stacktrace tests to new method names. > - **Release**: > - Changeset: minor version bumps for `@e2b/python-sdk` and `e2b`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 9c673f80eee37e530d05c6becf5a4a3c492ac9f3. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
2025-10-22 21:22:02 +02:00
async def test_traces_on_add_mcp_server():
Add mcp server prepull (#975) Adds prepulling mcp server images to the SDK. ```typescript export const template = Template() .fromTemplate("mcp-gateway") .betaAddMcpServer("arxiv") await Template.build(template, { alias: "arxiv-mcp-gateway", cpuCount: 1, memoryMB: 1024, onBuildLogs: console.log, }); ``` ```python template = Template().from_template("mcp-gateway").beta_add_mcp_server("arxiv") Template.build( template, alias="arxiv-mcp-gateway-v1", cpu_count=1, memory_mb=1024, ) ``` <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Introduce beta methods to prepull MCP servers via mcp-gateway in JS and Python templates, with typing, validation, and stacktrace-tested errors. > > - **Template SDKs** > - **JS**: > - Add `Template.betaAddMcpServer(servers: McpServerName | McpServerName[])` to run `mcp-gateway pull ...`. > - Enforce base template check (`'mcp-gateway'`), throwing `BuildError` with stack trace. > - Introduce and export `McpServerName` type (from `../sandbox/mcp`). > - **Python**: > - Add `Template.beta_add_mcp_server(servers: Union[str, List[str]])` to run `mcp-gateway pull ...`. > - Enforce `'mcp-gateway'` base template; raise `BuildException` with captured traceback. > - **Tests** > - Add stacktrace tests for `betaAddMcpServer` (JS) and `beta_add_mcp_server` (Python async/sync). > - **Release** > - Changeset: patch bumps for `@e2b/python-sdk` and `e2b`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 43b4a01ce3c856dff7def5ba6b706ee00eda0f84. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Joseph Lombrozo <joe.lombrozo@e2b.dev>
2025-10-20 14:52:30 -07:00
# needs mcp-gateway as base template, without it no mcp servers can be added
await _expect_to_throw_and_check_trace(
lambda: AsyncTemplate().from_base_image().skip_cache().add_mcp_server("exa"),
Promote beta MCP features to main (#986) <!-- CURSOR_SUMMARY --> > [!NOTE] > Promotes MCP to stable across JS/Python SDKs: add `mcp` config to sandbox creation, auto-select MCP template, start gateway with token, rename beta APIs to stable (`getMcpUrl`/`getMcpToken`, `addMcpServer`). > > - **JS SDK**: > - **Sandbox creation**: `Sandbox.create` now accepts `opts.mcp`; auto-selects `defaultMcpTemplate`, starts `mcp-gateway` with generated token, and returns initialized sandbox. > - **API opts**: Move `mcp` from `SandboxBetaCreateOpts` to `SandboxOpts`; pass `mcp` through `SandboxApi.createSandbox`. > - **Stable MCP APIs**: Rename `betaGetMcpUrl` -> `getMcpUrl`, `betaGetMcpToken` -> `getMcpToken`. > - **Template builder**: Rename `betaAddMcpServer` -> `addMcpServer`. > - **Tests**: Update stacktrace tests to new method names. > - **Python SDK**: > - **Sandbox creation**: `AsyncSandbox.create`/`Sandbox.create` accept `mcp`; auto-select MCP template when unset, start `mcp-gateway`, store token. > - **Stable MCP APIs**: Add `get_mcp_url`; rename `beta_get_mcp_token` -> `get_mcp_token`. > - **Types**: Minor signature tweaks (e.g., `secure` default handling). > - **Tests**: Update stacktrace tests to new method names. > - **Release**: > - Changeset: minor version bumps for `@e2b/python-sdk` and `e2b`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 9c673f80eee37e530d05c6becf5a4a3c492ac9f3. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
2025-10-22 21:22:02 +02:00
"add_mcp_server",
Add mcp server prepull (#975) Adds prepulling mcp server images to the SDK. ```typescript export const template = Template() .fromTemplate("mcp-gateway") .betaAddMcpServer("arxiv") await Template.build(template, { alias: "arxiv-mcp-gateway", cpuCount: 1, memoryMB: 1024, onBuildLogs: console.log, }); ``` ```python template = Template().from_template("mcp-gateway").beta_add_mcp_server("arxiv") Template.build( template, alias="arxiv-mcp-gateway-v1", cpu_count=1, memory_mb=1024, ) ``` <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Introduce beta methods to prepull MCP servers via mcp-gateway in JS and Python templates, with typing, validation, and stacktrace-tested errors. > > - **Template SDKs** > - **JS**: > - Add `Template.betaAddMcpServer(servers: McpServerName | McpServerName[])` to run `mcp-gateway pull ...`. > - Enforce base template check (`'mcp-gateway'`), throwing `BuildError` with stack trace. > - Introduce and export `McpServerName` type (from `../sandbox/mcp`). > - **Python**: > - Add `Template.beta_add_mcp_server(servers: Union[str, List[str]])` to run `mcp-gateway pull ...`. > - Enforce `'mcp-gateway'` base template; raise `BuildException` with captured traceback. > - **Tests** > - Add stacktrace tests for `betaAddMcpServer` (JS) and `beta_add_mcp_server` (Python async/sync). > - **Release** > - Changeset: patch bumps for `@e2b/python-sdk` and `e2b`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 43b4a01ce3c856dff7def5ba6b706ee00eda0f84. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Joseph Lombrozo <joe.lombrozo@e2b.dev>
2025-10-20 14:52:30 -07:00
)
@pytest.mark.skip_debug()
async def test_traces_on_dev_container_prebuild(async_build):
template = AsyncTemplate()
template = template.from_template("devcontainer")
template = template.skip_cache().beta_dev_container_prebuild(non_existent_path)
await _expect_to_throw_and_check_trace(
lambda: async_build(template, name="beta_dev_container_prebuild"),
Improve CI/CD speed for template tests (#1035) <!-- CURSOR_SUMMARY --> > [!NOTE] > Caches Playwright binaries in JS CI and refactors JS/Python template tests to use API mocks and aliases, add Dockerfile tests, and update install APIs to single-package calls. > > - **CI**: > - Cache Playwright binaries on `ubuntu-22.04` and `windows-latest` in `.github/workflows/js_sdk_tests.yml` to speed JS SDK tests. > - **JS SDK Tests**: > - Extend `buildTemplate` options to accept `alias` in `tests/setup.ts`. > - Add `fromDockerfile` tests and switch some builds to `fromBaseImage`; add build-from-base-template test. > - Update install method tests to single-package calls for `aptInstall`, `npmInstall`, `bunInstall`, `pipInstall`. > - Tweak `makeSymlink` test order to ensure overwrite behavior. > - Overhaul stacktrace tests to use `msw` server mocks and alias-based failure mapping. > - **Python SDK Tests**: > - `build`/`async_build` fixtures accept optional `alias`. > - Add `from_dockerfile` tests (sync/async); use base image/base template where applicable. > - Update install method tests to single-package calls. > - Rewrite stacktrace tests to monkeypatch API calls with alias-based failure mapping. > - **Dependencies**: > - Add dev dependency `msw` to `packages/js-sdk/package.json`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 1b7f84f4ce692f664c3ce4cdb345f4c3a028b17a. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
2025-11-28 22:34:13 +01:00
"beta_dev_container_prebuild",
)
@pytest.mark.skip_debug()
async def test_traces_on_set_dev_container_start(async_build):
template = AsyncTemplate()
template = template.from_template("devcontainer")
template = template.beta_set_dev_container_start(non_existent_path)
await _expect_to_throw_and_check_trace(
lambda: async_build(template, name="beta_set_dev_container_start"),
Improve CI/CD speed for template tests (#1035) <!-- CURSOR_SUMMARY --> > [!NOTE] > Caches Playwright binaries in JS CI and refactors JS/Python template tests to use API mocks and aliases, add Dockerfile tests, and update install APIs to single-package calls. > > - **CI**: > - Cache Playwright binaries on `ubuntu-22.04` and `windows-latest` in `.github/workflows/js_sdk_tests.yml` to speed JS SDK tests. > - **JS SDK Tests**: > - Extend `buildTemplate` options to accept `alias` in `tests/setup.ts`. > - Add `fromDockerfile` tests and switch some builds to `fromBaseImage`; add build-from-base-template test. > - Update install method tests to single-package calls for `aptInstall`, `npmInstall`, `bunInstall`, `pipInstall`. > - Tweak `makeSymlink` test order to ensure overwrite behavior. > - Overhaul stacktrace tests to use `msw` server mocks and alias-based failure mapping. > - **Python SDK Tests**: > - `build`/`async_build` fixtures accept optional `alias`. > - Add `from_dockerfile` tests (sync/async); use base image/base template where applicable. > - Update install method tests to single-package calls. > - Rewrite stacktrace tests to monkeypatch API calls with alias-based failure mapping. > - **Dependencies**: > - Add dev dependency `msw` to `packages/js-sdk/package.json`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 1b7f84f4ce692f664c3ce4cdb345f4c3a028b17a. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
2025-11-28 22:34:13 +01:00
"beta_set_dev_container_start",
)