Test migration 32, the cut, saved filters and the override rescore, and bring the READMEs and config comments to fetch text and the cut

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Opus 5.5 committed 2026-10-04 15:16:38 +02:00
1 parent 617356e60c
commit 8b6c6d5ac3
9 files changed
+260 -37

No files matched your search

+70 -1
View File
@@ -23,7 +23,7 @@ from pipeline import FINAL, JOBS, SCHEDULES, TASKS, JobQueue, Jobs, RunContext,
from plugins.ats import ATSSource # noqa: E402
from app.config import CALIBRATION, AgentSeed, Config, ConfigError # noqa: E402
from app.jobs import cascade, embed, score # noqa: E402
from app.models import Candidate, Gate, Limits, Prompt, Weights # noqa: E402
from app.models import Application, Candidate, Gate, Limits, Prompt, Weights # noqa: E402
from app.storage import Store # noqa: E402
from prepped import upsert # noqa: E402
@@ -991,6 +991,75 @@ def test_without_an_embedder_the_prompts_are_skipped_and_fit_is_out(
assert store.scores(agent.id) == {uid: (0.0, "no prompt vector")}
# --------------------------------------------------------------------- cut
def test_the_affinity_bonus_is_the_share_it_has_in_the_final_score() -> None:
w = Weights()
assert score.bonus(0, w) == 0
assert score.bonus(1, w) == pytest.approx(0.2 / 3 / 1.2) # about 0.056
assert score.bonus(2, w) == pytest.approx(0.4 / 3 / 1.2) # about 0.111
assert score.bonus(2, Weights(fit=0, recency=0, affinity=0, taste=0)) == 0
def _cands(*rows: tuple[str, str, int]) -> list[Candidate]:
"""`(uid, posted_at day, affinity)` as candidates."""
return [Candidate(uid=uid, posted_at=f"2026-09-{day}T00:00:00+00:00", affinity=affinity)
for uid, day, affinity in rows]
def test_the_cut_is_the_best_by_fit_then_by_cv_then_the_kept() -> None:
cands = _cands(("a", "10", 0), ("b", "11", 0), ("c", "12", 0), ("d", "13", 0),
("e", "14", 0), ("f", "15", 0), ("g", "16", 0))
fits = {"a": 0.9, "b": 0.8, "c": 0.7, "d": 0.65, "e": 0.3, "f": 0.2}
near = {"a": 0.99, "b": 0.1, "c": 0.1, "d": 0.75, "e": 0.8, "f": 0.5}
passed = {"a", "b", "c", "d", "e", "f"}
limits = Limits(cut_fit_top=2, cut_fit_min=0.6, cut_cv_top=2, cut_cv_min=0.6)
cut = score.cut_of(cands, passed, fits, near, {"f", "g", "b"}, Weights(), limits)
# a and b by fit; e and d the closest to the CV that those leave out (a,
# the closest of all, is in already); f kept; g kept but gated, so out.
assert cut == {"a": "fit", "b": "fit", "e": "cv", "d": "cv", "f": "kept"}
def test_the_minimum_stops_a_list_before_its_count() -> None:
cands = _cands(("a", "10", 0), ("b", "11", 0))
limits = Limits(cut_fit_top=500, cut_fit_min=0.6, cut_cv_top=150, cut_cv_min=0.6)
cut = score.cut_of(cands, {"a", "b"}, {"a": 0.61, "b": 0.59}, {"b": 0.59}, set(),
Weights(), limits)
assert cut == {"a": "fit"}
def test_affinity_lifts_a_level_over_the_minimum_but_is_no_pass() -> None:
cands = _cands(("liked", "10", 1), ("fave", "10", 2), ("plain", "10", 0),
("weak", "10", 2))
fits = {"liked": 0.56, "fave": 0.5, "plain": 0.59, "weak": 0.1}
cut = score.cut_of(cands, {c.uid for c in cands}, fits, {}, set(), Weights(),
Limits(cut_fit_min=0.6))
assert cut == {"liked": "fit", "fave": "fit"}
def test_a_tie_goes_to_the_newer_role_then_the_lower_uid() -> None:
cands = _cands(("b", "10", 0), ("a", "10", 0), ("old", "09", 0), ("new", "11", 0))
fits = dict.fromkeys(("a", "b", "old", "new"), 0.8)
cut = score.cut_of(cands, {c.uid for c in cands}, fits, {}, set(), Weights(),
Limits(cut_fit_top=3, cut_fit_min=0))
assert set(cut) == {"new", "a", "b"}
def test_a_like_and_a_save_put_a_role_in_the_cut_on_the_next_score(
store: Store, config: Config, fake: FakeEmbedder) -> None:
liked = role(store, "1", "Sales Manager", body="sales")
saved = role(store, "2", "Office Manager", body="office")
other = role(store, "3", "Barista", body="coffee")
agent = store.save_agent("Backend", "python backend",
limits=Limits(cut_fit_min=1, cut_cv_min=1))
store.set_vote(agent.id, liked, 1)
store.save_application(Application(role_uid=saved, role_title="Office Manager"))
run(config, store, embed.run_embed)
run(config, store, score.run_score)
assert store.cut(agent.id) == {liked: "kept", saved: "kept"}
assert other not in store.cut(agent.id)
def test_a_disabled_agent_is_not_scored(
store: Store, config: Config, fake: FakeEmbedder) -> None:
role(store, "1")