Gate a favourite by the require gates and drop its 0.9 floor

A favourite company skips the any group only; a require gate it fails
gates it with the usual reason. Its score is the weighted sum with the
affinity term at 1, and weights that sum to 0 give "no weights" as for
every other company.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
WolfandClaude committed 2026-09-29 21:52:26 +02:00
1 parent 64f367cc18
commit 3ab8035d0d
2 files changed
+101 -18

No files matched your search

+93 -4
View File
@@ -379,17 +379,106 @@ def test_a_prefer_gate_adds_its_weight_to_the_score(
assert scores[office][1] == ""
def test_a_favourite_skips_the_gates_and_is_floored(
def test_a_favourite_is_gated_by_a_require_gate_it_fails(
store: Store, config: Config, fake: FakeEmbedder) -> None:
"""A star widens the search to the company, not past a require gate: the
Munich role of a starred company is gated like anyone's."""
store.add_company("Fave")
fave = role(store, "1", company="Fave", place="Munich")
munich = role(store, "1", company="Fave", place="Munich")
berlin = role(store, "2", company="Fave", place="Berlin")
agent = store.save_agent("Berlin", "", [Gate(field="place", values=["Berlin"])])
store.set_affinity(agent.id, "fave", 2)
run(config, store, score.run_score)
value, reason = store.scores(agent.id)[fave]
assert reason == "" and value >= 0.9
scores = store.scores(agent.id)
assert scores[munich] == (0.0, "place not Berlin")
assert scores[berlin][1] == "" and scores[berlin][0] > 0
def test_a_favourite_passes_the_any_group_others_fail(
store: Store, config: Config, fake: FakeEmbedder) -> None:
""""Denmark or remote" gates the onsite German role of a neutral company
and lets the same role of a starred one through."""
store.add_company("Fave")
fave = role(store, "1", company="Fave", place="Berlin, Germany", remote="onsite")
other = role(store, "2", company="Other", place="Berlin, Germany", remote="onsite")
agent = store.save_agent("Copenhagen or remote", "", [
Gate(field="country", values=["DK"], mode="any"),
Gate(field="remote", values=["remote"], mode="any")])
store.set_affinity(agent.id, "fave", 2)
run(config, store, score.run_score)
scores = store.scores(agent.id)
assert scores[fave][1] == "" and scores[fave][0] > 0
assert scores[other] == (0.0, "none of country DK, remote remote")
def test_a_favourite_takes_both_halves_of_the_rule_in_one_agent() -> None:
gates = [Gate(field="country", values=["DK"]),
Gate(field="remote", values=["remote"], mode="any"),
Gate(field="seniority", values=["senior"], mode="any")]
def cand(affinity: int, *states: int) -> Candidate:
return Candidate(uid="u", posted_at=NOW.isoformat(), affinity=affinity,
gates=list(states))
# The any group fails for both; only the neutral company is gated by it.
assert score.failed_gates(cand(2, 1, 0, 0), gates) == []
assert score.failed_gates(cand(0, 1, 0, 0), gates) == [
"none of remote remote, seniority senior"]
# The require gate fails for both.
assert score.failed_gates(cand(2, 0, 0, 0), gates) == ["country not DK"]
assert score.failed_gates(cand(0, 0, 0, 0), gates) == [
"country not DK", "none of remote remote, seniority senior"]
def test_a_favourite_with_an_empty_column_is_not_gated() -> None:
"""A require gate rejects on evidence only, for a favourite as for anyone."""
gates = [Gate(field="country", values=["DK"])]
candidate = Candidate(uid="u", posted_at=NOW.isoformat(), affinity=2, gates=[-1])
assert score.failed_gates(candidate, gates) == []
value, reason = score.score_one(candidate, gates, Weights(), 0.5, NOW)
assert reason == "" and value > 0
def test_a_favourite_ranks_above_the_same_role_of_a_neutral_company(
store: Store, config: Config, fake: FakeEmbedder) -> None:
store.add_company("Fave")
fave = role(store, "1", company="Fave", body="python backend")
other = role(store, "2", company="Other", body="python backend")
agent = store.save_agent("Backend", "python backend")
store.set_affinity(agent.id, "fave", 2)
run(config, store, score.run_score)
scores = store.scores(agent.id)
assert scores[fave][1] == "" == scores[other][1]
# Same age, and no vectors here, so fit is out and recency and affinity
# share the weight: the affinity term alone (1 against 1/3) is the gap.
assert scores[fave][0] - scores[other][0] == pytest.approx(0.5 * (1 - 1 / 3), abs=1e-5)
def test_a_favourite_is_the_weighted_sum_with_its_affinity_at_one() -> None:
"""No floor: a stale, poorly fitting role of a favourite scores what its
terms say, well under the old 0.9."""
stale = (NOW - timedelta(days=28)).isoformat()
candidate = Candidate(uid="u", posted_at=stale, affinity=2)
value, reason = score.score_one(candidate, [], Weights(), 0.0, NOW)
assert reason == ""
assert value == pytest.approx((0.2 * 0.25 + 0.2 * 1.0) / 1.0)
assert value < 0.9
# A perfect role is not lifted to anything but 1.
fresh = Candidate(uid="u", posted_at=NOW.isoformat(), affinity=2)
assert score.score_one(fresh, [], Weights(), 1.0, NOW)[0] == pytest.approx(1.0)
def test_a_favourite_with_no_weights_is_scored_like_any_other_company() -> None:
"""Weights that sum to 0 leave nothing to average: 0 with a reason, not a
number a favourite alone would get."""
none = Weights(fit=0, recency=0, affinity=0, taste=0)
for affinity in (0, 2):
candidate = Candidate(uid="u", posted_at=NOW.isoformat(), affinity=affinity)
assert score.score_one(candidate, [], none, None, NOW) == (0.0, "no weights")
def test_a_hidden_company_is_never_scored_for_the_agent_that_hid_it(