0a9ff16dfc
v3 rewrites the search engine from the ground up: - Intelligent pre-research: resolves X handles, GitHub repos, subreddits, TikTok hashtags, and YouTube channels before searching - GitHub person-mode: PR velocity, top repos by stars, release notes - GitHub project-mode: live star counts, README, releases, top issues - ELI5 mode: plain language synthesis, no jargon - 13+ sources: Reddit, X, YouTube, TikTok, Instagram, HN, Polymarket, GitHub, Threads, Pinterest, Perplexity, Bluesky, Web - Free Reddit comments via public JSON (no API key needed) - Fun judge v2: humor scoring baked into narrative - Cookie consent before browser scanning - 10,000 free ScrapeCreators calls - 1,012 tests Thank you to the community contributors whose issues and PRs shaped v3: @uppinote20 (#143), @zerone0x (#134, #136), @thinkun (#116), @thomasmktong (#124), @fanispoulinakisai-boop (#100), @pejmanjohn (#78), @zl190 (#115), @hnshah (#84, #85, #86) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
44 lines
1.6 KiB
Python
44 lines
1.6 KiB
Python
import sys
|
|
import urllib.error
|
|
import unittest
|
|
from pathlib import Path
|
|
from unittest.mock import patch, MagicMock
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "scripts"))
|
|
|
|
from lib import http
|
|
|
|
|
|
class Test429RetryLimit(unittest.TestCase):
|
|
"""429 retries must be capped at max_429_retries to avoid wasting latency."""
|
|
|
|
@patch("lib.http.urllib.request.urlopen")
|
|
@patch("lib.http.time.sleep") # Don't actually sleep in tests
|
|
def test_429_retries_limited_to_2_by_default(self, mock_sleep, mock_urlopen):
|
|
"""With default max_429_retries=2, should attempt 2 times then raise."""
|
|
error = urllib.error.HTTPError(
|
|
"http://example.com", 429, "Too Many Requests", {}, None
|
|
)
|
|
mock_urlopen.side_effect = error
|
|
|
|
with self.assertRaises(http.HTTPError) as ctx:
|
|
http.request("GET", "http://example.com", retries=5)
|
|
|
|
self.assertEqual(ctx.exception.status_code, 429)
|
|
# Should be called exactly 2 times (initial + 1 retry), not 5
|
|
self.assertEqual(mock_urlopen.call_count, 2)
|
|
|
|
@patch("lib.http.urllib.request.urlopen")
|
|
@patch("lib.http.time.sleep")
|
|
def test_non_429_errors_still_use_full_retries(self, mock_sleep, mock_urlopen):
|
|
"""500 errors should still retry up to the full retries count."""
|
|
error = urllib.error.HTTPError(
|
|
"http://example.com", 500, "Internal Server Error", {}, None
|
|
)
|
|
mock_urlopen.side_effect = error
|
|
|
|
with self.assertRaises(http.HTTPError):
|
|
http.request("GET", "http://example.com", retries=3)
|
|
|
|
self.assertEqual(mock_urlopen.call_count, 3)
|