"""沙箱请求/响应模型测试:code/argv 互斥、language 默认、isolation_mode 回显。""" from __future__ import annotations import pytest from pydantic import ValidationError from app.integrations.sandbox.models import ExecRequest, ExecResponse def test_exec_request_code_mode_defaults_language_to_python() -> None: req = ExecRequest(code="print(1)") assert req.code == "print(1)" assert req.language == "python" assert req.argv is None def test_exec_request_argv_mode_still_works() -> None: req = ExecRequest(argv=["python3", "-c", "print(1)"]) assert req.argv == ["python3", "-c", "print(1)"] assert req.code is None def test_exec_request_rejects_both_argv_and_code() -> None: with pytest.raises(ValidationError): ExecRequest(argv=["python3"], code="print(1)") def test_exec_request_rejects_neither_argv_nor_code() -> None: with pytest.raises(ValidationError): ExecRequest() def test_exec_response_defaults_isolation_mode() -> None: resp = ExecResponse(ok=True, trace_id="t1") assert resp.isolation_mode == "process"