Close a search's roles by age only: a search read complete no longer closes every role its query stopped returning, since a search is never a company's whole list
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
1127d06f03
commit
19fb73caa0
2 files changed
+63
-25
No files matched your search
+35
-2
@@ -26,7 +26,7 @@ from plugins.readers import Ask, Fields, Reads, _runner # noqa: E402
|
||||
from plugins.search import SearchSource # noqa: E402
|
||||
from app.config import SearchSeed # noqa: E402
|
||||
from app.jobs import pull # noqa: E402
|
||||
from pipeline import Tally # noqa: E402
|
||||
from pipeline import RunContext, Tally # noqa: E402
|
||||
from app.models import country_of, remote_of # noqa: E402
|
||||
from app.storage import Store # noqa: E402
|
||||
from prepped import upsert # noqa: E402
|
||||
@@ -291,8 +291,12 @@ def _pull(store: Store) -> dict[str, Any]:
|
||||
return closed
|
||||
|
||||
|
||||
def test_a_complete_search_closes_what_it_stopped_listing(
|
||||
def test_a_complete_search_closes_nothing_by_its_list_only_by_age(
|
||||
store: Store, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""A search is never a company's whole list: one that read as many
|
||||
results as its provider stated is stamped complete, and a role it
|
||||
stopped listing still stays open until no search has listed it for
|
||||
`STALE_DAYS`."""
|
||||
store.add_subscription("search", "fake:cph", label="Copenhagen", board="fake",
|
||||
params={"q": "backend"})
|
||||
_fake_provider(monkeypatch, ["h1", "h2"], complete=True)
|
||||
@@ -304,10 +308,39 @@ def test_a_complete_search_closes_what_it_stopped_listing(
|
||||
|
||||
_fake_provider(monkeypatch, ["h2"], complete=True)
|
||||
result = _pull(store)
|
||||
assert store.state["search:complete:fake:cph"] == "1"
|
||||
assert {r.source_id for r in store.roles()} == {"fake:h1", "fake:h2"}
|
||||
assert (result["searches"], result["closed"]) == (1, 0)
|
||||
|
||||
old = (datetime.now(UTC) - timedelta(days=pull.STALE_DAYS + 1)).isoformat()
|
||||
with store.transaction() as conn:
|
||||
conn.execute("UPDATE roles SET last_seen = ? WHERE source_id = 'fake:h1'", (old,))
|
||||
result = _pull(store)
|
||||
assert {r.source_id for r in store.roles()} == {"fake:h2"}
|
||||
assert (result["searches"], result["closed"]) == (1, 1)
|
||||
|
||||
|
||||
def test_a_complete_search_that_lists_far_fewer_is_not_named_in_the_notice(
|
||||
store: Store, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""Fifteen of twenty roles dropping out of a complete search closed
|
||||
them, and named the search as closing many; now they stay open and the
|
||||
settle has nothing to say."""
|
||||
store.add_subscription("search", "fake:cph", label="Copenhagen", board="fake",
|
||||
params={"q": "backend"})
|
||||
twenty = [f"h{n}" for n in range(20)]
|
||||
_fake_provider(monkeypatch, twenty, complete=True)
|
||||
_pull(store)
|
||||
_fake_provider(monkeypatch, twenty[:5], complete=True)
|
||||
said: list[object] = []
|
||||
results = [pull.run_batch(FakeConfig(), store, **batch) # type: ignore[arg-type]
|
||||
for batch in pull._boards(FakeConfig(), store)] # type: ignore[arg-type]
|
||||
result = pull.close_boards(FakeConfig(), store, Tally(results=tuple(results)), # type: ignore[arg-type]
|
||||
context=RunContext(on_notice=said.append))
|
||||
assert (result["searches"], result["unanswered"], result["closed"]) == (1, 0, 0)
|
||||
assert len(store.roles()) == 20
|
||||
assert said == []
|
||||
|
||||
|
||||
def test_an_incomplete_search_closes_nothing_until_stale(
|
||||
store: Store, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
store.add_subscription("search", "fake:cph", label="Copenhagen", board="fake",
|
||||
|
||||
Reference in new issue
Block a user