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

+53 -4
View File
@@ -386,7 +386,7 @@ def test_companies_lists_board_and_open_role_count(
sub = store.add_subscription("ats", "greenhouse:acme", company="Acme", board="greenhouse")
store.add_company("Acme", key="acme", ats="greenhouse", country="DK")
store.upsert_role(posting("1", company="Acme"), sub)
store.add_company("Other", key="other") # known only from a search: no board
store.add_company("Other", key="other") # no board found
store.add_company("Novo", key="novo", ats="successfactors", # followed, not readable
careers_url="https://novo.example/careers")
@@ -395,7 +395,8 @@ def test_companies_lists_board_and_open_role_count(
[row] = [c for c in res.json() if c["key"] == "acme"]
assert row == {"key": "acme", "name": "Acme", "board": "greenhouse",
"subscription_id": sub.id, "on": True, "affinity": 0, "open_roles": 1,
"ats": "greenhouse", "careers_url": "", "country": "DK"}
"ats": "greenhouse", "ats_slug": "", "careers_url": "",
"country": "DK"}
[other] = [c for c in res.json() if c["key"] == "other"]
assert (other["board"], other["subscription_id"], other["on"], other["ats"]) == (
"", None, None, "")
@@ -653,7 +654,10 @@ def test_the_sources_page_has_a_section_per_plugin(client: TestClient) -> None:
# Company boards: the follow form, the agent select, the list.
assert 'id="companies-list"' in page and 'id="c-agent"' in page
assert 'id="b-host"' in page and 'id="b-slug"' in page and 'id="b-name"' in page
assert '<option value="greenhouse">' in page and '<option value="personio">' in page
# The host select is plugins.ats's HOSTS, not a list typed into the page.
from plugins.ats import HOSTS
for host, label in HOSTS.items():
assert f'<option value="{host}">{label}</option>' in page
boards = page[page.index('id="company-boards"'):page.index('id="runs"')].lower()
assert "hidden" in boards and "mute" not in boards
# Runs: the pull button, the queue's elements, and the log as its last
@@ -915,11 +919,56 @@ def test_a_board_is_followed_only_if_it_answers(
assert res.json()["found"] == 1 and res.json()["source"]["target"] == "ashby:acme"
assert store.company("acme") is not None
# Following a company that exists goes through `set_board`: the same
# board again is the same subscription, not a refusal or a second one.
again = client.post("/api/boards", json={"board": "ashby:acme", "name": "Acme"})
assert again.status_code == 422 and "already followed" in again.json()["detail"]
assert again.status_code == 201
assert again.json()["source"]["id"] == res.json()["source"]["id"]
bad = client.post("/api/boards", json={"board": "acme", "name": "Other"})
assert bad.status_code == 422 and "host:slug" in bad.json()["detail"]
def down(target: str) -> list[dict[str, str]]:
raise OSError("connection refused")
monkeypatch.setattr(ats, "fetch_board", down)
dead = client.post("/api/boards", json={"board": "ashby:other", "name": "Other"})
assert dead.status_code == 422 and "did not answer" in dead.json()["detail"]
assert store.company("other") is None
def test_a_companys_board_is_set_replaced_and_detached(
client: TestClient, store: Store, monkeypatch: pytest.MonkeyPatch) -> None:
import plugins.ats as ats
monkeypatch.setattr(ats, "fetch_board", lambda target: []) # between openings
store.add_company("Acme", key="acme", ats="teamtailor", ats_slug="acme")
res = client.post("/api/companies/acme/board", json={"board": "greenhouse:acme"})
assert res.status_code == 200
body = res.json()
assert (body["found"], body["closed"], body["source"]["target"]) == (0, 0, "greenhouse:acme")
sub_id = body["source"]["id"]
store.upsert_role(posting("1", company="Acme"), store.subscription(sub_id))
[row] = client.get("/api/companies").json()
assert (row["board"], row["subscription_id"], row["ats"], row["ats_slug"]) == (
"greenhouse", sub_id, "greenhouse", "acme")
res = client.post("/api/companies/acme/board", json={"board": "lever:acme"})
assert res.json()["closed"] == 1 and res.json()["source"]["id"] == sub_id
res = client.delete("/api/companies/acme/board")
assert res.status_code == 200 and res.json() == {"closed": 0}
[row] = client.get("/api/companies").json()
assert (row["board"], row["subscription_id"], row["ats"]) == ("", None, "lever")
assert client.get("/api/sources").json()["boards"] == []
assert client.delete("/api/companies/acme/board").status_code == 409
assert client.post("/api/companies/nope/board",
json={"board": "lever:acme"}).status_code == 404
assert client.delete("/api/companies/nope/board").status_code == 404
bad = client.post("/api/companies/acme/board", json={"board": "teamtailor:acme"})
assert bad.status_code == 422 and "host:slug" in bad.json()["detail"]
# ------------------------------------------------- roles: text and summary