From 6695754e75ed6d8cddca541f8a1cae207a27d5f9 Mon Sep 17 00:00:00 2001 From: Mish Ushakov <10400064+mishushakov@users.noreply.github.com> Date: Tue, 9 Jun 2026 16:20:33 +0200 Subject: [PATCH 1/2] test(sdk): add pty.kill coverage for JS and Python sync/async Covers both return paths of pty.kill(): killing a live PTY (returns true, process confirmed gone) and killing a non-existent PID (returns false). Co-Authored-By: Claude Opus 4.8 (1M context) --- .../js-sdk/tests/sandbox/pty/kill.test.ts | 25 +++++++++++++++++++ .../async/sandbox_async/pty/test_pty_kill.py | 20 +++++++++++++++ .../sync/sandbox_sync/pty/test_pty_kill.py | 20 +++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 packages/js-sdk/tests/sandbox/pty/kill.test.ts create mode 100644 packages/python-sdk/tests/async/sandbox_async/pty/test_pty_kill.py create mode 100644 packages/python-sdk/tests/sync/sandbox_sync/pty/test_pty_kill.py diff --git a/packages/js-sdk/tests/sandbox/pty/kill.test.ts b/packages/js-sdk/tests/sandbox/pty/kill.test.ts new file mode 100644 index 0000000000..f602515770 --- /dev/null +++ b/packages/js-sdk/tests/sandbox/pty/kill.test.ts @@ -0,0 +1,25 @@ +import { sandboxTest } from '../../setup' +import { assert, expect } from 'vitest' +import { ProcessExitError } from '../../../src/index.js' + +sandboxTest('kill PTY', async ({ sandbox }) => { + const terminal = await sandbox.pty.create({ + cols: 80, + rows: 24, + onData: () => {}, + }) + + const result = await sandbox.pty.kill(terminal.pid) + assert.isTrue(result) + + // The PTY process should no longer be running. + await expect( + sandbox.commands.run(`kill -0 ${terminal.pid}`) + ).rejects.toThrowError(ProcessExitError) +}) + +sandboxTest('kill non-existing PTY', async ({ sandbox }) => { + const nonExistingPid = 999999 + + await expect(sandbox.pty.kill(nonExistingPid)).resolves.toBe(false) +}) diff --git a/packages/python-sdk/tests/async/sandbox_async/pty/test_pty_kill.py b/packages/python-sdk/tests/async/sandbox_async/pty/test_pty_kill.py new file mode 100644 index 0000000000..2c5fc12664 --- /dev/null +++ b/packages/python-sdk/tests/async/sandbox_async/pty/test_pty_kill.py @@ -0,0 +1,20 @@ +import pytest + +from e2b import AsyncSandbox, CommandExitException +from e2b.sandbox.commands.command_handle import PtySize + + +async def test_kill_pty(async_sandbox: AsyncSandbox): + terminal = await async_sandbox.pty.create(PtySize(80, 24)) + + assert await async_sandbox.pty.kill(terminal.pid) + + # The PTY process should no longer be running. + with pytest.raises(CommandExitException): + await async_sandbox.commands.run(f"kill -0 {terminal.pid}") + + +async def test_kill_non_existing_pty(async_sandbox: AsyncSandbox): + non_existing_pid = 999999 + + assert not await async_sandbox.pty.kill(non_existing_pid) diff --git a/packages/python-sdk/tests/sync/sandbox_sync/pty/test_pty_kill.py b/packages/python-sdk/tests/sync/sandbox_sync/pty/test_pty_kill.py new file mode 100644 index 0000000000..e651a84151 --- /dev/null +++ b/packages/python-sdk/tests/sync/sandbox_sync/pty/test_pty_kill.py @@ -0,0 +1,20 @@ +import pytest + +from e2b import Sandbox, CommandExitException +from e2b.sandbox.commands.command_handle import PtySize + + +def test_kill_pty(sandbox: Sandbox): + terminal = sandbox.pty.create(PtySize(80, 24)) + + assert sandbox.pty.kill(terminal.pid) + + # The PTY process should no longer be running. + with pytest.raises(CommandExitException): + sandbox.commands.run(f"kill -0 {terminal.pid}") + + +def test_kill_non_existing_pty(sandbox: Sandbox): + non_existing_pid = 999999 + + assert not sandbox.pty.kill(non_existing_pid) From 1517a2c3e876f2cc6bcc6e4130415335464505ce Mon Sep 17 00:00:00 2001 From: Mish Ushakov <10400064+mishushakov@users.noreply.github.com> Date: Tue, 9 Jun 2026 16:40:02 +0200 Subject: [PATCH 2/2] fix(python-sdk): pass required on_data to async pty.create in kill test Async Pty.create requires on_data as a positional argument; without it the test raised TypeError before exercising pty.kill. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../python-sdk/tests/async/sandbox_async/pty/test_pty_kill.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/python-sdk/tests/async/sandbox_async/pty/test_pty_kill.py b/packages/python-sdk/tests/async/sandbox_async/pty/test_pty_kill.py index 2c5fc12664..2547270b0f 100644 --- a/packages/python-sdk/tests/async/sandbox_async/pty/test_pty_kill.py +++ b/packages/python-sdk/tests/async/sandbox_async/pty/test_pty_kill.py @@ -5,7 +5,7 @@ async def test_kill_pty(async_sandbox: AsyncSandbox): - terminal = await async_sandbox.pty.create(PtySize(80, 24)) + terminal = await async_sandbox.pty.create(PtySize(80, 24), on_data=lambda _: None) assert await async_sandbox.pty.kill(terminal.pid)