fix: keep agent streams alive during long tasks
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import os
|
||||
import tempfile
|
||||
import asyncio
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from unittest.mock import AsyncMock, patch
|
||||
@@ -50,7 +51,18 @@ class MixedPdfKnowledgeIntegrationTests(unittest.TestCase):
|
||||
database.initialize_database()
|
||||
knowledge.initialize()
|
||||
client = authenticated_client(app)
|
||||
with patch("app.main.recognize_image_text", return_value=ocr):
|
||||
ocr_execution_contexts: list[str] = []
|
||||
|
||||
def fake_ocr(*_args, **_kwargs):
|
||||
try:
|
||||
asyncio.get_running_loop()
|
||||
except RuntimeError:
|
||||
ocr_execution_contexts.append("worker")
|
||||
else:
|
||||
ocr_execution_contexts.append("event-loop")
|
||||
return ocr
|
||||
|
||||
with patch("app.main.recognize_image_text", side_effect=fake_ocr):
|
||||
indexed = client.post(
|
||||
"/v1/agent/knowledge/index",
|
||||
json={"workspace_path": str(workspace), "files": ["mixed.pdf"]},
|
||||
@@ -75,6 +87,7 @@ class MixedPdfKnowledgeIntegrationTests(unittest.TestCase):
|
||||
|
||||
self.assertEqual(indexed.status_code, 200, indexed.text)
|
||||
self.assertEqual(indexed.json()["indexed"][0]["ocr_pages"], 1)
|
||||
self.assertEqual(ocr_execution_contexts, ["worker"])
|
||||
self.assertTrue(indexed.json()["indexed"][0]["semantic_indexed"])
|
||||
self.assertEqual(digital.status_code, 200, digital.text)
|
||||
self.assertIn("IndexMarker", digital.json()["results"][0]["text"])
|
||||
|
||||
Reference in New Issue
Block a user