Roles is newsdesk's feed: rail, feed and reader, with read state and tags

The Roles tab takes newsdesk's shell, ported from its index.html and
app.css rather than rewritten: a filter rail (Show read, Best first or
Newest first, first seen, tag chips with counts, the old filters behind a
disclosure), the feed in newsdesk's row layout (score gutter, title,
company, place, badges, age, tags, the summary as excerpt, judge buttons)
and the reader as a third column that replaces the list on a phone. The
router pushes /roles/{uid}, which the server also renders with the reader
open, so the separate read page and role.js go. j/k, u/n/d, S, Enter,
Escape, o, /, f and c work as in newsdesk. The phone rules come with their
comments.

Two things the row lacked: roles.read_at, stamped when the reader opens a
role or a vote is cast, behind include_read on /api/roles; and role_tags,
written by summarise alongside the summary and served with counts by
/api/filters, filtered in SQL before LIMIT. Migration 5.

PyCharm run configurations in .run/ for serve, pull, seed and pytest.
core.autocrlf=input is set locally so a Windows-side checkout commits LF.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Fable 5.1 committed 2026-09-28 12:37:45 +02:00
1 parent 515d2250fc
commit a9290a6926
23 files changed
+2252 -715

No files matched your search

+65 -2
View File
@@ -199,6 +199,70 @@ def test_a_vote_moves_a_role_in_the_ranking_at_once(
assert ranked() == [("a", 1.0), ("c", 0.66), ("b", 0.6)] # capped at 1
def test_read_state_is_set_and_cleared_over_the_api(client: TestClient, store: Store) -> None:
store.upsert_role(posting("1"))
uid = posting("1").uid
res = client.post(f"/api/roles/{uid}/read")
assert res.status_code == 200
assert res.json()["read_at"] is not None
res = client.delete(f"/api/roles/{uid}/read")
assert res.status_code == 200
assert res.json()["read_at"] is None
assert client.post("/api/roles/nope/read").status_code == 404
assert client.delete("/api/roles/nope/read").status_code == 404
def test_list_roles_filters_by_include_read(client: TestClient, store: Store) -> None:
store.upsert_role(posting("1"))
store.upsert_role(posting("2"))
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"}
unread = client.get("/api/roles", params={"include_read": "false"}).json()
assert {r["source_id"] for r in unread["items"]} == {"2"}
assert unread["total"] == 1
def test_list_roles_filters_by_tags_any_and_all(client: TestClient, store: Store) -> None:
store.upsert_role(posting("1"))
store.upsert_role(posting("2"))
uid = {r.source_id: r.uid for r in store.roles()}
store.set_tags(uid["1"], ["python", "backend"])
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"}
both = client.get("/api/roles", params={"tags": ["python", "backend"],
"tag_mode": "all"})
assert {r["source_id"] for r in both.json()["items"]} == {"1"}
[item] = both.json()["items"]
assert item["tags"] == ["backend", "python"]
def test_filters_lists_tag_counts_and_respects_show_muted(
client: TestClient, store: Store) -> None:
store.add_company("Hidden", key="hidden", affinity=-1)
store.upsert_role(posting("1", company="Acme"))
store.upsert_role(posting("2", company="Hidden"))
uid = {r.source_id: r.uid for r in store.roles(hide_muted=False)}
store.set_tags(uid["1"], ["python"])
store.set_tags(uid["2"], ["python"])
res = client.get("/api/filters")
assert res.status_code == 200
assert res.json() == {"tags": [{"tag": "python", "count": 1, "unread": 1}]}
muted = client.get("/api/filters", params={"show_muted": "true"})
assert muted.json() == {"tags": [{"tag": "python", "count": 2, "unread": 2}]}
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
@@ -213,8 +277,7 @@ def test_one_role_and_its_read_page(client: TestClient, store: Store) -> None:
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
assert '<body data-reader="open">' in page.text and "/static/roles.js" in page.text
missing = client.get("/roles/nope")
assert missing.status_code == 404 and "text/html" in missing.headers["content-type"]