"""A2 — curator: tolerant JSON parse, contract mapping, and the disabled→None safety net. (Offline — the live Opus call is exercised in the cached e2e verification.)""" from app.engine import curate as C def test_parse_json_strips_fences_and_prose(): assert C._parse_json('```json\n{"kept":[]}\n```') == {"kept": []} assert C._parse_json('here: {"kept":[{"id":"1"}]} thanks')["kept"][0]["id"] == "1" def test_to_match_builds_full_contract(): m = C._to_match({ "id": "1", "score": 78, "fit": "fit", "archetype": "The Fit", "one_line": "strong but a gap", "breakdown": [{"name": "Skill match", "score": 80, "level": "Strong", "note": "real SQL"}], "coach_note": "lead with X", "growth": {"text": "close Y", "from": 78, "to": 85}, }) d = m.as_dict() assert d["score"] == 78 and d["archetype"] == "The Fit" and d["fit"] == "fit" assert d["breakdown"][0]["note"] == "real SQL" and d["coach_note"] == "lead with X" assert d["growth"]["from"] == 78 and d["growth"]["to"] == 85 and d["proofReady"] is True def test_curate_disabled_returns_none(monkeypatch): monkeypatch.setattr(C, "curate_enabled", lambda: False) assert C.curate({"title": "PM"}, None, [{"id": "1", "title": "PM"}]) is None