Per-agent ranking: votes, affinity and a taste term; settings are three sub-tabs
Votes on roles and company affinity move to role_votes and agent_companies, one row per search agent, so two agents rank the same roles differently. The score gains taste, the cosine to mean(liked) - mean(passed) of the agent's votes, as newsdesk ranks articles. The API takes agent on roles, votes and companies and falls back to the default agent, the enabled one with the lowest id. Settings become Search agents (a list again, with New and Delete), Sources (job boards, company boards and runs with the message log, one section per plugin) and Account. Old paths answer 301 to their section. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
515d2250fc
commit
a0772519b3
28 files changed
+1461
-668
No files matched your search
+185
-50
@@ -98,13 +98,25 @@ def test_muted_roles_are_hidden_unless_show_muted(client: TestClient, store: Sto
|
||||
store.add_company("Acme", key="acme")
|
||||
store.upsert_role(posting("1", company="Acme"))
|
||||
store.upsert_role(posting("2", company="Other"))
|
||||
agent = store.save_agent("A")
|
||||
other = store.save_agent("B")
|
||||
|
||||
assert {r["source_id"] for r in client.get("/api/roles").json()["items"]} == {"1", "2"}
|
||||
def shown(**params: Any) -> set[str]:
|
||||
return {r["source_id"] for r in client.get("/api/roles", params=params).json()["items"]}
|
||||
|
||||
assert shown() == {"1", "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 {r["source_id"] for r in client.get("/api/roles").json()["items"]} == {"2"}
|
||||
assert {r["source_id"] for r in
|
||||
client.get("/api/roles", params={"show_muted": "true"}).json()["items"]} == {"1", "2"}
|
||||
assert shown() == {"2"}
|
||||
assert shown(show_muted="true") == {"1", "2"}
|
||||
assert shown(agent=agent.id, order="newest") == {"2"}
|
||||
# Hidden is per agent: the other agent still sees Acme.
|
||||
assert shown(agent=other.id, order="newest") == {"1", "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]
|
||||
|
||||
|
||||
def test_muted_is_excluded_before_the_limit_not_after(
|
||||
@@ -115,7 +127,8 @@ def test_muted_is_excluded_before_the_limit_not_after(
|
||||
of roles, all freshly (re-)pulled at once, produces."""
|
||||
clock = Clock()
|
||||
store.clock = clock
|
||||
store.add_company("Acme", key="acme", affinity=-1)
|
||||
store.add_company("Acme", key="acme")
|
||||
store.set_affinity(store.save_agent("A").id, "acme", -1)
|
||||
store.upsert_role(posting("other", company="Other"))
|
||||
clock.tick()
|
||||
for i in range(3):
|
||||
@@ -149,32 +162,104 @@ def test_a_vote_is_set_cleared_and_filtered_on(client: TestClient, store: Store)
|
||||
for sid in ("liked", "passed", "fine", "open"):
|
||||
store.upsert_role(posting(sid))
|
||||
uid = {r.source_id: r.uid for r in store.roles()}
|
||||
agent = store.save_agent("A")
|
||||
|
||||
# No `agent` in the body: the default agent's vote.
|
||||
res = client.post(f"/api/roles/{uid['liked']}/vote", json={"value": 1})
|
||||
assert res.status_code == 200
|
||||
assert res.json()["vote"] == 1 and res.json()["voted_at"] is not None
|
||||
client.post(f"/api/roles/{uid['passed']}/vote", json={"value": -1})
|
||||
assert store.votes(agent.id) == {uid["liked"]: 1}
|
||||
client.post(f"/api/roles/{uid['passed']}/vote", json={"value": -1, "agent": agent.id})
|
||||
client.post(f"/api/roles/{uid['fine']}/vote", json={"value": 0})
|
||||
|
||||
def judged(value: str) -> set[str]:
|
||||
page = client.get("/api/roles", params={"judged": value}).json()
|
||||
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"]}
|
||||
|
||||
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 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
|
||||
|
||||
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"}
|
||||
cleared = client.delete(f"/api/roles/{uid['passed']}/vote", params={"agent": agent.id})
|
||||
assert cleared.status_code == 200 and cleared.json()["vote"] is None
|
||||
|
||||
assert client.post(f"/api/roles/{uid['open']}/vote",
|
||||
json={"value": 2}).status_code == 422
|
||||
assert client.post("/api/roles/nope/vote", json={"value": 1}).status_code == 404
|
||||
assert client.delete("/api/roles/nope/vote").status_code == 404
|
||||
assert client.post(f"/api/roles/{uid['open']}/vote",
|
||||
json={"value": 1, "agent": 999}).status_code == 404
|
||||
assert client.delete(f"/api/roles/{uid['open']}/vote", params={"agent": 999}).status_code == 404
|
||||
|
||||
|
||||
def test_votes_are_per_agent_over_the_api(client: TestClient, store: Store) -> None:
|
||||
store.upsert_role(posting("1"))
|
||||
uid = posting("1").uid
|
||||
one = store.save_agent("One")
|
||||
two = store.save_agent("Two")
|
||||
|
||||
assert client.post(f"/api/roles/{uid}/vote", json={"value": 1, "agent": one.id}).json()["vote"] == 1
|
||||
assert client.post(f"/api/roles/{uid}/vote", json={"value": -1, "agent": two.id}).json()["vote"] == -1
|
||||
assert client.get(f"/api/roles/{uid}", params={"agent": one.id}).json()["vote"] == 1
|
||||
assert client.get(f"/api/roles/{uid}", params={"agent": two.id}).json()["vote"] == -1
|
||||
assert client.get(f"/api/roles/{uid}").json()["vote"] == 1 # the default's
|
||||
assert client.get(f"/api/roles/{uid}", params={"agent": 999}).status_code == 404
|
||||
|
||||
def listed(**params: Any) -> list[int | None]:
|
||||
return [r["vote"] for r in client.get("/api/roles", params=params).json()["items"]]
|
||||
|
||||
assert listed(agent=one.id, order="newest") == [1]
|
||||
assert listed(agent=two.id, order="newest") == [-1]
|
||||
assert listed() == [1]
|
||||
|
||||
|
||||
def test_a_vote_or_an_affinity_needs_an_agent_to_belong_to(
|
||||
client: TestClient, store: Store) -> None:
|
||||
"""Nothing to vote as: a 422 with a sentence, not a vote that lands
|
||||
nowhere. Reading is fine, everything is simply unjudged and neutral."""
|
||||
store.upsert_role(posting("1"))
|
||||
store.add_company("Acme", key="acme")
|
||||
uid = posting("1").uid
|
||||
|
||||
res = client.post(f"/api/roles/{uid}/vote", json={"value": 1})
|
||||
assert res.status_code == 422 and "Settings" in res.json()["detail"]
|
||||
assert client.delete(f"/api/roles/{uid}/vote").status_code == 422
|
||||
assert client.post("/api/companies/acme/affinity", json={"affinity": 1}).status_code == 422
|
||||
assert client.get(f"/api/roles/{uid}").json()["vote"] is None
|
||||
assert client.get("/api/roles").json()["items"][0]["vote"] is None
|
||||
assert client.get("/api/companies").json()[0]["affinity"] == 0
|
||||
|
||||
|
||||
def test_roles_with_an_agent_can_be_ordered_newest_and_keep_the_votes(
|
||||
client: TestClient, store: Store) -> None:
|
||||
clock = Clock()
|
||||
store.clock = clock
|
||||
for sid in ("1", "2", "3"):
|
||||
store.upsert_role(posting(sid))
|
||||
clock.tick()
|
||||
uid = {r.source_id: r.uid for r in store.roles()}
|
||||
agent = store.save_agent("A")
|
||||
store.replace_scores(agent.id, [(uid["1"], 0.9, ""), (uid["2"], 0.1, "")]) # 3 unscored
|
||||
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["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 client.get("/api/roles", params={"agent": agent.id,
|
||||
"order": "best"}).status_code == 422
|
||||
|
||||
|
||||
def test_a_vote_moves_a_role_in_the_ranking_at_once(
|
||||
@@ -249,15 +334,27 @@ def test_companies_lists_board_and_open_role_count(
|
||||
def test_set_affinity_validates_updates_and_enqueues_a_score(
|
||||
client: TestClient, store: Store, queue: Any) -> None:
|
||||
store.add_company("Acme", key="acme")
|
||||
agent = store.save_agent("A")
|
||||
other = store.save_agent("B")
|
||||
|
||||
# No `agent` in the body: the default agent's affinity.
|
||||
res = client.post("/api/companies/acme/affinity", json={"affinity": 2})
|
||||
assert res.status_code == 200
|
||||
assert res.json()["affinity"] == 2
|
||||
assert store.company("acme").affinity == 2 # type: ignore[union-attr]
|
||||
assert store.company("acme", agent.id).affinity == 2 # type: ignore[union-attr]
|
||||
assert store.company("acme", other.id).affinity == 0 # type: ignore[union-attr]
|
||||
assert queue.jobs.last("score", states=("queued", "running", "done")) is not None
|
||||
|
||||
res = client.post("/api/companies/acme/affinity", json={"affinity": -1, "agent": other.id})
|
||||
assert res.status_code == 200 and res.json()["affinity"] == -1
|
||||
assert store.company("acme", agent.id).affinity == 2 # type: ignore[union-attr]
|
||||
assert [c["affinity"] for c in client.get("/api/companies", params={"agent": other.id}).json()] == [-1]
|
||||
|
||||
assert client.post("/api/companies/acme/affinity", json={"affinity": 9}).status_code == 422
|
||||
assert client.post("/api/companies/nope/affinity", json={"affinity": 1}).status_code == 404
|
||||
assert client.post("/api/companies/acme/affinity",
|
||||
json={"affinity": 1, "agent": 999}).status_code == 404
|
||||
assert client.get("/api/companies", params={"agent": 999}).status_code == 404
|
||||
|
||||
|
||||
# ----------------------------------------------------------- applications
|
||||
@@ -338,8 +435,7 @@ def test_the_applications_page_has_no_next_column(client: TestClient) -> None:
|
||||
|
||||
def test_every_page_renders_with_the_whole_nav(client: TestClient) -> None:
|
||||
assert [t.label for t in TABS] == ["Roles", "Applications"]
|
||||
assert [t.label for t in SETTINGS] == ["Ranking", "Searches", "Companies", "Pulls",
|
||||
"Messages", "Account"]
|
||||
assert [t.label for t in SETTINGS] == ["Search agents", "Sources", "Account"]
|
||||
assert all(t.path.startswith("/settings/") for t in SETTINGS)
|
||||
for tab in (*TABS, *SETTINGS):
|
||||
res = client.get(tab.path)
|
||||
@@ -352,80 +448,99 @@ def test_every_page_renders_with_the_whole_nav(client: TestClient) -> None:
|
||||
|
||||
|
||||
def test_the_cog_and_one_sub_tab_are_current_on_a_settings_page(client: TestClient) -> None:
|
||||
page = client.get("/settings/pulls").text
|
||||
page = client.get("/settings/sources").text
|
||||
assert 'class="icon active"' in page
|
||||
for tab in SETTINGS:
|
||||
assert f">{tab.label}</a>" in page
|
||||
assert page.count('aria-current="page"') == 1
|
||||
current = page.index('aria-current="page"')
|
||||
assert page.rindex('href="', 0, current) == page.index('href="/settings/pulls"')
|
||||
assert page.rindex('href="', 0, current) == page.index('href="/settings/sources"')
|
||||
assert 'class="icon active"' not in client.get("/").text
|
||||
|
||||
|
||||
def test_settings_is_ranking(client: TestClient) -> None:
|
||||
def test_settings_is_search_agents(client: TestClient) -> None:
|
||||
res = client.get("/settings", follow_redirects=False)
|
||||
assert res.status_code == 302 and res.headers["location"] == "/settings/ranking"
|
||||
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 and res.headers["location"] == f"{new}?agent=3&q=a+b"
|
||||
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
|
||||
|
||||
|
||||
def test_each_page_loads_only_its_own_script(client: TestClient) -> None:
|
||||
scripts = {"roles.js", "applications.js", "ranking.js", "companies.js", "sources.js",
|
||||
"""Sources is four sections' scripts on one page, each guarding on its own
|
||||
root element; every other page is one."""
|
||||
scripts = {"roles.js", "applications.js", "agents.js", "companies.js", "sources.js",
|
||||
"jobs.js", "messages.js"}
|
||||
for path, container, script in [
|
||||
("/", 'id="roles-list"', "roles.js"),
|
||||
("/applications", 'id="applications-list"', "applications.js"),
|
||||
("/settings/ranking", 'id="ranking-form"', "ranking.js"),
|
||||
("/settings/searches", 'id="searches-list"', "sources.js"),
|
||||
("/settings/companies", 'id="companies-list"', "companies.js"),
|
||||
("/settings/pulls", 'id="kinds"', "jobs.js"),
|
||||
("/settings/messages", 'id="notices"', "messages.js")]:
|
||||
for path, container, own in [
|
||||
("/", 'id="roles-list"', ["roles.js"]),
|
||||
("/applications", 'id="applications-list"', ["applications.js"]),
|
||||
("/settings/agents", 'id="agent-form"', ["agents.js"]),
|
||||
("/settings/sources", 'id="searches-list"',
|
||||
["sources.js", "companies.js", "jobs.js", "messages.js"])]:
|
||||
page = client.get(path).text
|
||||
assert container in page, path
|
||||
assert [s for s in scripts if f"/static/{s}" in page] == [script], path
|
||||
# toasts.js before app.js before the page's own script: `api()` needs
|
||||
assert sorted(s for s in scripts if f"/static/{s}" in page) == sorted(own), path
|
||||
# toasts.js before app.js before the page's own scripts: `api()` needs
|
||||
# `window.toast`, and every page script needs `api()` and the helpers.
|
||||
assert page.index("toasts.js") < page.index("app.js") < page.index(f"/static/{script}")
|
||||
assert client.get(f"/static/{script}").status_code == 200
|
||||
for script in own:
|
||||
assert page.index("toasts.js") < page.index("app.js") < page.index(f"/static/{script}")
|
||||
assert client.get(f"/static/{script}").status_code == 200
|
||||
assert "ROLEDESK_STATUSES" in client.get("/applications").text
|
||||
assert client.get("/static/ranking.js").status_code == 404
|
||||
|
||||
|
||||
def test_the_ranking_page_edits_one_ranking(client: TestClient) -> None:
|
||||
page = client.get("/settings/ranking").text
|
||||
def test_the_agents_page_lists_and_edits_search_agents(client: TestClient) -> None:
|
||||
page = client.get("/settings/agents").text
|
||||
assert 'id="agents-list"' in page and 'id="agents-count"' in page
|
||||
assert 'id="a-name"' in page and 'placeholder="My search"' in page
|
||||
assert 'id="a-intent"' in page and "<details" in page and 'id="a-gates"' in page
|
||||
assert 'id="a-delete"' not in page and 'id="a-new"' not in page
|
||||
assert 'id="agents-list"' not in page
|
||||
for weight in ("a-fit", "a-recency", "a-affinity", "a-taste"):
|
||||
assert f'id="{weight}"' in page
|
||||
assert 'id="a-taste" min="0" step="0.05" value="0.2"' in page
|
||||
assert 'id="a-new"' in page and 'id="a-delete"' in page
|
||||
assert "Save and score" in page
|
||||
|
||||
|
||||
def test_the_searches_page_offers_the_jobindex_areas(client: TestClient) -> None:
|
||||
page = client.get("/settings/searches").text
|
||||
assert 'id="searches-list"' in page
|
||||
assert 'value="1" selected>Region Hovedstaden' in page # from plugins.search
|
||||
# Boards and the prune tool moved to Companies; a search has no board.
|
||||
assert 'id="boards-list"' not in page and 'id="prune-form"' not in page
|
||||
assert 'id="pull-now"' not in page # moved to Pulls
|
||||
|
||||
|
||||
def test_the_companies_page_offers_the_follow_form_and_the_prune_tool(
|
||||
client: TestClient) -> None:
|
||||
page = client.get("/settings/companies").text
|
||||
assert 'id="companies-list"' in page
|
||||
def test_the_sources_page_has_a_section_per_plugin(client: TestClient) -> None:
|
||||
"""Job boards, company boards and the runs, in that order, with the
|
||||
message log at the end of the runs and a jump row to each section."""
|
||||
page = client.get("/settings/sources").text
|
||||
for anchor in ("job-boards", "company-boards", "runs"):
|
||||
assert f'href="#{anchor}"' in page and f'id="{anchor}"' in page
|
||||
assert page.index('id="job-boards"') < page.index('id="company-boards"') \
|
||||
< page.index('id="runs"') < page.index('id="messages"')
|
||||
# Job boards: the Jobindex areas and the Adzuna countries, from plugins.search.
|
||||
assert 'id="searches-list"' in page and 'id="search-form"' in page
|
||||
assert 'value="1" selected>Region Hovedstaden' in page
|
||||
assert "job board" in page.lower() and "saved search" not in page.lower()
|
||||
# Company boards: the follow form, the agent select, the list, the prune tool.
|
||||
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
|
||||
assert 'id="prune-form"' in page and "Switch off boards with no roles in a region" in page
|
||||
assert "hidden" in page.lower() and "mute" not in page.lower()
|
||||
boards = page[page.index('id="company-boards"'):page.index('id="runs"')].lower()
|
||||
assert "hidden" in boards and "mute" not in boards
|
||||
# Runs: Pull now, the queue's elements, one stage at a time, the log.
|
||||
assert 'id="pull-now"' in page and 'id="kinds"' in page
|
||||
assert 'id="notices"' in page and 'id="clear-all"' in page
|
||||
|
||||
|
||||
def test_the_modules_bring_their_own_elements(client: TestClient) -> None:
|
||||
pulls = client.get("/settings/pulls").text
|
||||
pulls = client.get("/settings/sources").text
|
||||
assert pulls.index("<desk-jobs>") < pulls.index("<desk-schedules>")
|
||||
assert "<auth-account>" in client.get("/settings/account").text
|
||||
|
||||
@@ -491,13 +606,14 @@ def test_agents_are_created_updated_listed_and_deleted(client: TestClient) -> No
|
||||
created = client.post("/api/agents", json=body)
|
||||
assert created.status_code == 200
|
||||
agent = created.json()
|
||||
assert agent["weights"] == {"fit": 0.6, "recency": 0.2, "affinity": 0.2}
|
||||
assert agent["weights"] == {"fit": 0.6, "recency": 0.2, "affinity": 0.2, "taste": 0.2}
|
||||
assert agent["gates"][0]["weight"] == 1.0
|
||||
|
||||
updated = client.post("/api/agents", json={**body, "id": agent["id"], "enabled": False,
|
||||
"weights": {"fit": 1, "recency": 0,
|
||||
"affinity": 0}})
|
||||
"affinity": 0, "taste": 0.5}})
|
||||
assert updated.json()["enabled"] is False and updated.json()["weights"]["fit"] == 1
|
||||
assert updated.json()["weights"]["taste"] == 0.5
|
||||
|
||||
assert [a["name"] for a in client.get("/api/agents").json()] == ["Berlin"]
|
||||
assert client.post("/api/agents", json=body).status_code == 409
|
||||
@@ -506,6 +622,25 @@ def test_agents_are_created_updated_listed_and_deleted(client: TestClient) -> No
|
||||
assert client.delete(f"/api/agents/{agent['id']}").status_code == 404
|
||||
|
||||
|
||||
def test_deleting_an_agent_takes_its_votes_and_affinities_with_it(
|
||||
client: TestClient, store: Store) -> None:
|
||||
store.upsert_role(posting("1"))
|
||||
store.add_company("Acme", key="acme")
|
||||
uid = posting("1").uid
|
||||
agent = client.post("/api/agents", json={"name": "A"}).json()
|
||||
kept = client.post("/api/agents", json={"name": "B"}).json()
|
||||
client.post(f"/api/roles/{uid}/vote", json={"value": 1, "agent": agent["id"]})
|
||||
client.post(f"/api/roles/{uid}/vote", json={"value": -1, "agent": kept["id"]})
|
||||
client.post("/api/companies/acme/affinity", json={"affinity": 2, "agent": agent["id"]})
|
||||
|
||||
assert client.delete(f"/api/agents/{agent['id']}").status_code == 204
|
||||
|
||||
with store.transaction() as conn:
|
||||
assert conn.execute("SELECT COUNT(*) FROM role_votes").fetchone()[0] == 1
|
||||
assert conn.execute("SELECT COUNT(*) FROM agent_companies").fetchone()[0] == 0
|
||||
assert client.get(f"/api/roles/{uid}", params={"agent": kept["id"]}).json()["vote"] == -1
|
||||
|
||||
|
||||
def test_a_gate_on_an_unknown_field_is_refused(client: TestClient) -> None:
|
||||
body = {"name": "Bad", "gates": [{"field": "salary", "values": [1]}]}
|
||||
assert client.post("/api/agents", json=body).status_code == 422
|
||||
|
||||
Reference in new issue
Block a user