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,17 @@
from e2b import Sandbox
from e2b.sandbox.commands.command_handle import PtySize
def test_pty(sandbox: Sandbox):
def append_data(data: list, x: bytes):
data.append(x.decode("utf-8"))
terminal = sandbox.pty.create(PtySize(80, 24), envs={"ABC": "123"}, cwd="/")
sandbox.pty.send_stdin(terminal.pid, b"echo $ABC\nexit\n")
output = []
result = terminal.wait(on_pty=lambda x: append_data(output, x))
assert result.exit_code == 0
assert "123" in "\n".join(output)
@@ -0,0 +1,30 @@
import pytest
from e2b.sandbox.commands.command_handle import PtySize
@pytest.mark.skip_debug()
def test_connect_to_pty(sandbox_factory):
sandbox = sandbox_factory(timeout=100)
output = []
def append_data(data: list, x: bytes):
data.append(x.decode("utf-8"))
terminal = sandbox.pty.create(PtySize(80, 24), envs={"FOO": "bar"})
sandbox.pty.send_stdin(terminal.pid, b"echo $FOO\n")
terminal.disconnect()
# Now connect again, with a new on_pty handler
reconnect_handle = sandbox.pty.connect(terminal.pid)
sandbox.pty.send_stdin(terminal.pid, b"echo $FOO\nexit\n")
result = reconnect_handle.wait(on_pty=lambda x: append_data(output, x))
assert terminal.pid == reconnect_handle.pid
assert result.exit_code == 0
assert "bar" in "".join(output)
@@ -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)
@@ -0,0 +1,28 @@
from e2b import Sandbox
from e2b.sandbox.commands.command_handle import PtySize
def test_resize(sandbox: Sandbox):
def append_data(data: list, x: bytes):
data.append(x.decode("utf-8"))
terminal = sandbox.pty.create(PtySize(cols=80, rows=24))
sandbox.pty.send_stdin(terminal.pid, b"tput cols\nexit\n")
output = []
result = terminal.wait(on_pty=lambda x: append_data(output, x))
assert result.exit_code == 0
assert "80" in "".join(output)
terminal = sandbox.pty.create(PtySize(cols=80, rows=24))
sandbox.pty.resize(terminal.pid, PtySize(cols=100, rows=24))
sandbox.pty.send_stdin(terminal.pid, b"tput cols\nexit\n")
output = []
result = terminal.wait(on_pty=lambda x: append_data(output, x))
assert result.exit_code == 0
assert "100" in "".join(output)
@@ -0,0 +1,9 @@
from e2b import Sandbox
from e2b.sandbox.commands.command_handle import PtySize
def test_send_input(sandbox: Sandbox):
terminal = sandbox.pty.create(PtySize(cols=80, rows=24))
sandbox.pty.send_stdin(terminal.pid, b"exit\n")
result = terminal.wait()
assert result.exit_code == 0