Tag a company All roles to read its big boards with the agents' wide reach; favourite scores only

Migration 21 adds companies.all_roles, tags every favourite of any agent and each company whose board had params {"reach": "all"} (logged per board, the param removed). reach.plan reads a tagged company's boards with the union of the enabled agents' require reach and the base reach; favourite no longer widens the fetch. POST /api/companies/{key}/all-roles sets it and queues a pull when on. The Companies list, the reader and the company strip draw the toggle beside the affinity buttons, the list filters on it, and the board's reach editor drops its All roles option.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Opus 5.5 committed 2026-09-30 10:44:41 +02:00
1 parent 8d9a059e24
commit 5d5b7e7d3f
20 files changed
+422 -124

No files matched your search

+40 -1
View File
@@ -147,7 +147,7 @@ def test_migration_20_seeds_an_old_file_and_leaves_collisions(tmp_path: Path) ->
"VALUES (?, ?, '', '')", (key, name))
conn.execute("PRAGMA user_version = 19")
reopened = Store(path)
assert reopened.migrations_applied == [20]
assert reopened.migrations_applied == [20, 21]
assert reopened.duplicate_companies() == [("orsted", ["orsted", "ørsted"])]
assert len(reopened.companies()) == 3
@@ -158,3 +158,42 @@ def test_the_step_runs_twice_without_harm(tmp_path: Path) -> None:
with sqlite3.connect(path) as conn:
undo_v20(conn)
_add_company_aliases(conn)
def test_migration_21_tags_the_favourites_and_the_boards_that_read_all_roles(tmp_path: Path) -> None:
path = tmp_path / "old.db"
store = Store(path)
store.add_company("Mistral AI")
store.add_company("Acme")
store.add_subscription("ats", "smartrecruiters:mistral", label="Mistral AI",
company="Mistral AI", board="smartrecruiters",
params={"reach": "all", "note": "kept"})
store.add_subscription("ats", "workday:acme", label="Acme", company="Acme",
board="workday", params={"countries": ["DK"]})
# A board whose company has no row: its params are cleaned, no flag lands.
store.add_subscription("ats", "greenhouse:ghost", label="Ghost", company="Ghost",
board="greenhouse", params={"reach": "all"})
# A favourite of any agent, enabled or not, is tagged: favourite no
# longer widens the fetch, the tag does.
store.add_company("Black Forest Labs")
store.add_company("Liked")
off = store.save_agent("Off", enabled=False)
store.set_affinity(off.id, "black-forest-labs", 2) # type: ignore[arg-type]
store.set_affinity(off.id, "liked", 1) # type: ignore[arg-type]
with sqlite3.connect(path) as conn:
conn.execute("ALTER TABLE companies DROP COLUMN all_roles")
conn.execute("PRAGMA user_version = 20")
reopened = Store(path)
assert reopened.migrations_applied == [21]
assert {c.key: c.all_roles for c in reopened.companies()} == {
"mistral-ai": 1, "acme": 0, "black-forest-labs": 1, "liked": 0}
params = {s.target: s.params for s in reopened.subscriptions(source="ats")}
assert params == {"smartrecruiters:mistral": {"note": "kept"},
"workday:acme": {"countries": ["DK"]}, "greenhouse:ghost": {}}
def test_a_merge_keeps_the_all_roles_tag(store: Store) -> None:
store.add_company("Mistral")
store.add_company("Mistral AI")
store.set_all_roles("mistral", True)
assert store.merge_companies("mistral-ai", "mistral").all_roles == 1
+1 -1
View File
@@ -246,7 +246,7 @@ def test_a_v17_file_gains_dup_of_with_its_first_rebuild(tmp_path: Path) -> None:
migrated = Store(path)
assert migrated.migrations_applied == [18, 19, 20]
assert migrated.migrations_applied == [18, 19, 20, 21]
assert dup_of(migrated) == {first.uid: None, second.uid: first.uid}
with sqlite3.connect(path) as conn:
assert conn.execute("SELECT 1 FROM sqlite_master WHERE name = 'idx_roles_dup_of'"
+81 -14
View File
@@ -1,5 +1,5 @@
"""The reach of a pull (`app.jobs.reach`): from the enabled agents' gates and
favourites to each board's `reach`, and through the pull's batches to the
All roles tags to each board's `reach`, and through the pull's batches to the
runner's `Ask`. No network: the runner's listing is stubbed."""
from __future__ import annotations
@@ -107,31 +107,72 @@ def test_the_require_reach_intersects_and_expands_europe(store: Store) -> None:
# ------------------------------------------------------------- per board
def test_a_favourite_is_read_across_the_require_reach(store: Store) -> None:
def test_a_company_tagged_all_roles_is_read_across_the_require_reach(store: Store) -> None:
_wolf(store)
_board(store, "workday:mistral.wd3/Jobs", "Mistral AI")
_board(store, "workday:acme.wd3/Jobs", "Acme")
store.set_all_roles("mistral-ai", True)
plan = reach.plan(store)
subs = {s.target.split(".")[0]: s for s in store.subscriptions(source="ats")}
wide, why = plan.why(subs["workday:mistral"])
# Europe, and the base's remote, which a tag never reads less than.
assert why == "tag" and {"DE", "FR", "DK"} <= wide.countries and wide.remote
assert reach.line(plan, subs["workday:mistral"]) == \
f"{len(wide.countries)} countries, remote · company tag"
assert plan.why(subs["workday:acme"]) == (plan.base, "agents")
def test_a_favourite_does_not_widen_the_fetch(store: Store) -> None:
wolf = _wolf(store)
_board(store, "smartrecruiters:mistral", "Mistral AI")
_board(store, "smartrecruiters:acme", "Acme")
store.set_affinity(wolf, "mistral-ai", 2)
plan = reach.plan(store)
subs = {s.target: s for s in store.subscriptions(source="ats")}
favourite, why = plan.why(subs["smartrecruiters:mistral"])
assert why == "favourite" and {"DE", "FR", "DK"} <= favourite.countries
assert plan.why(subs["smartrecruiters:acme"]) == (plan.base, "agents")
[sub] = store.subscriptions(source="ats")
assert plan.why(sub) == (plan.base, "agents")
def test_a_company_starred_by_one_agent_keeps_the_others_reach(store: Store) -> None:
wolf = _wolf(store)
@pytest.mark.parametrize("host", ["smartrecruiters", "successfactors", "eightfold"])
def test_a_tag_too_wide_for_a_one_host_reads_the_board_whole(store: Store, host: str) -> None:
_wolf(store)
_board(store, f"{host}:mistral", "Mistral AI")
store.set_all_roles("mistral-ai", True)
[sub] = store.subscriptions(source="ats")
assert reach.line(reach.plan(store), sub) == \
"all roles · company tag, too many countries to ask"
def test_a_tag_asks_phenom_for_europe_in_one_request(store: Store) -> None:
_wolf(store)
_board(store, "phenom:mistral", "Mistral AI")
store.set_all_roles("mistral-ai", True)
[sub] = store.subscriptions(source="ats")
found = reach.plan(store)
assert reach.line(found, sub) == f"{len(found.wide.countries)} countries · company tag"
def test_an_agent_without_a_required_place_makes_the_tag_everywhere(store: Store) -> None:
_wolf(store)
store.save_agent("Anywhere", gates=[Gate(field="country", values=["US"], mode="any")])
_board(store, "smartrecruiters:mistral", "Mistral AI")
store.set_affinity(wolf, "mistral-ai", 2)
favourite = reach.plan(store).favourites["mistral-ai"]
assert "US" in favourite.countries and "FR" in favourite.countries
_board(store, "workday:mistral.wd3/Jobs", "Mistral AI")
store.set_all_roles("mistral-ai", True)
plan = reach.plan(store)
[sub] = store.subscriptions(source="ats")
assert plan.why(sub) == (reach.EVERYWHERE, "tag")
assert plan.for_subscription(sub) is None
assert reach.line(plan, sub) == "all roles · company tag"
def test_a_boards_own_reach_wins_over_the_tag(store: Store) -> None:
_wolf(store)
_board(store, "workday:mistral.wd3/Jobs", "Mistral AI", params={"countries": ["FR"]})
store.set_all_roles("mistral-ai", True)
[sub] = store.subscriptions(source="ats")
assert reach.line(reach.plan(store), sub) == "FR · set here"
@pytest.mark.parametrize("size, params, why", [
(299, {}, "small"),
(None, {}, "unknown"),
(5000, {"reach": "all"}, "override"),
(5000, {"countries": ["DE"]}, "override"),
(300, {}, "agents"),
])
@@ -202,6 +243,32 @@ def test_the_pull_hands_each_board_its_reach_and_the_runner_narrows_it(
assert store.state["ats:size:smartrecruiters:BoschGroup"] == "1000"
def test_the_pull_reads_a_tagged_company_with_the_wide_reach(
store: Store, monkeypatch: pytest.MonkeyPatch) -> None:
_wolf(store)
_board(store, "phenom:jobs.mistral.ai/global/en", "Mistral AI")
_board(store, "smartrecruiters:bfl", "Black Forest Labs")
store.set_all_roles("mistral-ai", True)
store.set_all_roles("black-forest-labs", True)
asked: dict[str, Ask] = {}
def fake(module: object, slug: str, get: object, ask: Ask, **kwargs: object
) -> _runner.Listing:
asked[slug] = ask
return _runner.Listing([_row("1")], True, ["1"], _runner.filtered(ask)) # type: ignore[list-item]
monkeypatch.setattr(_runner, "read_listing", fake)
[batch] = _pull(store)
phenom = "phenom:jobs.mistral.ai/global/en"
assert set(batch["reach"]) == {phenom, "smartrecruiters:bfl"}
europe = set(batch["reach"][phenom]["countries"])
assert {"DE", "FR", "DK"} <= europe
assert set(asked["jobs.mistral.ai/global/en"].countries) == europe
# Europe is more series than SmartRecruiters is asked one by one: whole.
assert asked["bfl"] == Ask()
assert not store.state.get("ats:filtered:smartrecruiters:bfl")
def test_a_batch_queued_before_the_reach_existed_still_runs(
store: Store, monkeypatch: pytest.MonkeyPatch) -> None:
_board(store, "smartrecruiters:acme", "Acme")
-1
View File
@@ -242,7 +242,6 @@ def test_a_reach_too_wide_for_a_one_host_reads_it_unfiltered() -> None:
@pytest.mark.parametrize("params, expected", [
({"reach": "all"}, Ask()),
({"countries": ["DE"], "remote": False}, Ask(countries=("DE",))),
({"remote": True}, Ask(countries=("DK",), remote=True)),
])
+6 -6
View File
@@ -69,7 +69,7 @@ def test_schema_creates_on_an_empty_file(tmp_path: Path) -> None:
"application_events", "agents", "scores", "state"} <= tables
assert "idx_roles_cluster" in indexes
assert store.migrations_applied == []
assert LATEST == 20
assert LATEST == 21
# A second open finds it current and applies nothing.
assert Store(path).migrations_applied == []
@@ -186,7 +186,7 @@ def test_a_v14_file_gains_the_watchlist_columns_and_leaves_companies_unrated(
migrated = Store(path)
assert migrated.migrations_applied == [15, 16, 17, 18, 19, 20]
assert migrated.migrations_applied == [15, 16, 17, 18, 19, 20, 21]
acme = migrated.company("acme")
assert acme is not None
assert (acme.ats, acme.careers_url) == ("teamtailor", "https://a.example")
@@ -391,7 +391,7 @@ def test_v14_makes_each_intent_the_agents_one_prompt_with_its_vector(tmp_path: P
migrated = Store(path)
assert migrated.migrations_applied == [14, 15, 16, 17, 18, 19, 20]
assert migrated.migrations_applied == [14, 15, 16, 17, 18, 19, 20, 21]
assert migrated.agent(backend.id).prompts == [ # type: ignore[union-attr]
Prompt(name="Backend", text="python backend")]
assert migrated.agent(blank.id).prompts == [] # type: ignore[union-attr]
@@ -415,7 +415,7 @@ def test_v16_gives_a_company_no_reason_and_keeps_its_row(tmp_path: Path) -> None
migrated = Store(path)
assert migrated.migrations_applied == [16, 17, 18, 19, 20]
assert migrated.migrations_applied == [16, 17, 18, 19, 20, 21]
acme = migrated.company("acme")
assert acme is not None
assert (acme.careers_url, acme.notes, acme.hand_reason) == (
@@ -444,7 +444,7 @@ def test_v17_folds_every_place_and_levels_the_titles_extract_has_not_read(
migrated = Store(path)
assert migrated.migrations_applied == [17, 18, 19, 20]
assert migrated.migrations_applied == [17, 18, 19, 20, 21]
with sqlite3.connect(path) as conn:
rows = {uid: (fold, level) for uid, fold, level in conn.execute(
"SELECT uid, place_fold, seniority FROM roles")}
@@ -686,7 +686,7 @@ def test_v19_gives_every_role_its_places_and_splits_its_level(tmp_path: Path) ->
migrated = Store(path)
assert migrated.migrations_applied == [19, 20]
assert migrated.migrations_applied == [19, 20, 21]
assert [p.name for p in migrated.role_places(joined.uid)] == ["Copenhagen", "Malmö"]
assert [p.name for p in migrated.role_places(detailed.uid)] == ["Aarhus"]
assert migrated.role_places(stated.uid) == []
+2 -2
View File
@@ -537,7 +537,7 @@ def test_companies_lists_board_and_open_role_count(
"ats": "greenhouse", "ats_slug": "", "careers_url": "",
"country": "DK", "city": "", "domain": "", "watch": None,
"careers_opened_at": "", "failing_since": "", "failing_reason": "",
"from_search": False, "hand_reason": "", "by_hand": False,
"from_search": False, "hand_reason": "", "by_hand": False, "all_roles": False,
"reach_params": {}, "reach": "all roles · not read whole yet"}
[other] = [c for c in res.json() if c["key"] == "other"]
assert (other["board"], other["subscription_id"], other["on"], other["ats"]) == (
@@ -1387,7 +1387,7 @@ def test_a_company_is_added_by_hand_with_a_reason_and_a_link(
"ats": "", "ats_slug": "", "careers_url": "https://revolut.example/careers",
"country": "", "city": "", "watch": None, "careers_opened_at": "",
"failing_since": "", "failing_reason": "", "from_search": False,
"hand_reason": "added", "by_hand": True, "reach_params": {}, "reach": ""}
"hand_reason": "added", "by_hand": True, "all_roles": False, "reach_params": {}, "reach": ""}
assert store.company("revolut").hand_reason == "added" # type: ignore[union-attr]
other = client.post("/api/companies", json={"name": "Meta", "hand_reason": "blocked"})
+35 -6
View File
@@ -67,10 +67,6 @@ def test_a_boards_own_reach_is_kept_in_its_params_and_wins(
assert sub.params == {"note": "kept", "countries": ["DE", "SE"], "remote": True}
assert _row(client)["reach_params"] == {"countries": ["DE", "SE"], "remote": True}
res = client.post(f"/api/sources/{bosch}/reach", json={"mode": "all"})
assert res.json()["reach"] == "all roles · set here"
assert store.subscription(bosch).params == {"note": "kept", "reach": "all"} # type: ignore[union-attr]
res = client.post(f"/api/sources/{bosch}/reach", json={"mode": "agents"})
assert res.json()["reach"] == "DK · agents"
assert store.subscription(bosch).params == {"note": "kept"} # type: ignore[union-attr]
@@ -81,6 +77,7 @@ def test_a_boards_own_reach_is_kept_in_its_params_and_wins(
({"mode": "own", "countries": ["XX"]}, 422),
({"mode": "own", "countries": ["EU"]}, 422),
({"mode": "nowhere"}, 422),
({"mode": "all"}, 422), # every role is the company's tag now
])
def test_a_reach_that_names_nothing_is_refused(
client: TestClient, bosch: int, body: dict[str, object], status: int) -> None:
@@ -90,8 +87,40 @@ def test_a_reach_that_names_nothing_is_refused(
def test_a_search_or_an_unknown_board_has_no_reach(client: TestClient, store: Store) -> None:
search = store.add_subscription("search", "jobindex:x", label="X", board="jobindex",
params={"q": "python"})
assert client.post(f"/api/sources/{search.id}/reach", json={"mode": "all"}).status_code == 404
assert client.post("/api/sources/999/reach", json={"mode": "all"}).status_code == 404
assert client.post(f"/api/sources/{search.id}/reach",
json={"mode": "agents"}).status_code == 404
assert client.post("/api/sources/999/reach", json={"mode": "agents"}).status_code == 404
#: Every state a job may be in, for a "was one queued at all" check that does
#: not race a background worker draining it.
_ANY_STATE = ("queued", "running", "done", "failed", "cancelled")
def test_the_all_roles_tag_reads_the_wide_reach_and_on_queues_a_pull(
client: TestClient, app: FastAPI, store: Store, bosch: int) -> None:
queue = app.state.queue
res = client.post("/api/companies/bosch/all-roles", json={"on": True})
assert res.status_code == 200, res.text
assert res.json()["all_roles"] == 1
# On reopens roles, so it queues a pull as switching a board on does.
assert queue.jobs.last("pull", states=_ANY_STATE) is not None
row = _row(client)
# Wolf requires no place, so the wide reach is everywhere.
assert (row["all_roles"], row["reach"]) == (True, "all roles · company tag")
# A board's own countries win over the tag.
client.post(f"/api/sources/{bosch}/reach", json={"mode": "own", "countries": ["DE"]})
assert _row(client)["reach"] == "DE · set here"
def test_turning_the_tag_off_queues_nothing(
client: TestClient, app: FastAPI, store: Store, bosch: int) -> None:
store.set_all_roles("bosch", True)
res = client.post("/api/companies/bosch/all-roles", json={"on": False})
assert res.status_code == 200 and res.json()["all_roles"] == 0
assert app.state.queue.jobs.last("pull", states=_ANY_STATE) is None
assert _row(client)["reach"] == "DK · agents"
assert client.post("/api/companies/nobody/all-roles", json={"on": True}).status_code == 404
def test_the_readers_are_listed_with_what_they_declare(client: TestClient) -> None: