from __future__ import annotations

import os
from typing import TYPE_CHECKING

import pytest

from langchain_monza import MonzaSandbox

if TYPE_CHECKING:
    from collections.abc import Iterator

    from deepagents.backends.protocol import SandboxBackendProtocol

try:
    from langchain_tests.integration_tests import SandboxIntegrationTests
except ImportError:
    SandboxIntegrationTests = None  # type: ignore[misc, assignment]


@pytest.mark.skipif(
    SandboxIntegrationTests is None,
    reason="langchain_tests not installed",
)
class TestMonzaSandboxStandard(SandboxIntegrationTests):
    """Integration tests for MonzaSandbox; requires a running Monza backend."""

    @pytest.fixture(scope="class")
    def sandbox(self) -> Iterator[SandboxBackendProtocol]:
        base_url = os.environ.get("MONZA_BASE_URL", "http://localhost:8080")
        backend = MonzaSandbox(base_url=base_url)
        try:
            yield backend
        finally:
            backend.delete()
            backend.close()
