chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 12:47:58 +08:00
commit b16403ea71
789 changed files with 115226 additions and 0 deletions
@@ -0,0 +1,41 @@
import asyncio
from e2b import AsyncSandbox
from e2b.sandbox.commands.command_handle import PtySize
async def test_connect_to_pty(async_sandbox: AsyncSandbox):
output1 = []
output2 = []
def append_data(data: list, x: bytes):
data.append(x.decode("utf-8"))
# First, create a terminal and disconnect the on_data handler
terminal = await async_sandbox.pty.create(
PtySize(80, 24),
on_data=lambda x: append_data(output1, x),
envs={"FOO": "bar"},
)
await async_sandbox.pty.send_stdin(terminal.pid, b"echo $FOO\n")
# Give time for the command output in the first connection
await asyncio.sleep(0.3)
await terminal.disconnect()
# Now connect again, with a new on_data handler
reconnect_handle = await async_sandbox.pty.connect(
terminal.pid, on_data=lambda x: append_data(output2, x)
)
await async_sandbox.pty.send_stdin(terminal.pid, b"echo $FOO\nexit\n")
await reconnect_handle.wait()
assert terminal.pid == reconnect_handle.pid
assert reconnect_handle.exit_code == 0
assert "bar" in "".join(output1)
assert "bar" in "".join(output2)
@@ -0,0 +1,21 @@
from e2b import AsyncSandbox
from e2b.sandbox.commands.command_handle import PtySize
async def test_pty_create(async_sandbox: AsyncSandbox):
output = []
def append_data(data: list, x: bytes):
data.append(x.decode("utf-8"))
terminal = await async_sandbox.pty.create(
PtySize(80, 24), on_data=lambda x: append_data(output, x), envs={"ABC": "123"}
)
await async_sandbox.pty.send_stdin(terminal.pid, b"echo $ABC\n")
await async_sandbox.pty.send_stdin(terminal.pid, b"exit\n")
await terminal.wait()
assert terminal.exit_code == 0
assert "123" in "".join(output)
@@ -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), on_data=lambda _: None)
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)
@@ -0,0 +1,34 @@
from e2b import AsyncSandbox
from e2b.sandbox.commands.command_handle import PtySize
async def test_resize(async_sandbox: AsyncSandbox):
output = []
def append_data(data: list, x: bytes):
data.append(x.decode("utf-8"))
terminal = await async_sandbox.pty.create(
PtySize(cols=80, rows=24), on_data=lambda x: append_data(output, x)
)
await async_sandbox.pty.send_stdin(terminal.pid, b"tput cols\n")
await async_sandbox.pty.send_stdin(terminal.pid, b"exit\n")
await terminal.wait()
assert terminal.exit_code == 0
assert "80" in "".join(output)
output = []
terminal = await async_sandbox.pty.create(
PtySize(cols=80, rows=24), on_data=lambda x: append_data(output, x)
)
await async_sandbox.pty.resize(terminal.pid, PtySize(cols=100, rows=24))
await async_sandbox.pty.send_stdin(terminal.pid, b"tput cols\n")
await async_sandbox.pty.send_stdin(terminal.pid, b"exit\n")
await terminal.wait()
assert terminal.exit_code == 0
assert "100" in "".join(output)
@@ -0,0 +1,11 @@
from e2b import AsyncSandbox
from e2b.sandbox.commands.command_handle import PtySize
async def test_send_input(async_sandbox: AsyncSandbox):
terminal = await async_sandbox.pty.create(
PtySize(cols=80, rows=24), on_data=lambda x: print(x)
)
await async_sandbox.pty.send_stdin(terminal.pid, b"exit\n")
await terminal.wait()
assert terminal.exit_code == 0