#!/usr/bin/env python3 """ Test the corrected English articles collection. """ import os import sys # Add the parent directory to Python path current_dir = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, current_dir) def test_english_articles(): """Test the corrected English articles collection.""" print("๐ŸŽฏ Testing Corrected English Articles Collection") print("=" * 60) try: from cve_factchecker.firebase_loader import FirebaseNewsLoader loader = FirebaseNewsLoader() print(f"๐Ÿ“ก Project ID: {loader.project_id}") print(f"๐Ÿ“š English Collection: {loader.config.ENGLISH_ARTICLES_COLLECTION}") # Test fetching English articles print(f"\n๐Ÿ“Š Fetching English articles...") english_articles = loader.fetch_english_articles(limit=10) print(f"โœ… Successfully fetched {len(english_articles)} English articles") if english_articles: print(f"\n๐Ÿ“– Sample articles:") for i, article in enumerate(english_articles[:3], 1): print(f" {i}. {article.title[:80]}...") print(f" ๐Ÿ“ Content: {len(article.content)} chars") if hasattr(article, 'language') and article.language: print(f" ๐ŸŒ Language: {article.language}") if hasattr(article, 'url') and article.url: print(f" ๐Ÿ”— URL: {article.url}") print() # Test larger fetch print(f"๐Ÿ“Š Testing larger fetch (100 articles)...") large_batch = loader.fetch_english_articles(limit=100) print(f"โœ… Large batch: {len(large_batch)} articles") # Test unlimited fetch print(f"๐Ÿ“Š Testing unlimited fetch...") all_articles = loader.fetch_english_articles(limit=None) print(f"โœ… All articles: {len(all_articles)} articles") return len(all_articles) else: print("โŒ No English articles found") return 0 except Exception as e: print(f"โŒ Test failed: {e}") import traceback traceback.print_exc() return 0 def test_integration_with_system(): """Test integration with the rest of the system.""" print(f"\n๐Ÿ”ง Testing System Integration") print("=" * 60) try: from cve_factchecker.orchestrator import FactCheckSystem system = FactCheckSystem() print(f"๐Ÿ“Š Testing English articles ingestion...") result = system.ingest_firebase( collection="english_articles", # Use English collection limit=20, # Small test batch language="English" ) print(f"โœ… Ingestion result: {result}") if result.get("success"): synced_count = result.get("synced", 0) print(f"๐Ÿ“š Articles synced: {synced_count}") # Check if vector database has chunks now try: # Try a test search to see if chunks were stored test_results = system.retriever.semantic_search("test", k=1) chunks_count = len(test_results) print(f"๐Ÿงฉ Searchable chunks: {chunks_count}") if synced_count > 0: print(f"โœ… System integration successful!") return True else: print(f"โš ๏ธ No articles were synced") return False except Exception as e: print(f"โš ๏ธ Could not test vector search: {e}") # Still consider success if articles were synced return synced_count > 0 else: error = result.get("error", "Unknown error") print(f"โŒ Ingestion failed: {error}") return False except Exception as e: print(f"โŒ Integration test failed: {e}") import traceback traceback.print_exc() return False def main(): """Main test function.""" print("๐Ÿงช CVE Fact Checker - English Articles Collection Test") print("=" * 80) # Test English articles collection article_count = test_english_articles() # Test system integration if we have articles if article_count > 0: integration_success = test_integration_with_system() else: integration_success = False print(f"\n๐Ÿ“‹ Test Summary:") print(f" English articles found: {article_count}") print(f" System integration: {'โœ… OK' if integration_success else 'โŒ Failed'}") if article_count > 0 and integration_success: print(f"\n๐ŸŽ‰ Success! English articles collection is working correctly.") print(f"๐Ÿ’ก You can now use the system to fetch English articles from Firebase.") elif article_count > 0: print(f"\nโš ๏ธ Articles found but integration needs work.") else: print(f"\nโŒ No English articles found. Check Firebase collection.") return article_count > 0 if __name__ == "__main__": success = main() sys.exit(0 if success else 1)