Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions tests/roadmap/provider/test_retry_success.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import json
from unittest.mock import patch

from app.services import ai
from app.services.risk import get_assessment

VALID_ASSESSMENT = {
"label": "Safe",
"score": "Low",
"certainty": 90,
"reason": "No scam indicators found.",
}


def test_recovers_when_malformed_json_is_followed_by_valid_output():
with patch(
"app.services.risk.ask_deepseek",
side_effect=[
json.JSONDecodeError("Expecting value", "", 0),
VALID_ASSESSMENT,
],
) as provider:
result = get_assessment("untrusted sample text")

assert provider.call_count == 2
assert result.label == "Safe"
assert result.score == "Low"
assert result.certainty == 90
assert result.reason == "No scam indicators found."


def test_malformed_json_retry_does_not_call_live_provider(mocker):
"""Ensure the retry path uses mocked output only (no get_ai_client)."""
mocker.patch(
"app.services.risk.ask_deepseek",
side_effect=[
ai.json.JSONDecodeError("bad", "", 0),
VALID_ASSESSMENT,
],
)
client = mocker.patch("app.services.ai.get_ai_client")
get_assessment("hello")
client.assert_not_called()