Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

[WIP] Prepare tests

Tomas Valentaaaf66ae15776
diff --git a/packages/js-sdk/src/connectionConfig.ts b/packages/js-sdk/src/connectionConfig.ts
index a2942b823..32246f66d 100644
--- a/packages/js-sdk/src/connectionConfig.ts
+++ b/packages/js-sdk/src/connectionConfig.ts
@@ -5,7 +5,7 @@ const DEBUG = (process?.env?.E2B_DEBUG || 'false').toLowerCase() === 'true'
const API_KEY = process?.env?.E2B_API_KEY
const ACCESS_TOKEN = process?.env?.E2B_ACCESS_TOKEN
const REQUEST_TIMEOUT_MS = 30_000 // 30s
-export const KEEPALIVE_INTERVAL = 60_000 // 1m
+export const KEEPALIVE_INTERVAL = 90_000 // 90s
export interface ConnectionOpts {
apiKey?: string
diff --git a/packages/js-sdk/src/sandbox/process/processHandle.ts b/packages/js-sdk/src/sandbox/process/processHandle.ts
index c7f56ce94..af7812d82 100644
--- a/packages/js-sdk/src/sandbox/process/processHandle.ts
+++ b/packages/js-sdk/src/sandbox/process/processHandle.ts
@@ -5,11 +5,13 @@ import {
StartResponse,
} from '../../envd/process/process_pb'
-type Brand<K, T> = K & { __brand: T }
+declare const __brand: unique symbol
+type Brand<B> = { [__brand]: B }
+export type Branded<T, B> = T & Brand<B>
-export type Stdout = Brand<string, 'stdout'>
-export type Stderr = Brand<string, 'stderr'>
-export type Pty = Brand<Uint8Array, 'pty'>
+export type Stdout = Branded<string, 'stdout'>
+export type Stderr = Branded<string, 'stderr'>
+export type Pty = Branded<Uint8Array, 'pty'>
export interface ProcessResult {
exitCode: number
diff --git a/packages/js-sdk/src/sandbox/sandboxApi.ts b/packages/js-sdk/src/sandbox/sandboxApi.ts
index f746a1b02..5ab502c40 100644
--- a/packages/js-sdk/src/sandbox/sandboxApi.ts
+++ b/packages/js-sdk/src/sandbox/sandboxApi.ts
@@ -35,10 +35,13 @@ export interface SandboxInfo {
export class SandboxApi {
protected constructor() { }
- static async kill(
- sandboxID: string,
- opts?: ConnectionOpts,
- ): Promise<void> {
+ /**
+ * Kills sandbox specified by sandbox ID.
+ *
+ * @param sandboxID - Sandbox ID.
+ * @param opts - Connection options.
+ */
+ static async kill(sandboxID: string, opts?: ConnectionOpts): Promise<void> {
const config = new ConnectionConfig(opts)
const client = new ApiClient(config)
@@ -76,19 +79,17 @@ export class SandboxApi {
})) ?? []
}
- protected static async createSandbox(
- template: string,
- timeoutMs: number,
- opts?: ConnectionOpts & {
- metadata?: Record<string, string>,
- }): Promise<string> {
+ static async setTimeout(sandboxID: string, timeoutMs: number, opts?: ConnectionOpts): Promise<void> {
const config = new ConnectionConfig(opts)
const client = new ApiClient(config)
- const res = await client.api.POST('/sandboxes', {
+ const res = await client.api.POST('/sandboxes/{sandboxID}/timeout', {
+ params: {
+ path: {
+ sandboxID,
+ },
+ },
body: {
- templateID: template,
- metadata: opts?.metadata,
timeout: this.timeoutToSeconds(timeoutMs),
},
})
@@ -97,25 +98,21 @@ export class SandboxApi {
if (err) {
throw err
}
-
- return this.getSandboxID(res.data!)
}
- protected static async setTimeout(
- sandboxID: string,
+ protected static async createSandbox(
+ template: string,
timeoutMs: number,
- opts?: ConnectionOpts,
- ): Promise<void> {
+ opts?: ConnectionOpts & {
+ metadata?: Record<string, string>,
+ }): Promise<string> {
const config = new ConnectionConfig(opts)
const client = new ApiClient(config)
- const res = await client.api.POST('/sandboxes/{sandboxID}/timeout', {
- params: {
- path: {
- sandboxID,
- },
- },
+ const res = await client.api.POST('/sandboxes', {
body: {
+ templateID: template,
+ metadata: opts?.metadata,
timeout: this.timeoutToSeconds(timeoutMs),
},
})
@@ -124,6 +121,8 @@ export class SandboxApi {
if (err) {
throw err
}
+
+ return this.getSandboxID(res.data!)
}
private static timeoutToSeconds(timeout: number): number {
diff --git a/packages/js-sdk/test/runtime/browser.mjs b/packages/js-sdk/test/runtime/browser.mjs
new file mode 100644
index 000000000..e69de29bb
diff --git a/packages/js-sdk/test/runtime/bun.mjs b/packages/js-sdk/test/runtime/bun.mjs
new file mode 100644
index 000000000..e69de29bb
diff --git a/packages/js-sdk/test/runtime/deno.mjs b/packages/js-sdk/test/runtime/deno.mjs
new file mode 100644
index 000000000..e69de29bb
diff --git a/packages/js-sdk/test/runtime/edge.mjs b/packages/js-sdk/test/runtime/edge.mjs
new file mode 100644
index 000000000..e69de29bb
diff --git a/packages/js-sdk/test/runtime/node.mjs b/packages/js-sdk/test/runtime/node.mjs
new file mode 100644
index 000000000..e69de29bb
diff --git a/packages/js-sdk/vitest.config.ts b/packages/js-sdk/vitest.config.ts
index 87a4ad441..92bb05ccc 100644
--- a/packages/js-sdk/vitest.config.ts
+++ b/packages/js-sdk/vitest.config.ts
@@ -5,7 +5,7 @@ const env = config()
export default defineConfig({
test: {
- threads: false,
+ maxWorkers: 5,
globals: false,
testTimeout: 20000,
environment: 'node',
diff --git a/packages/python-sdk/package.json b/packages/python-sdk/package.json
index ec6d637ab..61dced553 100644
--- a/packages/python-sdk/package.json
+++ b/packages/python-sdk/package.json
@@ -3,7 +3,7 @@
"private": true,
"version": "0.17.0",
"scripts": {
- "test": "poetry run pytest -n 1 --verbose -x",
+ "test": "poetry run pytest -n 5 --verbose -x",
"postVersion": "poetry version $(pnpm pkg get version --workspaces=false | tr -d \\\")",
"postPublish": "poetry build && poetry config pypi-token.pypi ${PYPI_TOKEN} && poetry publish --skip-existing",
"pretest": "poetry install"