"""Integration tests for the interactive REPL CLI entry point.""" from __future__ import annotations from typing import Any import pytest from typer.testing import CliRunner from my_deepagent.cli.main import app runner = CliRunner() def test_help_shows_agent_and_model_options() -> None: """--help must list --agent and --model options.""" result = runner.invoke(app, ["--help"]) assert result.exit_code == 0 assert "--agent" in result.output assert "--model" in result.output def test_no_subcommand_governance_not_accepted_exits_nonzero( monkeypatch: pytest.MonkeyPatch, ) -> None: """When governance consent is absent, the REPL must exit with a non-zero code.""" import my_deepagent.governance as gov_module monkeypatch.setattr(gov_module, "has_consent", lambda _: False) result = runner.invoke(app, []) assert result.exit_code != 0 def test_quit_exits_repl(monkeypatch: pytest.MonkeyPatch, tmp_path: Any) -> None: """REPL launched with mocked PromptSession should exit 0 on /quit.""" import my_deepagent.governance as gov_module import my_deepagent.persona as persona_module from my_deepagent.enums import Backend, Capability, RiskLevel from my_deepagent.persona import Persona # Patch governance to skip consent check monkeypatch.setattr(gov_module, "has_consent", lambda _: True) # Build a minimal fake persona with all required fields fake_persona = Persona( name="default-interactive", version=1, description="test", backend=Backend.OPENROUTER, model="openrouter:deepseek/deepseek-chat", provider_origin="openrouter", capabilities=(Capability.CODE_EDIT,), max_risk_level=RiskLevel.LOW, system_prompt="You are a helpful assistant.", model_params={}, permissions=(), subagents=(), deepagents_backend="state", ) monkeypatch.setattr(persona_module, "load_personas_from_dir", lambda _: [fake_persona]) # Patch PromptSession to yield "/quit" then raise EOFError prompt_responses = ["/quit"] call_count = 0 async def fake_prompt_async(*args: Any, **kwargs: Any) -> str: nonlocal call_count if call_count < len(prompt_responses): resp = prompt_responses[call_count] call_count += 1 return resp raise EOFError from prompt_toolkit import PromptSession monkeypatch.setattr(PromptSession, "prompt_async", fake_prompt_async) # Patch Database to avoid real DB I/O from my_deepagent.persistence import db as db_module class FakeDB: async def init_schema(self) -> None: pass async def dispose(self) -> None: pass monkeypatch.setattr(db_module, "Database", lambda url: FakeDB()) result = runner.invoke(app, []) assert result.exit_code == 0