Take discovery's readable hosts, patterns and probes from the host modules, and find Lever boards on its EU instance

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Opus 5.5 committed 2026-09-29 17:07:34 +02:00
1 parent 8b14d8575b
commit a30b1ff09f
2 files changed
+141 -96

No files matched your search

+56 -9
View File
@@ -4,6 +4,7 @@ site's pages are read."""
from __future__ import annotations
import json
import types
from pathlib import Path
import httpx
@@ -36,16 +37,32 @@ def test_boards_in_names_readable_hosts_with_their_slug() -> None:
def test_boards_in_keeps_hosts_the_app_cannot_read() -> None:
page = """
<a href="https://novo.wd3.myworkdayjobs.com/en-US/careers">Workday</a>
<a href="https://performancemanager.successfactors.eu/career?company=x">SF</a>
<a href="https://novo.taleo.net/careersection/2/jobsearch.ftl">Taleo</a>
<a href="https://acme.teamtailor.com/jobs">TT</a>
"""
assert boards_in(page) == [
("workday", "novo", "https://novo.wd3.myworkdayjobs.com"),
("successfactors", "", "performancemanager.successfactors.eu"),
("taleo", "", ".taleo.net"),
("teamtailor", "acme", "https://acme.teamtailor.com")]
def test_boards_in_names_a_lever_eu_board_by_its_region() -> None:
page = ('<a href="https://jobs.eu.lever.co/tomtom/abc-123">EU</a>'
'<script src="https://api.eu.lever.co/v0/postings/tomtom?mode=json"></script>'
'<a href="https://jobs.lever.co/whereby">US</a>')
assert [(h, s) for h, s, _ in boards_in(page)] == [("lever", "eu/tomtom"),
("lever", "whereby")]
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")
taleo.PATTERNS = (r"https?://([a-z0-9-]+)\.taleo\.net",)
hosts = mod._hosts({"taleo": taleo}, mod._UNREADABLE)
assert [pattern.pattern for host, pattern in hosts if host == "taleo"] == [
r"https?://([a-z0-9-]+)\.taleo\.net"]
assert "taleo" not in mod.READABLE and ("taleo", r"\.taleo\.net") in mod._UNREADABLE
def test_boards_in_dedupes_and_skips_the_api_paths_own_words() -> None:
page = ('<a href="https://boards.greenhouse.io/embed/job_board?for=acme">a</a>'
'<a href="https://boards-api.greenhouse.io/v1/boards/acme/jobs">b</a>')
@@ -138,12 +155,12 @@ def test_a_careers_pages_own_link_is_followed_one_level_down() -> None:
def test_an_unreadable_host_named_by_a_page_is_the_answer_and_nothing_is_probed() -> None:
site = Site({
"https://acme.com/": "<p>welcome</p>",
"https://acme.com/careers": '<a href="https://acme.wd3.myworkdayjobs.com/x">Jobs</a>',
"https://acme.com/careers": '<a href="https://acme.taleo.net/careersection/x">Jobs</a>',
}, boards={("greenhouse", "acme")})
found = run(site)
assert found == Discovery(ats="workday", ats_slug="acme",
assert found == Discovery(ats="taleo", ats_slug="",
careers_url="https://acme.com/careers",
evidence="https://acme.wd3.myworkdayjobs.com")
evidence=".taleo.net")
assert not found.readable
# The page named the host: a probe could only find another tenant's
# board of the same name, like the greenhouse:acme this fake web has.
@@ -223,6 +240,36 @@ def test_slug_probes_find_a_board_the_pages_never_link() -> None:
assert found.evidence == "https://api.ashbyhq.com/posting-api/job-board/acme"
def test_a_lever_eu_board_is_found_by_its_probe() -> None:
site = Site({"https://acme.com/": "<p>a script draws the jobs</p>"},
boards={("lever", "eu/acme")})
found = run(site)
assert found.board == "lever:eu/acme"
assert found.evidence == "https://api.eu.lever.co/v0/postings/acme?limit=1&mode=json"
assert site.probed.index(("lever", "acme")) + 1 == site.probed.index(("lever", "eu/acme"))
def test_probe_asks_each_hosts_own_endpoint_and_body_check() -> None:
asked: list[str] = []
def handler(request: httpx.Request) -> httpx.Response:
asked.append(str(request.url))
if request.url.host == "api.eu.lever.co":
return httpx.Response(200, json=[])
if request.url.host == "api.ashbyhq.com":
return httpx.Response(200, content=b'{"jobs":[]}')
return httpx.Response(404)
with httpx.Client(transport=httpx.MockTransport(handler)) as client:
assert mod.probe(client, "lever", "eu/acme")
assert not mod.probe(client, "lever", "acme")
assert not mod.probe(client, "ashby", "acme") # an empty listing is no board
assert asked == ["https://api.eu.lever.co/v0/postings/acme?limit=1&mode=json",
"https://api.lever.co/v0/postings/acme?limit=1&mode=json",
"https://api.ashbyhq.com/posting-api/job-board/acme"]
assert "workable" not in mod._PROBES and "lever" in mod._PROBES
def test_a_site_that_never_answers_gives_an_empty_discovery() -> None:
site = Site({})
assert run(site) == Discovery()
@@ -251,7 +298,7 @@ def test_the_seed_keeps_a_company_the_app_cannot_read(store: Store, tmp_path: Pa
{"name": "Pleo", "domain": "pleo.io", "country": "DK", "city": "Copenhagen",
"board": "ashby:pleo"},
{"name": "Novo Nordisk", "domain": "novonordisk.com", "country": "DK",
"city": "Bagsværd", "ats": "successfactors",
"city": "Bagsværd", "ats": "taleo",
"careers_url": "https://www.novonordisk.com/careers.html"},
{"name": "Odd", "board": "nosuch:odd"},
]}))
@@ -266,7 +313,7 @@ def test_the_seed_keeps_a_company_the_app_cannot_read(store: Store, tmp_path: Pa
assert (sub.target, sub.company) == ("ashby:pleo", "Pleo")
novo = store.company("novo-nordisk")
assert novo is not None
assert (novo.ats, novo.careers_url) == ("successfactors",
assert (novo.ats, novo.careers_url) == ("taleo",
"https://www.novonordisk.com/careers.html")
odd = store.company("odd")
assert odd is not None and odd.ats == ""