diff --git a/app/jobs/discover.py b/app/jobs/discover.py index c118418..2e35765 100644 --- a/app/jobs/discover.py +++ b/app/jobs/discover.py @@ -10,6 +10,10 @@ read; any other host is recorded as `ats`, with its slug where the URL carries one, so the company is kept as one the app cannot read yet rather than dropped. +A Teamtailor site on the company's own domain names no slug: the page only +loads Teamtailor's CDN. The board there is the site's own host, and it is +taken only once that host answers `/jobs.rss` with a Teamtailor feed. + Only when no page names a host at all are the hosts with a cheap per-slug endpoint (`_PROBES`) probed with the company's own slug, because a site that draws its jobs from an iframe or a script leaves no link to find. A page that @@ -50,7 +54,7 @@ MAX_PAGES = 6 #: The hosts the `ats` plugin parses; a match on one of these is a `board`. READABLE = ("greenhouse", "lever", "ashby", "workable", "smartrecruiters", - "recruitee", "personio") + "recruitee", "personio", "teamtailor") #: host -> pattern over a URL. Group 1, where there is one, is the slug the #: host names the company by; a host with no group is recognised but its @@ -70,12 +74,14 @@ HOSTS: tuple[tuple[str, re.Pattern[str]], ...] = tuple( ("smartrecruiters", r"(?:jobs|careers|api)\.smartrecruiters\.com/(?:v1/companies/)?([A-Za-z0-9_-]+)"), ("recruitee", r"https?://([a-z0-9-]+)\.recruitee\.com"), ("personio", r"https?://([a-z0-9-]+)\.jobs\.personio\.(?:de|com)"), + ("teamtailor", r"https?://([a-z0-9-]+)\.teamtailor\.com"), + # No slug: a career site on the company's own domain, which only loads + # Teamtailor's CDN. `_discover` reads its board off the page's host. + ("teamtailor", r"cdn\.teamtailor\.com|teamtailor-cdn|teamtailor\.com/assets"), # Not readable. The slug, where the URL has one, is kept for the day # a parser exists. ("workday", r"https?://([a-z0-9-]+)\.wd\d+\.myworkdayjobs\.com"), ("successfactors", r"(?:career|jobs|performancemanager)\d*\.successfactors\.(?:eu|com)|\.sapsf\.(?:eu|com)"), - ("teamtailor", r"https?://([a-z0-9-]+)\.teamtailor\.com"), - ("teamtailor", r"cdn\.teamtailor\.com|teamtailor-cdn|teamtailor\.com/assets"), ("icims", r"https?://([a-z0-9-]+)\.icims\.com"), ("taleo", r"\.taleo\.net"), ("jobvite", r"jobs\.jobvite\.com/([a-z0-9-]+)"), @@ -97,6 +103,10 @@ HOSTS: tuple[tuple[str, re.Pattern[str]], ...] = tuple( ("hibob", r"https?://([a-z0-9-]+)\.hibob\.com"), )) +#: 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" + #: Paths a careers page usually lives at, tried after the home page's own #: links so the site's word for it wins over a guess. CAREERS_PATHS = ("/careers", "/careers/", "/jobs", "/en/careers", "/company/careers", @@ -117,9 +127,10 @@ _TAGS = re.compile(r"<[^>]+>") #: Words a pattern's slug group can catch that name no board: the hosts' #: own path segments, the analytics subdomain Recruitee sites embed, and -#: the CDN Teamtailor sites load from (cdn.teamtailor.com). +#: the CDN and the admin app Teamtailor sites load from (cdn.teamtailor.com, +#: app.teamtailor.com). _NOT_SLUGS = frozenset({"embed", "boards", "v1", "api", "www", "jobs", "careers", "apply", - "careers-analytics", "cdn"}) + "careers-analytics", "cdn", "app"}) Found = tuple[str, str, str] # (host, slug, the URL that named it) @@ -236,6 +247,7 @@ _PROBES = { "smartrecruiters": "https://api.smartrecruiters.com/v1/companies/{slug}/postings?limit=1", "recruitee": "https://{slug}.recruitee.com/api/offers/", "personio": "https://{slug}.jobs.personio.de/xml", + "teamtailor": "https://{slug}.teamtailor.com/jobs.rss", } @@ -260,6 +272,8 @@ def probe(client: httpx.Client, host: str, slug: str) -> bool: return b'"offers":[' in body and b'"offers":[]' not in body if host == "personio": return b"" in body + if host == "teamtailor": + return b"" in body return True @@ -305,6 +319,7 @@ def _discover(name: str, site: str, client: httpx.Client, fetch: Fetch, home_url, home = fetch(client, f"https://{site}/") unreadable: Discovery | None = None careers_page = "" + own_sites: list[tuple[str, str]] = [] # (host, page) that loaded Teamtailor's CDN def first_readable(found: list[Found], page: str) -> Discovery | None: """The first readable board on a page. Otherwise the first host named @@ -312,6 +327,9 @@ def _discover(name: str, site: str, client: httpx.Client, fetch: Fetch, may name teamtailor by its CDN before it links acme.teamtailor.com.""" nonlocal unreadable for host, slug, url in found: + site_host = httpx.URL(page).host if page else "" + if host == "teamtailor" and not slug and site_host and (site_host, page) not in own_sites: + own_sites.append((site_host, page)) if host in READABLE and slug: return Discovery(board=f"{host}:{slug}", ats=host, ats_slug=slug, careers_url=page, evidence=url) @@ -347,6 +365,14 @@ def _discover(name: str, site: str, client: httpx.Client, fetch: Fetch, if hit := first_readable(boards_in(text), final): return hit queue[:0] = [link for link in careers_links(text, final)[:2] if link not in seen] + # A page loaded Teamtailor's CDN and linked no *.teamtailor.com: the site + # itself is the board, if it serves the feed. + for site_host, page in own_sites: + feed = f"https://{site_host}/jobs.rss" + _final, text = fetch(client, feed) + if TEAMTAILOR_FEED in text: + return Discovery(board=f"teamtailor:{site_host}", ats="teamtailor", + ats_slug=site_host, careers_url=page, evidence=feed) # A page named a host the app cannot read: that is the answer, and a # probe could only add another tenant's board of the same name. if unreadable is not None: diff --git a/tests/test_discover.py b/tests/test_discover.py index 58fe9c9..5c1b581 100644 --- a/tests/test_discover.py +++ b/tests/test_discover.py @@ -160,7 +160,7 @@ def test_a_readable_board_on_a_later_page_still_beats_an_unreadable_host() -> No assert site.probed == [] -def test_an_unreadable_hosts_slug_is_kept_when_a_later_link_names_it() -> None: +def test_a_teamtailor_link_is_a_board_even_after_the_cdn_named_it_first() -> None: """The CDN names teamtailor before any link does; the slug comes from the first link that carries one, the acme of acme.teamtailor.com.""" site = Site({ @@ -168,9 +168,49 @@ def test_an_unreadable_hosts_slug_is_kept_when_a_later_link_names_it() -> None: "https://acme.com/careers": 'Jobs', }) found = run(site) - assert (found.ats, found.ats_slug, found.board) == ("teamtailor", "acme-jobs", "") + assert (found.ats, found.ats_slug, found.board) == ("teamtailor", "acme-jobs", + "teamtailor:acme-jobs") + assert found.readable assert found.evidence == "https://acme-jobs.teamtailor.com" - assert found.careers_url == "https://acme.com/" + assert found.careers_url == "https://acme.com/careers" + + +def test_a_teamtailor_site_on_its_own_domain_is_read_off_its_host() -> None: + """Only the CDN is named, so the site's host is the slug, once that host + serves the feed.""" + site = Site({ + "https://acme.com/": 'Careers', + "https://careers.acme.com/": '', + "https://careers.acme.com/jobs.rss": + '', + }) + found = run(site) + assert found == Discovery(board="teamtailor:careers.acme.com", ats="teamtailor", + ats_slug="careers.acme.com", + careers_url="https://careers.acme.com/", + evidence="https://careers.acme.com/jobs.rss") + assert site.probed == [] + + +def test_a_page_that_only_loads_the_cdn_is_not_a_board_without_the_feed() -> None: + site = Site({"https://acme.com/": ''}) + found = run(site) + assert (found.ats, found.ats_slug, found.board) == ("teamtailor", "", "") + assert not found.readable + assert "https://acme.com/jobs.rss" in site.fetched + + +def test_the_admin_app_and_cdn_hosts_are_no_teamtailor_slug() -> None: + page = 'a' + assert [(h, s) for h, s, _ in boards_in(page)] == [("teamtailor", "")] + + +def test_a_teamtailor_board_is_found_by_its_slug_probe() -> None: + site = Site({"https://acme.com/": "

a script draws the jobs

"}, + boards={("teamtailor", "acme")}) + found = run(site) + assert found.board == "teamtailor:acme" + assert found.evidence == "https://acme.teamtailor.com/jobs.rss" def test_slug_probes_find_a_board_the_pages_never_link() -> None: