File size: 1,286 Bytes
70f2179
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

"""Structural tests for the sandbox Protocols (no live sandbox needed)."""

from __future__ import annotations

from opencode_env.sandbox import (
    ExecResult,
    SandboxBackend,
    SandboxHandle,
    E2BSandboxBackend,
    E2BSandboxHandle,
)


def test_e2b_classes_import():
    # Ensure the e2b backend imports without needing an API key or live call.
    assert E2BSandboxBackend is not None
    assert E2BSandboxHandle is not None


def test_exec_result_dataclass():
    r = ExecResult(exit_code=0, stdout="ok", stderr="")
    assert r.exit_code == 0
    assert r.stdout == "ok"


def test_e2b_backend_requires_api_key(monkeypatch):
    monkeypatch.delenv("E2B_API_KEY", raising=False)
    import pytest
    with pytest.raises(RuntimeError, match="E2B_API_KEY"):
        E2BSandboxBackend()


def test_protocols_are_declared():
    # Static: the Protocols should be importable and non-empty.
    assert hasattr(SandboxBackend, "create")
    assert hasattr(SandboxHandle, "exec")
    assert hasattr(SandboxHandle, "start_bg")
    assert hasattr(SandboxHandle, "kill")