import asyncio

from tests.e2e.runner.runner import E2ERunner
from tests.fixtures.datasource import STORY_QUESTION
from verse_sdk import observe


class E2ERunnerAsync(E2ERunner):
    @observe("e2e.runner.async", type="trace")
    def run(self):
        async def _run():
            chunks = []
            full_response = ""

            async for chunk in self._agent.stream(STORY_QUESTION):
                chunks.append(chunk)
                full_response = "".join(chunks)

            return full_response

        response = asyncio.run(_run())

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