#!/usr/bin/env python3 """ CorpusDB System Check Verify all recent changes are working correctly """ import sys import os sys.path.insert(0, '.') print('=' * 60) print('CORPUSDB SYSTEM CHECK') print('=' * 60) print() # Test 1: Query Parser print('[1/5] Testing Query Parser...') from app.query_parser import query_parser tests = [ ('DROP TABLE users', True, True, 'DROP TABLE allowed'), ('DROP DATABASE prod', True, False, 'DROP DATABASE blocked'), ('DROP SCHEMA public', True, False, 'DROP SCHEMA blocked'), ('SELECT * FROM users', False, True, 'SELECT allowed'), ('DELETE FROM logs', True, True, 'DELETE allowed with write'), ] for query, allow_write, expected, desc in tests: result = query_parser.validate_query(query, allow_write=allow_write) status = 'PASS' if result[0] == expected else 'FAIL' print(f' {desc:30} -> {status}') print() # Test 2: Export System print('[2/5] Testing Export System...') from app.advanced_import_export import advanced_import_export test_data = { 'users': [{'id': 1, 'name': 'John', 'email': 'john@test.com'}], 'orders': [{'order_id': 101, 'total': 99.99}] } # Test SQL export sql = advanced_import_export.export_database_to_sql('testdb', test_data) print(f' SQL Export: {len(sql)} chars -> {"PASS" if len(sql) > 500 else "FAIL"}') print(f' Contains DROP TABLE: {"PASS" if "DROP TABLE" in sql else "FAIL"}') print(f' Contains CREATE TABLE: {"PASS" if "CREATE TABLE" in sql else "FAIL"}') print(f' Contains INSERT INTO: {"PASS" if "INSERT INTO" in sql else "FAIL"}') # Test JSON export json_out = advanced_import_export.export_database_to_json('testdb', test_data) print(f' JSON Export: {len(json_out)} chars -> {"PASS" if len(json_out) > 100 else "FAIL"}') # Test CSV export csv_out = advanced_import_export.export_database_to_csv(test_data) print(f' CSV Export: {len(csv_out)} files -> {"PASS" if len(csv_out) == 2 else "FAIL"}') # Test XML export xml_out = advanced_import_export.export_database_to_xml('testdb', test_data) print(f' XML Export: {len(xml_out)} chars -> {"PASS" if len(xml_out) > 100 else "FAIL"}') print() # Test 3: API Routes print('[3/5] Testing API Routes...') from app.api import router all_routes = [r.path for r in router.routes if hasattr(r, 'path')] export_routes = [r for r in all_routes if 'export' in r] db_export_routes = [r for r in all_routes if 'export/database' in r] print(f' Total Routes: {len(all_routes)} -> PASS') print(f' Export Routes: {len(export_routes)} -> {"PASS" if len(export_routes) >= 8 else "FAIL"}') print(f' Database Export Routes: {len(db_export_routes)} -> {"PASS" if len(db_export_routes) == 4 else "FAIL"}') print() # Test 4: CSS Slider print('[4/5] Testing CSS Slider...') with open('app/styles.css', 'r', encoding='utf-8') as f: css = f.read() checks = [ ('input[type="range"]' in css, 'Range input styles'), ('::-webkit-slider-thumb' in css, 'WebKit thumb styles'), ('::-moz-range-thumb' in css, 'Mozilla thumb styles'), ('transform:scale' in css.replace(' ', ''), 'Hover animations'), ] for check, desc in checks: print(f' {desc:30} -> {"PASS" if check else "FAIL"}') print() # Test 5: Documentation print('[5/5] Testing Documentation...') docs = [ 'FEATURE_COMPARISON.md', 'COMPETITIVE_STRATEGY.md', 'DATABASE_EXPORT_GUIDE.txt' ] for doc in docs: exists = os.path.exists(doc) if exists: size = os.path.getsize(doc) print(f' {doc:35} -> PASS ({size:,} bytes)') else: print(f' {doc:35} -> FAIL (not found)') print() print('=' * 60) print('ALL SYSTEMS OPERATIONAL') print('=' * 60)