Lead a role in several cities with the one nearest the viewing agent, in the row, the reader and the posting link
Places are ordered in tiers off the agent's gates (the any group, then the require scope, then the rest), and within a tier by the home the any group gives, since the gazetteer holds no coordinates. GET /api/roles and /api/roles/{uid} carry place_texts, lead_place and lead_url for the roles served; the gates and the dupes rule are unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ac4cdb8a48
commit
fb24c8e4c9
8 files changed
+277
-29
No files matched your search
@@ -301,3 +301,36 @@ def test_switching_a_board_off_shows_its_roles_copies_at_once(store: Store) -> N
|
||||
|
||||
set_fetch(store, sub.id, False)
|
||||
assert dup_of(store) == {board.uid: None, search.uid: None}
|
||||
|
||||
|
||||
def test_a_role_in_several_cities_leads_with_the_one_nearest_the_agent(store: Store) -> None:
|
||||
"""Mistral posts one role per city. For an agent kept to Europe the kept
|
||||
Montréal role leads with Paris, in the row and the reader, and opens the
|
||||
Paris copy; without an agent the host's order stands."""
|
||||
from app import prep
|
||||
from app.models import Gate
|
||||
items = [role(c, company="Mistral AI", place=p, board="ashby") for c, p in (
|
||||
("mtl", "Montréal"), ("nyc", "New York"), ("par", "Paris"))]
|
||||
for item in items:
|
||||
store.upsert_role(item)
|
||||
prep.run(store)
|
||||
kept = kept_of(store, *items)
|
||||
agent = store.save_agent("A", gates=[
|
||||
Gate(field="country", values=["FR", "DK", "EU"], mode="require"),
|
||||
Gate(field="country", values=["DK"], mode="any")])
|
||||
|
||||
got = store.role(kept, agent.id)
|
||||
assert got is not None
|
||||
own = next(p.text for p in got.places if not p.url)
|
||||
assert own != "Paris"
|
||||
assert (got.lead_place, got.lead_url) == ("Paris", "https://jobs.example/par")
|
||||
assert got.places[0].text == "Paris"
|
||||
(row,) = store.roles_page(agent=agent.id, by_score=False)
|
||||
assert (row.place, row.lead_place, row.lead_url) == ("Paris +2", "Paris", got.lead_url)
|
||||
assert row.place_texts[0] == "Paris" and len(row.place_texts) == 3
|
||||
|
||||
plain = store.role(kept)
|
||||
assert plain is not None
|
||||
assert plain.lead_place == own and plain.lead_url == ""
|
||||
(row,) = store.roles_page(by_score=False)
|
||||
assert row.place == f"{own} +2" and row.lead_url == ""
|
||||
@@ -429,3 +429,62 @@ def test_the_gazetteer_finds_what_the_words_found(
|
||||
by_places = uids(store, token)
|
||||
lost = {lines[uid][0] for uid in by_words - by_places}
|
||||
assert lost <= NOT_FOUND_ANY_MORE.get(token, set()), (token, lost)
|
||||
|
||||
|
||||
# ------------------------------------------------------------------ nearness
|
||||
|
||||
#: Agent 2's place gates: Europe as its scope, Denmark, Sweden, remote and
|
||||
#: the Øresund towns as its `any` group.
|
||||
EUROPE_DK_SE = [
|
||||
Gate(field="country", values=["DK", "FR", "DE", "IE", "SE", "GB", "EU"], mode="require"),
|
||||
Gate(field="country", values=["DK", "SE"], mode="any"),
|
||||
Gate(field="remote", values=["remote"], mode="any"),
|
||||
Gate(field="place", values=["Malmö", "copenhagen"], mode="any"),
|
||||
Gate(field="remote", values=["hybrid"], mode="prefer", weight=0.05),
|
||||
]
|
||||
|
||||
|
||||
def nearest(gates: list[Gate] | None, *texts: str) -> list[str]:
|
||||
gaz = gazetteer()
|
||||
near = places.Nearness(gaz, gates) if gates is not None else None
|
||||
entries = [(t, list(gaz.resolve(t)) or [None]) for t in texts]
|
||||
return [texts[i] for i in places.nearest_first(near, entries)]
|
||||
|
||||
|
||||
def test_a_place_in_the_scope_leads_the_ones_outside_it() -> None:
|
||||
"""Mistral's role in Montréal, Abu Dhabi, New York and Paris is a Paris
|
||||
role for an agent kept to Europe; the others keep the host's order."""
|
||||
assert nearest(EUROPE_DK_SE, "Montréal", "Abu Dhabi", "New York", "Paris") == [
|
||||
"Paris", "Montréal", "Abu Dhabi", "New York"]
|
||||
assert nearest(EUROPE_DK_SE, "San Francisco", "Dublin, Ireland") == [
|
||||
"Dublin, Ireland", "San Francisco"]
|
||||
|
||||
|
||||
def test_the_any_group_leads_the_scope_and_the_home_leads_the_group() -> None:
|
||||
"""Copenhagen, Stockholm and Malmö meet the `any` group, London and
|
||||
Lisbon only the scope; Denmark, the group's first value, is the home, so
|
||||
a Danish place leads the group."""
|
||||
assert nearest(EUROPE_DK_SE, "London", "Stockholm, Sweden", "Lisbon", "Copenhagen") == [
|
||||
"Copenhagen", "Stockholm, Sweden", "London", "Lisbon"]
|
||||
assert nearest(EUROPE_DK_SE, "London", "Malmö", "Copenhagen, Denmark") == [
|
||||
"Copenhagen, Denmark", "Malmö", "London"]
|
||||
|
||||
|
||||
def test_a_town_of_the_group_in_the_home_leads_the_rest_of_the_home() -> None:
|
||||
"""Copenhagen is one of the group's towns and in Denmark, so it leads
|
||||
"Denmark" and Billund, which lead Stockholm."""
|
||||
assert nearest(EUROPE_DK_SE, "Stockholm", "Denmark", "Billund", "Copenhagen") == [
|
||||
"Copenhagen", "Denmark", "Billund", "Stockholm"]
|
||||
|
||||
|
||||
def test_a_remote_place_is_near_by_its_area() -> None:
|
||||
"""A remote area within the scope meets the plain remote gate; one outside
|
||||
it, and "Remote" with no area, come last."""
|
||||
assert nearest(EUROPE_DK_SE, "Remote US", "Remote", "Berlin", "Remote - Europe") == [
|
||||
"Remote - Europe", "Berlin", "Remote US", "Remote"]
|
||||
|
||||
|
||||
def test_without_an_agent_or_its_gates_the_hosts_order_stands() -> None:
|
||||
texts = ("Montréal", "New York", "Paris")
|
||||
assert nearest(None, *texts) == list(texts)
|
||||
assert nearest([], *texts) == list(texts)
|
||||
+1
-1
@@ -1231,7 +1231,7 @@ def test_list_roles_serves_the_row_projection_and_not_the_big_columns(
|
||||
"seniority", "salary_min", "salary_max", "currency", "salary_text", "salary_state",
|
||||
"original_url", "posting_url", "posted_at", "score", "gated_reason", "prompt", "vote",
|
||||
"voted_at", "read_at", "tags", "excerpt", "copies", "remote_where", "deadline",
|
||||
"lang_flag", "lang_note", "cv_score", "cv_fit",
|
||||
"lang_flag", "lang_note", "cv_score", "cv_fit", "place_texts", "lead_place", "lead_url",
|
||||
}
|
||||
assert row["uid"] == uid
|
||||
assert row["company"] == "Acme" and row["place"] == "Berlin, Germany"
|
||||
|
||||
Reference in new issue
Block a user