Files
wehub-resource-sync 7a0da7932b
OSV-Scanner (Scheduled) / scan-scheduled (push) Failing after 0s
Create Release / test-gate (push) Has been cancelled
Create Release / release-gate (push) Has been cancelled
Create Release / ci-gate (push) Has been cancelled
Create Release / version-check (push) Has been cancelled
Create Release / e2e-test-gate (push) Has been cancelled
Create Release / responsive-test-gate (push) Has been cancelled
Create Release / compat-test-gate (push) Has been cancelled
Create Release / compose-integration-gate (push) Has been cancelled
Create Release / vulture-gate (push) Has been cancelled
Create Release / build (push) Has been cancelled
Create Release / provenance (push) Has been cancelled
Create Release / prerelease-docker (push) Has been cancelled
Create Release / publish-docker (push) Has been cancelled
Create Release / create-release (push) Has been cancelled
Create Release / cleanup-changelog (push) Has been cancelled
Create Release / trigger-pypi (push) Has been cancelled
Create Release / monitor-pypi (push) Has been cancelled
Create Release / Clean up orphan prerelease tags and signatures (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-form] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-metrics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-workflow] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-core] (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [history-news] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [library] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [link-analytics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-core] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-lifecycle] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [error-benchmark] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) (push) Has been cancelled
Docker Tests (Consolidated) / Accessibility Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Unit Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Example Tests (push) Has been cancelled
Docker Tests (Consolidated) / Production Image Smoke Test (push) Has been cancelled
Docker Tests (Consolidated) / Infrastructure Tests (push) Has been cancelled
OSSF Scorecard / OSSF Security Scorecard Analysis (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [mobile] (push) Has been cancelled
Backwards Compatibility / Verify Encryption Constants (push) Has been cancelled
Backwards Compatibility / PyPI Version Compatibility (push) Has been cancelled
Backwards Compatibility / Database Migration Tests (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Docker Tests (Consolidated) / detect-changes (push) Has been cancelled
Docker Tests (Consolidated) / Build Test Image (push) Has been cancelled
Docker Tests (Consolidated) / All Pytest Tests + Coverage (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [accessibility] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [api-crud] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-login] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-register] (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:08:55 +08:00

117 lines
3.7 KiB
Python

"""
Tests for LLM-specific rate limit detection.
Tests cover:
- Rate limit error detection from HTTP 429
- Rate limit error detection from message patterns
- Retry-after extraction from headers and messages
"""
from unittest.mock import Mock
class TestLLMRateLimitDetection:
"""Tests for LLM rate limit error detection."""
def test_is_llm_rate_limit_error_http_429(self):
"""Detect rate limit from HTTP 429 status code."""
from local_deep_research.web_search_engines.rate_limiting.llm.detection import (
is_llm_rate_limit_error,
)
# Create mock error with 429 response
error = Mock()
error.response = Mock()
error.response.status_code = 429
error.__str__ = lambda self: "HTTP 429 Too Many Requests"
error.__class__.__name__ = "HTTPError"
error.__class__.__module__ = "requests"
result = is_llm_rate_limit_error(error)
assert result is True
def test_is_llm_rate_limit_error_message_patterns(self):
"""Detect rate limit from error message patterns."""
from local_deep_research.web_search_engines.rate_limiting.llm.detection import (
is_llm_rate_limit_error,
)
# Test various rate limit message patterns
patterns = [
"Rate limit exceeded",
"rate_limit_error",
"Too many requests",
"Quota exceeded",
"Resource has been exhausted",
"Please try again later",
"429 error occurred",
]
for pattern in patterns:
error = Exception(pattern)
result = is_llm_rate_limit_error(error)
assert result is True, f"Failed to detect pattern: {pattern}"
def test_is_llm_rate_limit_error_not_rate_limit(self):
"""Non-rate-limit errors should return False."""
from local_deep_research.web_search_engines.rate_limiting.llm.detection import (
is_llm_rate_limit_error,
)
# Regular errors
error = Exception("Connection timeout")
assert is_llm_rate_limit_error(error) is False
error = Exception("Invalid API key")
assert is_llm_rate_limit_error(error) is False
error = Exception("Server error 500")
assert is_llm_rate_limit_error(error) is False
def test_extract_retry_after_header(self):
"""Extract retry time from Retry-After header."""
from local_deep_research.web_search_engines.rate_limiting.llm.detection import (
extract_retry_after,
)
# Create mock error with Retry-After header
error = Mock()
error.response = Mock()
error.response.headers = {"Retry-After": "30"}
error.__str__ = lambda self: "Rate limit error"
result = extract_retry_after(error)
assert result == 30.0
def test_extract_retry_after_message(self):
"""Extract retry time from error message."""
from local_deep_research.web_search_engines.rate_limiting.llm.detection import (
extract_retry_after,
)
# Error with retry time in message
error = Exception("Rate limited. Please try again in 45 seconds")
result = extract_retry_after(error)
assert result == 45.0
# Another pattern
error = Exception("Wait 60 seconds before retrying")
result = extract_retry_after(error)
assert result == 60.0
def test_extract_retry_after_not_found(self):
"""Return 0 when no retry time is specified."""
from local_deep_research.web_search_engines.rate_limiting.llm.detection import (
extract_retry_after,
)
error = Exception("Rate limit exceeded")
result = extract_retry_after(error)
assert result == 0