Store copies of one posting as roles.dup_of and leave them out of the feed, the counts and the model stages

Migration 18 adds roles.dup_of with a partial index and runs the first rebuild. Store.rebuild_dupes feeds app.dupes.assign the open roles of every (company_key, title_key) with more than one, rewrites dup_of where it changed, clears it on closed roles, and hands read_at and votes to a changed group's kept role. The pull's settle and `app dupes` run it. RoleRow.copies counts a row's open copies; Role.copies lists them and Role.dup_of names a copy's kept role.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Opus 5.5 committed 2026-09-29 23:09:20 +02:00
1 parent 55e353e764
commit 545c932f7b
10 files changed
+490 -41

No files matched your search

+27 -1
View File
@@ -1159,7 +1159,7 @@ def test_list_roles_serves_the_row_projection_and_not_the_big_columns(
"uid", "company_key", "company", "title", "place", "country", "remote", "function",
"seniority", "salary_min", "salary_max", "currency", "salary_text", "salary_state",
"original_url", "posted_at", "score", "gated_reason", "prompt", "vote",
"voted_at", "read_at", "tags", "excerpt",
"voted_at", "read_at", "tags", "excerpt", "copies",
}
assert row["uid"] == uid
assert row["company"] == "Acme" and row["place"] == "Berlin, Germany"
@@ -1644,3 +1644,29 @@ def test_summarise_queues_one_role_and_the_job_writes_it(
assert asked == [[uid]]
assert store.role(uid).summary == "Backend role in Berlin, Python." # type: ignore[union-attr]
assert client.post(f"/api/roles/{uid}/summarise").status_code == 409
def test_a_kept_role_lists_its_copies_and_a_copy_names_its_kept_role(
client: TestClient, store: Store) -> None:
"""The contract the reader and the feed row build on: `copies` on a row
is a count, on `GET /api/roles/{uid}` the list of open copies, and a copy
still opens, with `dup_of`."""
board = posting("board", company="Acme", place="Ballerup", board="greenhouse")
board.body = "The whole posting."
search = posting("search", company="Acme", place="Ballerup, Denmark", provider="jobindex")
for item in (board, search, posting("alone", company="Other")):
store.upsert_role(item)
store.rebuild_dupes()
page = client.get("/api/roles").json()
assert page["total"] == 2
assert {r["uid"]: r["copies"] for r in page["items"]} == {
board.uid: 1, posting("alone").uid: 0}
kept = client.get(f"/api/roles/{board.uid}").json()
assert kept["dup_of"] is None
assert kept["copies"] == [{
"uid": search.uid, "host": "jobindex", "place": "Ballerup, Denmark",
"original_url": search.location, "posted_at": kept["copies"][0]["posted_at"]}]
copy = client.get(f"/api/roles/{search.uid}").json()
assert copy["dup_of"] == board.uid and copy["copies"] == []