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:
1 parent
55e353e764
commit
545c932f7b
10 files changed
+490
-41
No files matched your search
+34
-5
@@ -31,11 +31,11 @@ class FakeConfig:
|
||||
searches: ClassVar[list[object]] = []
|
||||
|
||||
|
||||
def _item(board: str, slug: str, job_id: str) -> Item:
|
||||
def _item(board: str, slug: str, job_id: str, company: str = "Acme") -> Item:
|
||||
item = Item(
|
||||
source_id=f"{board}:{slug}:{job_id}", location=f"https://x.example/{job_id}",
|
||||
title="Engineer", body="", published_at=datetime(2026, 9, 20, tzinfo=UTC),
|
||||
raw={"company": "Acme", "place": "Berlin", "department": "",
|
||||
raw={"company": company, "place": "Berlin", "department": "",
|
||||
"function": "engineering", "remote": None, "salary_text": "",
|
||||
"board": board, "slug": slug})
|
||||
item.source = "ats"
|
||||
@@ -126,7 +126,7 @@ def test_close_boards_closes_what_a_completed_board_no_longer_lists(
|
||||
|
||||
store.upsert_role(_item("greenhouse", "acme", "1"), sub)
|
||||
store.upsert_role(_item("greenhouse", "acme", "2"), sub)
|
||||
store.upsert_role(_item("greenhouse", "other", "9"), other)
|
||||
store.upsert_role(_item("greenhouse", "other", "9", company="Other"), other)
|
||||
|
||||
# acme answered this run and now lists only "1"; other's board failed
|
||||
# (or its batch never got to it) and stamped nothing.
|
||||
@@ -140,7 +140,7 @@ def test_close_boards_closes_what_a_completed_board_no_longer_lists(
|
||||
result = pull.close_boards(FakeConfig(), store, FakeTally()) # type: ignore[arg-type]
|
||||
|
||||
assert result == {"boards": 1, "searches": 0, "failed": 1, "incomplete": 0,
|
||||
"roles": 1, "closed": 1}
|
||||
"roles": 1, "closed": 1, "copies": 0}
|
||||
assert {r.source_id for r in store.roles()} == {"greenhouse:acme:1", "greenhouse:other:9"}
|
||||
|
||||
|
||||
@@ -161,10 +161,39 @@ def test_close_boards_never_closes_a_board_stamped_by_an_earlier_run(
|
||||
result = pull.close_boards(FakeConfig(), store, FakeTally()) # type: ignore[arg-type]
|
||||
|
||||
assert result == {"boards": 0, "searches": 0, "failed": 1, "incomplete": 0,
|
||||
"roles": 0, "closed": 0}
|
||||
"roles": 0, "closed": 0, "copies": 0}
|
||||
assert {r.source_id for r in store.roles()} == {"greenhouse:acme:1"}
|
||||
|
||||
|
||||
def test_close_boards_rebuilds_the_copies_after_closing(store: Store) -> None:
|
||||
"""The settle's last step: a board's repeats of one job are one role,
|
||||
and when the kept one closes the next copy is kept in its place."""
|
||||
sub = store.add_subscription("ats", "greenhouse:acme", label="Acme",
|
||||
company="Acme", board="greenhouse")
|
||||
for job_id in ("1", "2", "3"):
|
||||
store.upsert_role(_item("greenhouse", "acme", job_id), sub)
|
||||
store.state["ats:ok:greenhouse:acme"] = "run-1"
|
||||
store.state["ats:complete:greenhouse:acme"] = "1"
|
||||
store.state["ats:ids:greenhouse:acme"] = json.dumps(
|
||||
["greenhouse:acme:1", "greenhouse:acme:2", "greenhouse:acme:3"])
|
||||
|
||||
class FakeTally:
|
||||
results = ({"roles": 3, "run": "run-1"},)
|
||||
|
||||
result = pull.close_boards(FakeConfig(), store, FakeTally()) # type: ignore[arg-type]
|
||||
assert result["copies"] == 2
|
||||
[kept] = store.roles_page()
|
||||
assert kept.copies == 2
|
||||
|
||||
gone = store.role(kept.uid).source_id # type: ignore[union-attr]
|
||||
store.state["ats:ids:greenhouse:acme"] = json.dumps(
|
||||
[f"greenhouse:acme:{n}" for n in "123" if f"greenhouse:acme:{n}" != gone])
|
||||
result = pull.close_boards(FakeConfig(), store, FakeTally()) # type: ignore[arg-type]
|
||||
assert (result["closed"], result["copies"]) == (1, 1)
|
||||
[after] = store.roles_page()
|
||||
assert after.uid != kept.uid and after.copies == 1
|
||||
|
||||
|
||||
# ---------------------------------------------- whole pulls, fetch stubbed
|
||||
|
||||
def _row(job_id: str) -> dict[str, object]:
|
||||
|
||||
Reference in new issue
Block a user