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

+94 -3
View File
@@ -62,7 +62,7 @@ def test_schema_creates_on_an_empty_file(tmp_path: Path) -> None:
"application_events", "agents", "scores", "state"} <= tables
assert "idx_roles_cluster" in indexes
assert store.migrations_applied == []
assert LATEST == 8
assert LATEST == 9
# A second open finds it current and applies nothing.
assert Store(path).migrations_applied == []
@@ -94,7 +94,7 @@ def test_a_v1_file_migrates_to_the_shape_a_new_file_has(tmp_path: Path) -> None:
# v1 had affinity on the company; the vote columns v4 added and v6
# drops again are not in a fresh file, so there is nothing to put back.
conn.execute("ALTER TABLE companies ADD COLUMN affinity INTEGER NOT NULL DEFAULT 0")
for column in ("ats", "country", "city"): # v7
for column in ("ats", "country", "city", "ats_slug"): # v7, v9
conn.execute(f"ALTER TABLE companies DROP COLUMN {column}")
for table in ("vectors", "role_tags", "agent_companies", "role_votes"):
conn.execute(f"DROP TABLE {table}")
@@ -107,6 +107,21 @@ def test_a_v1_file_migrates_to_the_shape_a_new_file_has(tmp_path: Path) -> None:
assert sorted(_columns(old, table)) == sorted(_columns(fresh, table))
def test_a_v8_file_gains_ats_slug_and_keeps_its_companies(tmp_path: Path) -> None:
path = tmp_path / "v8.db"
Store(path).add_company("Acme", ats="teamtailor", country="DK")
with sqlite3.connect(path) as conn:
conn.execute("ALTER TABLE companies DROP COLUMN ats_slug")
conn.execute("PRAGMA user_version = 8")
migrated = Store(path)
assert migrated.migrations_applied == [9]
acme = migrated.company("acme")
assert acme is not None
assert (acme.ats, acme.country, acme.ats_slug) == ("teamtailor", "DK", "")
def _downgrade_to_v4(path: Path) -> None:
"""A fresh file put back to the v4 shape: votes on the role, affinity on
the company, no read state, no tags, no per-agent tables."""
@@ -116,7 +131,7 @@ def _downgrade_to_v4(path: Path) -> None:
conn.execute("ALTER TABLE roles ADD COLUMN vote INTEGER CHECK (vote IN (-1, 0, 1))")
conn.execute("ALTER TABLE roles ADD COLUMN voted_at TEXT")
conn.execute("ALTER TABLE companies ADD COLUMN affinity INTEGER NOT NULL DEFAULT 0")
for column in ("ats", "country", "city"): # v7
for column in ("ats", "country", "city", "ats_slug"): # v7, v9
conn.execute(f"ALTER TABLE companies DROP COLUMN {column}")
conn.execute("ALTER TABLE agents DROP COLUMN limits") # v8
conn.execute("DROP TABLE agent_companies")
@@ -642,6 +657,82 @@ def test_open_role_counts_and_company_boards(store: Store) -> None:
assert store.company_boards() == {"acme": "greenhouse"}
def test_set_company_board_creates_the_row_and_its_board_together(store: Store) -> None:
company, sub, closed = store.set_company_board(
"acme", "greenhouse:acme", host="greenhouse", name="Acme",
fields={"ats": "greenhouse", "ats_slug": "acme", "country": "DK"})
assert (company.name, company.ats, company.ats_slug, company.country) == (
"Acme", "greenhouse", "acme", "DK")
assert sub is not None and closed == 0
assert (sub.target, sub.label, sub.company, sub.board, sub.show) == (
"greenhouse:acme", "Acme", "Acme", "greenhouse", 1)
assert store.company_subscription("acme") == sub
assert store.company_boards() == {"acme": "greenhouse"}
def test_a_board_clash_leaves_no_company_row(store: Store) -> None:
"""The subscription insert fails on UNIQUE (source, target), and the
company row written a statement earlier goes with it."""
store.set_company_board("acme", "greenhouse:acme", host="greenhouse", name="Acme")
with pytest.raises(ValueError, match="already has 'greenhouse:acme'"):
store.set_company_board("beta", "greenhouse:acme", host="greenhouse", name="Beta")
assert store.company("beta") is None
assert [s.company for s in store.subscriptions(source="ats")] == ["Acme"]
def test_a_clash_on_replace_leaves_the_old_board_and_its_roles(store: Store) -> None:
store.set_company_board("acme", "greenhouse:acme", host="greenhouse", name="Acme")
_, beta, _ = store.set_company_board("beta", "lever:beta", host="lever", name="Beta")
assert beta is not None
store.upsert_role(posting("1", company="Beta"), beta)
with pytest.raises(ValueError):
store.set_company_board("beta", "greenhouse:acme", host="greenhouse",
fields={"ats": "greenhouse"})
assert store.company_subscription("beta") == beta
assert store.company("beta").ats == "" # type: ignore[union-attr]
assert [r.source_id for r in store.roles()] == ["1"] # still open
def test_replacing_a_board_rewrites_it_in_place_and_closes_the_old_roles(
store: Store) -> None:
_, old, _ = store.set_company_board("acme", "greenhouse:acme", host="greenhouse",
name="Acme")
assert old is not None
store.update_subscription(old.id, fetch=False, target_id="gh-1")
store.upsert_role(posting("1", company="Acme"), old)
store.upsert_role(posting("2", company="Acme"), old)
company, new, closed = store.set_company_board("acme", "ashby:acme", host="ashby",
fields={"ats": "ashby"})
assert closed == 2 and store.roles() == []
assert new is not None and new.id == old.id
assert (new.target, new.board, new.target_id, new.fetch, new.subscribed) == (
"ashby:acme", "ashby", "", 1, 1)
assert company.ats == "ashby"
# The same board again closes nothing.
store.upsert_role(posting("3", company="Acme"), new)
assert store.set_company_board("acme", "ashby:acme", host="ashby")[2] == 0
assert [r.source_id for r in store.roles()] == ["3"]
def test_detaching_a_board_hides_it_closes_its_roles_and_keeps_the_row(
store: Store) -> None:
_, sub, _ = store.set_company_board("acme", "greenhouse:acme", host="greenhouse",
name="Acme")
assert sub is not None
store.upsert_role(posting("1", company="Acme"), sub)
company, detached, closed = store.set_company_board("acme", "")
assert closed == 1 and company.key == "acme"
assert detached is not None
assert (detached.subscribed, detached.fetch, detached.show) == (0, 0, 0)
assert store.company_boards() == {}
# The next board reuses the row rather than clashing on its label.
_, again, _ = store.set_company_board("acme", "lever:acme", host="lever")
assert again is not None and again.id == sub.id and again.show == 1
with pytest.raises(KeyError):
store.set_company_board("nope", "")
# ----------------------------------------------------------- subscriptions
def test_subscriptions_crud(store: Store) -> None: