Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Periodic E2E tests of our infra via calling sdks (#92)
Jakub Novák250ffc69c9e5
diff --git a/.github/workflows/release.yml b/.github/workflows/release.ymlindex 6595e0501..8e41012e8 100644--- a/.github/workflows/release.yml+++ b/.github/workflows/release.yml@@ -36,7 +36,7 @@ jobs:virtualenvs-in-project: trueinstaller-parallel: true- - name: Install Dependencies+ - name: Install dependenciesrun: npm ci- name: Cache node modules@@ -47,20 +47,14 @@ jobs:key: node_modules-${{hashFiles('package-lock.json')}}restore-keys: node_modules-+ - name: Run tests+ run: npm run test+- name: Create new versionsrun: npm run versionenv:GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}- - name: Commit new versions- run: |- git config user.name "github-actions[bot]"- git config user.email "github-actions[bot]@users.noreply.github.com"- git commit -am "[skip ci] Release new versions" || exit 0- git push- env:- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}-- name: Release new versionsuses: changesets/action@v1with:@@ -69,3 +63,12 @@ jobs:GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}NPM_TOKEN: ${{ secrets.NPM_TOKEN }}PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}++ - name: Commit new versions+ run: |+ git config user.name "github-actions[bot]"+ git config user.email "github-actions[bot]@users.noreply.github.com"+ git commit -am "[skip ci] Release new versions" || exit 0+ git push+ env:+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.ymlnew file mode 100644index 000000000..a594f5f79--- /dev/null+++ b/.github/workflows/tests.yml@@ -0,0 +1,47 @@+name: Periodic tests via Python SDK++on:+ schedule:+ - cron: "17 */8 * * *"++concurrency: ${{ github.workflow }}-${{ github.ref }}++permissions:+ contents: read++jobs:+ tests:+ name: Periodic tests+ runs-on: ubuntu-latest+ defaults:+ run:+ working-directory: ./packages/python-sdk+ steps:+ - name: Checkout Repo+ uses: actions/checkout@v3++ - name: Set up Python+ uses: actions/setup-python@v4+ with:+ python-version: "3.11"++ - name: Install and configure Poetry+ uses: snok/install-poetry@v1+ with:+ version: 1.5.1+ virtualenvs-create: true+ virtualenvs-in-project: true+ installer-parallel: true++ - name: Install dependencies+ run: poetry install++ - name: Run tests+ run: poetry run pytest -n auto+ env:+ E2B_API_KEY: ${{ secrets.E2B_API_KEY }}++ - name: Upload Results+ run: poetry run scripts/upload_test_results.py+ with:+ SUPABASE_POSTGRES_URL: ${{ secrets.SUPABASE_POSTGRES_URL }}diff --git a/package.json b/package.jsonindex 1bac349fc..7d7a37a09 100644--- a/package.json+++ b/package.json@@ -4,7 +4,8 @@"private": true,"scripts": {"version": "changeset version && npm run postVersion --workspaces --if-present",- "publish": "changeset publish && npm run postPublish --workspaces --if-present"+ "publish": "changeset publish && npm run postPublish --workspaces --if-present",+ "test": "npm run test --workspaces --if-present"},"workspaces": ["packages/*"diff --git a/packages/js-sdk/package.json b/packages/js-sdk/package.jsonindex a8bedb038..b517d3c84 100644--- a/packages/js-sdk/package.json+++ b/packages/js-sdk/package.json@@ -27,7 +27,7 @@"watch": "rollup -c -w","measure": "node test/performance.mjs","run": "node test/run.mjs",- "test": "vitest",+ "test": "vitest run","test:coverage": "vitest run --coverage","fix": "npx eslint **/src/**/*.{ts,js} --fix","format": "prettier --check --ignore-path .gitignore .",diff --git a/packages/python-sdk/e2b/session/session_connection.py b/packages/python-sdk/e2b/session/session_connection.pyindex c337210d6..94782be9c 100644--- a/packages/python-sdk/e2b/session/session_connection.py+++ b/packages/python-sdk/e2b/session/session_connection.py@@ -175,7 +175,7 @@ class SessionConnection:)else:logger.info(- f"No session to stop refreshing. Session was not created"+ "No session to stop refreshing. Session was not created")await self.close()diff --git a/packages/python-sdk/package.json b/packages/python-sdk/package.jsonindex 205c7d816..e109e8b88 100644--- a/packages/python-sdk/package.json+++ b/packages/python-sdk/package.json@@ -1,9 +1,11 @@{- "name": "@e2b/python-sdk",- "private": true,- "version": "0.2.2",- "scripts": {- "postVersion": "poetry version $(npm pkg get version --workspaces=false | tr -d \\\")",- "postPublish": "poetry build && poetry config pypi-token.pypi ${PYPI_TOKEN} && poetry publish"- }+ "name": "@e2b/python-sdk",+ "private": true,+ "version": "0.2.2",+ "scripts": {+ "test": "pytest -n auto",+ "postVersion": "poetry version $(npm pkg get version --workspaces=false | tr -d \\\")",+ "postPublish": "poetry build && poetry config pypi-token.pypi ${PYPI_TOKEN} && poetry publish",+ "postInstall": "poetry install"+ }}diff --git a/packages/python-sdk/poetry.lock b/packages/python-sdk/poetry.lockindex 0553090f0..40d13b46e 100644--- a/packages/python-sdk/poetry.lock+++ b/packages/python-sdk/poetry.lock@@ -611,6 +611,26 @@ files = [dev = ["pre-commit", "tox"]testing = ["pytest", "pytest-benchmark"]+[[package]]+name = "psycopg2"+version = "2.9.7"+description = "psycopg2 - Python-PostgreSQL Database Adapter"+optional = false+python-versions = ">=3.6"+files = [+ {file = "psycopg2-2.9.7-cp310-cp310-win32.whl", hash = "sha256:1a6a2d609bce44f78af4556bea0c62a5e7f05c23e5ea9c599e07678995609084"},+ {file = "psycopg2-2.9.7-cp310-cp310-win_amd64.whl", hash = "sha256:b22ed9c66da2589a664e0f1ca2465c29b75aaab36fa209d4fb916025fb9119e5"},+ {file = "psycopg2-2.9.7-cp311-cp311-win32.whl", hash = "sha256:44d93a0109dfdf22fe399b419bcd7fa589d86895d3931b01fb321d74dadc68f1"},+ {file = "psycopg2-2.9.7-cp311-cp311-win_amd64.whl", hash = "sha256:91e81a8333a0037babfc9fe6d11e997a9d4dac0f38c43074886b0d9dead94fe9"},+ {file = "psycopg2-2.9.7-cp37-cp37m-win32.whl", hash = "sha256:d1210fcf99aae6f728812d1d2240afc1dc44b9e6cba526a06fb8134f969957c2"},+ {file = "psycopg2-2.9.7-cp37-cp37m-win_amd64.whl", hash = "sha256:e9b04cbef584310a1ac0f0d55bb623ca3244c87c51187645432e342de9ae81a8"},+ {file = "psycopg2-2.9.7-cp38-cp38-win32.whl", hash = "sha256:d5c5297e2fbc8068d4255f1e606bfc9291f06f91ec31b2a0d4c536210ac5c0a2"},+ {file = "psycopg2-2.9.7-cp38-cp38-win_amd64.whl", hash = "sha256:8275abf628c6dc7ec834ea63f6f3846bf33518907a2b9b693d41fd063767a866"},+ {file = "psycopg2-2.9.7-cp39-cp39-win32.whl", hash = "sha256:c7949770cafbd2f12cecc97dea410c514368908a103acf519f2a346134caa4d5"},+ {file = "psycopg2-2.9.7-cp39-cp39-win_amd64.whl", hash = "sha256:b6bd7d9d3a7a63faae6edf365f0ed0e9b0a1aaf1da3ca146e6b043fb3eb5d723"},+ {file = "psycopg2-2.9.7.tar.gz", hash = "sha256:f00cc35bd7119f1fed17b85bd1007855194dde2cbd8de01ab8ebb17487440ad8"},+]+[[package]]name = "pydantic"version = "1.10.12"@@ -955,5 +975,5 @@ multidict = ">=4.0"[metadata]lock-version = "2.0"-python-versions = "^3.9"-content-hash = "900fe366641e9fe15fbf5b5b61af36a99ad54c2a58d42ebccbf1a7968e8b950c"+python-versions = "^3.8"+content-hash = "f647a60d1e72e35656c44252924d252f2865adac170777f2c9da67e2b7d5db40"diff --git a/packages/python-sdk/pyproject.toml b/packages/python-sdk/pyproject.tomlindex 16392b368..5a72d5555 100644--- a/packages/python-sdk/pyproject.toml+++ b/packages/python-sdk/pyproject.toml@@ -26,6 +26,7 @@ black = "^23.7.0"pytest = "^7.4.0"pytest-xdist = "^3.3.1"pytest-asyncio = "^0.21.1"+psycopg2 = "^2.9.7"[build-system]requires = ["poetry-core"]diff --git a/packages/python-sdk/scripts/upload_test_results.py b/packages/python-sdk/scripts/upload_test_results.pynew file mode 100644index 000000000..1d4583e12--- /dev/null+++ b/packages/python-sdk/scripts/upload_test_results.py@@ -0,0 +1,42 @@+import csv+import os+from urllib.parse import urlparse++import psycopg2++database_url = urlparse(os.getenv("SUPABASE_POSTGRES_URL"))++user = database_url.username+password = database_url.password+database = database_url.path[1:]+host = database_url.hostname+++# Read the results.csv file+with open("results.csv", "r") as f:+ reader = csv.DictReader(f)+ results = list(reader)++# Connect to the database+conn = psycopg2.connect(+ host=host,+ database=database,+ user=user,+ password=password,+)++# Create a cursor+cur = conn.cursor()++# Insert all results into the database+cur.execute(+ "INSERT INTO tests.test_results (test_name, duration) VALUES (%s, %s)",+ [(result["test_name"], result["duration"]) for result in results],+)++# Commit the changes+conn.commit()++# Close the cursor and connection+cur.close()+conn.close()diff --git a/packages/python-sdk/tests/conftest.py b/packages/python-sdk/tests/conftest.pynew file mode 100644index 000000000..bc589b916--- /dev/null+++ b/packages/python-sdk/tests/conftest.py@@ -0,0 +1,22 @@+import csv+import time++import pytest++[email protected](tryfirst=True)+def pytest_configure():+ with open("results.csv", "w") as f:+ writer = csv.DictWriter(f, ["test_name", "duration"])+ writer.writeheader()++[email protected](autouse=True)+def record(request):+ test_name = request.node.name+ start = time.time()+ yield+ end = time.time()+ with open("results.csv", "a") as f:+ writer = csv.DictWriter(f, ["test_name", "duration"])+ writer.writerow({"test_name": test_name, "duration": round(end - start, 4)})diff --git a/packages/python-sdk/tests/test_filesystem.py b/packages/python-sdk/tests/test_filesystem.pyindex a1b972fc9..5fe36825d 100644--- a/packages/python-sdk/tests/test_filesystem.py+++ b/packages/python-sdk/tests/test_filesystem.py@@ -1,10 +1,13 @@from asyncio import sleep+from os import getenvfrom e2b import Session+E2B_API_KEY = getenv("E2B_API_KEY")+async def test_list_files():- session = await Session.create("Nodejs")+ session = await Session.create("Nodejs", api_key=E2B_API_KEY)await session.filesystem.make_dir("/test/new")ls = await session.filesystem.list("/test")@@ -14,7 +17,7 @@ async def test_list_files():async def test_create_file():- session = await Session.create("Nodejs")+ session = await Session.create("Nodejs", api_key=E2B_API_KEY)await session.filesystem.make_dir("/test")await session.filesystem.write("/test/test.txt", "Hello World!")@@ -25,7 +28,7 @@ async def test_create_file():async def test_read_and_write():- session = await Session.create("Nodejs")+ session = await Session.create("Nodejs", api_key=E2B_API_KEY)await session.filesystem.write("/tmp/test.txt", "Hello World!")@@ -36,7 +39,7 @@ async def test_read_and_write():async def test_list_delete_files():- session = await Session.create("Nodejs")+ session = await Session.create("Nodejs", api_key=E2B_API_KEY)await session.filesystem.make_dir("/test/new")ls = await session.filesystem.list("/test")@@ -51,8 +54,7 @@ async def test_list_delete_files():async def test_watch_dir():- session = Session("Nodejs")- await session.open()+ session = await Session.create("Nodejs", api_key=E2B_API_KEY)await session.filesystem.write("/tmp/test.txt", "Hello")watcher = await session.filesystem.watch_dir("/tmp")diff --git a/packages/python-sdk/tests/test_process.py b/packages/python-sdk/tests/test_process.pyindex d86ec1782..3b9c8f104 100644--- a/packages/python-sdk/tests/test_process.py+++ b/packages/python-sdk/tests/test_process.py@@ -1,11 +1,13 @@-from asyncio import sleep+from os import getenvfrom unittest.mock import MagicMockfrom e2b import Session+E2B_API_KEY = getenv("E2B_API_KEY")+async def test_process_on_stdout_stderr():- session = await Session.create("Nodejs")+ session = await Session.create("Nodejs", api_key=E2B_API_KEY)stdout = []stderr = []@@ -19,7 +21,7 @@ async def test_process_on_stdout_stderr():output = await proc- assert output.error == False+ assert not output.errorassert output.stdout == "/tmp"assert output.stderr == ""assert list(map(lambda message: message.line, stdout)) == ["/tmp"]@@ -29,7 +31,7 @@ async def test_process_on_stdout_stderr():async def test_process_on_exit():- session = await Session.create("Nodejs")+ session = await Session.create("Nodejs", api_key=E2B_API_KEY)on_exit = MagicMock()@@ -45,10 +47,10 @@ async def test_process_on_exit():async def test_process_send_stdin():- session = await Session.create("Nodejs")+ session = await Session.create("Nodejs", api_key=E2B_API_KEY)proc = await session.process.start(- 'while IFS= read -r line; do echo "$line"; sleep 1; done',+ 'read -r line; echo "$line"',rootdir="/code",)await proc.send_stdin("ping\n")@@ -59,6 +61,6 @@ async def test_process_send_stdin():assert len(proc.output_messages) == 1message = proc.output_messages[0]assert message.line == "ping"- assert message.error == False+ assert not message.errorawait session.close()diff --git a/packages/python-sdk/tests/test_session.py b/packages/python-sdk/tests/test_session.pyindex 433b57f8a..bf4acefb6 100644--- a/packages/python-sdk/tests/test_session.py+++ b/packages/python-sdk/tests/test_session.py@@ -1,13 +1,17 @@+from os import getenv+from e2b import Session+E2B_API_KEY = getenv("E2B_API_KEY")+async def test_create_session():- session = await Session.create("Nodejs")+ session = await Session.create("Nodejs", api_key=E2B_API_KEY)await session.close()async def test_create_multiple_sessions():- session = await Session.create("Nodejs")- session2 = await Session.create("Nodejs")+ session = await Session.create("Nodejs", api_key=E2B_API_KEY)+ session2 = await Session.create("Nodejs", api_key=E2B_API_KEY)await session.close()await session2.close()