"""Regression tests for KIN-109: Auto-test должен использовать python3.11 вместо python3 (ссылается на 3.14). Root cause: Makefile test target used bare `pytest tests/` which resolves to the system pytest (Python 3.14). Tests written for Python 3.11 could fail under 3.14. Fix: Makefile test target changed to `python3.11 -m pytest tests/`. PR fix: _detect_test_command() now returns sys.executable -m pytest for pyproject.toml/setup.py projects (was bare 'pytest'). Coverage: (1) Makefile test target uses python3.11, not bare pytest (2) _detect_test_command still returns 'make test' for projects with Makefile (3) _detect_test_command returns sys.executable -m pytest for pyproject.toml/setup.py (4) Pipeline auto-test uses project.test_command when explicitly set (5) Pipeline auto-test uses _detect_test_command when project.test_command is NULL (6) PATCH /api/projects: test_command absent → DB field unchanged (decision #580) (7) Regression: pipeline auto-test early return (no test framework) does not crash """ import sys import re from pathlib import Path from unittest.mock import patch, MagicMock import pytest from core.db import init_db from core import models # --------------------------------------------------------------------------- # (1) Makefile — test target uses python3.11 -m pytest # --------------------------------------------------------------------------- class TestMakefileTestTarget: def test_makefile_test_uses_python311(self): """Makefile test target must use python3.11 -m pytest, not bare pytest.""" makefile = Path(__file__).parent.parent / "Makefile" assert makefile.is_file(), "Makefile must exist in project root" content = makefile.read_text() # Find test target block m = re.search(r"^test\s*:.*?\n((?:\t.+\n?)*)", content, re.MULTILINE) assert m is not None, "Makefile must have a 'test:' target" test_body = m.group(1) assert "python3.11 -m pytest" in test_body, ( f"Makefile test target must use 'python3.11 -m pytest', got:\n{test_body!r}" ) def test_makefile_test_does_not_use_bare_pytest(self): """Makefile test target must NOT use bare 'pytest' (would pick up Python 3.14).""" makefile = Path(__file__).parent.parent / "Makefile" content = makefile.read_text() m = re.search(r"^test\s*:.*?\n((?:\t.+\n?)*)", content, re.MULTILINE) assert m is not None test_body = m.group(1) # Bare pytest call (not prefixed by python3.11 -m) bare_pytest = re.search(r"(?