Files
ai-video-fullstack/backend/tests/test_task_backend_spine.py
T

32 lines
1.7 KiB
Python

"""F0: explicit simulated backend, real application-owned Pipecat Jobs."""
import asyncio
import json
from pathlib import Path
from types import SimpleNamespace
import unittest
from services.background_tasks.service import TaskService
from tests.test_background_tasks import MemoryRepository, SimulatedExecutor
class TaskBackendSpineTest(unittest.IsolatedAsyncioTestCase):
async def test_backend_resource_reaches_native_job_without_tool_definition(self):
SimulatedExecutor.release = asyncio.Event()
SimulatedExecutor.confirms_stop = True
service = TaskService(MemoryRepository(), SimulatedExecutor)
backend = SimpleNamespace(id="tb_smoke", type="opencode", config={"url": "https://simulated.test", "directory": "/demo", "timeout_seconds": 30}, secrets={})
await service.start()
try:
task = await service.submit(assistant_id="asst_smoke", conversation_id="conv_smoke", backend=backend, instruction="SIMULATED task", invocation_id="smoke")
SimulatedExecutor.release.set()
async with asyncio.timeout(3):
while (await service.get(task["id"])).status != "succeeded":
await asyncio.sleep(.005)
record = await service.get(task["id"])
self.assertEqual(record.connection["_backend_type"], "opencode")
self.assertTrue(record.job_id)
artifact = Path(__file__).resolve().parents[2] / "implement-stage/task-backends/backend-spine-smoke.json"
artifact.write_text(json.dumps({"simulated_remote": True, "native_job": "completed", "backend_id": backend.id, "tool_definition_required": False}) + "\n")
finally:
await service.close()