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

+39 -16
View File
@@ -9,9 +9,9 @@ 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.jobs.sources import seed_companies
from app.storage import Store
@@ -103,7 +103,7 @@ def run(site: Site, name: str = "Acme", domain: str = "acme.com") -> Discovery:
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",
assert run(site) == Discovery(board="lever:acme", ats="lever", ats_slug="acme",
careers_url="https://acme.com/",
evidence="jobs.lever.co/acme")
assert site.fetched == ["https://acme.com/"]
@@ -135,18 +135,42 @@ def test_a_careers_pages_own_link_is_followed_one_level_down() -> None:
"https://acme.com/careers/open-positions"]
def test_an_unreadable_host_is_kept_when_nothing_readable_turns_up() -> 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>',
})
}, boards={("greenhouse", "acme")})
found = run(site)
assert found == Discovery(ats="workday", careers_url="https://acme.com/careers",
assert found == Discovery(ats="workday", ats_slug="acme",
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
# 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.
assert site.probed == []
def test_a_readable_board_on_a_later_page_still_beats_an_unreadable_host() -> None:
site = Site({
"https://acme.com/": '<script src="https://cdn.teamtailor.com/x.js"></script>'
'<a href="/careers">Careers</a>',
"https://acme.com/careers": '<a href="https://jobs.lever.co/acme">Jobs</a>',
})
assert run(site).board == "lever:acme"
assert site.probed == []
def test_an_unreadable_hosts_slug_is_kept_when_a_later_link_names_it() -> 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({
"https://acme.com/": '<script src="https://cdn.teamtailor.com/x.js"></script>',
"https://acme.com/careers": '<a href="https://acme-jobs.teamtailor.com/jobs">Jobs</a>',
})
found = run(site)
assert (found.ats, found.ats_slug, found.board) == ("teamtailor", "acme-jobs", "")
assert found.evidence == "https://acme-jobs.teamtailor.com"
assert found.careers_url == "https://acme.com/"
def test_slug_probes_find_a_board_the_pages_never_link() -> None:
@@ -181,8 +205,7 @@ 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:
def test_the_seed_keeps_a_company_the_app_cannot_read(store: Store, tmp_path: Path) -> None:
seed = tmp_path / "companies.json"
seed.write_text(json.dumps({"companies": [
{"name": "Pleo", "domain": "pleo.io", "country": "DK", "city": "Copenhagen",
@@ -192,12 +215,13 @@ def test_the_seed_keeps_a_company_the_app_cannot_read(store: Store, tmp_path: Pa
"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}
result = seed_companies(store, seed)
assert result == {"added": 3, "boards": 1, "skipped": 0, "total": 3,
"problems": ["odd: 'nosuch:odd' is not a known board; kept without it"]}
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")
assert (pleo.ats, pleo.ats_slug, pleo.country, pleo.city, pleo.careers_url) == (
"ashby", "pleo", "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")
@@ -206,6 +230,5 @@ def test_the_seed_keeps_a_company_the_app_cannot_read(store: Store, tmp_path: Pa
"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
assert seed_companies(store, seed)["skipped"] == 3