76 lines
3.1 KiB
Python
76 lines
3.1 KiB
Python
|
|
"""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/`.
|
||
|
|
|
||
|
|
Coverage:
|
||
|
|
(1) Makefile test target uses python3.11, not bare pytest
|
||
|
|
(2) _detect_test_command still returns 'make test' for projects with Makefile
|
||
|
|
"""
|
||
|
|
|
||
|
|
import re
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
|
||
|
|
# ---------------------------------------------------------------------------
|
||
|
|
# (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"(?<!python3\.11 -m )(?<!\w)pytest\b", test_body)
|
||
|
|
assert bare_pytest is None, (
|
||
|
|
f"Makefile test target must not use bare 'pytest', got:\n{test_body!r}"
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
# ---------------------------------------------------------------------------
|
||
|
|
# (2) _detect_test_command still returns 'make test' for Makefile projects
|
||
|
|
# ---------------------------------------------------------------------------
|
||
|
|
|
||
|
|
class TestDetectTestCommandUnchanged:
|
||
|
|
def test_detect_returns_make_test_for_makefile(self, tmp_path):
|
||
|
|
"""_detect_test_command must return 'make test' when Makefile has test target."""
|
||
|
|
from agents.runner import _detect_test_command
|
||
|
|
|
||
|
|
(tmp_path / "Makefile").write_text("test:\n\tpython3.11 -m pytest\n")
|
||
|
|
assert _detect_test_command(str(tmp_path)) == "make test"
|
||
|
|
|
||
|
|
def test_kin_project_detects_make_test(self):
|
||
|
|
"""kin project itself must auto-detect 'make test' (has Makefile with test target)."""
|
||
|
|
from agents.runner import _detect_test_command
|
||
|
|
|
||
|
|
project_root = str(Path(__file__).parent.parent)
|
||
|
|
result = _detect_test_command(project_root)
|
||
|
|
assert result == "make test", (
|
||
|
|
f"kin project should detect 'make test', got {result!r}"
|
||
|
|
)
|