Merge branch 'wp-e2-copies'

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Opus 5.5 committed 2026-09-30 09:49:10 +02:00
commit 695d38c339
6 files changed
+336 -16

No files matched your search

+48 -1
View File
@@ -12,7 +12,15 @@ if str(ROOT) not in sys.path:
import pytest # noqa: E402
from app.dupes import Copy, assign, keep_order, same_posting # noqa: E402
from app.dupes import ( # noqa: E402
Copy,
assign,
fold,
keep_order,
place_line,
same_posting,
similar,
)
from app.places import towns # noqa: E402
@@ -194,3 +202,42 @@ def test_a_row_without_a_place_never_bridges_two_countries():
assert got == {"a": None, "b": "a", "c": "a", "d": None, "e": None}
assert not same_posting(cp("a", country="EU", place="Belgium"),
cp("b", country="EU", place="Netherlands"))
def pc(uid: str, place: str, text: str = "", host: str = "greenhouse", url: str = "u",
title: str = "engineer") -> Copy:
return Copy(uid, "acme", title, "DE", place, host, bool(text), None, text, url or "")
def test_one_posting_per_place_folds_into_the_first_and_only_within_a_host() -> None:
text = "We build the payment platform for our bank customers in Kotlin."
got = fold([pc("b", "Berlin", text), pc("m", "Munich", text), pc("h", "Hamburg", text),
pc("x", "Kiel", text, host="lever")])
assert got.dup_of == {"b": None, "m": "b", "h": "b", "x": None}
assert got.placed == {"m", "h"}
def test_folding_needs_the_same_title_a_link_and_texts_that_can_be_one_job() -> None:
a = "Build payment services in Kotlin for our bank customers and their teams."
b = "Negotiate enterprise cloud contracts with procurement and legal buyers."
got = fold([pc("1", "Berlin", a), pc("2", "Munich", b), pc("3", "Hamburg", a, url=""),
pc("4", "Kiel", a, title="manager")])
assert got.dup_of == {"1": None, "2": None, "3": None, "4": None}
assert fold([pc("1", "Berlin", a), pc("2", "Munich", "")]).placed == {"2"}
def test_a_copy_of_a_folded_row_follows_it_to_the_new_kept_role() -> None:
"""Berlin is kept over Munich; a second Munich row that was Munich's copy
now points at Berlin, and is not a place of its own."""
text = "We build the payment platform for our bank customers in Kotlin."
same = fold([pc("b", "Berlin", text), pc("m", "Munich", text),
pc("m2", "Munich, Germany", text)])
assert same.dup_of == {"b": None, "m": "b", "m2": "b"}
assert same.placed == {"m"} # m2 is m's own copy, not another place
def test_similar_and_place_line() -> None:
assert similar("", "anything at all") and similar("a job in Kotlin", "a job in Kotlin")
assert not similar("sell cloud contracts to buyers", "build kotlin payment services")
assert place_line(["Berlin", "Munich", "Berlin", "Hamburg"]) == "Berlin +2"
assert place_line(["Berlin", " "]) == "Berlin" and place_line([]) == ""
+73 -5
View File
@@ -37,9 +37,9 @@ def dup_of(store: Store) -> dict[str, str | None]:
def test_a_board_under_several_ids_is_one_role_and_another_town_stays_apart(
store: Store) -> None:
"""SAP's repeats: three Garching rows are one kept role (the one with
the description) and two copies; New York is its own role."""
the description) and two copies; New York, listed by another host, is its own role."""
garching = [role("1", body=""), role("2"), role("3", body="")]
york = role("4", place="New York, NY, US")
york = role("4", place="New York, NY, US", board="greenhouse")
for item in (*garching, york):
store.upsert_role(item)
@@ -61,12 +61,80 @@ def test_a_search_copy_of_a_board_role_is_hidden_behind_the_board(store: Store)
assert dup_of(store) == {board.uid: None, search.uid: board.uid}
def test_berlin_and_munich_stay_two_roles(store: Store) -> None:
for item in (role("b", place="Berlin"), role("m", place="Munich")):
def kept_of(store: Store, *items: Item) -> str:
"""The uid of the one of these roles that is not a copy."""
found = dup_of(store)
(kept,) = [i.uid for i in items if found[i.uid] is None]
return kept
def test_berlin_and_munich_of_one_host_fold_into_one_role_with_two_places(
store: Store) -> None:
"""One posting per place on one host is one role that lists both places,
each with its own link; the count of copies does not show it as `x2`."""
berlin, munich = role("b", place="Berlin"), role("m", place="Munich")
for item in (berlin, munich):
store.upsert_role(item)
assert store.rebuild_dupes() == (1, 1, 1)
kept = kept_of(store, berlin, munich)
got = store.role(kept)
assert got is not None
assert sorted(p.text for p in got.places) == ["Berlin", "Munich"]
assert sorted(p.url for p in got.places if p.url) in (
["https://jobs.example/b"], ["https://jobs.example/m"])
assert got.copies == []
(row,) = store.roles_page()
assert (row.uid, row.place, row.copies) == (kept, f"{got.places[0].text} +1", 0)
def test_places_of_two_hosts_or_two_different_texts_stay_apart(store: Store) -> None:
a = role("a", place="Berlin", body="Build payment services in Kotlin for our bank " * 5)
b = role("b", place="Munich", body="Sell cloud contracts to enterprise buyers " * 5)
c = role("c", place="Hamburg", board="greenhouse", body=a.body)
for item in (a, b, c):
store.upsert_role(item)
assert store.rebuild_dupes() == (0, 0, 0)
def own_and_copy_places(store: Store, uid: str) -> list[tuple[str, bool]]:
got = store.role(uid)
assert got is not None
return sorted((p.text, bool(p.url)) for p in got.places)
def test_a_place_copy_closing_or_its_board_off_takes_its_place_away(store: Store) -> None:
from app.jobs.sources import set_fetch
sub = store.add_subscription("ats", "successfactors:sap", label="SAP")
items = [role("b", place="Berlin"), role("m", place="Munich"), role("k", place="Kiel")]
for item in items:
store.upsert_role(item, sub)
store.rebuild_dupes()
kept = kept_of(store, *items)
assert [t for t, _ in own_and_copy_places(store, kept)] == ["Berlin", "Kiel", "Munich"]
closing = next(i for i in items if i.uid != kept)
with sqlite3.connect(store.path) as conn:
conn.execute("UPDATE roles SET closed_at = '2026-09-25' WHERE uid = ?", (closing.uid,))
store.rebuild_dupes()
assert len(own_and_copy_places(store, kept)) == 2
assert store.rebuild_dupes().changed == 0
set_fetch(store, sub.id, False)
assert set(dup_of(store).values()) == {None}
assert not any(url for _, url in own_and_copy_places(store, kept))
def test_a_repull_keeps_the_copies_places(store: Store) -> None:
items = [role("b", place="Berlin"), role("m", place="Munich")]
for item in items:
store.upsert_role(item)
store.rebuild_dupes()
kept = kept_of(store, *items)
store.upsert_role(next(i for i in items if i.uid == kept))
assert [t for t, _ in own_and_copy_places(store, kept)] == ["Berlin", "Munich"]
def test_closing_the_kept_role_hands_the_group_on_and_a_closed_copy_is_cleared(
store: Store) -> None:
first, second, third = role("1", day=18), role("2", day=19), role("3", day=20)
@@ -129,7 +197,7 @@ def test_a_closed_kept_role_hands_its_read_and_vote_to_the_next(store: Store) ->
def test_a_copy_is_left_out_of_the_feed_counts_and_model_stages(store: Store) -> None:
kept, copy, other = role("1", day=18), role("2", day=19), role("3", place="Berlin")
kept, copy, other = role("1", day=18), role("2", day=19), role("3", place="Berlin", board="greenhouse")
for item in (kept, copy, other):
store.upsert_role(item)
store.set_tags(item.uid, ["python"])