"""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:]))