Skip to content

Secure, Fast, and Extensible Sandbox runtime for AI agents.

test(cli): cover oversized durations through command options

Qiu764010f35917
diff --git a/cli/tests/test_duration_overflow.py b/cli/tests/test_duration_overflow.py
index 951f4a565..c74a5e44f 100644
--- a/cli/tests/test_duration_overflow.py
+++ b/cli/tests/test_duration_overflow.py
@@ -14,16 +14,42 @@
import click
import pytest
+from click.testing import CliRunner
from opensandbox_cli.utils import parse_duration
+
@pytest.mark.parametrize(
"value",
- ["9999999999999999999999999999", "99999999999999999999h", "²", "9" * 5000 + "h"],
+ [
+ "9999999999999999999999999999",
+ "99999999999999999999h",
+ "²",
+ "9" * 5000,
+ "9" * 5000 + "h",
+ ],
)
def test_out_of_range_is_a_cli_validation_error(value: str) -> None:
with pytest.raises(click.BadParameter, match="out of range"):
parse_duration(value)
+
def test_ordinary_duration_is_unchanged() -> None:
assert parse_duration("1h30m").total_seconds() == 5400
+
+
[email protected]("option", ["--timeout", "--ready-timeout"])
[email protected]("value", ["9999999999999999999999999999", "9" * 5000 + "h"])
+def test_oversized_duration_is_reported_by_cli(
+ runner: CliRunner, option: str, value: str
+) -> None:
+ from opensandbox_cli.main import cli
+
+ result = runner.invoke(
+ cli, ["sandbox", "create", "--image", "python:3.12", option, value]
+ )
+
+ assert result.exit_code == 2
+ assert "Invalid value" in result.output
+ assert "Traceback" not in result.output
+ assert isinstance(result.exception, SystemExit)