"""Pytest configuration and shared fixtures."""
import json
import shutil
import tempfile
from pathlib import Path
import pytest
@pytest.fixture
def sample_transcript_path(tmp_path):
"""Create a temporary transcript file."""
fixture_path = Path(__file__).parent / "fixtures" / "sample_transcript.jsonl"
transcript_path = tmp_path / "73cc9f9a-1234-5678-9abc-def012345678.jsonl"
shutil.copy(fixture_path, transcript_path)
return transcript_path
@pytest.fixture
def sample_todos_path(tmp_path):
"""Create a temporary todos file with session ID."""
fixture_path = Path(__file__).parent / "fixtures" / "sample_todos.json"
session_id = "73cc9f9a-1234-5678-9abc-def012345678"
todos_dir = tmp_path / "todos"
todos_dir.mkdir(exist_ok=True)
todos_path = todos_dir / f"{session_id}.json"
shutil.copy(fixture_path, todos_path)
return todos_path, session_id
@pytest.fixture
def sample_plan_path(tmp_path):
"""Create a temporary planning doc."""
fixture_path = Path(__file__).parent / "fixtures" / "sample_plan.md"
context_dir = tmp_path / ".context" / "dev" / "feat-auth"
context_dir.mkdir(parents=True, exist_ok=True)
plan_path = context_dir / "feat-auth-detailed-plan.md"
shutil.copy(fixture_path, plan_path)
return plan_path
@pytest.fixture
def mock_git_repo(tmp_path):
"""Create a mock git repository."""
import subprocess
# Initialize git repo
subprocess.run(["git", "init"], cwd=tmp_path, capture_output=True)
subprocess.run(["git", "config", "user.email", "test@example.com"], cwd=tmp_path, capture_output=True)
subprocess.run(["git", "config", "user.name", "Test User"], cwd=tmp_path, capture_output=True)
subprocess.run(["git", "checkout", "-b", "feat-auth"], cwd=tmp_path, capture_output=True)
# Create initial commit
test_file = tmp_path / "test.txt"
test_file.write_text("initial content")
subprocess.run(["git", "add", "."], cwd=tmp_path, capture_output=True)
subprocess.run(["git", "commit", "-m", "Initial commit"], cwd=tmp_path, capture_output=True)
return tmp_path
@pytest.fixture
def mock_git_repo_with_changes(mock_git_repo):
"""Create a mock git repo with uncommitted changes."""
uncommitted_file = mock_git_repo / "uncommitted.txt"
uncommitted_file.write_text("uncommitted content")
return mock_git_repo