#!/usr/bin/env python3 """ Manual Testing Helper for Markdown Rendering Feature (003-render-ai-analyis) This script creates test feedback with various markdown content to verify: - Markdown rendering (headings, lists, tables, code blocks, links) - XSS protection (script/iframe removal) - Link security attributes - Performance Usage: python test_markdown_manual.py """ import os import sys import uuid import yaml from pathlib import Path def create_test_feedback(product_id, feedback_id, content_text, analysis_markdown): """Create test feedback with markdown analysis. Args: product_id: Product ID (e.g., 'test-product') feedback_id: Unique feedback ID content_text: Feedback content text analysis_markdown: AI analysis in markdown format """ # Create feedback directory feedback_dir = Path(f'data/products/{product_id}/feedback/{feedback_id}') feedback_dir.mkdir(parents=True, exist_ok=True) # Create metadata metadata = { 'feedback_id': feedback_id, 'product_id': product_id, 'status': 'new', 'language': 'en', 'submitted_at': '2025-10-18T06:00:00Z', 'updated_at': '2025-10-18T06:00:00Z', 'content_preview': content_text[:100], 'has_attachments': False, 'attachment_count': 0, 'ai_category': 'Feature Request', 'ai_sentiment': 'Positive' } with open(feedback_dir / 'metadata.yaml', 'w') as f: yaml.dump(metadata, f) # Create content with open(feedback_dir / 'content.txt', 'w') as f: f.write(content_text) # Create analysis with open(feedback_dir / 'analysis.md', 'w') as f: f.write(analysis_markdown) print(f"✅ Created feedback: {feedback_id}") return feedback_id def main(): """Create test feedback samples for manual testing.""" print("=" * 70) print("MARKDOWN RENDERING - MANUAL TEST DATA GENERATOR") print("=" * 70) print() product_id = 'test-product' # Test 1: Rich Markdown Formatting print("Creating Test 1: Rich Markdown Formatting...") feedback_id_1 = str(uuid.uuid4()) analysis_1 = """## Summary The customer feedback is **highly positive** with some *minor concerns*. ### Key Points - Easy to use interface - Great performance improvements - Excellent customer support - Minor UI inconsistencies ### Recommendations 1. Improve documentation for advanced features 2. Add more customization options 3. Fix known bugs in the dashboard 4. Enhance mobile responsiveness ### Technical Details The system uses `Flask` framework with the following code structure: ```python @app.route('/dashboard') def dashboard(): return render_template('dashboard.html') ``` This provides a clean separation of concerns. ### External References See [Flask Documentation](https://flask.palletsprojects.com/) for more information about routing. Also check [Python Best Practices](https://docs.python-guide.org/) for coding standards. ### Data Summary | Metric | Value | Change | |---------------|----------|---------| | Score | 9/10 | +2 | | Sentiment | Positive | Same | | Response Time | 24h | Improved| | Priority | Medium | - | ### Code Example with Inline Code The `markdown_filter` function uses both `markdown2` and `bleach` libraries for safe rendering. """ create_test_feedback( product_id, feedback_id_1, "This product is amazing! Great features and excellent support.", analysis_1 ) # Test 2: XSS Security Testing print("Creating Test 2: XSS Security Testing...") feedback_id_2 = str(uuid.uuid4()) analysis_2 = """## Security Analysis This feedback contains **safe content** that should render properly. ### Attempted XSS Attacks (Should be blocked) Below are various XSS attempts that should be completely removed: **Bold text should still work** after the script tags. ### JavaScript Protocol This is a [dangerous link](javascript:alert('xss')) that should be sanitized. ### Embedded Content ![Image that should be removed](http://evil.com/tracker.png) ### Safe Content - This list should render normally - Even after dangerous content - **Bold** and *italic* should work The analysis engine detected potential security concerns. """ create_test_feedback( product_id, feedback_id_2, "Testing security features of the platform.", analysis_2 ) # Test 3: Complex Tables and Lists print("Creating Test 3: Complex Tables and Lists...") feedback_id_3 = str(uuid.uuid4()) analysis_3 = """## Feature Comparison Matrix ### Pricing Tiers | Feature | Free | Pro | Enterprise | |---------------------|------|------|------------| | Users | 5 | 25 | Unlimited | | Storage | 1GB | 50GB | 1TB | | API Access | ❌ | ✅ | ✅ | | Priority Support | ❌ | ❌ | ✅ | | Custom Domain | ❌ | ✅ | ✅ | ### Nested Lists 1. **Primary Features** - User Management - Role-based access - SSO integration - Dashboard Analytics - Real-time metrics - Custom reports 2. **Secondary Features** - Export functionality - API documentation - Webhook support 3. **Future Roadmap** - Mobile app - Advanced analytics - AI-powered insights ### Mixed List Types - Unordered item 1 - Unordered item 2 1. Ordered sub-item A 2. Ordered sub-item B - Unordered item 3 ### Code Samples Python example: ```python def analyze_feedback(text: str) -> dict: \"\"\"Analyze customer feedback.\"\"\" return { 'sentiment': 'positive', 'category': 'feature_request' } ``` JavaScript example: ```javascript function submitFeedback(data) { fetch('/api/feedback', { method: 'POST', body: JSON.stringify(data) }); } ``` """ create_test_feedback( product_id, feedback_id_3, "Requesting detailed feature comparison and roadmap information.", analysis_3 ) # Test 4: Long Content (Performance Test) print("Creating Test 4: Long Content (Performance Test)...") feedback_id_4 = str(uuid.uuid4()) # Generate long markdown content sections = [] for i in range(30): sections.append(f"""## Section {i + 1} This is section {i + 1} with **bold** and *italic* text for performance testing. ### Subsection {i + 1}.1 - Point A - Point B - Point C ### Subsection {i + 1}.2 1. Step one 2. Step two 3. Step three | Column A | Column B | Column C | |----------|----------|----------| | Value {i} | Data {i} | Info {i} | Code sample: ```python def function_{i}(): return {i} ``` """) analysis_4 = "\n\n".join(sections) create_test_feedback( product_id, feedback_id_4, "Performance testing with large markdown content.", analysis_4 ) print() print("=" * 70) print("✅ TEST DATA CREATED SUCCESSFULLY") print("=" * 70) print() print("Test Feedback IDs:") print(f" 1. Rich Formatting: {feedback_id_1}") print(f" 2. XSS Security: {feedback_id_2}") print(f" 3. Complex Tables: {feedback_id_3}") print(f" 4. Performance: {feedback_id_4}") print() print("Next Steps:") print(" 1. Start the Flask application: python run.py") print(" 2. Login at: http://localhost:5000/login") print(" Username: admin") print(" Password: admin123") print(" 3. View dashboard: http://localhost:5000/dashboard") print(" 4. Click on each feedback to verify markdown rendering") print() print("What to Verify:") print(" ✅ Headings (h2, h3) are rendered as HTML") print(" ✅ Lists (ul, ol) have proper bullets/numbers") print(" ✅ Tables have borders and proper structure") print(" ✅ Code blocks have monospace font and background") print(" ✅ Links open in new tab (target=\"_blank\")") print(" ✅ Links have rel=\"noopener noreferrer nofollow\"") print(" ✅ Script tags are completely removed") print(" ✅ Iframes are completely removed") print(" ✅ Images are removed") print(" ✅ Page loads in < 2 seconds (check browser devtools)") print("=" * 70) if __name__ == '__main__': main()