diff --git a/app/jobs/discover.py b/app/jobs/discover.py index b75405d..b52b8bb 100644 --- a/app/jobs/discover.py +++ b/app/jobs/discover.py @@ -106,6 +106,14 @@ def _hosts(modules: Mapping[str, ModuleType], #: joined by "/" (Lever's `eu/`). HOSTS: tuple[tuple[str, re.Pattern[str]], ...] = _hosts(atshosts.HOSTS, _UNREADABLE) +#: The hosts whose slugs keep the case the URL wrote them in, by their +#: module's `KEEP_CASE`: a Workday site is `LEGO_External`, and both its +#: listing and its robots.txt paths are case-sensitive. Every other slug is +#: lowercased, which is how a page that writes `BoschGroup` and one that +#: writes `boschgroup` name one board. +_KEEP_CASE = frozenset(name for name, module in atshosts.HOSTS.items() + if getattr(module, "KEEP_CASE", False)) + #: What a Teamtailor feed carries and a page that only looks like one does not: #: the namespace of `tt:locations`, declared on `` even when no role is open. TEAMTAILOR_FEED = "https://teamtailor.com/locations" @@ -128,7 +136,7 @@ _ANCHOR = re.compile(r"]*href\s*=\s*[\"']([^\"'#][^\"']*)[\"'][^>]*>(.*?) re.IGNORECASE | re.DOTALL) _TAGS = re.compile(r"<[^>]+>") -#: Words a pattern's slug group can catch that name no board: the hosts' +#: Words a pattern's group 1 can catch that name no board: the hosts' #: own path segments, the analytics subdomain Recruitee sites embed, and #: the CDN and the admin app Teamtailor sites load from (cdn.teamtailor.com, #: app.teamtailor.com). @@ -164,10 +172,13 @@ def boards_in(text: str) -> list[Found]: hits: list[tuple[int, str, str, str]] = [] for host, pattern in HOSTS: for m in pattern.finditer(text): - parts = [part.lower() for part in m.groups() if part] - if any(part in _NOT_SLUGS for part in parts): + # Only group 1 names a board or a host's own path word; a later + # group may be anything, a Workday site called `jobs` included. + if m.re.groups and (m.group(1) or "").lower() in _NOT_SLUGS: continue - slug = "/".join(parts) + slug = "/".join(part for part in m.groups() if part) + if host not in _KEEP_CASE: + slug = slug.lower() hits.append((m.start(), host, slug, m.group(0))) for _pos, host, slug, url in sorted(hits): if (host, slug) in seen: diff --git a/plugins/atshosts/__init__.py b/plugins/atshosts/__init__.py index 4e17355..ff929a0 100644 --- a/plugins/atshosts/__init__.py +++ b/plugins/atshosts/__init__.py @@ -70,6 +70,8 @@ def problems(module: ModuleType, name: str | None = None) -> list[str]: out.append(f"NAME is {module.NAME!r}, not the module's name {name!r}") if hasattr(module, "LABEL") and not (isinstance(module.LABEL, str) and module.LABEL): 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") patterns = getattr(module, "PATTERNS", ()) if isinstance(patterns, str) or not isinstance(patterns, Iterable): out.append("PATTERNS is not a tuple of strings") diff --git a/tests/test_discover.py b/tests/test_discover.py index e92e64b..c41dbff 100644 --- a/tests/test_discover.py +++ b/tests/test_discover.py @@ -4,6 +4,7 @@ site's pages are read.""" from __future__ import annotations import json +import re import types from pathlib import Path @@ -53,6 +54,33 @@ def test_boards_in_names_a_lever_eu_board_by_its_region() -> None: ("lever", "whereby")] +def test_boards_in_lowercases_a_slug_unless_the_host_keeps_its_case( + monkeypatch: pytest.MonkeyPatch) -> None: + """A Workday-shaped host with two groups and `KEEP_CASE`: the site keeps + its case, and a site called `jobs` is a site, since only group 1 is + checked against the hosts' own path words.""" + workday = re.compile(r"https?://([a-z0-9-]+\.wd\d+)\.myworkdayjobs\.com/" + r"(?:[a-z]{2}-[A-Z]{2}/)?([A-Za-z0-9_-]+)", re.IGNORECASE) + monkeypatch.setattr(mod, "HOSTS", (("workday", workday), + *(h for h in mod.HOSTS if h[0] != "workday"))) + monkeypatch.setattr(mod, "_KEEP_CASE", frozenset({"workday"})) + page = ('a' + 'b' + 'c' + 'd') + assert [(h, s) for h, s, _ in boards_in(page)] == [ + ("workday", "lego.wd103/LEGO_External"), ("workday", "redhat.wd5/jobs"), + ("smartrecruiters", "boschgroup"), ("lever", "eu/tomtom")] + # A host's own path word in group 1 still names no board. + assert boards_in('x') == [] + + +def test_no_module_of_the_eight_keeps_its_case() -> None: + """SmartRecruiters and Ashby ignore case (checked live, 2026-09-29), so a + slug from a page stays lowercased as it always was.""" + assert not mod._KEEP_CASE + + def test_a_host_that_gains_a_module_replaces_its_unreadable_pattern() -> None: """Wave by wave, a host named here becomes readable by its module alone.""" taleo = types.ModuleType("taleo")