The seed was jobhunt-hq's 186 US boards, chosen because they could be read. It is now a hand-picked list of European tech employers, with `board` filled by the new `app.jobs.discover` from each company's own careers site and every board fetched once before it landed: 175 have one, and the rest keep the ATS host their site runs on (Teamtailor 32, Workday 12, SuccessFactors 9, ...) and a careers URL, as rows the app cannot read yet. Companies shows them as "not readable yet" with a link, behind a filter, so the next parser to write is the host that filter shows most. `app companies discover NAME DOMAIN [--add]` reads the home page, its careers links and the usual paths for a link into a known host, one level down on a careers page, and probes Greenhouse, Lever, Ashby, SmartRecruiters, Recruitee and Personio by slug when the pages link nothing. It is what the LinkedIn flow will call. Migration 7 adds companies.ats, country and city. The Workable parser now reads the v3 shape its list endpoint actually sends (location object, department list, shortcode and no URL or text); the first populated board showed it. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
212 lines
9.1 KiB
Python
212 lines
9.1 KiB
Python
"""Board discovery: which ATS a careers site names, and in what order the
|
|
site's pages are read."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
from pathlib import Path
|
|
|
|
import httpx
|
|
import pytest
|
|
|
|
from app.cli import seed_companies
|
|
from app.jobs import discover as mod
|
|
from app.jobs.discover import Discovery, boards_in, careers_links, discover, slug_guesses
|
|
from app.storage import Store
|
|
|
|
|
|
# ------------------------------------------------------------------ parsing
|
|
|
|
def test_boards_in_names_readable_hosts_with_their_slug() -> None:
|
|
page = """
|
|
<a href="https://job-boards.greenhouse.io/pleo">Open roles</a>
|
|
<script src="https://boards.greenhouse.io/embed/job_board/js?for=pleo"></script>
|
|
<a href="https://jobs.lever.co/spotify/abc-123">One role</a>
|
|
<iframe src="https://jobs.ashbyhq.com/DeepL/embed"></iframe>
|
|
<a href="https://apply.workable.com/acme/">Workable</a>
|
|
<a href="https://jobs.smartrecruiters.com/Bosch/123">SR</a>
|
|
<a href="https://acme.recruitee.com/o/backend">Recruitee</a>
|
|
<a href="https://acme-gmbh.jobs.personio.de/job/1">Personio</a>
|
|
"""
|
|
assert [(h, s) for h, s, _url in boards_in(page)] == [
|
|
("greenhouse", "pleo"), ("lever", "spotify"), ("ashby", "deepl"),
|
|
("workable", "acme"), ("smartrecruiters", "bosch"), ("recruitee", "acme"),
|
|
("personio", "acme-gmbh")]
|
|
|
|
|
|
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://acme.teamtailor.com/jobs">TT</a>
|
|
"""
|
|
assert boards_in(page) == [
|
|
("workday", "novo", "https://novo.wd3.myworkdayjobs.com"),
|
|
("successfactors", "", "performancemanager.successfactors.eu"),
|
|
("teamtailor", "acme", "https://acme.teamtailor.com")]
|
|
|
|
|
|
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>')
|
|
assert [(h, s) for h, s, _ in boards_in(page)] == [("greenhouse", "acme")]
|
|
assert boards_in("nothing here") == []
|
|
|
|
|
|
def test_careers_links_keeps_on_site_links_that_read_as_careers() -> None:
|
|
html = """
|
|
<a href="/about">About</a>
|
|
<a href="/careers">Careers</a>
|
|
<a href="https://jobs.acme.com/">We are hiring</a>
|
|
<a href="https://other.example/jobs">Partner jobs</a>
|
|
<a href="/en/karriere#top"><span>Karriere</span></a>
|
|
<a href="mailto:jobs@acme.com">Mail</a>
|
|
<a href="/careers">Careers again</a>
|
|
"""
|
|
assert careers_links(html, "https://www.acme.com/") == [
|
|
"https://www.acme.com/careers", "https://jobs.acme.com/",
|
|
"https://www.acme.com/en/karriere"]
|
|
|
|
|
|
def test_slug_guesses_come_from_the_key_and_the_domain() -> None:
|
|
assert slug_guesses("Trade Republic Bank GmbH", "www.traderepublic.com") == [
|
|
"trade-republic-bank", "traderepublicbank", "traderepublic"]
|
|
assert slug_guesses("Pleo", "pleo.io") == ["pleo"]
|
|
|
|
|
|
# ------------------------------------------------------------------- discover
|
|
|
|
class Site:
|
|
"""A fake web: `pages` maps a URL to `(final URL, html)`; anything else
|
|
is a page that did not answer. Remembers the order of fetches."""
|
|
|
|
def __init__(self, pages: dict[str, tuple[str, str] | str],
|
|
boards: set[tuple[str, str]] = frozenset()) -> None:
|
|
self.pages = {k: (v if isinstance(v, tuple) else (k, v)) for k, v in pages.items()}
|
|
self.boards = boards
|
|
self.fetched: list[str] = []
|
|
self.probed: list[tuple[str, str]] = []
|
|
|
|
def fetch(self, client: httpx.Client, url: str) -> tuple[str, str]:
|
|
self.fetched.append(url)
|
|
return self.pages.get(url, ("", ""))
|
|
|
|
def probe(self, client: httpx.Client, host: str, slug: str) -> bool:
|
|
self.probed.append((host, slug))
|
|
return (host, slug) in self.boards
|
|
|
|
|
|
def run(site: Site, name: str = "Acme", domain: str = "acme.com") -> Discovery:
|
|
with httpx.Client() as client:
|
|
return discover(name, domain, fetch=site.fetch, probe_slug=site.probe, client=client)
|
|
|
|
|
|
def test_a_board_named_on_the_home_page_ends_discovery_there() -> None:
|
|
site = Site({"https://acme.com/": '<a href="https://jobs.lever.co/acme">Jobs</a>'})
|
|
assert run(site) == Discovery(board="lever:acme", ats="lever",
|
|
careers_url="https://acme.com/",
|
|
evidence="jobs.lever.co/acme")
|
|
assert site.fetched == ["https://acme.com/"]
|
|
assert site.probed == []
|
|
|
|
|
|
def test_the_home_pages_own_careers_link_is_read_before_the_usual_paths() -> None:
|
|
site = Site({
|
|
"https://acme.com/": '<a href="/company/join-us">Join us</a>',
|
|
"https://acme.com/company/join-us": ('https://acme.com/company/join-us',
|
|
'<a href="https://acme.recruitee.com/">Open</a>'),
|
|
"https://acme.com/careers": '<a href="https://jobs.lever.co/wrong">no</a>',
|
|
})
|
|
found = run(site)
|
|
assert found.board == "recruitee:acme"
|
|
assert found.careers_url == "https://acme.com/company/join-us"
|
|
assert site.fetched == ["https://acme.com/", "https://acme.com/company/join-us"]
|
|
|
|
|
|
def test_a_careers_pages_own_link_is_followed_one_level_down() -> None:
|
|
site = Site({
|
|
"https://acme.com/": "<p>no links</p>",
|
|
"https://acme.com/careers": '<a href="/careers/open-positions">See open positions</a>',
|
|
"https://acme.com/careers/open-positions":
|
|
'<iframe src="https://jobs.ashbyhq.com/acme"></iframe>',
|
|
})
|
|
assert run(site).board == "ashby:acme"
|
|
assert site.fetched[:3] == ["https://acme.com/", "https://acme.com/careers",
|
|
"https://acme.com/careers/open-positions"]
|
|
|
|
|
|
def test_an_unreadable_host_is_kept_when_nothing_readable_turns_up() -> None:
|
|
site = Site({
|
|
"https://acme.com/": "<p>welcome</p>",
|
|
"https://acme.com/careers": '<a href="https://acme.wd3.myworkdayjobs.com/x">Jobs</a>',
|
|
})
|
|
found = run(site)
|
|
assert found == Discovery(ats="workday", careers_url="https://acme.com/careers",
|
|
evidence="https://acme.wd3.myworkdayjobs.com")
|
|
assert not found.readable
|
|
# Every slug was still tried on the hosts with a probe, in case a readable
|
|
# board exists that the pages do not link.
|
|
assert ("greenhouse", "acme") in site.probed
|
|
|
|
|
|
def test_slug_probes_find_a_board_the_pages_never_link() -> None:
|
|
site = Site({"https://acme.com/": "<p>a script draws the jobs</p>",
|
|
"https://acme.com/jobs": "<div id=app></div>"},
|
|
boards={("ashby", "acme")})
|
|
found = run(site)
|
|
assert found.board == "ashby:acme"
|
|
assert found.careers_url == "https://acme.com/jobs"
|
|
assert found.evidence == "https://api.ashbyhq.com/posting-api/job-board/acme"
|
|
|
|
|
|
def test_a_site_that_never_answers_gives_an_empty_discovery() -> None:
|
|
site = Site({})
|
|
assert run(site) == Discovery()
|
|
assert len(site.fetched) <= mod.MAX_PAGES + 1
|
|
|
|
|
|
def test_a_domain_is_folded_to_its_site() -> None:
|
|
site = Site({"https://acme.com/": '<a href="https://jobs.lever.co/acme">Jobs</a>'})
|
|
with httpx.Client() as client:
|
|
found = discover("Acme", "https://www.acme.com/some/page", fetch=site.fetch,
|
|
probe_slug=site.probe, client=client)
|
|
assert found.board == "lever:acme"
|
|
assert discover("Acme", "", fetch=site.fetch, probe_slug=site.probe) == Discovery()
|
|
|
|
|
|
# ---------------------------------------------------------------- the seed
|
|
|
|
@pytest.fixture
|
|
def store(tmp_path: Path) -> Store:
|
|
return Store(tmp_path / "t.db")
|
|
|
|
|
|
def test_the_seed_keeps_a_company_the_app_cannot_read(store: Store, tmp_path: Path,
|
|
capsys: pytest.CaptureFixture[str]) -> None:
|
|
seed = tmp_path / "companies.json"
|
|
seed.write_text(json.dumps({"companies": [
|
|
{"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",
|
|
"careers_url": "https://www.novonordisk.com/careers.html"},
|
|
{"name": "Odd", "board": "nosuch:odd"},
|
|
]}))
|
|
assert seed_companies(store, str(seed)) == {"added": 3, "readable": 1, "skipped": 0,
|
|
"total": 3}
|
|
pleo = store.company("pleo")
|
|
assert pleo is not None
|
|
assert (pleo.ats, pleo.country, pleo.city, pleo.careers_url) == (
|
|
"ashby", "DK", "Copenhagen", "https://jobs.ashbyhq.com/pleo")
|
|
[sub] = store.subscriptions(source="ats")
|
|
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",
|
|
"https://www.novonordisk.com/careers.html")
|
|
odd = store.company("odd")
|
|
assert odd is not None and odd.ats == ""
|
|
assert "not a known board" in capsys.readouterr().err
|
|
# Re-running adds nothing and edits nothing.
|
|
assert seed_companies(store, str(seed))["skipped"] == 3
|