mirror of
https://github.com/NVIDIA/OpenShell.git
synced 2026-10-19 05:50:41 +08:00
Closes #13 ## Summary - add Python sandbox execution APIs for command and callable workflows - consolidate sandbox policy fixtures and expand e2e test coverage for policy and Python exec paths - update CI/build config and images for sandbox e2e execution dependencies ## Test Plan - mise run pre-commit
40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
if TYPE_CHECKING:
|
|
from collections.abc import Callable
|
|
|
|
from navigator import Sandbox
|
|
|
|
|
|
def test_exec_python_accepts_bound_methods(
|
|
sandbox: Callable[..., Sandbox],
|
|
) -> None:
|
|
class _Calculator:
|
|
def multiply(self, left: int, right: int) -> int:
|
|
return left * right
|
|
|
|
with sandbox(delete_on_exit=True) as sb:
|
|
calculator = _Calculator()
|
|
result = sb.exec_python(calculator.multiply, args=(6, 7), timeout_seconds=20)
|
|
|
|
assert result.exit_code == 0
|
|
assert result.stdout.strip() == "42"
|
|
|
|
|
|
def test_exec_python_surfaces_callable_errors(
|
|
sandbox: Callable[..., Sandbox],
|
|
) -> None:
|
|
class _Boom:
|
|
def fail(self) -> None:
|
|
raise RuntimeError("expected-failure")
|
|
|
|
with sandbox(delete_on_exit=True) as sb:
|
|
result = sb.exec_python(_Boom().fail, timeout_seconds=20)
|
|
|
|
assert result.exit_code != 0
|
|
output = f"{result.stdout}\n{result.stderr}"
|
|
assert "expected-failure" in output
|
|
assert "RuntimeError" in output
|