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.
66 lines
2.8 KiB
Python
66 lines
2.8 KiB
Python
"""The honest rubric — the displayed score is COMPUTED from dimension ratings, never model-emitted."""
|
|
import pytest
|
|
|
|
from app.engine import rubric as R
|
|
|
|
|
|
def test_weights_sum_to_one():
|
|
assert abs(sum(R.WEIGHTS.values()) - 1.0) < 1e-9
|
|
|
|
|
|
def test_perfect_match_scores_high_90s():
|
|
# all dimensions genuinely aligned → the overall lands in the high 90s (earned, not prompted)
|
|
perfect = {k: 100 for k in R.KEYS}
|
|
assert R.aggregate(perfect) == 100
|
|
strong = {"role": 100, "skills": 92, "seniority": 95, "location": 100, "industry": 95, "experience": 90}
|
|
assert R.aggregate(strong) >= 94 # a real strong match reaches the 90s
|
|
|
|
|
|
def test_partial_match_scores_mid():
|
|
partial = {"role": 75, "skills": 50, "seniority": 70, "location": 60, "industry": 65, "experience": 60}
|
|
s = R.aggregate(partial)
|
|
assert 55 <= s <= 72 # honestly a partial, not inflated
|
|
|
|
|
|
def test_weak_role_drags_score_down():
|
|
# role is 25% — a wrong-function job can't score high no matter how good the rest is
|
|
weak = {"role": 15, "skills": 90, "seniority": 90, "location": 100, "industry": 90, "experience": 90}
|
|
assert R.aggregate(weak) < 80
|
|
|
|
|
|
def test_absent_dimension_redistributes_not_zeroes():
|
|
# industry absent (no preference) must NOT act as a 0 that tanks the score — weight redistributes
|
|
no_ind = {"role": 100, "skills": 100, "seniority": 100, "location": 100, "experience": 100}
|
|
assert R.aggregate(no_ind) == 100 # not dragged down by the missing 10% industry weight
|
|
|
|
|
|
def test_empty_is_zero_not_crash():
|
|
assert R.aggregate({}) == 0
|
|
|
|
|
|
def test_scores_are_clamped():
|
|
assert R.aggregate({k: 150 for k in R.KEYS}) == 100
|
|
assert R.aggregate({k: -20 for k in R.KEYS}) == 0
|
|
|
|
|
|
def test_level_bands():
|
|
assert R.level_for(90) == "Strong" and R.level_for(60) == "Solid" and R.level_for(40) == "Light"
|
|
|
|
|
|
def test_prompt_block_lists_every_dimension():
|
|
block = R.prompt_block()
|
|
for k in R.KEYS:
|
|
assert f'"{k}"' in block # every rubric key is shown to the curator
|
|
|
|
|
|
def test_calibration_is_monotonic_floor_anchored_and_lifts_top():
|
|
# the transparent "little bias": strictly increasing, floor fixed, top expanded into the 90s
|
|
assert R.calibrate(50) == 50 # floor unchanged — weak stays weak
|
|
assert R.calibrate(49) == 49 and R.calibrate(20) == 20 # below floor untouched
|
|
assert R.calibrate(100) == 100 # ceiling fixed
|
|
assert R.calibrate(90) >= 93 # genuinely-strong → presents in the 90s
|
|
assert R.calibrate(60) <= 65 # a weak match is NOT lifted into the strong zone
|
|
# strictly monotonic across the range (ordering never lies)
|
|
vals = [R.calibrate(x) for x in range(50, 101, 5)]
|
|
assert all(b > a for a, b in zip(vals, vals[1:]))
|