Every way a company gets a board is set_board, and an unreadable host keeps its slug

`app.jobs.sources.set_board` attaches a board to an existing company,
replaces the one it has (closing the old board's open roles) or creates
the company, with row and subscription changed in one transaction by
`Store.set_company_board`. A board that lists zero roles is kept. `add`,
`discover --add`, the seed importer (moved out of app/cli.py) and the new
`POST|DELETE /api/companies/{key}/board` all go through it; a seed re-run
attaches a board to a row that never had one. A company's subscription is
rewritten in place, and detaching hides it.

`companies.ats_slug` (migration 9) keeps the slug of a host the app
cannot read yet, and discovery returns such a host before probing slugs.
The Companies rows get Set board / Change, the host select is rendered
from `plugins.ats.HOSTS`, and a row with nothing found reads "board not
found" and is in the "Not readable yet" filter.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Opus 5.5 committed 2026-09-29 14:04:52 +02:00
1 parent 0558ef19ed
commit 3b209d628a
18 files changed
+1038 -178

No files matched your search

+30 -14
View File
@@ -6,16 +6,20 @@ website, not from a board. This module gets from the one to the other: it
fetches the site's careers page, or the pages the home page links to as
careers, and looks for a link into one of the hosts in `HOSTS`. A readable
host (one the `ats` plugin parses) becomes a `board` target the pull can
read; any other host is recorded as `ats`, so the company is kept as one the
app cannot read yet rather than dropped.
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.
When no page names a host, the three hosts with a cheap per-slug endpoint
(Greenhouse, Lever, Ashby) are 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.
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
names an unreadable host is the answer: a probe on a common name can hit
another tenant's board.
found = discover("Pleo", "pleo.io")
found.board # "greenhouse:pleo", or "" when nothing readable
found.ats # "greenhouse", "workday", ... or "" when unknown
found.ats_slug # the name that host knows the company by, or ""
found.careers_url # the page that named the host, or the careers page
found.evidence # the URL that named it
@@ -30,7 +34,7 @@ from __future__ import annotations
import logging
import re
from collections.abc import Callable, Iterable
from dataclasses import dataclass
from dataclasses import dataclass, replace
from urllib.parse import urljoin
import httpx
@@ -112,9 +116,10 @@ _ANCHOR = re.compile(r"<a\b[^>]*href\s*=\s*[\"']([^\"'#][^\"']*)[\"'][^>]*>(.*?)
_TAGS = re.compile(r"<[^>]+>")
#: Words a pattern's slug group can catch that name no board: the hosts'
#: own path segments, and the analytics subdomain Recruitee sites embed.
#: own path segments, the analytics subdomain Recruitee sites embed, and
#: the CDN Teamtailor sites load from (cdn.teamtailor.com).
_NOT_SLUGS = frozenset({"embed", "boards", "v1", "api", "www", "jobs", "careers", "apply",
"careers-analytics"})
"careers-analytics", "cdn"})
Found = tuple[str, str, str] # (host, slug, the URL that named it)
@@ -125,6 +130,7 @@ class Discovery:
board: str = ""
ats: str = ""
ats_slug: str = ""
careers_url: str = ""
evidence: str = ""
@@ -301,14 +307,22 @@ def _discover(name: str, site: str, client: httpx.Client, fetch: Fetch,
careers_page = ""
def first_readable(found: list[Found], page: str) -> Discovery | None:
"""The first readable board on a page. Otherwise the first host named
is remembered, with the first slug any page gives that host: a page
may name teamtailor by its CDN before it links acme.teamtailor.com."""
nonlocal unreadable
for host, slug, url in found:
if host in READABLE and slug:
return Discovery(board=f"{host}:{slug}", ats=host, careers_url=page,
evidence=url)
return Discovery(board=f"{host}:{slug}", ats=host, ats_slug=slug,
careers_url=page, evidence=url)
if unreadable is None and found:
host, slug, url = found[0]
unreadable = Discovery(ats=host, careers_url=page, evidence=url)
unreadable = Discovery(ats=host, ats_slug=slug, careers_url=page, evidence=url)
if unreadable is not None and not unreadable.ats_slug:
for host, slug, url in found:
if host == unreadable.ats and slug:
unreadable = replace(unreadable, ats_slug=slug, evidence=url)
break
return None
if home and (hit := first_readable(boards_in(home), home_url)):
@@ -333,11 +347,13 @@ 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 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:
return unreadable
for slug in slug_guesses(name, site):
for host in _PROBES:
if probe_slug(client, host, slug):
return Discovery(board=f"{host}:{slug}", ats=host,
return Discovery(board=f"{host}:{slug}", ats=host, ats_slug=slug,
careers_url=careers_page, evidence=_PROBES[host].format(slug=slug))
if unreadable is not None:
return unreadable
return Discovery(careers_url=careers_page)