52 lines
1.8 KiB
Python
52 lines
1.8 KiB
Python
import pytest
|
|
from pathlib import Path
|
|
import subprocess
|
|
|
|
from fixtures.sample_repo import MockLLMProvider
|
|
|
|
|
|
class TestReviewWorkflow:
|
|
def test_review_with_no_staged_changes(self, temp_git_repo, mock_config):
|
|
from src.core.review_engine import ReviewEngine
|
|
from src.llm import LLMProvider
|
|
|
|
engine = ReviewEngine(config=mock_config, llm_provider=MockLLMProvider())
|
|
engine.set_repo(temp_git_repo)
|
|
result = engine.review_staged_changes([])
|
|
assert result.error == "No staged changes found"
|
|
|
|
def test_review_with_staged_file(self, temp_git_repo, sample_python_file, mock_config):
|
|
from src.core.review_engine import ReviewEngine
|
|
from src.git import get_staged_changes
|
|
|
|
subprocess.run(["git", "add", "test.py"], cwd=temp_git_repo, capture_output=True)
|
|
changes = get_staged_changes(temp_git_repo)
|
|
|
|
engine = ReviewEngine(config=mock_config, llm_provider=MockLLMProvider())
|
|
engine.set_repo(temp_git_repo)
|
|
result = engine.review_staged_changes(changes)
|
|
|
|
assert result.review_mode == "balanced"
|
|
assert result.error is None or len(result.issues) >= 0
|
|
|
|
|
|
class TestHookInstallation:
|
|
def test_install_hook(self, temp_git_repo):
|
|
from src.hooks import install_pre_commit_hook
|
|
|
|
result = install_pre_commit_hook(temp_git_repo)
|
|
assert result is True
|
|
|
|
hook_path = temp_git_repo / ".git" / "hooks" / "pre-commit"
|
|
assert hook_path.exists()
|
|
|
|
content = hook_path.read_text()
|
|
assert "aicr" in content or "review" in content
|
|
|
|
def test_check_hook_installed(self, temp_git_repo):
|
|
from src.hooks import install_pre_commit_hook, check_hook_installed
|
|
|
|
assert check_hook_installed(temp_git_repo) is False
|
|
install_pre_commit_hook(temp_git_repo)
|
|
assert check_hook_installed(temp_git_repo) is True
|