From a9fb4397ac01988b8dda2e18f185fcfa2a530ae9 Mon Sep 17 00:00:00 2001 From: Wolf Date: Tue, 29 Sep 2026 19:38:18 +0200 Subject: [PATCH] Order the hosts by a RANK per module, which restores the select's and the probes' order from before the modules Co-Authored-By: Claude Opus 5.5 --- plugins/atshosts/__init__.py | 20 ++++++++++++++------ plugins/atshosts/ashby.py | 1 + plugins/atshosts/greenhouse.py | 1 + plugins/atshosts/lever.py | 1 + plugins/atshosts/personio.py | 1 + plugins/atshosts/recruitee.py | 1 + plugins/atshosts/smartrecruiters.py | 1 + plugins/atshosts/teamtailor.py | 1 + plugins/atshosts/workable.py | 1 + tests/test_atshosts.py | 28 ++++++++++++++++++++++++++-- tests/test_discover.py | 23 +++++++++++++++++++++++ 11 files changed, 71 insertions(+), 8 deletions(-) diff --git a/plugins/atshosts/__init__.py b/plugins/atshosts/__init__.py index ff929a0..0538693 100644 --- a/plugins/atshosts/__init__.py +++ b/plugins/atshosts/__init__.py @@ -53,6 +53,10 @@ import re from collections.abc import Iterable from types import ModuleType +#: The rank of a module that states none: after the eight first hosts, whose +#: ranks (10 to 80) keep the order they had before there were modules. +DEFAULT_RANK = 100 + #: What every host module defines. REQUIRED = ("NAME", "LABEL", "PATTERNS", "slug_ok", "allowed", "careers_url") @@ -72,6 +76,9 @@ def problems(module: ModuleType, name: str | None = None) -> list[str]: out.append("LABEL is not a non-empty string") if not isinstance(getattr(module, "KEEP_CASE", False), bool): out.append("KEEP_CASE is not a bool") + rank = getattr(module, "RANK", DEFAULT_RANK) + if not isinstance(rank, int) or isinstance(rank, bool): + out.append("RANK is not an int") patterns = getattr(module, "PATTERNS", ()) if isinstance(patterns, str) or not isinstance(patterns, Iterable): out.append("PATTERNS is not a tuple of strings") @@ -97,9 +104,9 @@ def problems(module: ModuleType, name: str | None = None) -> list[str]: def load(path: Iterable[str], package: str) -> dict[str, ModuleType]: """`NAME -> module` for every module of `package` (found on `path`) whose - name does not start with `_`, sorted by name. Raises ImportError naming - the first module that breaks the contract.""" - hosts: dict[str, ModuleType] = {} + name does not start with `_`, in order of `(RANK, NAME)`. Raises + ImportError naming the first module that breaks the contract.""" + modules: list[ModuleType] = [] for info in sorted(pkgutil.iter_modules(path), key=lambda info: info.name): if info.name.startswith("_"): continue @@ -107,9 +114,10 @@ def load(path: Iterable[str], package: str) -> dict[str, ModuleType]: if found := problems(module, info.name): raise ImportError(f"{package}.{info.name} breaks the host contract: " + "; ".join(found)) - hosts[module.NAME] = module - return hosts + modules.append(module) + modules.sort(key=lambda module: (getattr(module, "RANK", DEFAULT_RANK), module.NAME)) + return {module.NAME: module for module in modules} -#: host -> its module, in order of name. +#: host -> its module, in order of `(RANK, NAME)`. HOSTS: dict[str, ModuleType] = load(__path__, __name__) diff --git a/plugins/atshosts/ashby.py b/plugins/atshosts/ashby.py index 8685c38..0513477 100644 --- a/plugins/atshosts/ashby.py +++ b/plugins/atshosts/ashby.py @@ -17,6 +17,7 @@ from ._shared import Row, is_web_url, num, only, parse_dt, path_slug_ok, pay_lin NAME = "ashby" LABEL = "Ashby" +RANK = 30 PATTERNS = ( r"jobs\.ashbyhq\.com/([A-Za-z0-9_.-]+)", r"api\.ashbyhq\.com/posting-api/job-board/([A-Za-z0-9_.-]+)", diff --git a/plugins/atshosts/greenhouse.py b/plugins/atshosts/greenhouse.py index de40e05..ce0ceb6 100644 --- a/plugins/atshosts/greenhouse.py +++ b/plugins/atshosts/greenhouse.py @@ -17,6 +17,7 @@ from ._shared import Row, is_web_url, num, only, parse_dt, path_slug_ok, pay_lin NAME = "greenhouse" LABEL = "Greenhouse" +RANK = 10 PATTERNS = ( r"(?:boards|job-boards|api)\.(?:eu\.)?greenhouse\.io/(?:v1/boards/|embed/job_board\?[^\"'\s]*for=)?([A-Za-z0-9_-]+)", r"greenhouse\.io/embed/job_board/js\?for=([A-Za-z0-9_-]+)", diff --git a/plugins/atshosts/lever.py b/plugins/atshosts/lever.py index 7c33843..f988ce6 100644 --- a/plugins/atshosts/lever.py +++ b/plugins/atshosts/lever.py @@ -25,6 +25,7 @@ from ._shared import Row, is_web_url, num, only, parse_dt, path_slug_ok, pay_lin NAME = "lever" LABEL = "Lever" +RANK = 20 #: Two groups on the EU hosts, `eu` and the site, which discovery joins into #: the slug `eu/`. PATTERNS = ( diff --git a/plugins/atshosts/personio.py b/plugins/atshosts/personio.py index e4a4c20..0e1116c 100644 --- a/plugins/atshosts/personio.py +++ b/plugins/atshosts/personio.py @@ -16,6 +16,7 @@ from ._shared import Row, label_slug_ok, num, only, parse_dt, pay_line, yearly_a NAME = "personio" LABEL = "Personio" +RANK = 70 PATTERNS = (r"https?://([a-z0-9-]+)\.jobs\.personio\.(?:de|com)",) #: Personio's `salaryInformation/type` spellings, to the plain period word diff --git a/plugins/atshosts/recruitee.py b/plugins/atshosts/recruitee.py index 611ff09..81e9903 100644 --- a/plugins/atshosts/recruitee.py +++ b/plugins/atshosts/recruitee.py @@ -17,6 +17,7 @@ from ._shared import Row, is_web_url, label_slug_ok, num, only, parse_dt, pay_li NAME = "recruitee" LABEL = "Recruitee" +RANK = 60 PATTERNS = (r"https?://([a-z0-9-]+)\.recruitee\.com",) diff --git a/plugins/atshosts/smartrecruiters.py b/plugins/atshosts/smartrecruiters.py index 5bd93c9..62d2633 100644 --- a/plugins/atshosts/smartrecruiters.py +++ b/plugins/atshosts/smartrecruiters.py @@ -15,6 +15,7 @@ from ._shared import Get, Page, Row, only, parse_dt, path_slug_ok NAME = "smartrecruiters" LABEL = "SmartRecruiters" +RANK = 50 PATTERNS = ( r"(?:jobs|careers|api)\.smartrecruiters\.com/(?:v1/companies/)?([A-Za-z0-9_-]+)", ) diff --git a/plugins/atshosts/teamtailor.py b/plugins/atshosts/teamtailor.py index 281bd62..490fc50 100644 --- a/plugins/atshosts/teamtailor.py +++ b/plugins/atshosts/teamtailor.py @@ -20,6 +20,7 @@ from ._shared import Get, Page, Row, is_web_url, only, parse_dt NAME = "teamtailor" LABEL = "Teamtailor" +RANK = 80 PATTERNS = ( r"https?://([a-z0-9-]+)\.teamtailor\.com", # No slug: a career site on the company's own domain, which only loads diff --git a/plugins/atshosts/workable.py b/plugins/atshosts/workable.py index 6b2f0a6..9495065 100644 --- a/plugins/atshosts/workable.py +++ b/plugins/atshosts/workable.py @@ -15,6 +15,7 @@ from ._shared import Get, Page, Row, only, parse_dt, path_slug_ok NAME = "workable" LABEL = "Workable" +RANK = 40 PATTERNS = ( r"apply\.workable\.com/(?:api/v\d/accounts/)?([A-Za-z0-9_-]+)", r"https?://(?!apply\.|www\.)([a-z0-9-]+)\.workable\.com", diff --git a/tests/test_atshosts.py b/tests/test_atshosts.py index 4965d6d..0495fd3 100644 --- a/tests/test_atshosts.py +++ b/tests/test_atshosts.py @@ -28,10 +28,10 @@ FIXTURES = ROOT / "tests" / "fixtures" / "ats" # --------------------------------------------------------------- registry -def test_the_registry_finds_every_module_in_order_of_name() -> None: +def test_the_registry_finds_every_module() -> None: names = sorted(p.stem for p in (ROOT / "plugins" / "atshosts").glob("*.py") if not p.stem.startswith("_")) - assert list(atshosts.HOSTS) == names + assert sorted(atshosts.HOSTS) == names assert set(names) >= {"greenhouse", "lever", "ashby", "workable", "smartrecruiters", "recruitee", "personio", "teamtailor"} assert all(not atshosts.problems(module, name) for name, module in atshosts.HOSTS.items()) @@ -71,6 +71,28 @@ def test_the_registry_loads_a_package_by_name_and_skips_private_modules( assert list(atshosts.load(path, "hostsok")) == ["alpha", "zeta"] +def test_the_registry_orders_by_rank_then_name( + tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: + path = _package(tmp_path, monkeypatch, "hostsranked", { + "alpha": _GOOD.format(name="alpha"), # the default, 100 + "beta": _GOOD.format(name="beta") + "RANK = 5\n", + "gamma": _GOOD.format(name="gamma") + "RANK = 100\n"}) + assert list(atshosts.load(path, "hostsranked")) == ["beta", "alpha", "gamma"] + + +def test_the_eight_first_hosts_keep_the_order_they_had_before_modules() -> None: + """The Sources page's select opens on Greenhouse, which its hint names, + and a guessed slug on two hosts goes to the one probed first, as before.""" + first = ["greenhouse", "lever", "ashby", "workable", "smartrecruiters", "recruitee", + "personio", "teamtailor"] + assert list(ats.HOSTS)[:8] == first + assert ats.ATSSource.description.startswith( + "Company job boards: Greenhouse, Lever, Ashby, Workable, SmartRecruiters, " + "Recruitee, Personio, Teamtailor") + assert all(module.RANK < atshosts.DEFAULT_RANK + for name, module in atshosts.HOSTS.items() if name in first) + + def test_the_registry_refuses_a_module_missing_a_required_name( tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: broken = _GOOD.format(name="broken").replace("def careers_url", "def not_careers_url") @@ -85,12 +107,14 @@ def test_the_contract_check_names_each_problem() -> None: module.slug_ok = module.allowed = module.careers_url = lambda slug: "" module.page = lambda get, slug, cursor: None module.probe_ok = lambda body: True + module.RANK, module.KEEP_CASE = "1", "yes" found = atshosts.problems(module, "odd") assert "NAME is 'other', not the module's name 'odd'" in found assert "LABEL is not a non-empty string" in found assert any(p.startswith("PATTERNS has '('") for p in found) assert "page without rows" in found assert "probe_ok without probe_url" in found + assert "RANK is not an int" in found and "KEEP_CASE is not a bool" in found # ------------------------------------------------------------ the fetch diff --git a/tests/test_discover.py b/tests/test_discover.py index c41dbff..f853c33 100644 --- a/tests/test_discover.py +++ b/tests/test_discover.py @@ -268,6 +268,29 @@ def test_slug_probes_find_a_board_the_pages_never_link() -> None: assert found.evidence == "https://api.ashbyhq.com/posting-api/job-board/acme" +@pytest.mark.parametrize(("boards", "found"), [ + ({("greenhouse", "acme"), ("ashby", "acme")}, "greenhouse:acme"), + ({("lever", "acme"), ("ashby", "acme")}, "lever:acme"), + ({("smartrecruiters", "acme"), ("personio", "acme")}, "smartrecruiters:acme"), + ({("lever", "eu/acme"), ("personio", "acme")}, "lever:eu/acme"), +]) +def test_a_slug_on_two_hosts_goes_to_the_one_probed_first( + boards: set[tuple[str, str]], found: str) -> None: + site = Site({}, boards=boards) + assert run(site).board == found + + +def test_the_probe_order_is_the_one_before_modules() -> None: + assert list(mod._PROBES)[:7] == ["greenhouse", "lever", "ashby", "smartrecruiters", + "recruitee", "personio", "teamtailor"] + site = Site({}) + run(site) + assert site.probed[:8] == [("greenhouse", "acme"), ("lever", "acme"), ("lever", "eu/acme"), + ("ashby", "acme"), ("smartrecruiters", "acme"), + ("recruitee", "acme"), ("personio", "acme"), + ("teamtailor", "acme")] + + def test_a_lever_eu_board_is_found_by_its_probe() -> None: site = Site({"https://acme.com/": "

a script draws the jobs

"}, boards={("lever", "eu/acme")})