from pathlib import Path import click import pytest from afk_developer.grillme.interviewer import _detect_intent, run_interview from afk_developer.grillme.questions import auto_discover_project, count_files, count_test_files from afk_developer.grillme.spec_model import TaskIntent def test_build_request_with_documentation_is_an_implementation_task(): intent = _detect_intent("Build a pygame application and document its controls in a README.") assert intent is TaskIntent.IMPLEMENT def test_build_request_with_validation_fixes_is_an_implementation_task(): intent = _detect_intent("Build a game, run validation, and fix every failure.") assert intent is TaskIntent.IMPLEMENT def test_read_only_request_without_an_implementation_verb_is_analysis(): intent = _detect_intent("Analyze and document the current codebase.") assert intent is TaskIntent.ANALYZE def test_project_discovery_ignores_virtual_environment_and_reads_pyproject(tmp_path: Path) -> None: (tmp_path / "pyproject.toml").write_text( """ [project] dependencies = ["fastapi>=0.115"] [project.optional-dependencies] dev = ["pytest>=8", "ruff>=0.6"] """.strip(), encoding="utf-8", ) (tmp_path / "src" / "app.py").parent.mkdir() (tmp_path / "src" / "app.py").write_text("", encoding="utf-8") (tmp_path / "tests").mkdir() (tmp_path / "tests" / "test_app.py").write_text("", encoding="utf-8") (tmp_path / ".venv" / "Lib" / "site-packages").mkdir(parents=True) (tmp_path / ".venv" / "Lib" / "site-packages" / "test_hidden.py").write_text( "", encoding="utf-8" ) context = auto_discover_project(tmp_path) assert context.framework == "FastAPI" assert context.test_framework == "pytest" assert context.linter == "ruff" assert context.package_manager == "pip" assert count_files(tmp_path) == 3 assert count_test_files(tmp_path) == 1 assert context.existing_files_count == 3 def test_run_interview_creates_missing_directory_without_prompting_when_goal_given( tmp_path: Path, monkeypatch: pytest.MonkeyPatch ) -> None: def _fail_if_prompted(*args, **kwargs): raise AssertionError("click.confirm must not be called in non-interactive (-g) mode") monkeypatch.setattr(click, "confirm", _fail_if_prompted) missing_dir = tmp_path / "new-project" spec = run_interview(str(missing_dir), goal="Build a pygame pinball game") assert missing_dir.is_dir() assert spec.approved is True def test_run_interview_creates_missing_directory_without_prompting_when_yes_flag_set( tmp_path: Path, monkeypatch: pytest.MonkeyPatch ) -> None: def _fail_if_prompted(*args, **kwargs): raise AssertionError("click.confirm must not be called when yes=True") monkeypatch.setattr(click, "confirm", _fail_if_prompted) missing_dir = tmp_path / "another-new-project" spec = run_interview(str(missing_dir), goal="Build a pygame pinball game", yes=True) assert missing_dir.is_dir() assert spec.approved is True