Roles as a feed, a read page, votes that move the rank, unstar

The Roles tab is news's feed row: the title opens /roles/{uid}, company,
place and age under it, the badges, a one-line excerpt (summary, else the
description's opening), and ▲ ● ▼ ★ on the right, under the text at 640px.
The company affinity control leaves the row. A passed role and a hidden
company's are dimmed and stay. The filter bar is one row: order, search and
a Filters <details> holding the rest, with a judged select and "Show hidden
companies". The list loads 60 and appends on an IntersectionObserver
sentinel; back from a read page restores the filters, rows and scroll.

GET /api/roles takes offset, defaults to 60 and answers {items, total}.
judged= is a WHERE on roles.vote. Under a ranking the served score and the
order are the stored score moved by the vote (x0.5 pass, x1.2 like, capped
at 1), so a vote shows at once without a rescore. POST and DELETE
/api/roles/{uid}/vote set and clear it; pressing the pressed stance clears.

★ saves; pressed again it calls DELETE /api/applications/{id}, which drops
the application while it is still saved and answers 409 after. save_role no
longer writes the placeholder next step.

The read page (role.html, role.js) is news's reader: a bar with back,
▲ ● ▼ ★ and ↗, the company with its affinity control, place, badges, salary,
summary, the text (fetched posting, else description) and the link out.
It offers Fetch the posting for a teaser and Summarise without a summary,
against the /text and /summarise routes B4 adds. The vote and star buttons
are judge.js, shared by the feed and the reader.

Applications: titles open the read page, the Next column is gone, a Saved
column instead, and the lede says what the page is for.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Fable 5.1 committed 2026-09-25 21:51:48 +02:00
1 parent 7d31cca394
commit 09c5dde113
13 files changed
+1216 -192

No files matched your search

+55
View File
@@ -205,6 +205,61 @@ def test_roles_hide_muted_excludes_before_the_limit(store: Store, clock: Clock)
assert {r.source_id for r in store.roles()} == {"a0", "a1", "a2", "other"}
def test_roles_page_by_offset_and_count_the_same_filter(
store: Store, clock: Clock) -> None:
for sid in ("1", "2", "3", "4"):
store.upsert_role(posting(sid, company="Acme" if sid != "4" else "Other"))
clock.tick()
assert [r.source_id for r in store.roles(limit=2, offset=1)] == ["3", "2"]
assert [r.source_id for r in store.roles(limit=2, offset=3)] == ["1"]
assert store.count_roles() == 4
assert store.count_roles(company="acme") == 3
store.add_company("Other", key="other", affinity=-1)
assert store.count_roles(hide_muted=True) == 3
def test_a_vote_is_stamped_cleared_and_filtered(store: Store, clock: Clock) -> None:
for sid in ("up", "down", "fine", "none"):
store.upsert_role(posting(sid))
uid = {r.source_id: r.uid for r in store.roles()}
role = store.set_vote(uid["up"], 1)
assert (role.vote, role.voted_at) == (1, clock().isoformat(timespec="seconds"))
store.set_vote(uid["down"], -1)
store.set_vote(uid["fine"], 0)
assert [r.source_id for r in store.roles(judged="liked")] == ["up"]
assert [r.source_id for r in store.roles(judged="passed")] == ["down"]
assert [r.source_id for r in store.roles(judged="unjudged")] == ["none"]
assert store.count_roles(judged="unjudged") == 1
with pytest.raises(ValueError, match="judged"):
store.roles(judged="maybe")
cleared = store.set_vote(uid["up"], None)
assert (cleared.vote, cleared.voted_at) == (None, None)
with pytest.raises(ValueError):
store.set_vote(uid["up"], 2)
with pytest.raises(ValueError):
store.set_vote(uid["up"], True)
with pytest.raises(KeyError):
store.set_vote("nope", 1)
def test_a_vote_moves_the_served_score_and_the_order(store: Store) -> None:
for sid in ("a", "b", "c"):
store.upsert_role(posting(sid))
uid = {r.source_id: r.uid for r in store.roles()}
agent = store.save_agent("A")
store.replace_scores(agent.id, [(uid["a"], 0.9, ""), (uid["b"], 0.5, ""),
(uid["c"], 0.4, "")])
store.set_vote(uid["a"], -1) # 0.45
store.set_vote(uid["c"], 1) # 0.48
ranked = [(r.source_id, round(r.score or 0, 3)) for r in store.roles(agent=agent.id)]
assert ranked == [("b", 0.5), ("c", 0.48), ("a", 0.45)]
assert store.scores(agent.id)[uid["a"]][0] == 0.9 # the stored score is kept
store.set_vote(uid["a"], 1)
assert store.roles(agent=agent.id, limit=1)[0].score == 1.0
def test_mark_closed_closes_what_the_board_no_longer_lists(store: Store) -> None:
sub = store.add_subscription("ats", "greenhouse:acme")
other = store.add_subscription("ats", "greenhouse:other")
+138 -13
View File
@@ -71,19 +71,19 @@ def test_list_roles_filters_by_query_place_and_function(
res = client.get("/api/roles", params={"q": "engineer", "place": "Berlin"})
assert res.status_code == 200
assert {r["source_id"] for r in res.json()} == {"1", "3"}
assert {r["source_id"] for r in res.json()["items"]} == {"1", "3"}
res = client.get("/api/roles", params={"function": "sales"})
assert [r["source_id"] for r in res.json()] == ["2"]
assert [r["source_id"] for r in res.json()["items"]] == ["2"]
res = client.get("/api/roles", params={"company": "other"})
assert [r["source_id"] for r in res.json()] == ["3"]
assert [r["source_id"] for r in res.json()["items"]] == ["3"]
def test_list_roles_limit_is_bounded(client: TestClient, store: Store) -> None:
for i in range(3):
store.upsert_role(posting(str(i)))
assert len(client.get("/api/roles", params={"limit": 1}).json()) == 1
assert len(client.get("/api/roles", params={"limit": 1}).json()["items"]) == 1
assert client.get("/api/roles", params={"limit": 0}).status_code == 422
assert client.get("/api/roles", params={"limit": 1001}).status_code == 422
@@ -93,12 +93,12 @@ def test_muted_roles_are_hidden_unless_show_muted(client: TestClient, store: Sto
store.upsert_role(posting("1", company="Acme"))
store.upsert_role(posting("2", company="Other"))
assert {r["source_id"] for r in client.get("/api/roles").json()} == {"1", "2"}
assert {r["source_id"] for r in client.get("/api/roles").json()["items"]} == {"1", "2"}
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()} == {"2"}
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()} == {"1", "2"}
client.get("/api/roles", params={"show_muted": "true"}).json()["items"]} == {"1", "2"}
def test_muted_is_excluded_before_the_limit_not_after(
@@ -117,7 +117,109 @@ def test_muted_is_excluded_before_the_limit_not_after(
clock.tick()
res = client.get("/api/roles", params={"limit": 1})
assert [r["source_id"] for r in res.json()] == ["other"]
assert [r["source_id"] for r in res.json()["items"]] == ["other"]
assert res.json()["total"] == 1
def test_list_roles_pages_by_offset_and_counts_the_total(
client: TestClient, store: Store) -> None:
clock = Clock()
store.clock = clock
for i in range(5):
store.upsert_role(posting(str(i)))
clock.tick()
first = client.get("/api/roles", params={"limit": 2}).json()
assert [r["source_id"] for r in first["items"]] == ["4", "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 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
def test_a_vote_is_set_cleared_and_filtered_on(client: TestClient, store: Store) -> None:
for sid in ("liked", "passed", "fine", "open"):
store.upsert_role(posting(sid))
uid = {r.source_id: r.uid for r in store.roles()}
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})
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()
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 client.get("/api/roles", params={"judged": "maybe"}).status_code == 422
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 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
def test_a_vote_moves_a_role_in_the_ranking_at_once(
client: TestClient, store: Store) -> None:
for sid in ("a", "b", "c"):
store.upsert_role(posting(sid))
uid = {r.source_id: r.uid for r in store.roles()}
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"]]
assert ranked() == [("a", 0.9), ("b", 0.6), ("c", 0.55)]
client.post(f"/api/roles/{uid['a']}/vote", json={"value": -1})
client.post(f"/api/roles/{uid['c']}/vote", json={"value": 1})
assert ranked() == [("c", 0.66), ("b", 0.6), ("a", 0.45)]
client.post(f"/api/roles/{uid['b']}/vote", json={"value": 0})
client.post(f"/api/roles/{uid['a']}/vote", json={"value": 1})
assert ranked() == [("a", 1.0), ("c", 0.66), ("b", 0.6)] # capped at 1
def test_one_role_and_its_read_page(client: TestClient, store: Store) -> None:
store.upsert_role(posting("1", company="Acme", place="Berlin"))
uid = posting("1").uid
res = client.get(f"/api/roles/{uid}")
assert res.status_code == 200
body = res.json()
assert (body["uid"], body["company"], body["description"]) == (uid, "Acme",
"Build things.")
assert body["vote"] is None and body["summary"] == "" and body["article_text"] == ""
assert client.get("/api/roles/nope").status_code == 404
page = client.get(f"/roles/{uid}")
assert page.status_code == 200
assert 'id="role"' in page.text and "/static/role.js" in page.text
assert "/static/roles.js" not in page.text
missing = client.get("/roles/nope")
assert missing.status_code == 404 and "text/html" in missing.headers["content-type"]
def test_the_roles_page_offers_the_judged_filter_and_hidden_companies(
client: TestClient) -> None:
page = client.get("/").text
assert 'id="f-judged"' in page and "<details" in page
for label in ("Liked", "Unjudged", "Passed", "Show hidden companies"):
assert label in page
assert "Show muted" not in page
# --------------------------------------------------------------- companies
@@ -160,8 +262,8 @@ def test_save_creates_an_application_with_a_saved_event(
assert body["role_uid"] == uid
assert body["status"] == "saved"
assert body["company_key"] == "acme"
assert body["next_action"] == "Read the posting and decide"
assert body["next_date"] is not None
# No placeholder: a next step is the CLI's to set.
assert body["next_action"] == "" and body["next_date"] is None
events = store.application_events(body["id"])
assert [e.status for e in events] == ["saved"]
@@ -198,6 +300,29 @@ def test_set_status_validates_and_writes_an_event(
json={"status": "applied"}).status_code == 404
def test_unsave_drops_a_saved_application_and_refuses_one_that_moved_on(
client: TestClient, store: Store) -> None:
store.upsert_role(posting("1", company="Acme"))
store.upsert_role(posting("2", company="Acme"))
first = client.post("/api/applications", json={"role_uid": posting("1").uid}).json()
second = client.post("/api/applications", json={"role_uid": posting("2").uid}).json()
assert client.delete(f"/api/applications/{first['id']}").status_code == 204
assert store.application(first["id"]) is None
assert store.application_events(first["id"]) == []
assert client.delete(f"/api/applications/{first['id']}").status_code == 404
client.post(f"/api/applications/{second['id']}/status", json={"status": "applied"})
refused = client.delete(f"/api/applications/{second['id']}")
assert refused.status_code == 409 and "withdrawn" in refused.json()["detail"]
assert store.application(second["id"]) is not None
def test_the_applications_page_has_no_next_column(client: TestClient) -> None:
page = client.get("/applications").text
assert "<th>Next</th>" not in page and "<th>Saved</th>" in page
# -------------------------------------------------------------------- tabs
def test_every_page_renders_with_the_whole_nav(client: TestClient) -> None:
@@ -371,12 +496,12 @@ def test_roles_by_agent_are_ordered_by_score_and_hide_the_gated(
store.replace_scores(agent.id, [(uids["low"], 0.2, ""), (uids["high"], 0.8, ""),
(uids["gated"], 0.0, "place unknown")])
shown = client.get(f"/api/roles?agent={agent.id}").json()
shown = client.get(f"/api/roles?agent={agent.id}").json()["items"]
assert [r["source_id"] for r in shown] == ["high", "low"]
assert shown[0]["score"] == 0.8
everything = client.get(f"/api/roles?agent={agent.id}&gated=1").json()
everything = client.get(f"/api/roles?agent={agent.id}&gated=1").json()["items"]
assert everything[-1]["gated_reason"] == "place unknown"
assert client.get("/api/roles").json()[0]["score"] is None
assert client.get("/api/roles").json()["items"][0]["score"] is None
assert client.get("/api/roles?agent=999").status_code == 404