"""Shared pytest fixtures for Kin test suite.""" import pytest from unittest.mock import patch @pytest.fixture(autouse=True) def _set_kin_secret_key(monkeypatch): """Set KIN_SECRET_KEY for all tests (required by _encrypt_auth/_decrypt_auth).""" from cryptography.fernet import Fernet monkeypatch.setenv("KIN_SECRET_KEY", Fernet.generate_key().decode()) @pytest.fixture(autouse=True) def _clear_kin_noninteractive(monkeypatch): """Ensure KIN_NONINTERACTIVE is not inherited from parent process. Tests that need it explicitly set it via @patch.dict("os.environ", {"KIN_NONINTERACTIVE": "1"}). Without this fixture, KIN_NONINTERACTIVE=1 (set by web API when launching agent subprocesses) leaks into the test environment and causes _run_claude to add --dangerously-skip-permissions even when noninteractive=False. """ monkeypatch.delenv("KIN_NONINTERACTIVE", raising=False) @pytest.fixture(autouse=True) def _mock_check_claude_auth(): """Авто-мок agents.runner.check_claude_auth для всех тестов. run_pipeline() вызывает check_claude_auth() перед запуском агентов. Без мока тесты, использующие side_effect-очереди для subprocess.run, ломаются: первый вызов (auth-check) потребляет элемент очереди. Тесты TestCheckClaudeAuth (test_runner.py) НЕ затрагиваются: они вызывают check_claude_auth через напрямую импортированную ссылку (bound at module load time), а не через agents.runner.check_claude_auth. """ with patch("agents.runner.check_claude_auth"): yield