Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Modify tests
Tomas Valenta296386df6612
diff --git a/packages/js-sdk/test/cwd.test.mjs b/packages/js-sdk/test/cwd.test.mjsindex 6368f2161..59ae60bea 100644--- a/packages/js-sdk/test/cwd.test.mjs+++ b/packages/js-sdk/test/cwd.test.mjs@@ -22,7 +22,7 @@ test(// filesystem respects cwd{- await session.filesystem.write('hello.txt', `Hello VM!`)+ await session.filesystem.write('hello.txt', 'Hello VM!')const proc = await session.process.start({ cmd: 'cat /home/user/hello.txt' })await proc.finishedconst out = proc.output.stdoutdiff --git a/packages/js-sdk/test/envVars.test.mjs b/packages/js-sdk/test/envVars.test.mjsindex 7767e070d..253d85572 100644--- a/packages/js-sdk/test/envVars.test.mjs+++ b/packages/js-sdk/test/envVars.test.mjs@@ -1,12 +1,12 @@-import {Session} from '../src'-import {expect, test} from 'vitest'+import { Session } from '../src'+import { expect, test } from 'vitest'test('test_env_vars', async () => {- const session = await Session.create({id: 'Bash'})+ const session = await Session.create({ id: 'Bash' })const process = await session.process.start({cmd: 'echo $FOO',- envVars: {FOO: 'BAR'},+ envVars: { FOO: 'BAR' },})await process.finishedconst output = process.output.stdout@@ -16,10 +16,10 @@ test('test_env_vars', async () => {})test('test_profile_env_vars', async () => {- const session = await Session.create({id: 'Bash'})+ const session = await Session.create({ id: 'Bash' })await session.filesystem.write('/home/user/.profile', 'export FOO=BAR')- const process = await session.process.start({cmd: 'echo $FOO'})+ const process = await session.process.start({ cmd: 'echo $FOO' })await process.finishedconst output = process.output.stdoutexpect(output).toEqual('BAR')@@ -28,9 +28,9 @@ test('test_profile_env_vars', async () => {})test('test_default_env_vars', async () => {- const session = await Session.create({id: 'Bash', envVars: {FOO: 'BAR'}})+ const session = await Session.create({ id: 'Bash', envVars: { FOO: 'BAR' } })- const process = await session.process.start({cmd: 'echo $FOO'})+ const process = await session.process.start({ cmd: 'echo $FOO' })await process.finishedconst output = process.output.stdoutexpect(output).toEqual('BAR')@@ -39,11 +39,11 @@ test('test_default_env_vars', async () => {})test('test_overriding_env_vars', async () => {- const session = await Session.create({id: 'Bash', envVars: {FOO: 'BAR'}})+ const session = await Session.create({ id: 'Bash', envVars: { FOO: 'BAR' } })const process = await session.process.start({cmd: 'echo $FOO',- envVars: {FOO: 'QUX'},+ envVars: { FOO: 'QUX' },})await process.finishedconst output = process.output.stdoutdiff --git a/packages/js-sdk/test/filesystem.test.mjs b/packages/js-sdk/test/filesystem.test.mjsindex ada63e0a0..ca60e6397 100644--- a/packages/js-sdk/test/filesystem.test.mjs+++ b/packages/js-sdk/test/filesystem.test.mjs@@ -56,26 +56,30 @@ test('list delete files', async () => {await session.close()})-test('watch dir', async () => {- const session = new Session({ id: 'Nodejs' })- await session.open()- await session.filesystem.write('/tmp/test.txt', 'Hello')+test(+ 'watch dir',+ async () => {+ const session = new Session({ id: 'Nodejs' })+ await session.open()+ await session.filesystem.write('/tmp/test.txt', 'Hello')- const watcher = session.filesystem.watchDir('/tmp')+ const watcher = session.filesystem.watchDir('/tmp')- const events = []- watcher.addEventListener(ev => events.push(ev))+ const events = []+ watcher.addEventListener(ev => events.push(ev))- await watcher.start()- await session.filesystem.write('/tmp/test.txt', 'World!')- await new Promise(r => setTimeout(r, 1000))- await watcher.stop()+ await watcher.start()+ await session.filesystem.write('/tmp/test.txt', 'World!')+ await new Promise(r => setTimeout(r, 2500))+ await watcher.stop()- expect(events.length).toBeGreaterThanOrEqual(1)+ expect(events.length).toBeGreaterThanOrEqual(1)- const event = events[0]- expect(event['operation']).toEqual('Write')- expect(event['path']).toEqual('/tmp/test.txt')+ const event = events[0]+ expect(event['operation']).toEqual('Write')+ expect(event['path']).toEqual('/tmp/test.txt')- await session.close()-})+ await session.close()+ },+ { timeout: 10_000 },+)diff --git a/packages/js-sdk/test/logging.test.mjs b/packages/js-sdk/test/logging.test.mjsindex d0afa6209..46426f095 100644--- a/packages/js-sdk/test/logging.test.mjs+++ b/packages/js-sdk/test/logging.test.mjs@@ -1,5 +1,5 @@-import {Session} from '../src'-import {expect, test, vi} from 'vitest'+import { Session } from '../src'+import { expect, test, vi } from 'vitest'test('no logs in console during very basic scenario', async () => {const consoleSpy = {@@ -9,7 +9,7 @@ test('no logs in console during very basic scenario', async () => {error: vi.spyOn(console, 'error'),}- const session = await Session.create({id: 'Nodejs'})+ const session = await Session.create({ id: 'Nodejs' })await session.filesystem.write('test.txt', 'Hello World')await session.close()@@ -18,7 +18,6 @@ test('no logs in console during very basic scenario', async () => {expect(consoleSpy.error).toHaveBeenCalledTimes(0)})-// TODO: Re-enable https://e2b-team.slack.com/archives/C05AGT4UFMJ/p1694697558738799?thread_ts=1694697479.308769&cid=C05AGT4UFMJtest.skip('warn logs in console during convoluted scenario', async () => {const consoleSpy = {@@ -28,7 +27,7 @@ test.skip('warn logs in console during convoluted scenario', async () => {error: vi.spyOn(console, 'error'),}- const session = await Session.create({id: 'Nodejs'})+ const session = await Session.create({ id: 'Nodejs' })await session.close() // Note that we are intentionally closing and then trying to writeconst warnsAmount = consoleSpy.warn.mock.calls.lengthdiff --git a/packages/js-sdk/test/performance.mjs b/packages/js-sdk/test/performance.mjsindex 3ed23f7fd..b98318950 100644--- a/packages/js-sdk/test/performance.mjs+++ b/packages/js-sdk/test/performance.mjs@@ -1,6 +1,6 @@-import {writeFileSync} from 'fs'+import { writeFileSync } from 'fs'-import {Session} from '../dist/cjs/index.js'+import { Session } from '../dist/cjs/index.js'const reportSummaryFile = process.env.SUMMARY_FILE || './test.md'@@ -8,7 +8,6 @@ const codeSnippetIDs = ['5udkAFHBVrGz']const samplePerID = 15const upperBoundary = 1000 // 1s-async function spinSession(id) {console.log('Creating session...')let session@@ -23,12 +22,9 @@ async function spinSession(id) {const endTime = performance.now()return endTime - startTime} catch (e) {- console.error(- `Measuring ${id} failed`,- e,- )+ console.error(`Measuring ${id} failed`, e)} finally {- ;(async () => {+ ; (async () => {try {// await session?.close()} catch (e) {@@ -80,9 +76,8 @@ async function sample(id, size) {return {[entryName]: {- result: `${averageTime}ms ${- averageTime < upperBoundary ? ':heavy_check_mark:' : ':x:'- }`,+ result: `${averageTime}ms ${averageTime < upperBoundary ? ':heavy_check_mark:' : ':x:'+ }`,size,},}@@ -101,7 +96,7 @@ async function main() {for (const id of codeSnippetIDs) {const entry = await sample(id, samplePerID)- entries = {...entries, ...entry}+ entries = { ...entries, ...entry }}// for (const id of codeSnippetIDs) {diff --git a/packages/js-sdk/test/process.test.mjs b/packages/js-sdk/test/process.test.mjsindex dc112b291..c270576a7 100644--- a/packages/js-sdk/test/process.test.mjs+++ b/packages/js-sdk/test/process.test.mjs@@ -36,7 +36,7 @@ test('process expected stderr', async () => {test('process on exit', async () => {const session = await Session.create({ id: 'Nodejs' })- const onExit = vi.fn(() => {})+ const onExit = vi.fn(() => { })const process = await session.process.start({cmd: 'pwd',@@ -70,7 +70,7 @@ test('process send stdin', async () => {}, 10000)test('test default on exit', async () => {- const onExit = vi.fn(() => {})+ const onExit = vi.fn(() => { })const session = await Session.create({ id: 'Nodejs', onExit })const processOverride = await session.process.start({@@ -91,15 +91,15 @@ test('test default on exit', async () => {})test('test default on stdout/stderr', async () => {- const onStdout = vi.fn(() => {})- const onStderr = vi.fn(() => {})+ const onStdout = vi.fn(() => { })+ const onStderr = vi.fn(() => { })const session = await Session.create({ id: 'Nodejs', onStdout, onStderr })const processOverride = await session.process.start({cmd: "node -e \"console.log('Hello'); throw new Error('Ooopsie -_-')\"",- onStdout: () => {},- onStderr: () => {},+ onStdout: () => { },+ onStderr: () => { },})await processOverride.finisheddiff --git a/packages/js-sdk/test/runCode.test.mjs b/packages/js-sdk/test/runCode.test.mjsindex 9a78f6888..9c38d307d 100644--- a/packages/js-sdk/test/runCode.test.mjs+++ b/packages/js-sdk/test/runCode.test.mjs@@ -1,14 +1,13 @@-import {runCode} from '../src'-import {expect, test} from 'vitest'+import { runCode } from '../src'+import { expect, test } from 'vitest'test('run code', async () => {-const code = `test="test\\n"print(10*test)raise Exception("err")`- const {stdout, stderr} = await runCode('Python3', code)+ const { stdout, stderr } = await runCode('Python3', code)console.log('stdout', stdout)console.log('stderr', stderr)expect(stdout.length).toEqual(50)diff --git a/packages/js-sdk/test/session.test.mjs b/packages/js-sdk/test/session.test.mjsindex bc62f3b4b..9eb444a94 100644--- a/packages/js-sdk/test/session.test.mjs+++ b/packages/js-sdk/test/session.test.mjs@@ -1,16 +1,14 @@-import {Session} from '../src'-import {test} from 'vitest'-+import { Session } from '../src'+import { test } from 'vitest'test('create session', async () => {- const session = await Session.create({id: 'Nodejs'})+ const session = await Session.create({ id: 'Nodejs' })await session.close()})-test('create multiple sessions', async () => {- const session = await Session.create({id: 'Nodejs'})- const session2 = await Session.create({id: 'Nodejs'})+ const session = await Session.create({ id: 'Nodejs' })+ const session2 = await Session.create({ id: 'Nodejs' })await session.close()await session2.close()}, 10000)diff --git a/packages/js-sdk/test/templates/dataAnalysis.test.mjs b/packages/js-sdk/test/templates/dataAnalysis.test.mjsindex 9c83039a4..a03cd44d5 100644--- a/packages/js-sdk/test/templates/dataAnalysis.test.mjs+++ b/packages/js-sdk/test/templates/dataAnalysis.test.mjs@@ -1,5 +1,5 @@-import {DataAnalysis} from "../../src"-import {expect, test} from 'vitest'+import { DataAnalysis } from '../../src'+import { expect, test } from 'vitest'test('test_data_analysis', async () => {const session = await DataAnalysis.create()@@ -10,7 +10,7 @@ import matplotlib.pyplot as pltplt.plot([1, 2, 3, 4])plt.ylabel('some numbers')plt.show()- `+ `,)await session.close()expect(result.artifacts.length).toEqual(1)diff --git a/packages/js-sdk/test/timeout.test.mjs b/packages/js-sdk/test/timeout.test.mjsindex dab4833b4..1931f0c5c 100644--- a/packages/js-sdk/test/timeout.test.mjs+++ b/packages/js-sdk/test/timeout.test.mjs@@ -1,14 +1,11 @@-import {expect, test} from 'vitest'--import {Session} from '../src'-import {TimeoutError} from '../src/error.ts'+import { expect, test } from 'vitest'+import { Session } from '../src'+import { TimeoutError } from '../src/error.ts'// TODO: Make it work on CI and re-enable!test.skip('timeout session', async () => {- await expect(- Session.create({id: 'Nodejs', timeout: 10}),- ).rejects.toThrow()+ await expect(Session.create({ id: 'Nodejs', timeout: 10 })).rejects.toThrow()})// TODO: Make it work on CI and re-enable!@@ -22,35 +19,35 @@ test.skip('dont timeout session', async () => {// TODO: Make it work on CI and re-enable!test.skip('timeout filesystem', async () => {- const session = await Session.create({id: 'Nodejs'})+ const session = await Session.create({ id: 'Nodejs' })await expect(- session.filesystem.write('/home/test.txt', 'Hello World', {timeout: 10}),+ session.filesystem.write('/home/test.txt', 'Hello World', { timeout: 10 }),).rejects.toThrow(TimeoutError)await expect(- session.filesystem.read('/home/test.txt', {timeout: 10}),+ session.filesystem.read('/home/test.txt', { timeout: 10 }),).rejects.toThrow(TimeoutError)- await expect(session.filesystem.list('/home', {timeout: 10})).rejects.toThrow(+ await expect(session.filesystem.list('/home', { timeout: 10 })).rejects.toThrow(TimeoutError,)await expect(- session.filesystem.makeDir('/home/test/', {timeout: 10}),+ session.filesystem.makeDir('/home/test/', { timeout: 10 }),).rejects.toThrow(TimeoutError)await session.filesystem.write('/home/test.txt', 'Hello World')await expect(- session.filesystem.remove('/home/test.txt', {timeout: 10}),+ session.filesystem.remove('/home/test.txt', { timeout: 10 }),).rejects.toThrow(TimeoutError)})// TODO: Make it work on CI and re-enable!test.skip('timeout process', async () => {- const session = await Session.create({id: 'Nodejs'})+ const session = await Session.create({ id: 'Nodejs' })await expect(- session.process.start({cmd: "node -e 'setTimeout(() => {}, 10000)'", timeout: 10}),+ session.process.start({ cmd: "node -e 'setTimeout(() => {}, 10000)'", timeout: 10 }),).rejects.toThrow(TimeoutError)const process = await session.process.start({cmd: "while true; do echo 'Hello World'; sleep 1; done",})- await expect(process.sendStdin('Hello World', {timeout: 10})).rejects.toThrow(+ await expect(process.sendStdin('Hello World', { timeout: 10 })).rejects.toThrow(TimeoutError,)})@@ -60,7 +57,7 @@ test.skip('timeout longer than cmd should not leak',() =>new Promise(async resolve => {- const session = await Session.create({id: 'Nodejs'})+ const session = await Session.create({ id: 'Nodejs' })const proc = await session.process.start({cmd: "node -e 'setTimeout(() => {}, 1000)'", // should take around 1 secondonExit: () => {@@ -71,5 +68,5 @@ test.skip(})await proc.finished}),- {timeout: 12_000},+ { timeout: 12_000 },)