"""A1 โ€” sift: rank-fusion math + graceful degradation when the vibe-engineer is unavailable. (Offline โ€” no network; the embedding path is exercised in the cached e2e verification.)""" from app.engine import sift as S def test_ranks_normalization(): r = S._ranks({"a": 0.9, "b": 0.5, "c": 0.1}) assert r["a"] == 1.0 and r["c"] == 0.0 and 0.0 < r["b"] < 1.0 assert S._ranks({"x": 0.5}) == {"x": 1.0} # single item โ†’ top def test_sift_degrades_to_whitebox_when_no_vibe(monkeypatch): monkeypatch.setattr(S._embed, "vibe_scores", lambda *a, **k: None) # embeddings unavailable jobs = [{"id": str(i), "title": "Product Manager", "organization": "X", "location_city": "New Delhi", "location_country": "India", "details": {"description": "product manager roadmap"}} for i in range(30)] prefs = {"title": "Product Manager", "location": ["New Delhi ยท India"]} top, dbg = S.sift(prefs, None, jobs, k=18) assert dbg["mode"] == "whitebox-only" and len(top) == 18 assert all("match" in j for j in top) # white-box match block rides along def test_sift_empty_input(): top, dbg = S.sift({"title": "PM"}, None, [], k=18) assert top == [] and dbg["mode"] == "empty"