Merge branch 'r2-web'

# Conflicts:
#	app/static/roles.js
#	app/web/api.py
#	tests/test_web.py
This commit is contained in:
Wolf committed 2026-09-29 15:31:35 +02:00
commit a629eda8de
13 files changed
+548 -203

No files matched your search

+177 -67
View File
@@ -17,8 +17,9 @@ from fastapi.testclient import TestClient
from app.config import Config, ServerConfig
from app.main import create_app
from app.models import excerpt as models_excerpt
from app.storage import Store
from app.web import MOVED, SETTINGS, TABS
from app.web import SETTINGS, TABS
from app.web.api import _score_after_change
from app.web.pages import SECTIONS
from auth import AuthConfig
@@ -78,16 +79,17 @@ def test_list_roles_filters_by_query_place_and_function(
store.upsert_role(posting("1", company="Acme", place="Berlin", function="engineering"))
store.upsert_role(posting("2", company="Acme", place="Munich", function="sales"))
store.upsert_role(posting("3", company="Other", place="Berlin", function="engineering"))
uid = {r.source_id: r.uid for r in store.roles()}
res = client.get("/api/roles", params={"q": "engineer", "place": "Berlin"})
assert res.status_code == 200
assert {r["source_id"] for r in res.json()["items"]} == {"1", "3"}
assert {r["uid"] for r in res.json()["items"]} == {uid["1"], uid["3"]}
res = client.get("/api/roles", params={"function": "sales"})
assert [r["source_id"] for r in res.json()["items"]] == ["2"]
assert [r["uid"] for r in res.json()["items"]] == [uid["2"]]
res = client.get("/api/roles", params={"company": "other"})
assert [r["source_id"] for r in res.json()["items"]] == ["3"]
assert [r["uid"] for r in res.json()["items"]] == [uid["3"]]
def test_list_roles_exposes_and_filters_by_pay(client: TestClient, store: Store) -> None:
@@ -98,19 +100,20 @@ def test_list_roles_exposes_and_filters_by_pay(client: TestClient, store: Store)
currency="EUR", salary_text="EUR 70,000 to 90,000 per year"))
store.upsert_role(posting("stated", salary_text="USD 45 to 60 per hour"))
store.upsert_role(posting("none"))
uid = {r.source_id: r.uid for r in store.roles()}
items = {r["source_id"]: r for r in client.get("/api/roles").json()["items"]}
assert items["normalised"]["salary_text"] == "EUR 70,000 to 90,000 per year"
assert items["normalised"]["salary_state"] == "normalised"
assert items["stated"]["salary_state"] == "stated"
assert items["none"]["salary_state"] == ""
items = {r["uid"]: r for r in client.get("/api/roles").json()["items"]}
assert items[uid["normalised"]]["salary_text"] == "EUR 70,000 to 90,000 per year"
assert items[uid["normalised"]]["salary_state"] == "normalised"
assert items[uid["stated"]]["salary_state"] == "stated"
assert items[uid["none"]]["salary_state"] == ""
res = client.get("/api/roles", params={"pay": "stated"})
assert {r["source_id"] for r in res.json()["items"]} == {"normalised", "stated"}
assert {r["uid"] for r in res.json()["items"]} == {uid["normalised"], uid["stated"]}
res = client.get("/api/roles", params={"pay": "normalised"})
assert [r["source_id"] for r in res.json()["items"]] == ["normalised"]
assert [r["uid"] for r in res.json()["items"]] == [uid["normalised"]]
res = client.get("/api/roles", params={"pay": "stated_only"})
assert [r["source_id"] for r in res.json()["items"]] == ["stated"]
assert [r["uid"] for r in res.json()["items"]] == [uid["stated"]]
assert client.get("/api/roles", params={"pay": "bogus"}).status_code == 422
@@ -128,20 +131,21 @@ def test_muted_roles_are_hidden_unless_show_muted(client: TestClient, store: Sto
store.upsert_role(posting("2", company="Other"))
agent = store.save_agent("A")
other = store.save_agent("B")
uid = {r.source_id: r.uid for r in store.roles()}
def shown(**params: Any) -> set[str]:
return {r["source_id"] for r in client.get("/api/roles", params=params).json()["items"]}
return {r["uid"] for r in client.get("/api/roles", params=params).json()["items"]}
assert shown() == {"1", "2"}
assert shown() == {uid["1"], uid["2"]}
# No agent in the body: the default agent's, which is also who a list
# without `agent` hides for.
assert client.post("/api/companies/acme/affinity", json={"affinity": -1}).status_code == 200
assert shown() == {"2"}
assert shown(show_muted="true") == {"1", "2"}
assert shown(agent=agent.id, order="newest") == {"2"}
assert shown() == {uid["2"]}
assert shown(show_muted="true") == {uid["1"], uid["2"]}
assert shown(agent=agent.id, order="newest") == {uid["2"]}
# Hidden is per agent: the other agent still sees Acme.
assert shown(agent=other.id, order="newest") == {"1", "2"}
assert shown(agent=other.id, order="newest") == {uid["1"], uid["2"]}
assert [c["affinity"] for c in client.get("/api/companies").json()] == [-1]
assert [c["affinity"] for c in
client.get("/api/companies", params={"agent": other.id}).json()] == [0]
@@ -162,9 +166,10 @@ def test_muted_is_excluded_before_the_limit_not_after(
for i in range(3):
store.upsert_role(posting(f"a{i}", company="Acme"))
clock.tick()
uid = {r.source_id: r.uid for r in store.roles()}
res = client.get("/api/roles", params={"limit": 1})
assert [r["source_id"] for r in res.json()["items"]] == ["other"]
assert [r["uid"] for r in res.json()["items"]] == [uid["other"]]
assert res.json()["total"] == 1
@@ -175,12 +180,13 @@ def test_list_roles_pages_by_offset_and_counts_the_total(
for i in range(5):
store.upsert_role(posting(str(i)))
clock.tick()
uid = {r.source_id: r.uid for r in store.roles()}
first = client.get("/api/roles", params={"limit": 2}).json()
assert [r["source_id"] for r in first["items"]] == ["4", "3"]
assert [r["uid"] for r in first["items"]] == [uid["4"], uid["3"]]
assert first["total"] == 5
rest = client.get("/api/roles", params={"limit": 2, "offset": 4}).json()
assert [r["source_id"] for r in rest["items"]] == ["0"] and rest["total"] == 5
assert [r["uid"] for r in rest["items"]] == [uid["0"]] and rest["total"] == 5
assert client.get("/api/roles", params={"offset": 9}).json() == {"items": [], "total": 5}
assert client.get("/api/roles", params={"offset": -1}).status_code == 422
assert len(client.get("/api/roles").json()["items"]) == 5 # default 60
@@ -202,13 +208,13 @@ def test_a_vote_is_set_cleared_and_filtered_on(client: TestClient, store: Store)
def judged(value: str, **params: Any) -> set[str]:
page = client.get("/api/roles", params={"judged": value, **params}).json()
return {r["source_id"] for r in page["items"]}
return {r["uid"] for r in page["items"]}
assert judged("liked") == {"liked"}
assert judged("passed") == {"passed"}
assert judged("unjudged") == {"open"}
assert judged("") == {"liked", "passed", "fine", "open"} # a pass is not hidden
assert judged("liked", agent=agent.id, order="newest") == {"liked"}
assert judged("liked") == {uid["liked"]}
assert judged("passed") == {uid["passed"]}
assert judged("unjudged") == {uid["open"]}
assert judged("") == {uid["liked"], uid["passed"], uid["fine"], uid["open"]} # a pass is not hidden
assert judged("liked", agent=agent.id, order="newest") == {uid["liked"]}
assert client.get("/api/roles", params={"judged": "maybe"}).status_code == 422
assert client.get(f"/api/roles/{uid['liked']}").json()["vote"] == 1
assert client.get(f"/api/roles/{uid['liked']}", params={"agent": agent.id}).json()["vote"] == 1
@@ -216,7 +222,7 @@ def test_a_vote_is_set_cleared_and_filtered_on(client: TestClient, store: Store)
cleared = client.delete(f"/api/roles/{uid['liked']}/vote")
assert cleared.status_code == 200
assert cleared.json()["vote"] is None and cleared.json()["voted_at"] is None
assert judged("unjudged") == {"open", "liked"}
assert judged("unjudged") == {uid["open"], uid["liked"]}
cleared = client.delete(f"/api/roles/{uid['passed']}/vote", params={"agent": agent.id})
assert cleared.status_code == 200 and cleared.json()["vote"] is None
@@ -280,12 +286,12 @@ def test_roles_with_an_agent_can_be_ordered_newest_and_keep_the_votes(
store.set_vote(agent.id, uid["1"], 1)
page = client.get("/api/roles", params={"agent": agent.id, "order": "newest"}).json()
assert [r["source_id"] for r in page["items"]] == ["3", "2", "1"]
assert [r["uid"] for r in page["items"]] == [uid["3"], uid["2"], uid["1"]]
assert [r["score"] for r in page["items"]] == [None, None, None]
assert [r["vote"] for r in page["items"]] == [None, None, 1]
assert page["total"] == 3
scored = client.get("/api/roles", params={"agent": agent.id, "order": "score"}).json()
assert [r["source_id"] for r in scored["items"]] == ["1", "2"]
assert [r["uid"] for r in scored["items"]] == [uid["1"], uid["2"]]
assert client.get("/api/roles", params={"agent": agent.id,
"order": "best"}).status_code == 422
@@ -295,13 +301,14 @@ def test_a_vote_moves_a_role_in_the_ranking_at_once(
for sid in ("a", "b", "c"):
store.upsert_role(posting(sid))
uid = {r.source_id: r.uid for r in store.roles()}
label = {v: k for k, v in uid.items()}
agent = store.save_agent("A")
store.replace_scores(agent.id, [(uid["a"], 0.9, ""), (uid["b"], 0.6, ""),
(uid["c"], 0.55, "")])
def ranked() -> list[tuple[str, float]]:
page = client.get("/api/roles", params={"agent": agent.id}).json()
return [(r["source_id"], round(r["score"], 3)) for r in page["items"]]
return [(label[r["uid"]], round(r["score"], 3)) for r in page["items"]]
assert ranked() == [("a", 0.9), ("b", 0.6), ("c", 0.55)]
client.post(f"/api/roles/{uid['a']}/vote", json={"value": -1})
@@ -331,14 +338,15 @@ def test_read_state_is_set_and_cleared_over_the_api(client: TestClient, store: S
def test_list_roles_filters_by_include_read(client: TestClient, store: Store) -> None:
store.upsert_role(posting("1"))
store.upsert_role(posting("2"))
ids = {r.source_id: r.uid for r in store.roles()}
uid = posting("1").uid
client.post(f"/api/roles/{uid}/read")
all_ = client.get("/api/roles").json()
assert {r["source_id"] for r in all_["items"]} == {"1", "2"}
assert {r["uid"] for r in all_["items"]} == {ids["1"], ids["2"]}
unread = client.get("/api/roles", params={"include_read": "false"}).json()
assert {r["source_id"] for r in unread["items"]} == {"2"}
assert {r["uid"] for r in unread["items"]} == {ids["2"]}
assert unread["total"] == 1
@@ -350,11 +358,11 @@ def test_list_roles_filters_by_tags_any_and_all(client: TestClient, store: Store
store.set_tags(uid["2"], ["python", "frontend"])
res = client.get("/api/roles", params={"tags": ["python"]})
assert {r["source_id"] for r in res.json()["items"]} == {"1", "2"}
assert {r["uid"] for r in res.json()["items"]} == {uid["1"], uid["2"]}
both = client.get("/api/roles", params={"tags": ["python", "backend"],
"tag_mode": "all"})
assert {r["source_id"] for r in both.json()["items"]} == {"1"}
assert {r["uid"] for r in both.json()["items"]} == {uid["1"]}
[item] = both.json()["items"]
assert item["tags"] == ["backend", "python"]
@@ -678,11 +686,10 @@ def test_every_settings_page_has_the_rail_and_not_the_tab_row(client: TestClient
< rail.index('href="/settings/account"')
def test_a_moved_section_is_one_the_sources_page_shows(client: TestClient) -> None:
"""Every old path that lands on a fragment of Sources names a section of
`SECTIONS` or an element inside one, and each section is a `<section
data-section>` on the page, which is what sources.js shows one of. The
old Messages paths land on `#messages`, the log at the end of Runs."""
def test_every_section_of_the_sources_page_exists(client: TestClient) -> None:
"""Each entry of `SECTIONS["/settings/sources"]` is a `<section
data-section>` on the page, which is what sources.js shows one of, and
the log at the end of Runs still answers `#messages`."""
anchors = [anchor for anchor, _ in SECTIONS["/settings/sources"]]
assert anchors == ["job-boards", "company-boards", "runs"]
page = client.get("/settings/sources").text
@@ -690,12 +697,7 @@ def test_a_moved_section_is_one_the_sources_page_shows(client: TestClient) -> No
for anchor in anchors:
assert f'<section class="card" id="{anchor}" data-section>' in page
runs = page[page.index('id="runs"'):]
for to in MOVED.values():
path, _, anchor = to.partition("#")
if anchor:
assert path == "/settings/sources", to
assert anchor in anchors or f'id="{anchor}"' in runs, to
assert MOVED["/messages"] == MOVED["/settings/messages"] == "/settings/sources#messages"
assert 'id="messages"' in runs
def test_settings_is_search_agents(client: TestClient) -> None:
@@ -703,21 +705,15 @@ def test_settings_is_search_agents(client: TestClient) -> None:
assert res.status_code == 302 and res.headers["location"] == "/settings/agents"
@pytest.mark.parametrize(("old", "new"), sorted(MOVED.items()))
def test_an_old_tab_moves_permanently_and_keeps_its_query(
client: TestClient, old: str, new: str) -> None:
"""A merged page's old path lands on its section: the query goes before
the anchor, or the browser would take `#runs?q=` as one fragment."""
assert {"/agents", "/settings/ranking", "/companies", "/sources", "/jobs",
"/schedules", "/messages", "/settings/searches", "/settings/companies",
"/settings/pulls", "/settings/messages", "/account"} <= set(MOVED)
path, _, anchor = new.partition("#")
res = client.get(old, follow_redirects=False)
assert res.status_code == 301 and res.headers["location"] == new
res = client.get(f"{old}?agent=3&q=a+b", follow_redirects=False)
assert res.status_code == 301
assert res.headers["location"] == f"{path}?agent=3&q=a+b" + (f"#{anchor}" if anchor else "")
assert client.get(old).status_code == 200
@pytest.mark.parametrize("old", ["/agents", "/settings/ranking", "/companies", "/sources",
"/jobs", "/schedules", "/messages", "/settings/searches",
"/settings/companies", "/settings/pulls",
"/settings/messages", "/account"])
def test_an_old_tab_path_is_gone(client: TestClient, old: str) -> None:
"""The paths the settings cog moved off of answer 404 now, not a cached
301: a browser caches a 301 indefinitely, so a path reused later would be
unreachable were the redirect still there."""
assert client.get(old).status_code == 404
def test_each_page_loads_only_its_own_script(client: TestClient) -> None:
@@ -946,7 +942,7 @@ def test_roles_by_agent_are_ordered_by_score_and_hide_the_gated(
(uids["gated"], 0.0, "place unknown")])
shown = client.get(f"/api/roles?agent={agent.id}").json()["items"]
assert [r["source_id"] for r in shown] == ["high", "low"]
assert [r["uid"] for r in shown] == [uids["high"], uids["low"]]
assert shown[0]["score"] == 0.8
everything = client.get(f"/api/roles?agent={agent.id}&gated=1").json()["items"]
assert everything[-1]["gated_reason"] == "place unknown"
@@ -954,6 +950,67 @@ def test_roles_by_agent_are_ordered_by_score_and_hide_the_gated(
assert client.get("/api/roles?agent=999").status_code == 404
def test_list_roles_serves_the_row_projection_and_not_the_big_columns(
client: TestClient, store: Store) -> None:
"""`GET /api/roles` is `RoleRow`: the fields a feed row draws, an
`excerpt` built on the server, and never `description`, `feed_text`,
`raw` or `article_text` — those are what the reader's own fetch,
`GET /api/roles/{uid}`, still answers in full."""
long_description = "Build things. " * 50
item = posting("1", company="Acme", place="Berlin, Germany", remote="hybrid",
function="engineering")
item.body = long_description
store.upsert_role(item)
uid = item.uid
row = client.get("/api/roles").json()["items"][0]
assert set(row) == {
"uid", "company_key", "company", "title", "place", "country", "remote", "function",
"salary_min", "salary_max", "currency", "salary_text", "salary_state",
"original_url", "posted_at", "score", "gated_reason", "vote",
"voted_at", "read_at", "tags", "excerpt",
}
assert row["uid"] == uid
assert row["company"] == "Acme" and row["place"] == "Berlin, Germany"
assert row["remote"] == "hybrid" and row["function"] == "engineering"
assert len(row["excerpt"]) <= 200
assert row["excerpt"] == models_excerpt(long_description)
full = client.get(f"/api/roles/{uid}").json()
assert full["description"] == long_description
def test_list_roles_page_stays_small_even_with_long_postings(
client: TestClient, store: Store) -> None:
"""The size bound the projection exists for: a page of rows with a real
posting's worth of text each (description, feed_text, raw and
article_text set, as a board's upsert would leave them) stays small,
because none of the four ever reach the response. Measured against a
copy of the live database in the report; this is the regression guard."""
big = "Requirement. " * 500 # ~6.5 KB, decisions.md's own average
for n in range(60):
item = posting(str(n), company="Acme")
item.body = big
store.upsert_role(item)
with store.transaction() as conn:
conn.execute("UPDATE roles SET feed_text = ?, raw = ?, article_text = ?",
(big, json.dumps({"blob": big}), big))
page = client.get("/api/roles", params={"limit": 60})
assert len(page.json()["items"]) == 60
# Well under one tenth of what 60 full roles (about 5.5 KB each,
# decisions.md's own figure) would answer with.
assert len(page.content) < 100_000
def test_list_roles_excerpt_prefers_the_summary(client: TestClient, store: Store) -> None:
store.upsert_role(posting("1"))
uid = posting("1").uid
store.set_summary(uid, "A short, hand-written summary.")
row = client.get("/api/roles").json()["items"][0]
assert row["excerpt"] == "A short, hand-written summary."
# ----------------------------------------------------------------- sources
def _fake_search(monkeypatch: pytest.MonkeyPatch, rows: int) -> None:
@@ -985,8 +1042,13 @@ def test_sources_lists_searches_and_boards_with_their_countries(
assert res["searches"][0]["params"] == {"q": "backend", "area": 1}
def test_switching_a_board_off_closes_its_roles_and_on_keeps_them_closed_until_a_pull(
client: TestClient, store: Store) -> None:
#: Every non-final state a job may be in, for a "was one queued at all" check
#: that does not race a background worker draining it before the assertion.
_ANY_STATE = ("queued", "running", "done", "failed", "cancelled")
def test_switching_a_board_off_closes_its_roles_and_on_queues_a_pull(
client: TestClient, store: Store, queue: Any) -> None:
board = store.add_subscription("ats", "greenhouse:acme", label="Acme", company="Acme",
board="greenhouse")
store.upsert_role(posting("1", company="Acme"), board)
@@ -995,14 +1057,18 @@ def test_switching_a_board_off_closes_its_roles_and_on_keeps_them_closed_until_a
assert off["closed"] == 1 and off["source"]["on"] is False
assert store.subscriptions(source="ats", fetchable=True) == []
assert store.roles() == []
assert queue.jobs.last("pull", states=_ANY_STATE) is None # off reads nothing again
on = client.post(f"/api/sources/{board.id}/switch", json={"on": True}).json()
assert on["closed"] == 0 and on["source"]["on"] is True
# On queues a pull right after, so the reopened board is read by the one
# running or the next one rather than the schedule, up to six hours away.
assert queue.jobs.last("pull", states=_ANY_STATE) is not None
assert client.post("/api/sources/999/switch", json={"on": True}).status_code == 404
def test_a_search_is_tried_saved_updated_and_removed(
client: TestClient, store: Store, monkeypatch: pytest.MonkeyPatch) -> None:
client: TestClient, store: Store, queue: Any, monkeypatch: pytest.MonkeyPatch) -> None:
_fake_search(monkeypatch, 3)
body = {"provider": "jobindex", "name": "Copenhagen backend", "q": "backend", "area": 1}
@@ -1011,10 +1077,14 @@ def test_a_search_is_tried_saved_updated_and_removed(
assert tried["sample"][0] == {"title": "Engineer 0", "company": "Acme",
"place": "København", "url": "https://x.example/0"}
assert store.subscriptions(source="search") == []
assert queue.jobs.last("pull", states=_ANY_STATE) is None # a mere try reads nothing
saved = client.post("/api/searches", json=body).json()
assert saved["source"]["target"] == "jobindex:copenhagen-backend"
assert saved["source"]["params"] == {"q": "backend", "area": 1}
# Saving queues a pull right after, so its roles are read by the one
# running or the next one rather than the schedule, up to six hours away.
assert queue.jobs.last("pull", states=_ANY_STATE) is not None
updated = client.post("/api/searches", json={**body, "q": "python", "pages": 3}).json()
assert updated["source"]["id"] == saved["source"]["id"]
@@ -1040,7 +1110,7 @@ def test_a_search_that_finds_nothing_or_is_malformed_is_refused(
def test_a_board_is_followed_only_if_it_answers(
client: TestClient, store: Store, monkeypatch: pytest.MonkeyPatch) -> None:
client: TestClient, store: Store, queue: Any, monkeypatch: pytest.MonkeyPatch) -> None:
import plugins.ats as ats
monkeypatch.setattr(ats, "fetch_board", lambda target: ([{"source_id": "1"}], True))
@@ -1048,6 +1118,10 @@ def test_a_board_is_followed_only_if_it_answers(
assert res.status_code == 201
assert res.json()["found"] == 1 and res.json()["source"]["target"] == "ashby:acme"
assert store.company("acme") is not None
# Following a board queues a pull right after, so its roles are read by
# the one running or the next one rather than the schedule, up to six
# hours away.
assert queue.jobs.last("pull", states=_ANY_STATE) 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.
@@ -1067,7 +1141,7 @@ def test_a_board_is_followed_only_if_it_answers(
def test_a_companys_board_is_set_replaced_and_detached(
client: TestClient, store: Store, monkeypatch: pytest.MonkeyPatch) -> None:
client: TestClient, store: Store, queue: Any, monkeypatch: pytest.MonkeyPatch) -> None:
import plugins.ats as ats
monkeypatch.setattr(ats, "fetch_board", lambda target: ([], True)) # between openings
@@ -1082,16 +1156,24 @@ def test_a_companys_board_is_set_replaced_and_detached(
[row] = client.get("/api/companies").json()
assert (row["board"], row["subscription_id"], row["ats"], row["ats_slug"]) == (
"greenhouse", sub_id, "greenhouse", "acme")
# Setting a board queues a pull right after, so it is read by the one
# running or the next one rather than the schedule, up to six hours away.
assert queue.jobs.last("pull", states=_ANY_STATE) is not None
res = client.post("/api/companies/acme/board", json={"board": "lever:acme"})
assert res.json()["closed"] == 1 and res.json()["source"]["id"] == sub_id
before_detach = queue.jobs.last("pull", states=_ANY_STATE)
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
# Detach reads nothing, so it queues no new pull.
after_detach = queue.jobs.last("pull", states=_ANY_STATE)
assert (before_detach.id if before_detach else None) == (
after_detach.id if after_detach else None)
assert client.post("/api/companies/nope/board",
json={"board": "lever:acme"}).status_code == 404
@@ -1100,6 +1182,34 @@ def test_a_companys_board_is_set_replaced_and_detached(
assert bad.status_code == 422 and "host:slug" in bad.json()["detail"]
def test_the_pull_a_source_switch_queues_is_refused_quietly_while_one_runs(
app: FastAPI, store: Store) -> None:
"""The four actions that queue a `pull` (switching a source on, following
or setting a board, saving a search) all go through the same job, whose
own refusal while another pull is in flight is not an error — see
`app.jobs.pull.claim_run` and `app.jobs.cascade.run_pull`. Exercised here
through the switch route as a stand-in for the other three, which queue
the identical `pull` job. No lifespan on this client, so no background
worker races the assertion: the queued job waits for the explicit
`drain`, and a refused pull starts no cascade — no fetch, no embed,
nothing else here needs mocking."""
from app.jobs import pull
client = TestClient(app)
board = store.add_subscription("ats", "greenhouse:acme", label="Acme", company="Acme",
board="greenhouse")
running = pull.claim_run(store)
assert running
res = client.post(f"/api/sources/{board.id}/switch", json={"on": True})
assert res.status_code == 200
app.state.queue.drain(timeout=30)
job = app.state.queue.jobs.last("pull", states=("done",))
assert job is not None
assert job.result == {"skipped": pull.ALREADY_RUNNING, "running": running}
# ------------------------------------------------- roles: text and summary
def test_the_posting_text_is_fetched_once(