From 37855b97a6320d0473ef0f0396e205175a586d66 Mon Sep 17 00:00:00 2001 From: 0div Date: Thu, 16 Jan 2025 09:38:43 -0800 Subject: [PATCH 01/17] add host test for sandbox not found error --- packages/js-sdk/tests/sandbox/host.test.ts | 43 ++++++++++++++++++++-- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/packages/js-sdk/tests/sandbox/host.test.ts b/packages/js-sdk/tests/sandbox/host.test.ts index f499f7d3e8..42d39094e7 100644 --- a/packages/js-sdk/tests/sandbox/host.test.ts +++ b/packages/js-sdk/tests/sandbox/host.test.ts @@ -1,12 +1,15 @@ import { assert } from 'vitest' -import { isDebug, sandboxTest, wait } from '../setup.js' +import Sandbox from '../../src/index.js' +import { isDebug, sandboxTest, template, 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) + await wait(10_000) const host = sandbox.getHost(8000) @@ -21,3 +24,35 @@ sandboxTest('ping server in sandbox', async ({ sandbox }) => { } } }) + +sandboxTest('ping server in non-running sandbox', async () => { + const sbx = await Sandbox.create(template, { timeoutMs: 60_000 }) + + const cmd = await sbx.commands.run('python -m http.server 8000', { + background: true, + }) + + try { + await wait(10_000) + + const host = sbx.getHost(8000) + + const res = await fetch(`${isDebug ? 'http' : 'https'}://${host}`) + + assert.equal(res.status, 200) + + await sbx.kill() + + const res2 = await fetch(`${isDebug ? 'http' : 'https'}://${host}`) + assert.equal(res2.status, 502) + + const text = await res2.text() + assert.equal(text, 'Sandbox does not exist.') + } finally { + try { + await cmd.kill() + } catch (e) { + console.error(e) + } + } +}) From 91770ae3eb425cf6e196ed5ee37bca9147c8d0f1 Mon Sep 17 00:00:00 2001 From: 0div Date: Thu, 16 Jan 2025 09:40:01 -0800 Subject: [PATCH 02/17] skip to not block wokflow --- packages/js-sdk/tests/sandbox/host.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/js-sdk/tests/sandbox/host.test.ts b/packages/js-sdk/tests/sandbox/host.test.ts index 42d39094e7..b6a72aac03 100644 --- a/packages/js-sdk/tests/sandbox/host.test.ts +++ b/packages/js-sdk/tests/sandbox/host.test.ts @@ -25,7 +25,8 @@ sandboxTest('ping server in running sandbox', async ({ sandbox }) => { } }) -sandboxTest('ping server in non-running sandbox', async () => { +// TODO: unskip when we have this new error handling deployed +sandboxTest.skip('ping server in non-running sandbox', async () => { const sbx = await Sandbox.create(template, { timeoutMs: 60_000 }) const cmd = await sbx.commands.run('python -m http.server 8000', { From 55ecbaf05bfa62082f7c84e7dfd5c8470909a44a Mon Sep 17 00:00:00 2001 From: 0div <98087403+0div@users.noreply.github.com> Date: Thu, 16 Jan 2025 22:33:29 +0100 Subject: [PATCH 03/17] Update packages/js-sdk/tests/sandbox/host.test.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jakub Novák --- packages/js-sdk/tests/sandbox/host.test.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/js-sdk/tests/sandbox/host.test.ts b/packages/js-sdk/tests/sandbox/host.test.ts index b6a72aac03..42d39094e7 100644 --- a/packages/js-sdk/tests/sandbox/host.test.ts +++ b/packages/js-sdk/tests/sandbox/host.test.ts @@ -25,8 +25,7 @@ sandboxTest('ping server in running sandbox', async ({ sandbox }) => { } }) -// TODO: unskip when we have this new error handling deployed -sandboxTest.skip('ping server in non-running sandbox', async () => { +sandboxTest('ping server in non-running sandbox', async () => { const sbx = await Sandbox.create(template, { timeoutMs: 60_000 }) const cmd = await sbx.commands.run('python -m http.server 8000', { From c00f73f063077067d3e18e82e56ee2d199d690c2 Mon Sep 17 00:00:00 2001 From: 0div Date: Thu, 16 Jan 2025 13:48:01 -0800 Subject: [PATCH 04/17] skip ifdebug --- .../tests/sandbox/commands/sendStdin.test.ts | 4 +++- packages/js-sdk/tests/sandbox/connect.test.ts | 24 ++++++++++++++++++- packages/js-sdk/tests/sandbox/host.test.ts | 9 ++++--- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/packages/js-sdk/tests/sandbox/commands/sendStdin.test.ts b/packages/js-sdk/tests/sandbox/commands/sendStdin.test.ts index 550c04a157..5b447d90c9 100644 --- a/packages/js-sdk/tests/sandbox/commands/sendStdin.test.ts +++ b/packages/js-sdk/tests/sandbox/commands/sendStdin.test.ts @@ -1,5 +1,5 @@ import { assert } from 'vitest' -import { sandboxTest } from '../../setup.js' +import { sandboxTest, wait } from '../../setup.js' sandboxTest('send stdin to process', async ({ sandbox }) => { const text = 'Hello, World!' @@ -29,6 +29,8 @@ sandboxTest('send special characters to stdin', async ({ sandbox }) => { await sandbox.commands.sendStdin(cmd.pid, text) + await wait(5_000) + 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.ts index 7311713a3e..d5eb1b2131 100644 --- a/packages/js-sdk/tests/sandbox/connect.test.ts +++ b/packages/js-sdk/tests/sandbox/connect.test.ts @@ -1,4 +1,4 @@ -import { test, assert } from 'vitest' +import { assert, test } from 'vitest' import { Sandbox } from '../../src' import { isDebug, template } from '../setup.js' @@ -19,3 +19,25 @@ test('connect', async () => { } } }) + +test('connect to non-running sandbox', async () => { + const sbx = await Sandbox.create(template, { timeoutMs: 10_000 }) + let isKilled = false + + try { + const isRunning = await sbx.isRunning() + assert.isTrue(isRunning) + await sbx.kill() + isKilled = true + + const sbxConnection = await Sandbox.connect(sbx.sandboxId) + const isRunning2 = await sbxConnection.isRunning() + assert.isFalse(isRunning2) + + await sbxConnection.commands.run('echo "hello"') + } finally { + if (!isKilled) { + await sbx.kill() + } + } +}) diff --git a/packages/js-sdk/tests/sandbox/host.test.ts b/packages/js-sdk/tests/sandbox/host.test.ts index b6a72aac03..b77c8dcc33 100644 --- a/packages/js-sdk/tests/sandbox/host.test.ts +++ b/packages/js-sdk/tests/sandbox/host.test.ts @@ -3,7 +3,7 @@ import { assert } from 'vitest' import Sandbox from '../../src/index.js' import { isDebug, sandboxTest, template, wait } from '../setup.js' -sandboxTest('ping server in running sandbox', async ({ sandbox }) => { +sandboxTest.skip('ping server in running sandbox', async ({ sandbox }) => { const cmd = await sandbox.commands.run('python -m http.server 8000', { background: true, }) @@ -25,16 +25,15 @@ sandboxTest('ping server in running sandbox', async ({ sandbox }) => { } }) -// TODO: unskip when we have this new error handling deployed -sandboxTest.skip('ping server in non-running sandbox', async () => { - const sbx = await Sandbox.create(template, { timeoutMs: 60_000 }) +sandboxTest.skipIf(isDebug)('ping server in non-running sandbox', async () => { + const sbx = await Sandbox.create(template, { timeoutMs: 120_000 }) const cmd = await sbx.commands.run('python -m http.server 8000', { background: true, }) try { - await wait(10_000) + await wait(20_000) const host = sbx.getHost(8000) From ad3d8fbf9f1c41d93cf6cc8279944357c553d0c5 Mon Sep 17 00:00:00 2001 From: 0div Date: Thu, 16 Jan 2025 13:49:56 -0800 Subject: [PATCH 05/17] skip ifdebug --- packages/js-sdk/tests/sandbox/host.test.ts | 33 ++++++++++++---------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/packages/js-sdk/tests/sandbox/host.test.ts b/packages/js-sdk/tests/sandbox/host.test.ts index b77c8dcc33..cd8dc7b4f2 100644 --- a/packages/js-sdk/tests/sandbox/host.test.ts +++ b/packages/js-sdk/tests/sandbox/host.test.ts @@ -3,27 +3,30 @@ import { assert } from 'vitest' import Sandbox from '../../src/index.js' import { isDebug, sandboxTest, template, wait } from '../setup.js' -sandboxTest.skip('ping server in running sandbox', async ({ sandbox }) => { - const cmd = await sandbox.commands.run('python -m http.server 8000', { - background: true, - }) +sandboxTest.skipIf(isDebug)( + 'ping server in running sandbox', + async ({ sandbox }) => { + const cmd = await sandbox.commands.run('python -m http.server 8000', { + background: true, + }) - try { - await wait(10_000) + try { + await wait(10_000) - const host = sandbox.getHost(8000) + const host = sandbox.getHost(8000) - const res = await fetch(`${isDebug ? 'http' : 'https'}://${host}`) + const res = await fetch(`${isDebug ? 'http' : 'https'}://${host}`) - 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) + } } } -}) +) sandboxTest.skipIf(isDebug)('ping server in non-running sandbox', async () => { const sbx = await Sandbox.create(template, { timeoutMs: 120_000 }) From a9c283e6d30d2000ed7c9655f01eff66ff9dfb9f Mon Sep 17 00:00:00 2001 From: 0div Date: Thu, 16 Jan 2025 19:29:13 -0800 Subject: [PATCH 06/17] edits based on feedback --- packages/js-sdk/tests/sandbox/host.test.ts | 48 +++++++++++----------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/packages/js-sdk/tests/sandbox/host.test.ts b/packages/js-sdk/tests/sandbox/host.test.ts index cd8dc7b4f2..6ba8788edc 100644 --- a/packages/js-sdk/tests/sandbox/host.test.ts +++ b/packages/js-sdk/tests/sandbox/host.test.ts @@ -1,7 +1,6 @@ import { assert } from 'vitest' -import Sandbox from '../../src/index.js' -import { isDebug, sandboxTest, template, wait } from '../setup.js' +import { isDebug, sandboxTest, wait } from '../setup.js' sandboxTest.skipIf(isDebug)( 'ping server in running sandbox', @@ -28,34 +27,35 @@ sandboxTest.skipIf(isDebug)( } ) -sandboxTest.skipIf(isDebug)('ping server in non-running sandbox', async () => { - const sbx = await Sandbox.create(template, { timeoutMs: 120_000 }) - - const cmd = await sbx.commands.run('python -m http.server 8000', { - background: true, - }) +sandboxTest.skipIf(isDebug)( + 'ping server in non-running sandbox', + async ({ sandbox }) => { + const cmd = await sandbox.commands.run('python -m http.server 8000', { + background: true, + }) - try { - await wait(20_000) + try { + await wait(20_000) - const host = sbx.getHost(8000) + const host = sandbox.getHost(8000) - const res = await fetch(`${isDebug ? 'http' : 'https'}://${host}`) + const res = await fetch(`${isDebug ? 'http' : 'https'}://${host}`) - assert.equal(res.status, 200) + assert.equal(res.status, 200) - await sbx.kill() + await sandbox.kill() - const res2 = await fetch(`${isDebug ? 'http' : 'https'}://${host}`) - assert.equal(res2.status, 502) + const res2 = await fetch(`${isDebug ? 'http' : 'https'}://${host}`) + assert.equal(res2.status, 502) - const text = await res2.text() - assert.equal(text, 'Sandbox does not exist.') - } finally { - try { - await cmd.kill() - } catch (e) { - console.error(e) + const text = await res2.text() + assert.equal(text, 'Sandbox does not exist.') + } finally { + try { + await cmd.kill() + } catch (e) { + console.error(e) + } } } -}) +) From 06ef25766c93de70f99dbaf50b6a1135087ab1c5 Mon Sep 17 00:00:00 2001 From: 0div Date: Fri, 17 Jan 2025 18:54:13 -0800 Subject: [PATCH 07/17] address PR comments --- .../tests/sandbox/commands/sendStdin.test.ts | 6 +---- packages/js-sdk/tests/sandbox/host.test.ts | 24 ++++++++++++------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/packages/js-sdk/tests/sandbox/commands/sendStdin.test.ts b/packages/js-sdk/tests/sandbox/commands/sendStdin.test.ts index 0d9cebd477..b6914fc67e 100644 --- a/packages/js-sdk/tests/sandbox/commands/sendStdin.test.ts +++ b/packages/js-sdk/tests/sandbox/commands/sendStdin.test.ts @@ -1,5 +1,5 @@ import { assert } from 'vitest' -import { sandboxTest, wait } from '../../setup.js' +import { sandboxTest } from '../../setup.js' sandboxTest('send stdin to process', async ({ sandbox }) => { const text = 'Hello, World!' @@ -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 @@ -37,8 +36,6 @@ sandboxTest('send special characters to stdin', async ({ sandbox }) => { await sandbox.commands.sendStdin(cmd.pid, text) - await wait(5_000) - for (let i = 0; i < 5; i++) { if (cmd.stdout === text) { break @@ -66,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/host.test.ts b/packages/js-sdk/tests/sandbox/host.test.ts index 9b68bfef41..2d3322e990 100644 --- a/packages/js-sdk/tests/sandbox/host.test.ts +++ b/packages/js-sdk/tests/sandbox/host.test.ts @@ -10,11 +10,20 @@ sandboxTest.skipIf(isDebug)( }) try { - await wait(10_000) + await wait(1000) const host = sandbox.getHost(8000) - const res = await fetch(`${isDebug ? 'http' : 'https'}://${host}`) + let res = await fetch(`${isDebug ? 'http' : 'https'}://${host}`) + + for (let i = 0; i < 10; i++) { + if (res.status === 200) { + break + } + + res = await fetch(`${isDebug ? 'http' : 'https'}://${host}`) + await wait(500) + } assert.equal(res.status, 200) } finally { @@ -35,17 +44,16 @@ sandboxTest.skipIf(isDebug)( }) try { - await wait(10_000) + const host = sandbox.getHost(49983) + const url = `${isDebug ? 'http' : 'https'}://${host}/health` - const host = sandbox.getHost(8000) - - const res = await fetch(`${isDebug ? 'http' : 'https'}://${host}`) + const res = await fetch(url) - assert.equal(res.status, 200) + assert.equal(res.status, 204) await sandbox.kill() - const res2 = await fetch(`${isDebug ? 'http' : 'https'}://${host}`) + const res2 = await fetch(url) assert.equal(res2.status, 502) const text = await res2.text() From a7606f5d8024d7e20564efc28cca2e2aeda6f597 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Nov=C3=A1k?= Date: Mon, 20 Jan 2025 14:58:11 -0800 Subject: [PATCH 08/17] Apply suggestions from code review --- packages/js-sdk/tests/sandbox/host.test.ts | 29 +++++++--------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/packages/js-sdk/tests/sandbox/host.test.ts b/packages/js-sdk/tests/sandbox/host.test.ts index 2d3322e990..e517d67457 100644 --- a/packages/js-sdk/tests/sandbox/host.test.ts +++ b/packages/js-sdk/tests/sandbox/host.test.ts @@ -39,31 +39,20 @@ sandboxTest.skipIf(isDebug)( sandboxTest.skipIf(isDebug)( 'ping server in non-running sandbox', async ({ sandbox }) => { - const cmd = await sandbox.commands.run('python -m http.server 8000', { - background: true, - }) + const host = sandbox.getHost(49983) + const url = `${isDebug ? 'http' : 'https'}://${host}/health` - try { - const host = sandbox.getHost(49983) - const url = `${isDebug ? 'http' : 'https'}://${host}/health` - - const res = await fetch(url) + const res = await fetch(url) - assert.equal(res.status, 204) + assert.equal(res.status, 204) - await sandbox.kill() + await sandbox.kill() - const res2 = await fetch(url) - assert.equal(res2.status, 502) + const res2 = await fetch(url) + assert.equal(res2.status, 502) - const text = await res2.text() - assert.equal(text, 'Sandbox does not exist.') - } finally { - try { - await cmd.kill() - } catch (e) { - console.error(e) - } + const text = await res2.text() + assert.equal(text, 'Sandbox does not exist.') } } ) From f5cde50df429bbdafeb6cb1ac4db98d91e574a05 Mon Sep 17 00:00:00 2001 From: 0div Date: Mon, 27 Jan 2025 15:44:29 -0800 Subject: [PATCH 09/17] fix type in host test --- packages/js-sdk/tests/sandbox/host.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/js-sdk/tests/sandbox/host.test.ts b/packages/js-sdk/tests/sandbox/host.test.ts index e517d67457..e6f81ab031 100644 --- a/packages/js-sdk/tests/sandbox/host.test.ts +++ b/packages/js-sdk/tests/sandbox/host.test.ts @@ -53,6 +53,5 @@ sandboxTest.skipIf(isDebug)( const text = await res2.text() assert.equal(text, 'Sandbox does not exist.') - } } ) From f3886455a8756ed23a862e891a2c1c2476742253 Mon Sep 17 00:00:00 2001 From: 0div Date: Thu, 24 Apr 2025 10:19:49 -0700 Subject: [PATCH 10/17] update tests --- packages/js-sdk/tests/sandbox/connect.test.ts | 2 -- packages/js-sdk/tests/sandbox/host.test.ts | 9 ++++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/js-sdk/tests/sandbox/connect.test.ts b/packages/js-sdk/tests/sandbox/connect.test.ts index d5eb1b2131..22126dd0d8 100644 --- a/packages/js-sdk/tests/sandbox/connect.test.ts +++ b/packages/js-sdk/tests/sandbox/connect.test.ts @@ -33,8 +33,6 @@ test('connect to non-running sandbox', async () => { const sbxConnection = await Sandbox.connect(sbx.sandboxId) const isRunning2 = await sbxConnection.isRunning() assert.isFalse(isRunning2) - - await sbxConnection.commands.run('echo "hello"') } finally { if (!isKilled) { await sbx.kill() diff --git a/packages/js-sdk/tests/sandbox/host.test.ts b/packages/js-sdk/tests/sandbox/host.test.ts index 80072149ef..3d53476ef1 100644 --- a/packages/js-sdk/tests/sandbox/host.test.ts +++ b/packages/js-sdk/tests/sandbox/host.test.ts @@ -52,6 +52,13 @@ sandboxTest.skipIf(isDebug)( assert.equal(res2.status, 502) const text = await res2.text() - assert.equal(text, 'Sandbox not found') + 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) } ) From c2fa3a91491d2c1749bbd98da8fe795b1d9e1603 Mon Sep 17 00:00:00 2001 From: 0div Date: Thu, 24 Apr 2025 14:32:45 -0700 Subject: [PATCH 11/17] make js-sdk host test independent of e2b domain being used (local vs remote) --- packages/js-sdk/tests/sandbox/host.test.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/js-sdk/tests/sandbox/host.test.ts b/packages/js-sdk/tests/sandbox/host.test.ts index 3d53476ef1..a1b4ec3943 100644 --- a/packages/js-sdk/tests/sandbox/host.test.ts +++ b/packages/js-sdk/tests/sandbox/host.test.ts @@ -39,12 +39,17 @@ sandboxTest.skipIf(isDebug)( sandboxTest.skipIf(isDebug)( 'ping server in non-running sandbox', async ({ sandbox }) => { - const host = sandbox.getHost(49983) - const url = `${isDebug ? 'http' : 'https'}://${host}/health` + const cmd = await sandbox.commands.run('python -m http.server 8000', { + background: true, + }) + + await wait(1000) + const host = sandbox.getHost(8000) + const url = `${isDebug ? 'http' : 'https'}://${host}` const res = await fetch(url) - assert.equal(res.status, 204) + assert.equal(res.status, 200) await sandbox.kill() From 2c9c296a476c8240a86462fb760867c0f46cc691 Mon Sep 17 00:00:00 2001 From: 0div <98087403+0div@users.noreply.github.com> Date: Fri, 25 Apr 2025 10:18:24 -0700 Subject: [PATCH 12/17] Update packages/js-sdk/tests/sandbox/host.test.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jakub Novák --- packages/js-sdk/tests/sandbox/host.test.ts | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/packages/js-sdk/tests/sandbox/host.test.ts b/packages/js-sdk/tests/sandbox/host.test.ts index a1b4ec3943..7e7149576f 100644 --- a/packages/js-sdk/tests/sandbox/host.test.ts +++ b/packages/js-sdk/tests/sandbox/host.test.ts @@ -39,19 +39,15 @@ sandboxTest.skipIf(isDebug)( sandboxTest.skipIf(isDebug)( 'ping server in non-running sandbox', async ({ sandbox }) => { - const cmd = await sandbox.commands.run('python -m http.server 8000', { - background: true, - }) + const host = sandbox.getHost(3000) + const url = `https://{host}` - await wait(1000) + await sandbox.kill() - const host = sandbox.getHost(8000) - const url = `${isDebug ? 'http' : 'https'}://${host}` const res = await fetch(url) + assert.equal(res.status, 502) - assert.equal(res.status, 200) - - await sandbox.kill() + const text = await res.text() const res2 = await fetch(url) assert.equal(res2.status, 502) From 7fc707fa145a65da1ed8b1de986d1b6576740348 Mon Sep 17 00:00:00 2001 From: 0div <98087403+0div@users.noreply.github.com> Date: Fri, 25 Apr 2025 10:18:34 -0700 Subject: [PATCH 13/17] Update packages/js-sdk/tests/sandbox/connect.test.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jakub Novák --- packages/js-sdk/tests/sandbox/connect.test.ts | 25 ++++++------------- 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/packages/js-sdk/tests/sandbox/connect.test.ts b/packages/js-sdk/tests/sandbox/connect.test.ts index 22126dd0d8..95f4e1fa72 100644 --- a/packages/js-sdk/tests/sandbox/connect.test.ts +++ b/packages/js-sdk/tests/sandbox/connect.test.ts @@ -19,23 +19,12 @@ test('connect', async () => { } } }) +sandboxTest('connect to non-running sandbox', async ({ sandbox }) => { + const isRunning = await sbx.isRunning() + assert.isTrue(isRunning) + await sbx.kill() -test('connect to non-running sandbox', async () => { - const sbx = await Sandbox.create(template, { timeoutMs: 10_000 }) - let isKilled = false - - try { - const isRunning = await sbx.isRunning() - assert.isTrue(isRunning) - await sbx.kill() - isKilled = true - - const sbxConnection = await Sandbox.connect(sbx.sandboxId) - const isRunning2 = await sbxConnection.isRunning() - assert.isFalse(isRunning2) - } finally { - if (!isKilled) { - await sbx.kill() - } - } + const sbxConnection = await Sandbox.connect(sbx.sandboxId) + const isRunning2 = await sbxConnection.isRunning() + assert.isFalse(isRunning2) }) From 86c39a4307b2b4f7b95deb7c27c0d5d3dfb4137c Mon Sep 17 00:00:00 2001 From: 0div <98087403+0div@users.noreply.github.com> Date: Fri, 25 Apr 2025 10:18:51 -0700 Subject: [PATCH 14/17] Update packages/js-sdk/tests/sandbox/host.test.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jakub Novák --- packages/js-sdk/tests/sandbox/host.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/js-sdk/tests/sandbox/host.test.ts b/packages/js-sdk/tests/sandbox/host.test.ts index 7e7149576f..9b0800bcc9 100644 --- a/packages/js-sdk/tests/sandbox/host.test.ts +++ b/packages/js-sdk/tests/sandbox/host.test.ts @@ -2,7 +2,7 @@ import { assert } from 'vitest' import { isDebug, sandboxTest, wait } from '../setup.js' -sandboxTest.skipIf(isDebug)( +sandboxTest( 'ping server in running sandbox', async ({ sandbox }) => { const cmd = await sandbox.commands.run('python -m http.server 8000', { From 02161bdb4115eefa21e11b555f0a9d5cdeb81ac7 Mon Sep 17 00:00:00 2001 From: 0div Date: Fri, 25 Apr 2025 14:02:44 -0700 Subject: [PATCH 15/17] fix tests from commit suggestions --- packages/js-sdk/tests/sandbox/connect.test.ts | 11 ++++++----- packages/js-sdk/tests/sandbox/host.test.ts | 6 +++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/js-sdk/tests/sandbox/connect.test.ts b/packages/js-sdk/tests/sandbox/connect.test.ts index 95f4e1fa72..1d974bce22 100644 --- a/packages/js-sdk/tests/sandbox/connect.test.ts +++ b/packages/js-sdk/tests/sandbox/connect.test.ts @@ -1,7 +1,7 @@ import { assert, test } from 'vitest' -import { Sandbox } from '../../src' -import { isDebug, template } from '../setup.js' +import sandbox, { Sandbox } from '../../src' +import { isDebug, sandboxTest, template } from '../setup.js' test('connect', async () => { const sbx = await Sandbox.create(template, { timeoutMs: 10_000 }) @@ -19,12 +19,13 @@ test('connect', async () => { } } }) + sandboxTest('connect to non-running sandbox', async ({ sandbox }) => { - const isRunning = await sbx.isRunning() + const isRunning = await sandbox.isRunning() assert.isTrue(isRunning) - await sbx.kill() + await sandbox.kill() - const sbxConnection = await Sandbox.connect(sbx.sandboxId) + 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.ts index 9b0800bcc9..85a1e3b1f4 100644 --- a/packages/js-sdk/tests/sandbox/host.test.ts +++ b/packages/js-sdk/tests/sandbox/host.test.ts @@ -40,7 +40,7 @@ sandboxTest.skipIf(isDebug)( 'ping server in non-running sandbox', async ({ sandbox }) => { const host = sandbox.getHost(3000) - const url = `https://{host}` + const url = `https://${host}` await sandbox.kill() @@ -52,8 +52,8 @@ sandboxTest.skipIf(isDebug)( const res2 = await fetch(url) assert.equal(res2.status, 502) - const text = await res2.text() - const json = JSON.parse(text) as { + const text2 = await res2.text() + const json = JSON.parse(text2) as { message: string sandboxId: string code: number From 004caee4e65be096bae7e4650c42a457ec4f7c9e Mon Sep 17 00:00:00 2001 From: 0div Date: Fri, 25 Apr 2025 14:25:13 -0700 Subject: [PATCH 16/17] disable connect to non-running sandbox test for local envd bc we dont have proxy logic there --- packages/js-sdk/tests/sandbox/connect.test.ts | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/js-sdk/tests/sandbox/connect.test.ts b/packages/js-sdk/tests/sandbox/connect.test.ts index 1d974bce22..d7eddd802d 100644 --- a/packages/js-sdk/tests/sandbox/connect.test.ts +++ b/packages/js-sdk/tests/sandbox/connect.test.ts @@ -1,6 +1,6 @@ import { assert, test } from 'vitest' -import sandbox, { Sandbox } from '../../src' +import { Sandbox } from '../../src' import { isDebug, sandboxTest, template } from '../setup.js' test('connect', async () => { @@ -20,12 +20,15 @@ test('connect', async () => { } }) -sandboxTest('connect to non-running sandbox', async ({ sandbox }) => { - const isRunning = await sandbox.isRunning() - assert.isTrue(isRunning) - await sandbox.kill() +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) -}) + const sbxConnection = await Sandbox.connect(sandbox.sandboxId) + const isRunning2 = await sbxConnection.isRunning() + assert.isFalse(isRunning2) + } +) From c85b499cda3e124cc711fdb386a5c6e46898d778 Mon Sep 17 00:00:00 2001 From: 0div Date: Fri, 25 Apr 2025 14:39:42 -0700 Subject: [PATCH 17/17] remove redundant request in host test --- packages/js-sdk/tests/sandbox/host.test.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/js-sdk/tests/sandbox/host.test.ts b/packages/js-sdk/tests/sandbox/host.test.ts index 85a1e3b1f4..219740326b 100644 --- a/packages/js-sdk/tests/sandbox/host.test.ts +++ b/packages/js-sdk/tests/sandbox/host.test.ts @@ -48,12 +48,7 @@ sandboxTest.skipIf(isDebug)( assert.equal(res.status, 502) const text = await res.text() - - const res2 = await fetch(url) - assert.equal(res2.status, 502) - - const text2 = await res2.text() - const json = JSON.parse(text2) as { + const json = JSON.parse(text) as { message: string sandboxId: string code: number