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:
1 parent
515d2250fc
commit
a9290a6926
23 files changed
+2252
-715
No files matched your search
+126
-2
@@ -86,19 +86,38 @@ def test_a_v1_file_migrates_to_the_shape_a_new_file_has(tmp_path: Path) -> None:
|
||||
Store(old)
|
||||
with sqlite3.connect(old) as conn:
|
||||
for column in ("permit", "languages", "extract_tries", "vote", "voted_at",
|
||||
"summary", "summarised_at", "article_text", "article_at"):
|
||||
"summary", "summarised_at", "article_text", "article_at",
|
||||
"read_at"):
|
||||
conn.execute(f"ALTER TABLE roles DROP COLUMN {column}")
|
||||
for column in ("intent_key", "intent_vec"):
|
||||
conn.execute(f"ALTER TABLE agents DROP COLUMN {column}")
|
||||
conn.execute("DROP TABLE vectors")
|
||||
conn.execute("DROP TABLE role_tags")
|
||||
conn.execute("PRAGMA user_version = 1")
|
||||
|
||||
assert Store(old).migrations_applied == list(range(2, LATEST + 1))
|
||||
# ALTER appends, so the order differs; every read is by column name.
|
||||
for table in ("roles", "agents", "vectors"):
|
||||
for table in ("roles", "agents", "vectors", "role_tags"):
|
||||
assert sorted(_columns(old, table)) == sorted(_columns(fresh, table))
|
||||
|
||||
|
||||
def test_a_v4_file_migrates_read_state_and_tags(tmp_path: Path) -> None:
|
||||
fresh, old = tmp_path / "fresh.db", tmp_path / "old.db"
|
||||
Store(fresh)
|
||||
Store(old)
|
||||
with sqlite3.connect(old) as conn:
|
||||
conn.execute("ALTER TABLE roles DROP COLUMN read_at")
|
||||
conn.execute("DROP TABLE role_tags")
|
||||
conn.execute("PRAGMA user_version = 4")
|
||||
|
||||
assert Store(old).migrations_applied == [5]
|
||||
assert sorted(_columns(old, "roles")) == sorted(_columns(fresh, "roles"))
|
||||
with sqlite3.connect(old) as conn:
|
||||
tables = {r[0] for r in conn.execute(
|
||||
"SELECT name FROM sqlite_master WHERE type='table'")}
|
||||
assert "role_tags" in tables
|
||||
|
||||
|
||||
def test_state_is_a_mapping(store: Store) -> None:
|
||||
store.state["ats:last"] = "2026-09-23"
|
||||
assert store.state["ats:last"] == "2026-09-23"
|
||||
@@ -244,6 +263,97 @@ def test_a_vote_is_stamped_cleared_and_filtered(store: Store, clock: Clock) -> N
|
||||
store.set_vote("nope", 1)
|
||||
|
||||
|
||||
def test_read_state_is_set_cleared_and_a_vote_marks_read(
|
||||
store: Store, clock: Clock) -> None:
|
||||
store.upsert_role(posting("1"))
|
||||
uid = posting("1").uid
|
||||
role = store.role(uid)
|
||||
assert role is not None and role.read_at is None
|
||||
|
||||
read = store.set_read(uid)
|
||||
assert read.read_at == clock().isoformat(timespec="seconds")
|
||||
clock.tick()
|
||||
again = store.set_read(uid)
|
||||
assert again.read_at == read.read_at, "reading twice keeps the first stamp"
|
||||
|
||||
cleared = store.set_read(uid, False)
|
||||
assert cleared.read_at is None
|
||||
|
||||
voted = store.set_vote(uid, 1)
|
||||
assert voted.read_at is not None, "voting is reading"
|
||||
stamp = voted.read_at
|
||||
unvoted = store.set_vote(uid, None)
|
||||
assert unvoted.read_at == stamp, "clearing a vote is not un-reading"
|
||||
|
||||
with pytest.raises(KeyError):
|
||||
store.set_read("nope")
|
||||
|
||||
|
||||
def test_roles_include_read_excludes_a_read_role_before_the_limit(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_read(uid["1"])
|
||||
|
||||
assert {r.source_id for r in store.roles()} == {"1", "2"}
|
||||
assert {r.source_id for r in store.roles(include_read=False)} == {"2"}
|
||||
assert store.count_roles(include_read=False) == 1
|
||||
|
||||
|
||||
def test_set_tags_normalises_dedupes_and_caps(store: Store) -> None:
|
||||
store.upsert_role(posting("1"))
|
||||
uid = posting("1").uid
|
||||
long_tag = "x" * 50
|
||||
|
||||
tags = store.set_tags(uid, [" Backend Engineer ", "python", "PYTHON", "", " ",
|
||||
long_tag, *[f"t{i}" for i in range(15)]])
|
||||
|
||||
assert tags == sorted(tags)
|
||||
assert len(tags) == 12 # capped at _MAX_TAGS
|
||||
assert len(set(tags)) == 12 # no repeats
|
||||
assert all(len(t) <= 40 for t in tags) # cut to _MAX_TAG_LEN
|
||||
assert "backend engineer" in tags and "python" in tags
|
||||
role = store.role(uid)
|
||||
assert role is not None and role.tags == tags # loaded sorted, with the role
|
||||
|
||||
with pytest.raises(KeyError):
|
||||
store.set_tags("nope", ["x"])
|
||||
|
||||
|
||||
def test_roles_filters_by_tags_any_and_all(store: Store) -> None:
|
||||
store.upsert_role(posting("1"))
|
||||
store.upsert_role(posting("2"))
|
||||
store.upsert_role(posting("3"))
|
||||
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"])
|
||||
store.set_tags(uid["3"], ["go"])
|
||||
|
||||
assert {r.source_id for r in store.roles(tags=["python"])} == {"1", "2"}
|
||||
assert {r.source_id for r in store.roles(tags=["python", "go"])} == {"1", "2", "3"}
|
||||
assert {r.source_id for r in
|
||||
store.roles(tags=["python", "backend"], tag_mode="all")} == {"1"}
|
||||
assert store.count_roles(tags=["python"]) == 2
|
||||
assert store.count_roles(tags=["python", "backend"], tag_mode="all") == 1
|
||||
with pytest.raises(ValueError, match="tag_mode"):
|
||||
store.roles(tags=["python"], tag_mode="maybe")
|
||||
|
||||
|
||||
def test_tag_counts_orders_by_count_then_tag_and_respects_muted(store: Store) -> None:
|
||||
store.add_company("Hidden", key="hidden", affinity=-1)
|
||||
store.upsert_role(posting("1", company="Acme"))
|
||||
store.upsert_role(posting("2", company="Acme"))
|
||||
store.upsert_role(posting("3", company="Hidden"))
|
||||
uid = {r.source_id: r.uid for r in store.roles(hide_muted=False)}
|
||||
store.set_tags(uid["1"], ["python", "backend"])
|
||||
store.set_tags(uid["2"], ["python"])
|
||||
store.set_tags(uid["3"], ["python", "backend"])
|
||||
store.set_read(uid["1"])
|
||||
|
||||
assert store.tag_counts() == [("python", 2, 1), ("backend", 1, 0)]
|
||||
assert store.tag_counts(show_muted=True) == [("python", 3, 2), ("backend", 2, 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))
|
||||
@@ -389,6 +499,20 @@ def test_a_summary_is_written_once(store: Store) -> None:
|
||||
assert store.set_summary("nope", "x") is False
|
||||
|
||||
|
||||
def test_a_summarys_tags_land_with_it_and_not_on_a_rejected_late_answer(
|
||||
store: Store) -> None:
|
||||
store.upsert_role(posting())
|
||||
uid = posting().uid
|
||||
assert store.set_summary(uid, "First.", ["Python", "backend"]) is True
|
||||
role = store.role(uid)
|
||||
assert role is not None and role.tags == ["backend", "python"]
|
||||
|
||||
# A second write is rejected (already summarised), and does not touch tags.
|
||||
assert store.set_summary(uid, "Second.", ["go"]) is False
|
||||
role = store.role(uid)
|
||||
assert role is not None and role.tags == ["backend", "python"]
|
||||
|
||||
|
||||
def test_summarise_waits_on_the_top_of_each_enabled_agent(store: Store) -> None:
|
||||
"""Two agents each contribute their own top one; a closed role, a hidden
|
||||
company's role and a gated score are not in anybody's top."""
|
||||
|
||||
Reference in new issue
Block a user