56 lines
1.5 KiB
Python
56 lines
1.5 KiB
Python
import os
|
|
import shutil
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
REPO_ROOT = Path(__file__).resolve().parents[1]
|
|
FIXTURE = REPO_ROOT / "examples" / "fixtures" / "acme-app"
|
|
|
|
sys.path.insert(0, str(REPO_ROOT / "src"))
|
|
sys.path.insert(0, str(REPO_ROOT / "llm")) # atrapa serwera OpenAI
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def hermetyczne_srodowisko(monkeypatch):
|
|
"""Testy nie mogą zależeć od lokalnego .env developera.
|
|
|
|
Taskfile ładuje `.env`, więc bez tego wynik testów zmieniałby się w zależności
|
|
od tego, jaki endpoint albo budżet ktoś ustawił sobie na swojej maszynie.
|
|
"""
|
|
for key in list(os.environ):
|
|
if key.startswith("CODEMOD_"):
|
|
monkeypatch.delenv(key, raising=False)
|
|
|
|
|
|
@pytest.fixture()
|
|
def repo_root() -> Path:
|
|
return REPO_ROOT
|
|
|
|
|
|
@pytest.fixture()
|
|
def acme_app(tmp_path: Path) -> Path:
|
|
"""Kopia fixture'u - testy nigdy nie modyfikują wzorca w repozytorium."""
|
|
target = tmp_path / "acme-app"
|
|
shutil.copytree(FIXTURE, target, ignore=shutil.ignore_patterns("__pycache__", ".pytest_cache"))
|
|
return target
|
|
|
|
|
|
@pytest.fixture()
|
|
def settings(tmp_path: Path):
|
|
from agentic_codemod.config import Settings
|
|
|
|
config = Settings.from_env()
|
|
config.apm_root = REPO_ROOT
|
|
config.run_dir = tmp_path / "run"
|
|
config.verify_timeout_s = 120
|
|
return config
|
|
|
|
|
|
@pytest.fixture()
|
|
def audit(tmp_path: Path):
|
|
from agentic_codemod.observability.audit import AuditLog
|
|
|
|
return AuditLog(run_dir=tmp_path / "audit")
|