fix(projekt-matching): retry chat_json on empty/unparseable vLLM completion

This commit is contained in:
tlg
2026-07-09 15:33:11 +02:00
parent cf088f0bd3
commit 20796b3a68
2 changed files with 32 additions and 13 deletions

View File

@@ -35,6 +35,20 @@ def test_chat_json_strips_markdown_fences():
assert out == {"a": 2}
def test_chat_json_retries_on_empty_content():
good = json.dumps({"a": 1})
with mock.patch("projektmatch.llm.time.sleep", lambda s: None), \
mock.patch("projektmatch.llm.requests.post", fake_post(["", good])):
assert llm.chat_json("http://v/v1", "m", [], {"type": "object"}) == {"a": 1}
def test_chat_json_raises_after_exhausted_retries():
with mock.patch("projektmatch.llm.time.sleep", lambda s: None), \
mock.patch("projektmatch.llm.requests.post", fake_post(["", "", ""])):
with pytest.raises(llm.LlmError, match="kein JSON"):
llm.chat_json("http://v/v1", "m", [], {"type": "object"})
def test_match_cv_retries_on_missing_nr_then_raises():
reqs = [{"nr": 1, "text": "Python"}, {"nr": 2, "text": "K8s"}]
partial = json.dumps({"ratings": [