"""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_scored_card_computes_overall_from_rubric(): # Stage 1: the curator RATES dimensions; _scored_card COMPUTES the overall (no model-picked score) from app.engine import rubric as R sc = C._scored_card({ "id": "1", "fit": "fit", "dimensions": { "role": {"score": 100, "note": "same function"}, "skills": {"score": 80, "note": "real SQL"}, "seniority": {"score": 90, "note": "right level"}, "location": {"score": 100, "note": "target city"}, "industry": {"score": 85, "note": "adjacent"}, "experience": {"score": 80, "note": "aligned"}, }, }) expected = R.aggregate({"role": 100, "skills": 80, "seniority": 90, "location": 100, "industry": 85, "experience": 80}) assert sc["overall"] == expected and sc["fit"] == "fit" assert C._scored_card({"id": "x", "dimensions": {}}) is None # no dims → dropped def test_to_match_merges_score_and_prose(): # Stage 1 scored card + Stage 2 prose → the full MatchResult contract sc = C._scored_card({ "id": "1", "fit": "fit", "dimensions": {"role": {"score": 100, "note": "same function"}, "skills": {"score": 80, "note": "real SQL"}, "seniority": {"score": 90}, "location": {"score": 100}, "experience": {"score": 80}}, }) prose = {"archetype": "The Fit", "one_line": "strong but a gap", "coach_note": "lead with X", "growth": {"text": "close Y", "from": 78, "to": 85}} d = C._to_match(sc, prose).as_dict() assert d["score"] == sc["overall"] and d["archetype"] == "The Fit" and d["coach_note"] == "lead with X" assert any(dim["note"] == "real SQL" for dim in d["breakdown"]) assert d["growth"]["from"] == 78 and d["growth"]["to"] == 85 and d["proofReady"] is True def test_to_match_falls_back_to_templated_prose(): # Stage 2 failed (prose=None) → score + breakdown survive, prose is templated (never blank) sc = C._scored_card({"id": "1", "fit": "fit", "dimensions": {"role": {"score": 95}, "skills": {"score": 85}, "seniority": {"score": 90}, "location": {"score": 100}, "experience": {"score": 80}}}) d = C._to_match(sc, None).as_dict() assert d["score"] == sc["overall"] and d["archetype"] and d["one_line"] # templated, not empty 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