π The fast, Pythonic way to build MCP servers and clients.
Fail backlog collection when pagination ends early (#5988)
nate nowack37301f9dee0f
diff --git a/scripts/backlog_status.py b/scripts/backlog_status.pyindex 963b2dc8b..7b65b66e9 100644--- a/scripts/backlog_status.py+++ b/scripts/backlog_status.py@@ -34,6 +34,29 @@ def fetch_items() -> list[dict]:return [json.loads(line) for line in result.stdout.splitlines() if line.strip()]+def newest_number() -> int:+ result = subprocess.run(+ [+ "gh",+ "api",+ f"repos/{REPO}/issues?state=all&per_page=1&sort=created&direction=desc",+ "--jq",+ ".[0].number",+ ],+ capture_output=True,+ text=True,+ check=True,+ )+ return int(result.stdout)+++def require_complete(items: list[dict], newest: int) -> None:+ if newest not in {item["number"] for item in items}:+ raise RuntimeError(+ f"Collected {len(items)} items without #{newest}; pagination ended early"+ )++def parse_time(value: str) -> datetime:return datetime.fromisoformat(value.replace("Z", "+00:00"))@@ -153,7 +176,12 @@ def main() -> None:# Timestamp the beginning of collection so updates during pagination are# not represented as a snapshot from after an item was read.now = datetime.now(timezone.utc).replace(microsecond=0)- doc = build(fetch_items(), previous, now)+ # Pages are oldest-first, so a listing that stops early silently drops the+ # newest items. Anything created before collection began must be present.+ newest = newest_number()+ items = fetch_items()+ require_complete(items, newest)+ doc = build(items, previous, now)args.output.write_text(json.dumps(doc, separators=(",", ":")) + "\n")diff --git a/tests/test_backlog_status.py b/tests/test_backlog_status.pyindex 582d3f647..1fcc678ad 100644--- a/tests/test_backlog_status.py+++ b/tests/test_backlog_status.py@@ -107,3 +107,32 @@ def test_explicit_missing_history_fails_without_reset(backlog, tmp_path, monkeypwith pytest.raises(FileNotFoundError):backlog.main()assert not output.exists()+++def test_truncated_collection_fails_without_publishing(backlog, tmp_path, monkeypatch):+ previous = tmp_path / "previous.json"+ previous.write_text('{"schema": "fastmcp-backlog/1", "samples": []}')+ output = tmp_path / "backlog.json"+ monkeypatch.setattr(backlog, "newest_number", lambda: 3)+ monkeypatch.setattr(+ backlog,+ "fetch_items",+ lambda: [item(1, closed="2026-10-19T16:00:00Z", reason="completed"), item(2)],+ )+ monkeypatch.setattr(+ "sys.argv",+ [+ "backlog_status.py",+ "--previous",+ str(previous),+ "--output",+ str(output),+ ],+ )+ with pytest.raises(RuntimeError, match="#3"):+ backlog.main()+ assert not output.exists()+++def test_items_created_during_collection_are_accepted(backlog):+ backlog.require_complete([item(1), item(2), item(3)], 2)