import asyncio

from tests.e2e.runner.runner import E2ERunner
from verse_sdk import observe


class E2ERunnerAsync(E2ERunner):
    @observe("e2e.runner.async", type="trace")
    async def _run_agent(self):
        chunks = []
        async for chunk in self._agent.stream(
            "Tell me a story about the day in the life of Cleo the Cat. "
            "Include details about their friends, their job, and the town they live in."
        ):
            chunks.append(chunk)

        return "".join(chunks)

    def run(self):
        response = asyncio.run(self._run_agent())

        self.setup()
        self.assert_messages_in_conversation()
        self.assert_response_len(response)
        self.assert_validity()
        self.teardown()
