"""Smoke test for {{ project_name }}.VersicherungsCrew.

Uses a mock Planner so the test never hits Ollama / a network — runs in
< 1 s on any CI. The StringGuardrail also needs a mocked llm_client to
return a valid ``{"passed": true}`` verdict during the smoke run.
"""

from __future__ import annotations

from unittest.mock import AsyncMock, MagicMock

import pytest

from {{ project_name }}.crew import VersicherungsCrew


@pytest.mark.asyncio
async def test_crew_kickoff_with_mock_planner(monkeypatch):
    from cognithor.core.observer import ResponseEnvelope

    mock_planner = MagicMock()
    mock_planner.formulate_response = AsyncMock(
        return_value=ResponseEnvelope(content="MOCK_OUTPUT", directive=None),
    )
    mock_registry = MagicMock()
    mock_registry.get_tools_for_role.return_value = []

    monkeypatch.setattr(
        "cognithor.crew.runtime.get_default_tool_registry",
        lambda: mock_registry,
    )
    monkeypatch.setattr(
        "cognithor.crew.runtime.get_default_planner",
        lambda: mock_planner,
    )

    # The StringGuardrail in write() needs an ollama_client that can answer
    # ``{"passed": true}`` during the smoke run — otherwise it short-circuits
    # with passed=False and we hit GuardrailFailure.
    mock_ollama = MagicMock()
    mock_ollama.chat = AsyncMock(
        return_value={"message": {"content": '{"passed": true, "feedback": null}'}},
    )

    crew = VersicherungsCrew(ollama_client=mock_ollama).assemble()
    result = await crew.kickoff_async(
        inputs={"topic": "PKV", "customer_info": "Freelancer, 35"},
    )
    assert result.raw == "MOCK_OUTPUT"
    assert len(result.tasks_output) == 3
