Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Test new error handling indicating when the sandbox is not found (#540)
0div8bfd3c0eed07
diff --git a/packages/js-sdk/tests/sandbox/commands/sendStdin.test.ts b/packages/js-sdk/tests/sandbox/commands/sendStdin.test.tsindex 56bcd025a..b6914fc67 100644--- a/packages/js-sdk/tests/sandbox/commands/sendStdin.test.ts+++ b/packages/js-sdk/tests/sandbox/commands/sendStdin.test.ts@@ -7,7 +7,6 @@ sandboxTest('send stdin to process', async ({ sandbox }) => {await sandbox.commands.sendStdin(cmd.pid, text)-for (let i = 0; i < 5; i++) {if (cmd.stdout === text) {break@@ -64,6 +63,5 @@ sandboxTest('send multiline string to stdin', async ({ sandbox }) => {await cmd.kill()-assert.equal(cmd.stdout, text)})diff --git a/packages/js-sdk/tests/sandbox/connect.test.ts b/packages/js-sdk/tests/sandbox/connect.test.tsindex 7311713a3..d7eddd802 100644--- a/packages/js-sdk/tests/sandbox/connect.test.ts+++ b/packages/js-sdk/tests/sandbox/connect.test.ts@@ -1,7 +1,7 @@-import { test, assert } from 'vitest'+import { assert, test } from 'vitest'import { Sandbox } from '../../src'-import { isDebug, template } from '../setup.js'+import { isDebug, sandboxTest, template } from '../setup.js'test('connect', async () => {const sbx = await Sandbox.create(template, { timeoutMs: 10_000 })@@ -19,3 +19,16 @@ test('connect', async () => {}}})++sandboxTest.skipIf(isDebug)(+ 'connect to non-running sandbox',+ async ({ sandbox }) => {+ const isRunning = await sandbox.isRunning()+ assert.isTrue(isRunning)+ await sandbox.kill()++ const sbxConnection = await Sandbox.connect(sandbox.sandboxId)+ const isRunning2 = await sbxConnection.isRunning()+ assert.isFalse(isRunning2)+ }+)diff --git a/packages/js-sdk/tests/sandbox/host.test.ts b/packages/js-sdk/tests/sandbox/host.test.tsindex 3ff7c6964..219740326 100644--- a/packages/js-sdk/tests/sandbox/host.test.ts+++ b/packages/js-sdk/tests/sandbox/host.test.ts@@ -2,30 +2,59 @@ import { assert } from 'vitest'import { isDebug, sandboxTest, wait } from '../setup.js'-sandboxTest('ping server in sandbox', async ({ sandbox }) => {- const cmd = await sandbox.commands.run('python -m http.server 8000', { background: true })+sandboxTest(+ 'ping server in running sandbox',+ async ({ sandbox }) => {+ const cmd = await sandbox.commands.run('python -m http.server 8000', {+ background: true,+ })- try {- await wait(1000)+ try {+ await wait(1000)- const host = sandbox.getHost(8000)+ const host = sandbox.getHost(8000)- let res = await fetch(`${isDebug ? 'http' : 'https'}://${host}`)+ let res = await fetch(`${isDebug ? 'http' : 'https'}://${host}`)- for (let i = 0; i < 20; i++) {- if (res.status === 200) {- break- }+ for (let i = 0; i < 20; i++) {+ if (res.status === 200) {+ break+ }- res = await fetch(`${isDebug ? 'http' : 'https'}://${host}`)- await wait(500)+ res = await fetch(`${isDebug ? 'http' : 'https'}://${host}`)+ await wait(500)+ }+ assert.equal(res.status, 200)+ } finally {+ try {+ await cmd.kill()+ } catch (e) {+ console.error(e)+ }}- assert.equal(res.status, 200)- } finally {- try {- await cmd.kill()- } catch (e) {- console.error(e)+ },+ 60_000+)++sandboxTest.skipIf(isDebug)(+ 'ping server in non-running sandbox',+ async ({ sandbox }) => {+ const host = sandbox.getHost(3000)+ const url = `https://${host}`++ await sandbox.kill()++ const res = await fetch(url)+ assert.equal(res.status, 502)++ const text = await res.text()+ const json = JSON.parse(text) as {+ message: string+ sandboxId: string+ code: number}+ assert.equal(json.message, 'Sandbox not found')+ assert.isTrue(sandbox.sandboxId.startsWith(json.sandboxId))+ assert.equal(json.code, 0)}-}, 60_000 )+)