"""
Shared pytest fixtures.

Integration tests that need a real database should use a separate PostgreSQL
instance (e.g. a Docker service spun up by the CI job) and set DATABASE_URL
in the environment before importing the app.

For unit tests of pure functions no database is needed at all.
"""
import os
import pytest


@pytest.fixture(autouse=True)
def _isolate_env(request, monkeypatch):
    """Prevent unit tests from accidentally reading production env vars.

    Integration tests (marked `integration`) are skipped here: they must use the
    real DATABASE_URL injected by the CI integration lane, not the fake one.
    """
    if request.node.get_closest_marker("integration"):
        return
    monkeypatch.setenv("DATABASE_URL", "postgresql+asyncpg://test:test@localhost/test")
    monkeypatch.setenv("SECRET_KEY", "test-secret-key")
    monkeypatch.setenv("OLLAMA_URL", "http://localhost:11434")
