Skip to content

AI agent skill that researches any topic across Reddit, X, YouTube, HN, Polymarket, and the web - then synthesizes a grounded summary

Merge origin/main into PR 603

Trevin Chowe65914a9c122
diff --cc skills/last30days/scripts/lib/hackernews.py
index 8c826529,a35ef43b..97164fd9
--- a/skills/last30days/scripts/lib/hackernews.py
+++ b/skills/last30days/scripts/lib/hackernews.py
@@@ -97,8 -93,12 +97,12 @@@ def search_hackernews
core_flat = _flatten_query_for_algolia(core)
_log(f"Searching for '{core_flat}' (raw: '{topic}', since {from_date}, count={count})")
- # Use relevance-sorted search with date filters. Algolia's HN index rejects
- # engagement fields in numericFilters, so points are filtered client-side.
+ # Use relevance-sorted search. The HN Algolia index only allows
+ # `created_at_i` in numericFilters; `points` is NOT in its
+ # `numericAttributesForFiltering`, so a `points>N` clause makes the API
+ # return HTTP 400 ("invalid numeric attribute(points)") and zero stories.
- # Low-engagement stories are demoted by parse-time relevance scoring
- # (rank + engagement_boost in parse_hackernews_response) instead.
++ # Low-engagement stories are filtered client-side after overfetching so the
++ # invalid numeric filter is not reintroduced.
# NOTE: restrictSearchableAttributes=title omitted intentionally — it would
# miss Ask HN/Show HN threads where the topic appears in the body.
params = {
diff --cc tests/test_hackernews.py
index 26f70cd8,bdc324ad..8ab57ba6
--- a/tests/test_hackernews.py
+++ b/tests/test_hackernews.py
@@@ -270,42 -266,27 +270,62 @@@ def test_search_hackernews_http_error_h
@patch('lib.hackernews.http.request')
+def test_search_hackernews_engagement_filter(mock_request):
+ """Test that low-engagement stories are filtered client-side."""
+ mock_request.return_value = {
+ "hits": [
+ create_mock_hit(object_id="low", points=2),
+ create_mock_hit(object_id="high", points=3),
+ ],
+ "nbHits": 2,
+ }
+
+ result = hackernews.search_hackernews("test", "2026-01-01", "2026-01-31")
+
+ call_args = mock_request.call_args[0]
+ url = call_args[1]
+
+ # Algolia rejects points in numericFilters; keep only supported date filters.
+ assert "points" not in url
+ assert [hit["objectID"] for hit in result["hits"]] == ["high"]
+
+
++@patch('lib.hackernews.http.request')
+ def test_search_hackernews_no_points_numericfilter(mock_request):
+ """numericFilters must NOT include a `points` clause.
+
+ `points` is not in the HN Algolia index's `numericAttributesForFiltering`,
+ so a `points>2` clause returns HTTP 400 ("invalid numeric attribute(points)")
- and zero stories. Engagement is reflected in parse-time relevance scoring
++ and zero stories. Engagement is filtered client-side after overfetching
+ instead. This guards against the invalid filter being reintroduced.
-
- (Previously this test asserted `points` + `%3E2` were present in the URL,
- pinning the very bug that broke every HN query — a bug-encoding test.)
+ """
+ mock_request.return_value = {"hits": [], "nbHits": 0}
+
+ hackernews.search_hackernews("test", "2026-01-01", "2026-01-31")
+
+ url = mock_request.call_args[0][1]
+
+ # Date filter stays; the invalid points filter must be gone.
+ assert "created_at_i" in url
+ assert "points" not in url
+
++
+@patch('lib.hackernews.http.request')
+def test_search_hackernews_truncates_after_overfetch(mock_request):
+ """Test that overfetching does not return more than the requested depth."""
+ mock_request.return_value = {
+ "hits": [
+ create_mock_hit(object_id=str(i), points=10)
+ for i in range(20)
+ ],
+ "nbHits": 20,
+ }
+
+ result = hackernews.search_hackernews("test", "2026-01-01", "2026-01-31", depth="quick")
+
+ assert len(result["hits"]) == 15
+ assert [hit["objectID"] for hit in result["hits"]] == [str(i) for i in range(15)]
+
# === Tests for parse_hackernews_response() ===