Skip to content

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

test: cover parallel grounding backend

Dinakar Sarbadaf458e0f5af51
diff --git a/tests/test_grounding_v3.py b/tests/test_grounding_v3.py
index 30d663b6..e881506d 100644
--- a/tests/test_grounding_v3.py
+++ b/tests/test_grounding_v3.py
@@ -122,6 +122,48 @@ class ExaSearchTests(unittest.TestCase):
self.assertEqual(0, artifact["resultCount"])
+class ParallelSearchTests(unittest.TestCase):
+ def test_parallel_search_filters_to_in_range_dated_items(self):
+ mock_response = {
+ "results": [
+ {
+ "title": "Parallel Result",
+ "url": "https://example.com/parallel",
+ "snippet": "A parallel snippet",
+ "published_date": "2026-03-15T00:00:00Z",
+ },
+ {
+ "title": "Old Parallel Result",
+ "url": "https://example.com/old-parallel",
+ "snippet": "Should be filtered",
+ "published_date": "2025-12-01T00:00:00Z",
+ },
+ {
+ "title": "Undated Parallel Result",
+ "url": "https://example.com/undated-parallel",
+ "snippet": "Should also be filtered",
+ },
+ ]
+ }
+ with patch("lib.grounding.http.request", return_value=mock_response) as mock_req:
+ items, artifact = grounding.parallel_search(
+ "test", ("2026-02-25", "2026-03-27"), "fake-parallel-key"
+ )
+ self.assertEqual(1, len(items))
+ self.assertEqual("Parallel Result", items[0]["title"])
+ self.assertEqual("https://example.com/parallel", items[0]["url"])
+ self.assertEqual("2026-03-15", items[0]["date"])
+ self.assertTrue(items[0]["id"].startswith("WP"))
+ self.assertEqual("parallel", artifact["label"])
+ self.assertEqual(1, artifact["resultCount"])
+ self.assertEqual("POST", mock_req.call_args.args[0])
+ self.assertEqual("https://api.parallel.ai/v1/search", mock_req.call_args.args[1])
+ self.assertEqual(
+ "Bearer fake-parallel-key",
+ mock_req.call_args.kwargs["headers"]["Authorization"],
+ )
+
+
class WebSearchDispatchTests(unittest.TestCase):
def test_auto_selects_brave_when_key_present(self):
config = {"BRAVE_API_KEY": "test-key"}
@@ -141,6 +183,12 @@ class WebSearchDispatchTests(unittest.TestCase):
grounding.web_search("test", ("2026-02-25", "2026-03-27"), config, backend="auto")
mock.assert_called_once()
+ def test_auto_selects_parallel_when_only_parallel_key(self):
+ config = {"PARALLEL_API_KEY": "test-key"}
+ with patch("lib.grounding.parallel_search", return_value=([], {})) as mock:
+ grounding.web_search("test", ("2026-02-25", "2026-03-27"), config, backend="auto")
+ mock.assert_called_once()
+
def test_auto_returns_empty_when_no_keys(self):
items, artifact = grounding.web_search("test", ("2026-02-25", "2026-03-27"), {}, backend="auto")
self.assertEqual([], items)
@@ -185,6 +233,10 @@ class WebSearchDispatchTests(unittest.TestCase):
with self.assertRaises(RuntimeError):
grounding.web_search("test", ("2026-02-25", "2026-03-27"), {}, backend="brave")
+ def test_explicit_parallel_without_key_raises(self):
+ with self.assertRaises(RuntimeError):
+ grounding.web_search("test", ("2026-02-25", "2026-03-27"), {}, backend="parallel")
+
def test_unsupported_backend_raises(self):
with self.assertRaises(ValueError):
grounding.web_search("test", ("2026-02-25", "2026-03-27"), {}, backend="google")