Merge the location gate that rejects on evidence only, judging an agent with a CV alone, extract reading a role again when its text arrives, and rail counts that follow the fetch gate (wp-rev-core)
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
commit
c3c527dc6c
11 files changed
+402
-82
No files matched your search
@@ -130,6 +130,46 @@ def test_the_next_upsert_keeps_what_extract_filled(
|
||||
assert role is not None and (role.country, role.seniority) == ("DE", "mid")
|
||||
|
||||
|
||||
def test_a_role_read_from_its_title_is_read_again_once_its_text_arrives(
|
||||
store: Store, config: Config, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""Fetch text stores what a page filled through `upsert_role`: a better
|
||||
text than the role was read from puts it back in extract's queue, its
|
||||
tries forgiven, and a pull that brings no better text does not."""
|
||||
bare = posting("1")
|
||||
bare.body = ""
|
||||
upsert(store, bare)
|
||||
ranked(store, bare)
|
||||
stub(monkeypatch, lambda roles: [answer(r["uid"], seniority="mid", function="sales")
|
||||
for r in roles])
|
||||
modeltask.run(extract.TASK, config, store)
|
||||
with store.transaction() as conn:
|
||||
conn.execute("UPDATE roles SET extract_tries = 2 WHERE source_id = '1'")
|
||||
|
||||
upsert(store, bare)
|
||||
assert store.extract_pending() == 0, "the same text again is no reason to read it"
|
||||
|
||||
upsert(store, posting("1", function="engineering"))
|
||||
|
||||
role = store.role(bare.uid)
|
||||
assert role is not None and role.extracted_at is None
|
||||
assert role.function == "sales", "the pull that brings the text keeps extract's function"
|
||||
assert [r.uid for r in store.extract_waiting(10)] == [bare.uid]
|
||||
with store.transaction() as conn:
|
||||
assert conn.execute("SELECT extract_tries FROM roles WHERE uid = ?",
|
||||
(bare.uid,)).fetchone()[0] == 0
|
||||
model = stub(monkeypatch, lambda roles: [answer(r["uid"], seniority="senior")
|
||||
for r in roles])
|
||||
modeltask.run(extract.TASK, config, store)
|
||||
[[sent]] = model.asked
|
||||
assert sent["text"] == "We pay 80.000-95.000 EUR. Hybrid in Berlin."
|
||||
role = store.role(bare.uid)
|
||||
assert role is not None and role.extracted_at is not None
|
||||
assert (role.seniority_model, role.seniority) == ("senior", "senior")
|
||||
|
||||
upsert(store, posting("1"))
|
||||
assert store.extract_pending() == 0, "a text no better than before is read once"
|
||||
|
||||
|
||||
def test_closed_and_answered_roles_are_not_offered(
|
||||
store: Store, config: Config, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
for sid in ("open", "closed", "done"):
|
||||
|
||||
@@ -237,6 +237,24 @@ def test_a_batch_stores_what_the_pages_filled_and_drops_those_vectors(
|
||||
assert again.place == "Copenhagen"
|
||||
|
||||
|
||||
def test_a_role_extract_read_without_text_waits_for_it_again_once_its_page_is_read(
|
||||
store: Store, tmp_path: Path, web: dict[str, Any]) -> None:
|
||||
"""Extract read the title alone; the page's text puts the role back in
|
||||
its queue, and a page that gave nothing leaves it read."""
|
||||
board(store, "fake:acme")
|
||||
filled, empty = (role(store, "fake:acme", n) for n in ("1", "2"))
|
||||
with store.transaction() as conn:
|
||||
conn.execute("UPDATE roles SET extracted_at = '2026-09-22T00:00:00+00:00', "
|
||||
"extract_tries = 1")
|
||||
web["answers"].update({f"{BASE}/acme/1": b"Python in full"})
|
||||
|
||||
fetch_text.run_batch(config(tmp_path), store, target="fake:acme", uids=[filled, empty])
|
||||
|
||||
first, second = store.role(filled), store.role(empty)
|
||||
assert first is not None and first.extracted_at is None
|
||||
assert second is not None and second.extracted_at == "2026-09-22T00:00:00+00:00"
|
||||
|
||||
|
||||
def test_a_board_switched_off_since_the_plan_reads_nothing(
|
||||
store: Store, tmp_path: Path, web: dict[str, Any]) -> None:
|
||||
sub = board(store, "fake:acme")
|
||||
|
||||
@@ -343,8 +343,9 @@ def test_a_place_gate_matches_over_the_gazetteer(store: Store,
|
||||
several: dict[str, str]) -> None:
|
||||
found = gates(store, Gate(field="place", values=["Malmö", "Lund", "oberkochen"],
|
||||
mode="any"))
|
||||
# "Remote (SE)" is placed at Sweden, which holds Malmö: no evidence against.
|
||||
assert {uid for uid, g in found.items() if g == 1} == {
|
||||
several["malmo"], several["lund"], several["zeiss"]}
|
||||
several["malmo"], several["lund"], several["zeiss"], several["remote"]}
|
||||
|
||||
|
||||
# ------------------------------------------------------------ unresolved texts
|
||||
|
||||
+19
-3
@@ -194,12 +194,28 @@ def hashlib_old_key(agent: Any, text: str) -> str:
|
||||
return hashlib.sha1(blob.encode()).hexdigest()[:16]
|
||||
|
||||
|
||||
def test_only_enabled_agents_with_a_cv_and_a_prompt_are_judged(store: Store) -> None:
|
||||
def test_only_enabled_agents_with_a_cv_are_judged(store: Store) -> None:
|
||||
for name, kwargs in (("No CV", {"cv": " "}), ("Off", {"enabled": False})):
|
||||
ranked(store, hunter(store, name, **kwargs), name)
|
||||
bare = store.save_agent("No prompt", cv_text=CV)
|
||||
ranked(store, bare, "bare")
|
||||
assert judge.waiting(store) == []
|
||||
[uid] = ranked(store, bare, "bare")
|
||||
assert [(a.id, row["uid"]) for a, row, _, _ in judge.waiting(store)] == [(bare.id, uid)]
|
||||
|
||||
|
||||
def test_an_agent_without_a_prompt_is_judged_without_wants(
|
||||
store: Store, config: Config, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""A CV alone is enough: the cut is the CV list, and the profile has no
|
||||
`<wants>` block."""
|
||||
bare = store.save_agent("No prompt", cv_text=CV)
|
||||
[uid] = ranked(store, bare, "1")
|
||||
model = stub(monkeypatch)
|
||||
|
||||
modeltask.run(judge.TASK, config, store)
|
||||
|
||||
found = store.judgement(bare.id, uid)
|
||||
assert found is not None and (found.skills, found.experience, found.career) == (8, 7, 9)
|
||||
[system] = model.systems
|
||||
assert CV in system and "<wants" not in system
|
||||
|
||||
|
||||
def test_the_agents_cut_is_what_is_read_by_fit_then_cv_then_kept(store: Store) -> None:
|
||||
|
||||
@@ -15,7 +15,7 @@ import pytest
|
||||
|
||||
from desk.models import Item
|
||||
from app import places, prep
|
||||
from app.jobs import extract, reach
|
||||
from app.jobs import extract, reach, score
|
||||
from app.models import Agent, Gate
|
||||
from app.places import Gazetteer, label, known, parse, seed, suggest
|
||||
from app.prep import words
|
||||
@@ -468,6 +468,10 @@ def test_the_api_suggests_labels_and_filters_the_remote_tokens(tmp_path: Path) -
|
||||
prep.run(store, dupes=False)
|
||||
agent = store.save_agent("Europe", "python backend", [
|
||||
Gate(field="country", values=EUROPE, mode="require")])
|
||||
# Scored as `score` would, since a named agent's counts are its feed's.
|
||||
store.replace_scores(agent.id, [
|
||||
(c.uid, 0.5, ", ".join(score.failed_gates(c, agent.gates)))
|
||||
for c in store.score_candidates(agent.id, agent.gates)])
|
||||
with TestClient(app) as client:
|
||||
found = client.get("/api/suggest/places", params={"q": "remote"}).json()
|
||||
assert found[0] == {"token": "remote:any", "label": "Remote", "kind": "remote",
|
||||
|
||||
+125
-3
@@ -346,9 +346,113 @@ def test_any_gates_are_one_group_a_role_must_match_one_of(
|
||||
assert scores[copenhagen][1] == "" and scores[remote_de][1] == ""
|
||||
assert scores[onsite_de] == (0.0, "none of country DK, remote remote")
|
||||
assert scores[blank][1] == ""
|
||||
# "Hybrid" is a country-less line the remote lookup reads as hybrid, so
|
||||
# the group has evidence against remote and none for country: gated.
|
||||
assert scores[hybrid_nowhere][1].startswith("none of")
|
||||
# "Hybrid" is a country-less line the remote lookup reads as hybrid: the
|
||||
# role may still be in Denmark, so it passes until extract reads it.
|
||||
assert scores[hybrid_nowhere][1] == ""
|
||||
|
||||
|
||||
def test_an_unknown_location_passes_the_any_group_whatever_its_remote(
|
||||
store: Store, config: Config, fake: FakeEmbedder) -> None:
|
||||
"""A place line the gazetteer cannot resolve is no evidence the role is
|
||||
elsewhere, for the country and for the place gate: the role passes,
|
||||
hybrid or not. One whose unknown line names a gate value by whole words
|
||||
matches it, and a role in a resolved place elsewhere is still gated, its
|
||||
remote unknown or not."""
|
||||
jobbank = role(store, "1", place="Storkøbenhavn; Udlandet (øvrige)", remote="hybrid")
|
||||
office = role(store, "2", place="Fleet Place Office", remote="onsite")
|
||||
avedore = role(store, "3", place="Avedøre Holme")
|
||||
berlin = role(store, "4", place="Berlin, Germany")
|
||||
berlin_hybrid = role(store, "5", place="Berlin, Germany", remote="hybrid")
|
||||
agent = store.save_agent("Malmö, Avedøre or remote", "", [
|
||||
Gate(field="country", values=["SE"], mode="any"),
|
||||
Gate(field="remote", values=["remote"], mode="any"),
|
||||
Gate(field="place", values=["Malmö", "Avedøre Holme"], mode="any")])
|
||||
|
||||
run(config, store, score.run_score)
|
||||
|
||||
states = {c.uid: c.gates for c in store.score_candidates(agent.id, agent.gates)}
|
||||
assert states[jobbank] == [-1, 0, -1] and states[office] == [-1, 0, -1]
|
||||
assert states[avedore] == [-1, -1, 1]
|
||||
assert states[berlin] == [0, -1, 0]
|
||||
scores = store.scores(agent.id)
|
||||
assert all(scores[uid][1] == "" for uid in (jobbank, office, avedore))
|
||||
reason = "none of country SE, remote remote, place Malmö / Avedøre Holme"
|
||||
assert scores[berlin] == (0.0, reason) and scores[berlin_hybrid] == (0.0, reason)
|
||||
|
||||
|
||||
def test_a_remote_only_group_still_gates_a_hybrid_role(
|
||||
store: Store, config: Config, fake: FakeEmbedder) -> None:
|
||||
"""With no country or place in the group, remote is the only evidence:
|
||||
a hybrid role is gated, one whose remote is unknown passes."""
|
||||
hybrid = role(store, "1", place="Headquarters", remote="hybrid")
|
||||
unknown = role(store, "2", place="Headquarters")
|
||||
agent = store.save_agent("Remote", "", [Gate(field="remote", values=["remote"], mode="any")])
|
||||
|
||||
run(config, store, score.run_score)
|
||||
|
||||
scores = store.scores(agent.id)
|
||||
assert scores[hybrid] == (0.0, "none of remote remote")
|
||||
assert scores[unknown][1] == ""
|
||||
|
||||
|
||||
def test_a_region_that_holds_the_agents_places_is_no_evidence_against(
|
||||
store: Store, config: Config, fake: FakeEmbedder) -> None:
|
||||
"""Øresund holds the Capital Region and Skåne, so a role placed only
|
||||
there meets a gate on Denmark and one on Copenhagen; Berlin meets
|
||||
neither. The feed's Place filter still reads only what lies under."""
|
||||
oresund = role(store, "1", place="Øresundsregionen", remote="onsite")
|
||||
berlin = role(store, "2", place="Berlin, Germany", remote="onsite")
|
||||
by_country = store.save_agent("Denmark", "", [
|
||||
Gate(field="country", values=["DK"], mode="any")])
|
||||
by_town = store.save_agent("Copenhagen", "", [
|
||||
Gate(field="place", values=["copenhagen"], mode="any")])
|
||||
world = store.save_agent("Denmark only", "", [Gate(field="country", values=["DK"])])
|
||||
|
||||
run(config, store, score.run_score)
|
||||
|
||||
for agent in (by_country, by_town, world):
|
||||
scores = store.scores(agent.id)
|
||||
assert scores[oresund][1] == ""
|
||||
assert scores[berlin][1] != ""
|
||||
assert oresund not in {r.uid for r in store.roles(places=["country:DK"])}
|
||||
|
||||
|
||||
def test_a_wider_place_beside_a_place_elsewhere_is_no_match(
|
||||
store: Store, config: Config, fake: FakeEmbedder) -> None:
|
||||
"""Europe alone is no evidence against Denmark; `London; Europe` is in
|
||||
London, and `Aarhus; Denmark` is not in Copenhagen."""
|
||||
europe = role(store, "1", place="Europe", remote="onsite")
|
||||
london = role(store, "2", place="London; Europe", remote="onsite")
|
||||
aarhus = role(store, "3", place="Aarhus; Denmark", remote="onsite")
|
||||
denmark = role(store, "4", place="Denmark", remote="onsite")
|
||||
by_country = store.save_agent("Denmark", "", [
|
||||
Gate(field="country", values=["DK"], mode="any")])
|
||||
by_town = store.save_agent("Copenhagen", "", [
|
||||
Gate(field="place", values=["copenhagen"], mode="any")])
|
||||
|
||||
run(config, store, score.run_score)
|
||||
|
||||
scores = store.scores(by_country.id)
|
||||
assert scores[europe][1] == "" and scores[aarhus][1] == "" and scores[denmark][1] == ""
|
||||
assert scores[london] == (0.0, "none of country DK")
|
||||
scores = store.scores(by_town.id)
|
||||
assert scores[europe][1] == "" and scores[denmark][1] == ""
|
||||
assert scores[london] == (0.0, "none of place copenhagen")
|
||||
assert scores[aarhus] == (0.0, "none of place copenhagen")
|
||||
|
||||
|
||||
def test_a_country_that_holds_the_agents_town_is_no_match_for_a_role_placed_elsewhere(
|
||||
store: Store, config: Config, fake: FakeEmbedder) -> None:
|
||||
"""Sweden holds Malmö, yet a role in Stockholm is evidence against it."""
|
||||
stockholm = role(store, "1", place="Stockholm, Sweden", remote="onsite")
|
||||
malmo = role(store, "2", place="Malmö, Sweden", remote="onsite")
|
||||
agent = store.save_agent("Malmö", "", [Gate(field="place", values=["Malmö"], mode="any")])
|
||||
|
||||
run(config, store, score.run_score)
|
||||
|
||||
scores = store.scores(agent.id)
|
||||
assert scores[stockholm] == (0.0, "none of place Malmö")
|
||||
assert scores[malmo][1] == ""
|
||||
|
||||
|
||||
def test_failed_gates_reads_evidence_only() -> None:
|
||||
@@ -365,6 +469,24 @@ def test_failed_gates_reads_evidence_only() -> None:
|
||||
"none of remote remote, seniority senior"]
|
||||
|
||||
|
||||
def test_an_any_group_with_every_place_member_empty_does_not_fail() -> None:
|
||||
"""Remote is no evidence against a role whose location is unknown; a
|
||||
known location elsewhere is, also with remote unknown."""
|
||||
gates = [Gate(field="country", values=["DK"], mode="any"),
|
||||
Gate(field="remote", values=["remote"], mode="any"),
|
||||
Gate(field="place", values=["Malmö"], mode="any")]
|
||||
def cand(*states: int) -> Candidate:
|
||||
return Candidate(uid="u", posted_at=NOW.isoformat(), gates=list(states))
|
||||
assert score.failed_gates(cand(-1, 0, -1), gates) == []
|
||||
assert score.failed_gates(cand(0, -1, -1), gates) == [
|
||||
"none of country DK, remote remote, place Malmö"]
|
||||
assert score.failed_gates(cand(-1, -1, 0), gates) == [
|
||||
"none of country DK, remote remote, place Malmö"]
|
||||
remote_only = [Gate(field="remote", values=["remote"], mode="any")]
|
||||
assert score.failed_gates(cand(0), remote_only) == ["none of remote remote"]
|
||||
assert score.failed_gates(cand(-1), remote_only) == []
|
||||
|
||||
|
||||
def test_a_gate_is_require_any_or_exclude_and_has_no_weight() -> None:
|
||||
"""Prefer gates left the agent: hybrid is a feed filter now."""
|
||||
with pytest.raises(ValidationError):
|
||||
|
||||
+34
-1
@@ -219,11 +219,44 @@ def test_suggest_companies_folds_the_name_and_leaves_out_the_hidden(
|
||||
assert [c["name"] for c in suggest("big da")] == ["Big Data Corp"]
|
||||
assert [c["name"] for c in suggest("data", limit=1)] == ["Big Data Corp"]
|
||||
assert suggest("") == []
|
||||
# Another agent hid nothing.
|
||||
# Another agent hid nothing; named, it counts what its feed shows.
|
||||
other = store.save_agent("B")
|
||||
store.replace_scores(other.id, [(r.uid, 0.5, "") for r in store.roles()])
|
||||
assert "Hidden Data" in [c["name"] for c in suggest("data", agent=other.id)]
|
||||
|
||||
|
||||
def test_a_named_agents_rail_counts_are_what_its_feed_shows(
|
||||
client: TestClient, store: Store) -> None:
|
||||
"""Tag, company and place counts, "Remote" included, cover the roles the
|
||||
feed lists for a named agent: past its fetch gate, of a company it has
|
||||
not hidden. Without one they count as before."""
|
||||
for sid in "1234":
|
||||
upsert(store, posting(sid, company="Gone" if sid == "4" else "Acme",
|
||||
place="Malmö", remote="remote"))
|
||||
uid = {r.source_id: r.uid for r in store.roles()}
|
||||
for one in uid.values():
|
||||
store.set_tags(one, ["python"])
|
||||
store.save_agent("Default")
|
||||
agent = store.save_agent("A")
|
||||
store.replace_scores(agent.id, [(uid["1"], 0.5, ""), (uid["2"], 0.4, ""),
|
||||
(uid["3"], 0.0, "title sales"), (uid["4"], 0.3, "")])
|
||||
store.set_affinity(agent.id, "gone", -1)
|
||||
|
||||
def counts(**params: Any) -> tuple[int, int, int, int]:
|
||||
tags = client.get("/api/filters", params=params).json()["tags"]
|
||||
[acme] = client.get("/api/suggest/companies", params={"q": "acme", **params}).json()
|
||||
malmo = client.get("/api/suggest/places", params={"q": "malm", **params}).json()
|
||||
remote = client.get("/api/suggest/places", params={"q": "remote", **params}).json()
|
||||
return (tags[0]["count"], acme["count"],
|
||||
next(s["count"] for s in malmo if s["token"] == "place:malmo"),
|
||||
next(s["count"] for s in remote if s["token"] == "remote:any"))
|
||||
|
||||
feed = client.get("/api/roles", params={"agent": agent.id, "order": "newest"}).json()
|
||||
assert feed["total"] == 2
|
||||
assert counts(agent=agent.id) == (2, 2, 2, 2)
|
||||
assert counts() == (4, 3, 4, 4)
|
||||
|
||||
|
||||
def test_suggest_places_and_read_labels_back(client: TestClient, store: Store) -> None:
|
||||
for sid, place in (("1", "Malmö"), ("2", "Malmö"), ("3", "Lund"),
|
||||
("4", "København K"), ("5", "Kolding")):
|
||||
|
||||
Reference in new issue
Block a user