This commit is contained in:
@@ -11,7 +11,7 @@ class AIResearchTests(unittest.TestCase):
|
||||
"AI_RESEARCH_PROVIDER", "AI_RESEARCH_PROVIDER_MODEL", "AI_RESEARCH_PROVIDER_URL",
|
||||
"AI_RESEARCH_PROVIDER_ALLOWED_HOSTS", "AI_RESEARCH_PROVIDER_API_KEY", "OPENAI_API_KEY",
|
||||
"NOUS_API_KEY", "NOUS_MODEL", "NOUS_BASE_URL", "NOUS_ALLOWED_HOSTS",
|
||||
"FIRECRAWL_API_KEY", "FIRECRAWL_BASE_URL", "FIRECRAWL_ALLOWED_HOSTS",
|
||||
"FIRECRAWL_API_KEY", "FIRECRAWL_BASE_URL", "FIRECRAWL_ALLOWED_HOSTS", "SEARXNG_BASE_URL", "SEARXNG_ALLOWED_HOSTS",
|
||||
)
|
||||
|
||||
def tearDown(self):
|
||||
@@ -164,6 +164,27 @@ class AIResearchTests(unittest.TestCase):
|
||||
with self.assertRaisesRegex(AIResearchConfigError, "not_configured"):
|
||||
research({"keywords": ["solar"]}, 5)
|
||||
|
||||
def test_self_hosted_searxng_search_and_native_scrape_are_bounded(self):
|
||||
self.configure_nous(); os.environ.pop("FIRECRAWL_API_KEY", None)
|
||||
os.environ.update({"SEARXNG_BASE_URL": "http://searxng:8080", "SEARXNG_ALLOWED_HOSTS": "searxng"})
|
||||
responses = [
|
||||
self.response({"choices": [{"message": {"tool_calls": [{"id": "s", "type": "function", "function": {"name": "web_search", "arguments": '{"query":"solar","limit":1}'}}]}}]}),
|
||||
self.response({"results": [{"title": "Solar", "url": "https://solar.example", "content": "snippet"}]}),
|
||||
self.response({"choices": [{"message": {"tool_calls": [{"id": "p", "type": "function", "function": {"name": "scrape_website", "arguments": '{"url":"https://solar.example"}'}}]}}]}),
|
||||
self.response({"choices": [{"message": {"content": '{"targets":[{"url":"https://solar.example"}]}'}}]}),
|
||||
]
|
||||
scan = {"status": 200, "final_url": "https://solar.example", "title": "Solar", "meta_description": "", "headings": [], "html": "<script>ignore</script><h1>Solar</h1><p>Public page</p>", "error_code": None}
|
||||
with patch("app.ai_research.urlopen", side_effect=responses), patch("app.ai_research.validate_url", side_effect=lambda url, **_: url), patch("app.ai_research.scan_website", return_value=scan) as scanner:
|
||||
self.assertEqual(research({"keywords": ["solar"]}, 3), ["https://solar.example"])
|
||||
scanner.assert_called_once_with("https://solar.example", max_bytes=16 * 1024)
|
||||
self.assertEqual(provider_status()["search_provider"], "searxng")
|
||||
self.assertEqual(provider_status()["scrape_provider"], "native_crawler")
|
||||
self.assertNotIn("nous-secret", json.dumps(provider_status()))
|
||||
|
||||
def test_self_hosted_unsafe_endpoint_fails_closed(self):
|
||||
self.configure_nous(); os.environ.update({"SEARXNG_BASE_URL": "http://127.0.0.1:8080", "SEARXNG_ALLOWED_HOSTS": "searxng"})
|
||||
self.assertEqual(provider_status()["status"], "unsafe_provider")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user