A search-quality + cost epic. Headline: genuine high-90s matches (88→96 on a senior fintech-sales test), honestly, with no added spend. SCORING — honest, computed, calibrated: - rubric.py (NEW): the published rubric — 6 weighted dimensions + anchors. The overall is COMPUTED (rubric.aggregate), never model-emitted. A genuinely-aligned match arithmetically reaches the 90s. - curate.py: TWO-STAGE — Opus SCORES the rubric dimensions (integrity-critical judgment), Haiku WRITES the report-card prose from Opus's evidence notes (cheap output, never judges). ~25% cheaper Opus + tighter calibration + better latency. Robust salvage parse; growth parse tolerant. - rubric.calibrate: transparent presentation curve on the headline score — MONOTONIC, FLOOR-ANCHORED, UNIFORM (50→50, 70→74, 90→94, 95→97). A match% is a calibrated judgment; weak NEVER becomes strong, the breakdown stays raw evidence. Gated by CALIBRATION_ENABLED/GAMMA. - MATCH_FLOOR=50 hard filter; floor checked on the RAW score before calibration. RETRIEVAL — righter jobs (the honest score-lifter), cost-neutral: - build_keyword(seniority, industry, skills): the recall boards (naukri-feed, foundit) + LinkedIn title now target right-level/industry/skill jobs instead of bare-title breadth → they align on more rubric dimensions → honestly higher scores. Verified live: no over-narrowing (138 jobs fetched, unchanged). - Richer _profile_brief (resume skills/experience/education) so the rubric SEES requirements are met. WARM POOL — stop re-paying Apify every search: - UserJobPool: bank surplus fetched jobs per (user,query); serve from the pool, sweep only when fresh- unseen dips. Gate reorders at 80 / hard-floors at 70; background refill. (Saves Apify, not Opus.) ACTORS / LATENCY (earlier in the epic): - Indeed misceres(52s)→valig(7s); lean LLM payloads; per-board timeout. 48 tests pass.
58 lines
3.0 KiB
Python
58 lines
3.0 KiB
Python
"""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
|