fix: minor issue fixes

This commit is contained in:
Alex committed 2026-06-30 18:36:06 +02:00
1 parent 99484e02c8
commit 75e07af78f
16 files changed
+950 -43

No files matched your search

+47
View File
@@ -327,6 +327,53 @@ class TestMcpOauthTask:
assert result == {"url": "http://auth"}
class TestParseDocumentTask:
"""parse_document runs on the parsing queue under a bounded time limit."""
@pytest.mark.unit
@patch("application.api.user.tasks.parse_document_worker")
def test_calls_parse_document_worker(self, mock_worker):
from application.api.user.tasks import parse_document
mock_worker.return_value = {"status": "ok", "content": "hi"}
result = parse_document(
"art-1", {"conversation_id": "c1"}, "user1", {"output": "markdown"},
)
mock_worker.assert_called_once_with(
ANY, "art-1", {"conversation_id": "c1"}, "user1",
{"output": "markdown"},
)
assert result == {"status": "ok", "content": "hi"}
@pytest.mark.unit
@patch("application.api.user.tasks.parse_document_worker")
def test_soft_time_limit_returns_clean_error(self, mock_worker):
from celery.exceptions import SoftTimeLimitExceeded
from application.api.user.tasks import parse_document
mock_worker.side_effect = SoftTimeLimitExceeded("parse")
# The task must swallow the soft-limit signal and return the worker's
# clean error shape so the parsing-worker slot frees instead of crashing.
result = parse_document("art-1", {"conversation_id": "c1"}, "user1")
assert result["status"] == "error"
assert "timed out" in result["error"]
@pytest.mark.unit
def test_time_limits_derived_from_document_parse_timeout(self):
from application.api.user.tasks import parse_document
from application.core.settings import settings
assert parse_document.soft_time_limit == settings.DOCUMENT_PARSE_TIMEOUT
assert parse_document.time_limit == settings.DOCUMENT_PARSE_TIMEOUT + 30
# Hard limit must exceed the soft limit so the handler can unwind first.
assert parse_document.time_limit > parse_document.soft_time_limit
class TestDurableTaskRetryPolicy:
"""The long-running tasks share a uniform retry policy."""