Split the All tag into two company overrides: All countries and All roles (WP L)

Fetching has two filters, and a company now overrides each on its own.
All countries (companies.all_countries) is the old All roles tag: its big
boards are read with the agents' wide reach. All roles (companies.all_roles,
new meaning) drops the agents' fetch terms and any later role filter.

- Migration 24 copies the old tag to all_countries and keeps all_roles for
  those companies, and moves a board's {"terms": false} to its company.
- The runner no longer reads {"terms": false}; the plan leaves the terms out
  for a company set to All roles.
- POST /api/companies/{key}/all-countries and /all-roles, each queueing a
  pull when turned on; CompanyOut carries both.
- Two toggles replace All on the Companies row, the reader and the Roles
  strip; the reach line states countries and role types in plain words;
  the filter select gets both options.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Opus 5.5 committed 2026-09-30 12:50:45 +02:00
1 parent 795ca3628c
commit e52857dea5
23 files changed
+602 -215

No files matched your search

+7 -4
View File
@@ -148,7 +148,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, 21, 22, 23]
assert reopened.migrations_applied == [20, 21, 22, 23, 24]
assert reopened.duplicate_companies() == [("orsted", ["orsted", "ørsted"])]
assert len(reopened.companies()) == 3
@@ -183,11 +183,14 @@ def test_migration_21_tags_the_favourites_and_the_boards_that_read_all_roles(tmp
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("ALTER TABLE companies DROP COLUMN all_countries")
conn.execute("PRAGMA user_version = 20")
reopened = Store(path)
assert reopened.migrations_applied == [21, 22, 23]
assert {c.key: c.all_roles for c in reopened.companies()} == {
"mistral-ai": 1, "acme": 0, "black-forest-labs": 1, "liked": 0}
assert reopened.migrations_applied == [21, 22, 23, 24]
# The tag of 21 is All countries and All roles since 24.
tagged = {"mistral-ai": 1, "acme": 0, "black-forest-labs": 1, "liked": 0}
assert {c.key: c.all_roles for c in reopened.companies()} == tagged
assert {c.key: c.all_countries for c in reopened.companies()} == tagged
params = {s.target: s.params for s in reopened.subscriptions(source="ats")}
assert params == {"smartrecruiters:mistral": {"note": "kept"},
"workday:acme": {"countries": ["DK"]}, "greenhouse:ghost": {}}
+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, 21, 22, 23]
assert migrated.migrations_applied == [18, 19, 20, 21, 22, 23, 24]
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'"
+17 -10
View File
@@ -72,7 +72,7 @@ def _board(store: Store, target: str, company: str, size: int | None = 1000,
store.state[f"ats:size:{target}"] = str(size)
if tagged:
from app.models import company_key
store.set_all_roles(company_key(company), True)
store.set_all_countries(company_key(company), True)
def _sub(store: Store, target: str) -> Any:
@@ -123,12 +123,12 @@ def test_the_narrow_reach_takes_no_terms(store: Store) -> None:
sub = _sub(store, "smartrecruiters:BoschGroup")
ask = _runner.ask_for(smartrecruiters, sub.params, plan.for_subscription(sub))
assert ask == Ask(countries=("DK", "SE"))
assert reach.line(plan, sub) == "DK, SE · agents"
assert reach.line(plan, sub) == "follows agents: DK, SE · all roles"
@pytest.mark.parametrize("size, params", [
(299, {}), (None, {}), (5000, {"countries": ["DE"]}), (5000, {"terms": False}),
], ids=["small", "never read whole", "own reach", "terms off"])
(299, {}), (None, {}), (5000, {"countries": ["DE"]}),
], ids=["small", "never read whole", "own reach"])
def test_small_unknown_overridden_and_switched_off_boards_take_no_terms(
store: Store, size: int | None, params: dict[str, object]) -> None:
_wolf(store, TERMS)
@@ -148,7 +148,13 @@ def test_the_agents_reach_takes_terms_once_it_is_too_many_countries_to_ask(
sub = _sub(store, "smartrecruiters:BoschGroup")
ask = _runner.ask_for(smartrecruiters, sub.params, plan.for_subscription(sub))
assert ask == Ask(terms=("data", "engineer", "product"))
assert reach.line(plan, sub) == "all places · agents · 3 terms"
assert reach.line(plan, sub) == \
"all places, too many countries to ask · follows agents' terms: data, engineer, product"
# All roles drops them there too; the countries stay dropped.
store.set_all_roles("bosch", True)
plan = reach.plan(store)
assert _runner.ask_for(smartrecruiters, sub.params, plan.for_subscription(sub)) == Ask()
assert reach.line(plan, sub) == "too many countries to ask: read whole"
# ------------------------------------------------------ terms times the reach
@@ -234,16 +240,16 @@ def test_the_reach_line_counts_the_terms(store: Store) -> None:
plan = reach.plan(store)
philips = _sub(store, "phenom:www.careers.philips.com/global/en")
assert reach.line(plan, philips) == \
f"{len(plan.wide.countries)} countries · company tag · 3 terms"
"all countries (Europe) · follows agents' terms: data, engineer, head of"
assert reach.line(plan, _sub(store, "smartrecruiters:BoschGroup")) == \
"all places · company tag · 3 terms"
"all places, too many countries to ask · follows agents' terms: data, engineer, head of"
def test_one_term_is_one_term(store: Store) -> None:
_wolf(store, ["engineer"])
_board(store, "smartrecruiters:BoschGroup", "Bosch")
assert reach.line(reach.plan(store), _sub(store, "smartrecruiters:BoschGroup")) == \
"all places · company tag · 1 term"
"all places, too many countries to ask · follows agents' terms: engineer"
# ------------------------------------------------------ each host's request
@@ -431,7 +437,7 @@ def test_migration_23_gives_every_agent_no_terms(tmp_path: Path) -> None:
conn.execute("ALTER TABLE agents DROP COLUMN fetch_terms")
conn.execute("PRAGMA user_version = 22")
migrated = Store(path)
assert migrated.migrations_applied == [23]
assert migrated.migrations_applied == [23, 24]
assert migrated.agents()[0].fetch_terms == []
@@ -469,4 +475,5 @@ def test_the_companies_list_says_the_terms(client: TestClient, app: FastAPI) ->
_wolf(store, ["engineer", "data", "head of"])
_board(store, "smartrecruiters:BoschGroup", "Bosch")
row = next(c for c in client.get("/api/companies").json() if c["key"] == "bosch")
assert row["reach"] == "all places · company tag · 3 terms"
assert row["reach"] == \
"all places, too many countries to ask · follows agents' terms: data, engineer, head of"
+155
View File
@@ -0,0 +1,155 @@
"""A company's two fetch overrides (see "The agents set the reach of a pull"
and "Fetch terms" in `docs/decisions.md`): All countries reads its big boards
with the agents' wide reach, All roles with no role-type narrowing. The four
combinations, the reach line, migration 24 and a merge. No network."""
from __future__ import annotations
import json
import sqlite3
import sys
from pathlib import Path
import pytest
ROOT = Path(__file__).resolve().parents[1]
if str(ROOT) not in sys.path:
sys.path.insert(0, str(ROOT))
from app.jobs import reach # noqa: E402
from app.models import Gate # noqa: E402
from app.storage import Store # noqa: E402
from plugins.readers import Ask, _runner, phenom # noqa: E402
TERMS = ["engineer", "product", "data"]
PHILIPS = "phenom:www.careers.philips.com/global/en"
@pytest.fixture
def store(tmp_path: Path) -> Store:
found = Store(tmp_path / "roledesk.db")
# Agent 2 of 2026-09-30: Europe required; Denmark, Sweden or remote.
found.save_agent("Wolf", fetch_terms=TERMS, gates=[
Gate(field="place", values=["Europe"], mode="require"),
Gate(field="country", values=["DK", "SE"], mode="any"),
Gate(field="remote", values=["remote"], mode="any")])
return found
def _board(store: Store, target: str, company: str, size: int = 5000) -> None:
store.add_subscription("ats", target, label=company, company=company,
board=target.partition(":")[0])
store.add_company(company)
store.state[f"ats:size:{target}"] = str(size)
def _read(store: Store, target: str) -> tuple[Ask, str]:
"""What the next pull asks the board for, and the Companies list's line."""
plan = reach.plan(store)
sub = next(s for s in store.subscriptions(source="ats") if s.target == target)
return _runner.ask_for(phenom, sub.params, plan.for_subscription(sub)), reach.line(plan, sub)
@pytest.mark.parametrize("countries, roles, line", [
(False, False, "follows agents: DK, SE · all roles"),
(False, True, "follows agents: DK, SE · all roles"),
(True, False, "all countries (Europe) · follows agents' terms: data, engineer, product"),
(True, True, "all countries (Europe) · all roles"),
], ids=["neither", "all roles alone", "all countries alone", "both"])
def test_the_four_combinations(store: Store, countries: bool, roles: bool, line: str) -> None:
_board(store, PHILIPS, "Philips")
store.set_all_countries("philips", countries)
store.set_all_roles("philips", roles)
ask, said = _read(store, PHILIPS)
assert said == line
# Phenom asks for countries, many in one request, and not for remote.
if countries:
assert {"DE", "FR", "DK", "SE"} <= set(ask.countries) and len(ask.countries) > 30
else:
assert ask.countries == ("DK", "SE")
# Terms go only with the wide reach, and never to a company set to All roles.
assert ask.terms == (("data", "engineer", "product") if countries and not roles else ())
def test_all_roles_alone_changes_nothing_today(store: Store) -> None:
_board(store, PHILIPS, "Philips")
before = _read(store, PHILIPS)
store.set_all_roles("philips", True)
assert _read(store, PHILIPS) == before
@pytest.mark.parametrize("target, size, line", [
(PHILIPS, 120, "under 300 roles: read whole"),
("greenhouse:acme", 5000, "Greenhouse cannot filter: read whole"),
], ids=["small", "greenhouse"])
def test_a_board_read_whole_says_why_whatever_the_overrides(
store: Store, target: str, size: int, line: str) -> None:
_board(store, target, "Acme", size)
for countries, roles in ((False, False), (True, False), (True, True)):
store.set_all_countries("acme", countries)
store.set_all_roles("acme", roles)
assert _read(store, target)[1] == line
def test_a_merge_keeps_both_overrides(store: Store) -> None:
store.add_company("Mistral")
store.add_company("Mistral AI")
store.set_all_countries("mistral", True)
store.set_all_roles("mistral-ai", True)
kept = store.merge_companies("mistral-ai", "mistral")
assert (kept.all_countries, kept.all_roles) == (1, 1)
# ------------------------------------------------------------ migration 24
def test_migration_24_splits_the_tag_and_moves_terms_off(tmp_path: Path) -> None:
path = tmp_path / "old.db"
store = Store(path)
for name in ("Mistral AI", "Acme", "Plain"):
store.add_company(name)
store.add_subscription("ats", "workday:acme", label="Acme", company="Acme",
board="workday", params={"terms": False, "note": "kept"})
store.add_subscription("ats", "workday:plain", label="Plain", company="Plain",
board="workday", params={"countries": ["DK"]})
# A board whose company has no row: its params are cleaned, no flag lands.
store.add_subscription("ats", "workday:ghost", label="Ghost", company="Ghost",
board="workday", params={"terms": False})
with sqlite3.connect(path) as conn:
conn.execute("ALTER TABLE companies DROP COLUMN all_countries")
# Before 24, all_roles was the All roles tag, the wide reach.
conn.execute("UPDATE companies SET all_roles=1 WHERE key='mistral-ai'")
conn.execute("PRAGMA user_version = 23")
migrated = Store(path)
assert migrated.migrations_applied == [24]
flags = {c.key: (c.all_countries, c.all_roles) for c in migrated.companies()}
assert flags == {"mistral-ai": (1, 1), "acme": (0, 1), "plain": (0, 0)}
params = {s.target: s.params for s in migrated.subscriptions(source="ats")}
assert params == {"workday:acme": {"note": "kept"}, "workday:plain": {"countries": ["DK"]},
"workday:ghost": {}}
def test_migration_24_runs_twice_without_harm(tmp_path: Path) -> None:
from app.storage.schema import _split_all_roles
path = tmp_path / "db.db"
store = Store(path)
store.add_company("Acme")
store.set_all_roles("acme", True)
with sqlite3.connect(path) as conn:
_split_all_roles(conn)
row = conn.execute("SELECT all_countries, all_roles FROM companies").fetchone()
assert json.dumps(list(row)) == "[0, 1]"
def test_the_wide_reach_is_named_as_the_gates_name_it(store: Store) -> None:
gaz = store.gazetteer()
europe = Gate(field="country", values=["AT", "DK", "SE", "FR", "EU"], mode="require")
nordics = Gate(field="country", values=["DK", "SE"], mode="require")
anywhere = Gate(field="country", values=["DK"], mode="any")
agents = [a.model_copy(update={"gates": [g]}) for a, g in
((store.agents()[0], europe), (store.agents()[0], nordics))]
# Countries one by one are named by their continent; a short list as written.
assert reach.wide_names(agents[:1], gaz) == "Europe"
assert reach.wide_names(agents[1:], gaz) == "DK, SE"
assert reach.wide_names([agents[0].model_copy(update={"gates": [anywhere]})],
gaz) == "everywhere"
+1 -1
View File
@@ -299,7 +299,7 @@ def test_migration_22_fills_the_host_words_from_raw(tmp_path: Path) -> None:
migrated = Store(path)
assert migrated.migrations_applied == [22, 23]
assert migrated.migrations_applied == [22, 23, 24]
one = row(migrated, "1")
assert (one["seniority_host"], one["employment_host"], one["remote_host"],
one["country_host"]) == ("senior", "full_time", "true", "DK")
+15 -16
View File
@@ -111,14 +111,14 @@ def test_a_company_tagged_all_roles_is_read_across_the_require_reach(store: Stor
_wolf(store)
_board(store, "workday:mistral.wd3/Jobs", "Mistral AI")
_board(store, "workday:acme.wd3/Jobs", "Acme")
store.set_all_roles("mistral-ai", True)
store.set_all_countries("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 why == "countries" and {"DE", "FR", "DK"} <= wide.countries and wide.remote
# The gate lists Europe's countries one by one; the line names the continent.
assert reach.line(plan, subs["workday:mistral"]) == "all countries (Europe) · all roles"
assert plan.why(subs["workday:acme"]) == (plan.base, "agents")
@@ -135,39 +135,38 @@ def test_a_favourite_does_not_widen_the_fetch(store: Store) -> None:
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)
store.set_all_countries("mistral-ai", True)
[sub] = store.subscriptions(source="ats")
assert reach.line(reach.plan(store), sub) == \
"all roles · company tag, too many countries to ask"
assert reach.line(reach.plan(store), sub) == "too many countries to ask: read whole"
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)
store.set_all_countries("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"
assert reach.line(found, sub) == "all countries (Europe) · all roles"
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, "workday:mistral.wd3/Jobs", "Mistral AI")
store.set_all_roles("mistral-ai", True)
store.set_all_countries("mistral-ai", True)
plan = reach.plan(store)
[sub] = store.subscriptions(source="ats")
assert plan.why(sub) == (reach.EVERYWHERE, "tag")
assert plan.why(sub) == (reach.EVERYWHERE, "countries")
assert plan.for_subscription(sub) is None
assert reach.line(plan, sub) == "all roles · company tag"
assert reach.line(plan, sub) == "all countries (everywhere): read whole"
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)
store.set_all_countries("mistral-ai", True)
[sub] = store.subscriptions(source="ats")
assert reach.line(reach.plan(store), sub) == "FR · set here"
assert reach.line(reach.plan(store), sub) == "set here: FR · all roles"
@pytest.mark.parametrize("size, params, why", [
@@ -248,8 +247,8 @@ def test_the_pull_reads_a_tagged_company_with_the_wide_reach(
_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)
store.set_all_countries("mistral-ai", True)
store.set_all_countries("black-forest-labs", True)
asked: dict[str, Ask] = {}
def fake(module: object, slug: str, get: object, ask: Ask, **kwargs: object
+6 -6
View File
@@ -70,7 +70,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 == 23
assert LATEST == 24
# A second open finds it current and applies nothing.
assert Store(path).migrations_applied == []
@@ -187,7 +187,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, 21, 22, 23]
assert migrated.migrations_applied == [15, 16, 17, 18, 19, 20, 21, 22, 23, 24]
acme = migrated.company("acme")
assert acme is not None
assert (acme.ats, acme.careers_url) == ("teamtailor", "https://a.example")
@@ -392,7 +392,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, 21, 22, 23]
assert migrated.migrations_applied == [14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]
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]
@@ -416,7 +416,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, 21, 22, 23]
assert migrated.migrations_applied == [16, 17, 18, 19, 20, 21, 22, 23, 24]
acme = migrated.company("acme")
assert acme is not None
assert (acme.careers_url, acme.notes, acme.hand_reason) == (
@@ -445,7 +445,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, 21, 22, 23]
assert migrated.migrations_applied == [17, 18, 19, 20, 21, 22, 23, 24]
with sqlite3.connect(path) as conn:
rows = {uid: (fold, level) for uid, fold, level in conn.execute(
"SELECT uid, place_fold, seniority FROM roles")}
@@ -687,7 +687,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, 21, 22, 23]
assert migrated.migrations_applied == [19, 20, 21, 22, 23, 24]
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) == []
+5 -3
View File
@@ -538,8 +538,9 @@ 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, "all_roles": False,
"reach_params": {}, "reach": "all roles · not read whole yet"}
"from_search": False, "hand_reason": "", "by_hand": False,
"all_countries": False, "all_roles": False,
"reach_params": {}, "reach": "size not known yet: read whole"}
[other] = [c for c in res.json() if c["key"] == "other"]
assert (other["board"], other["subscription_id"], other["on"], other["ats"]) == (
"", None, None, "")
@@ -1388,7 +1389,8 @@ 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, "all_roles": False, "reach_params": {}, "reach": ""}
"hand_reason": "added", "by_hand": True, "all_countries": False, "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"})
+32 -15
View File
@@ -53,7 +53,7 @@ def _row(client: TestClient) -> dict[str, object]:
def test_a_company_row_says_what_its_board_is_asked_for(client: TestClient, bosch: int) -> None:
row = _row(client)
# SmartRecruiters cannot ask for remote, so only the country is asked.
assert (row["reach"], row["reach_params"]) == ("DK · agents", {})
assert (row["reach"], row["reach_params"]) == ("follows agents: DK · all roles", {})
def test_a_boards_own_reach_is_kept_in_its_params_and_wins(
@@ -61,14 +61,14 @@ def test_a_boards_own_reach_is_kept_in_its_params_and_wins(
res = client.post(f"/api/sources/{bosch}/reach",
json={"mode": "own", "countries": ["de", "se"], "remote": True})
assert res.status_code == 200, res.text
assert res.json()["reach"] == "DE, SE · set here"
assert res.json()["reach"] == "set here: DE, SE · all roles"
sub = store.subscription(bosch)
assert sub is not None
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": "agents"})
assert res.json()["reach"] == "DK · agents"
assert res.json()["reach"] == "follows agents: DK · all roles"
assert store.subscription(bosch).params == {"note": "kept"} # type: ignore[union-attr]
@@ -97,30 +97,47 @@ def test_a_search_or_an_unknown_board_has_no_reach(client: TestClient, store: St
_ANY_STATE = ("queued", "running", "done", "failed", "cancelled")
def test_the_all_roles_tag_reads_the_wide_reach_and_on_queues_a_pull(
def test_all_countries_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})
res = client.post("/api/companies/bosch/all-countries", json={"on": True})
assert res.status_code == 200, res.text
assert res.json()["all_roles"] == 1
assert (res.json()["all_countries"], res.json()["all_roles"]) == (1, 0)
# 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.
assert (row["all_countries"], row["all_roles"], row["reach"]) == (
True, False, "all countries (everywhere): read whole")
# A board's own countries win over it.
client.post(f"/api/sources/{bosch}/reach", json={"mode": "own", "countries": ["DE"]})
assert _row(client)["reach"] == "DE · set here"
assert _row(client)["reach"] == "set here: DE · all roles"
def test_turning_the_tag_off_queues_nothing(
def test_all_roles_is_its_own_switch_and_on_queues_a_pull(
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
res = client.post("/api/companies/bosch/all-roles", json={"on": True})
assert res.status_code == 200, res.text
assert (res.json()["all_countries"], res.json()["all_roles"]) == (0, 1)
assert app.state.queue.jobs.last("pull", states=_ANY_STATE) is not None
row = _row(client)
# The narrow reach takes no terms, so on its own it changes nothing today.
assert (row["all_countries"], row["all_roles"], row["reach"]) == (
False, True, "follows agents: DK · all roles")
@pytest.mark.parametrize("path, setter", [("all-countries", "set_all_countries"),
("all-roles", "set_all_roles")])
def test_turning_an_override_off_queues_nothing(
client: TestClient, app: FastAPI, store: Store, bosch: int, path: str,
setter: str) -> None:
getattr(store, setter)("bosch", True)
res = client.post(f"/api/companies/bosch/{path}", json={"on": False})
assert res.status_code == 200
assert (res.json()["all_countries"], res.json()["all_roles"]) == (0, 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
assert _row(client)["reach"] == "follows agents: DK · all roles"
assert client.post(f"/api/companies/nobody/{path}", json={"on": True}).status_code == 404
def test_the_readers_are_listed_with_what_they_declare(client: TestClient) -> None: