Guard each target in a batch, close remote-unasked and narrowed roles by age, settle failing searches, and raise one notice per settle naming what needs a look

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Fable 5.1 committed 2026-09-30 15:53:47 +02:00
1 parent 24a165818c
commit 9c8a610787
4 files changed
+576 -115

No files matched your search

+53
View File
@@ -371,3 +371,56 @@ def test_a_search_switched_off_mid_pull_ends_the_pull_closed(
assert store.roles() == []
# And a batch that starts after the switch reads nothing.
assert pull.run_batch(FakeConfig(), store, **batches[0])["roles"] == 0 # type: ignore[arg-type]
# ------------------------------------------------- failures and the guard
def _broken_provider(monkeypatch: pytest.MonkeyPatch) -> None:
"""The provider `fake` of `_fake_provider`, answering with an error."""
_fake_provider(monkeypatch, [], complete=True)
def page(get: Any, slug: str, cursor: Any, ask: Ask) -> Any:
raise ValueError("hits renamed")
readers.PROVIDERS["fake"].page = page
def test_a_search_whose_provider_raises_is_recorded_failing(
store: Store, monkeypatch: pytest.MonkeyPatch) -> None:
store.add_subscription("search", "fake:cph", label="Copenhagen", board="fake",
params={"q": "backend"})
_fake_provider(monkeypatch, ["h1"], complete=True)
_pull(store)
_broken_provider(monkeypatch)
result = _pull(store)
assert result["unanswered"] == 1
since, reason = pull.failing_boards(store)["fake:cph"]
assert since and reason == "ValueError: hits renamed"
assert {r.source_id for r in store.roles()} == {"fake:h1"}
# Failing for `STALE_DAYS` closes its roles, as a board's.
old = (datetime.now(UTC) - timedelta(days=pull.STALE_DAYS + 1)).isoformat(
timespec="seconds")
store.state["search:failing:fake:cph"] = json.dumps({"since": old, "reason": reason})
_pull(store)
assert store.roles() == []
# Its next answer removes the record and reopens what it lists.
_fake_provider(monkeypatch, ["h1"], complete=True)
_pull(store)
assert pull.failing_boards(store) == {}
assert {r.source_id for r in store.roles()} == {"fake:h1"}
def test_a_search_that_lists_nothing_after_forty_is_suspect(
store: Store, monkeypatch: pytest.MonkeyPatch) -> None:
store.add_subscription("search", "fake:cph", label="Copenhagen", board="fake",
params={"q": "backend"})
forty = [f"h{n}" for n in range(40)]
_fake_provider(monkeypatch, forty, complete=True)
_pull(store)
_fake_provider(monkeypatch, [], complete=True)
result = _pull(store)
assert (result["unanswered"], result["closed"]) == (1, 0)
assert len(store.roles()) == 40
assert "under 10% of the 40" in pull.failing_boards(store)["fake:cph"][1]