"""Shared fixtures for CLI unit tests."""

from __future__ import annotations

import pytest


@pytest.fixture(autouse=True)
def _clear_langsmith_env(monkeypatch: pytest.MonkeyPatch) -> None:
    """Prevent LangSmith env vars loaded from `.env` from leaking into tests.

    `dotenv.load_dotenv()` may inject `LANGSMITH_*` variables from a local
    `.env` file. These cause spurious failures in unit tests that run with
    `--disable-socket` because the LangSmith client attempts real HTTP
    requests.

    Each test that *needs* LangSmith variables should set them explicitly
    via `monkeypatch.setenv` or `patch.dict("os.environ", ...)`.
    """
    for key in (
        "LANGSMITH_API_KEY",
        "LANGCHAIN_API_KEY",
        "LANGSMITH_TRACING",
        "LANGCHAIN_TRACING_V2",
        "LANGSMITH_PROJECT",
        "DEEPAGENTS_CLI_LANGSMITH_PROJECT",
        "DEEPAGENTS_CLI_LANGSMITH_API_KEY",
        "DEEPAGENTS_CLI_LANGCHAIN_API_KEY",
        "DEEPAGENTS_CLI_LANGSMITH_TRACING",
        "DEEPAGENTS_CLI_LANGCHAIN_TRACING_V2",
    ):
        monkeypatch.delenv(key, raising=False)
