#!/usr/bin/env python3 """ Test Final Web Fix - End to End Test the complete web analysis workflow: 1. URL detection and cleaning 2. Logical continuation (fetch content directly) 3. Intelligent web content summaries """ import sys from pathlib import Path # Add project root to path project_root = Path(__file__).parent sys.path.insert(0, str(project_root)) def test_complete_web_workflow(): """Test the complete web analysis workflow""" print("๐ŸŒ TESTING COMPLETE WEB WORKFLOW") print("=" * 40) try: from atles_desktop_pyqt import ATLESCommunicationThread comm_thread = ATLESCommunicationThread() # Test 1: URL Detection and Function Call Generation print("1๏ธโƒฃ Testing URL detection and function call generation...") user_message = "https://huggingface.co/papers/2508.10874 can you read this and sum it up" # Extract URLs (simulate the URL detection) import re url_pattern = r'https?://[^\s<>"{}|\\^`\[\]]+' urls = re.findall(url_pattern, user_message) print(f" Detected URLs: {urls}") if urls: print(" โœ… URL detection works") else: print(" โŒ URL detection failed") return False # Test 2: URL Cleaning print("\n2๏ธโƒฃ Testing URL cleaning...") problematic_url = "https://huggingface.co/papers/2508.10874'" clean_url = problematic_url.strip("'\"") print(f" Original: {problematic_url}") print(f" Cleaned: {clean_url}") if not clean_url.endswith("'") and not clean_url.endswith('"'): print(" โœ… URL cleaning works") else: print(" โŒ URL cleaning failed") return False # Test 3: Logical Continuation Response Generation print("\n3๏ธโƒฃ Testing logical continuation response...") response = comm_thread._create_url_aware_response( user_message, "Let me analyze this content", urls, False # has_fake_commands ) print(" Generated response preview:") print(" " + "-" * 50) print(" " + response[:200] + "...") print(" " + "-" * 50) # Check for logical continuation if "FUNCTION_CALL:fetch_url_content" in response: print(" โœ… Uses fetch_url_content (logical continuation)") elif "FUNCTION_CALL:check_url_accessibility" in response: print(" โš ๏ธ Still using check_url_accessibility (partial fix)") else: print(" โŒ No function call detected") return False # Test 4: Intelligent Web Content Processing print("\n4๏ธโƒฃ Testing intelligent web content processing...") # Simulate successful web content fetch result function_result = '''Function fetch_url_content executed successfully: { "success": true, "url": "https://huggingface.co/papers/2508.10874", "content": "Advanced Multimodal Reasoning with Vision-Language Models

Advanced Multimodal Reasoning

Abstract: This paper presents novel approaches to multimodal AI systems that can process and reason about both visual and textual information. We introduce new benchmark datasets and evaluation metrics for vision-language models.

Our research focuses on improving cross-modal understanding and generation capabilities through innovative training techniques and architectural improvements.

Authors: Research Team
Published: 2024
", "content_type": "text/html", "content_length": 650, "message": "Successfully fetched content from https://huggingface.co/papers/2508.10874" }''' intelligent_response = comm_thread._process_function_result( function_result, user_message, response ) print(" Intelligent response preview:") print(" " + "-" * 50) print(" " + intelligent_response[:300] + "...") print(" " + "-" * 50) # Check intelligent processing elements checks = [ ("Web Content Analysis Complete" in intelligent_response, "Analysis header"), ("Hugging Face Paper Analysis" in intelligent_response, "HF-specific analysis"), ("Advanced Multimodal Reasoning" in intelligent_response, "Title extraction"), ("Abstract" in intelligent_response or "multimodal" in intelligent_response, "Content analysis"), ("Ask me anything" in intelligent_response, "Follow-up invitation"), ('"success": true' not in intelligent_response, "Raw JSON hidden") ] passed_checks = 0 for check, description in checks: if check: print(f" โœ… {description}") passed_checks += 1 else: print(f" โŒ Missing {description}") if passed_checks >= 4: print(" โœ… Intelligent processing works") else: print(" โŒ Intelligent processing needs work") return False return True except Exception as e: print(f"โŒ Test failed: {e}") import traceback traceback.print_exc() return False def main(): """Main test runner""" print("๐ŸŽฏ FINAL WEB FIX TEST") print("=" * 50) print(""" TESTING COMPLETE WEB ANALYSIS WORKFLOW: This tests the end-to-end process from URL detection to intelligent content analysis. """) success = test_complete_web_workflow() # Summary print(f"\n๐Ÿ“Š FINAL TEST RESULT") print("=" * 50) if success: print(f"๐ŸŽ‰ COMPLETE WEB ANALYSIS FIX SUCCESSFUL!") print("โœ… URL detection and cleaning works") print("โœ… Function calls generated properly") print("โœ… Intelligent content analysis works") print("โœ… Hugging Face paper-specific summaries") print("โœ… Raw JSON hidden from users") print(f"\n๐Ÿ’ก ATLES NOW PROVIDES:") print("๐Ÿ”— Automatic URL detection") print("๐Ÿงน Clean JSON function calls (no syntax errors)") print("๐Ÿ”„ Logical continuation (fetches content directly)") print("๐Ÿง  Intelligent summaries (not raw HTML)") print("๐Ÿ“„ Paper-specific analysis for research content") print("๐Ÿ’ฌ User-friendly responses with follow-up invitations") print(f"\n๐Ÿš€ READY FOR TESTING!") print("Try asking ATLES: 'https://huggingface.co/papers/2508.10874 can you read this and sum it up'") print("You should get an intelligent summary, not raw JSON or HTML!") else: print(f"โš ๏ธ Web analysis still needs work") print("Check the test output above for specific issues") return success if __name__ == "__main__": try: success = main() if success: print(f"\nโœจ All web analysis fixes are working!") else: print(f"\nโš ๏ธ Some issues remain.") except KeyboardInterrupt: print(f"\nโน๏ธ Test interrupted") except Exception as e: print(f"\n๐Ÿ’ฅ Test error: {e}") import traceback traceback.print_exc()