fix(agent): proxy gradio config and reduce translate blocking

This commit is contained in:
2026-07-07 17:37:36 +03:00
parent b95df37cd5
commit 0d09e24434
14 changed files with 191 additions and 8 deletions

View File

@@ -83,16 +83,37 @@ class TestCreateBatch:
class TestDetectLanguages:
"""Verify _detect_languages."""
def test_detects_languages(self, db_session):
@pytest.mark.asyncio
async def test_detects_languages(self, db_session):
config = MagicMock()
svc = BatchProcessingService(db_session, config)
rows = _batch_rows(2)
with patch('src.plugins.translate._batch_proc.batch_detect',
return_value=["en", "fr"]):
svc._detect_languages(rows, ["fr", "de"])
await svc._detect_languages(rows, ["fr", "de"])
assert rows[0]["_detected_lang"] == "en"
assert rows[1]["_detected_lang"] == "fr"
@pytest.mark.asyncio
async def test_detect_languages_offloads_to_thread(self, db_session):
"""Regression: CPU-bound lingua batch detection must not run on event loop."""
config = MagicMock()
svc = BatchProcessingService(db_session, config)
rows = _batch_rows(2)
async def fake_to_thread(fn, texts, target_languages):
assert fn.__name__ == "batch_detect"
assert texts == ["Hello world 0", "Hello world 1"]
assert target_languages == ["fr"]
return ["en", "en"]
with patch('src.plugins.translate._batch_proc.asyncio.to_thread',
new=AsyncMock(side_effect=fake_to_thread)) as mock_to_thread:
await svc._detect_languages(rows, ["fr"])
mock_to_thread.assert_awaited_once()
assert [row["_detected_lang"] for row in rows] == ["en", "en"]
class TestCheckCache:
"""Verify _check_cache."""