Recheck a board's size from the Companies row, the route and app companies size
POST /api/sources/{id}/size sizes the board again, keeps the day and queues a pull; /api/companies returns size and size_checked, and the row shows "999 roles · checked 30 Sep" with Recheck beside Change. app companies size <key> does the same from the CLI, and --missing sizes every board without a size.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a0882e9659
commit
6085017943
5 files changed
+209
-5
No files matched your search
@@ -1,5 +1,5 @@
|
||||
"""A board's size, set once: `ats.board_size` per kind of host, `set_board`
|
||||
that keeps it, the pull that sizes a board
|
||||
and the Recheck (route and CLI) that keep it, the pull that sizes a board
|
||||
with none before it reads it, and the Companies line that names what a
|
||||
site's own ids leave out. No network: `ats._get` or the runner's listing is
|
||||
stubbed."""
|
||||
@@ -8,19 +8,25 @@ from __future__ import annotations
|
||||
|
||||
import json
|
||||
import sys
|
||||
from collections.abc import Iterator
|
||||
from datetime import UTC, datetime
|
||||
from pathlib import Path
|
||||
from typing import Any, ClassVar
|
||||
from urllib.parse import parse_qs, urlsplit
|
||||
|
||||
import pytest
|
||||
from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
if str(ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(ROOT))
|
||||
|
||||
from pipeline import Tally # noqa: E402
|
||||
from app.cli import main # noqa: E402
|
||||
from app.config import Config, ServerConfig # noqa: E402
|
||||
from app.jobs import pull, reach, sources # noqa: E402
|
||||
from app.main import create_app # noqa: E402
|
||||
from app.models import Gate # noqa: E402
|
||||
from app.storage import Store # noqa: E402
|
||||
from plugins import ats # noqa: E402
|
||||
@@ -341,3 +347,82 @@ def test_a_boards_own_reach_is_named_the_same_and_remote_alone_is_read_whole(
|
||||
"set here: DK · NO not on this site · all roles"
|
||||
assert reach.line(plan, _sub(store, "workday:other.wd3/Jobs")) == \
|
||||
"all places, no remote option on this site · all roles"
|
||||
|
||||
|
||||
# ------------------------------------------------------ Recheck and the CLI
|
||||
|
||||
@pytest.fixture
|
||||
def app(tmp_path: Path) -> FastAPI:
|
||||
return create_app(Config(server=ServerConfig(host="127.0.0.1", port=0),
|
||||
database=tmp_path / "roledesk.db"))
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client(app: FastAPI) -> Iterator[TestClient]:
|
||||
with TestClient(app) as c:
|
||||
yield c
|
||||
|
||||
|
||||
def test_recheck_sizes_the_board_again_and_queues_a_pull(
|
||||
app: FastAPI, client: TestClient, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
store: Store = app.state.store
|
||||
_wolf(store)
|
||||
_board(store, BOSCH, "Bosch", size=120)
|
||||
store.state[f"ats:sizechecked:{BOSCH}"] = "2026-09-01"
|
||||
sub_id = _sub(store, BOSCH).id
|
||||
[row] = client.get("/api/companies").json()
|
||||
assert (row["size"], row["size_checked"], row["reach"]) == (
|
||||
120, "2026-09-01", "under 300 roles: read whole")
|
||||
|
||||
monkeypatch.setattr(ats, "_get", SmartRecruiters(4830))
|
||||
res = client.post(f"/api/sources/{sub_id}/size")
|
||||
assert res.status_code == 200, res.text
|
||||
assert res.json() == {"size": 4830, "size_checked": TODAY,
|
||||
"reach": "follows agents: DK, SE · all roles"}
|
||||
assert app.state.queue.jobs.last("pull", states=("queued", "running", "done")) is not None
|
||||
[row] = client.get("/api/companies").json()
|
||||
assert (row["size"], row["size_checked"]) == (4830, TODAY)
|
||||
|
||||
# A board that does not answer keeps the size it had.
|
||||
monkeypatch.setattr(ats, "_get", SmartRecruiters(5, down=True))
|
||||
res = client.post(f"/api/sources/{sub_id}/size")
|
||||
assert res.status_code == 422 and "did not answer" in res.json()["detail"]
|
||||
assert store.state[f"ats:size:{BOSCH}"] == "4830"
|
||||
assert client.post("/api/sources/9999/size").status_code == 404
|
||||
|
||||
|
||||
def _cli(tmp_path: Path, *argv: str) -> int:
|
||||
config = tmp_path / "config.yaml"
|
||||
if not config.exists():
|
||||
config.write_text(f"database: {tmp_path / 't.db'}\n")
|
||||
return main(["-c", str(config), "companies", *argv])
|
||||
|
||||
|
||||
def test_the_cli_sizes_one_board_or_every_board_without_a_size(
|
||||
store: Store, tmp_path: Path, monkeypatch: pytest.MonkeyPatch,
|
||||
capsys: pytest.CaptureFixture[str]) -> None:
|
||||
_wolf(store)
|
||||
_board(store, BOSCH, "Bosch", size=12)
|
||||
_board(store, "smartrecruiters:tiny", "Tiny")
|
||||
_board(store, "smartrecruiters:gone", "Gone")
|
||||
monkeypatch.setattr(ats, "_get", SmartRecruiters(4830))
|
||||
assert _cli(tmp_path, "size", "bosch") == 0
|
||||
assert json.loads(capsys.readouterr().out) == {
|
||||
"board": BOSCH, "size": 4830, "reach": "follows agents: DK, SE · all roles"}
|
||||
|
||||
def some(client: Any, url: str, host: str, slug: str, **kwargs: Any) -> bytes:
|
||||
if slug == "gone":
|
||||
raise OSError("connection refused")
|
||||
return SmartRecruiters(40)(client, url, host, slug)
|
||||
|
||||
monkeypatch.setattr(ats, "_get", some)
|
||||
assert _cli(tmp_path, "size", "--missing") == 1
|
||||
out, err = capsys.readouterr()
|
||||
assert out.splitlines() == [
|
||||
json.dumps({"board": "smartrecruiters:tiny", "size": 40,
|
||||
"reach": "under 300 roles: read whole"}),
|
||||
"sized 1 of 2 boards without a size"]
|
||||
assert "smartrecruiters:gone did not answer" in err
|
||||
assert store.state[f"ats:size:{BOSCH}"] == "4830"
|
||||
assert _cli(tmp_path, "size") == 2
|
||||
assert _cli(tmp_path, "size", "nobody") == 1
|
||||
+3
-2
@@ -603,7 +603,8 @@ def test_companies_lists_board_and_open_role_count(
|
||||
"careers_opened_at": "", "failing_since": "", "failing_reason": "",
|
||||
"from_search": False, "hand_reason": "", "by_hand": False,
|
||||
"all_countries": False, "all_roles": False,
|
||||
"reach_params": {}, "reach": "size not known yet: sized on the next pull"}
|
||||
"reach_params": {}, "reach": "size not known yet: sized on the next pull",
|
||||
"size": None, "size_checked": ""}
|
||||
[other] = [c for c in res.json() if c["key"] == "other"]
|
||||
assert (other["board"], other["subscription_id"], other["on"], other["ats"]) == (
|
||||
"", None, None, "")
|
||||
@@ -1453,7 +1454,7 @@ def test_a_company_is_added_by_hand_with_a_reason_and_a_link(
|
||||
"country": "", "city": "", "watch": None, "careers_opened_at": "",
|
||||
"failing_since": "", "failing_reason": "", "from_search": False,
|
||||
"hand_reason": "added", "by_hand": True, "all_countries": False, "all_roles": False,
|
||||
"reach_params": {}, "reach": ""}
|
||||
"reach_params": {}, "reach": "", "size": None, "size_checked": ""}
|
||||
assert store.company("revolut").hand_reason == "added" # type: ignore[union-attr]
|
||||
|
||||
other = client.post("/api/companies", json={"name": "Meta", "hand_reason": "blocked"})
|
||||
|
||||
Reference in new issue
Block a user