|
#!/bin/bash |
|
|
|
|
|
cat > /home/ubuntu/cursor-rules-generator/.env << EOL |
|
# App settings |
|
DEBUG=True |
|
PORT=5000 |
|
|
|
# API keys (these are placeholders, real keys should be provided by users) |
|
GEMINI_API_KEY= |
|
OPENAI_API_KEY= |
|
OPENROUTER_API_KEY= |
|
EOL |
|
|
|
|
|
cat > /home/ubuntu/cursor-rules-generator/test_backend.py << EOL |
|
""" |
|
Test script for Cursor Rules Generator backend functionality. |
|
""" |
|
|
|
import os |
|
import sys |
|
import json |
|
from backend.llm.factory import LLMAdapterFactory |
|
from backend.engine.rule_generator import RuleGenerator |
|
from backend.config.settings import Settings |
|
|
|
def test_factory(): |
|
"""Test the LLM adapter factory.""" |
|
print("Testing LLM adapter factory...") |
|
|
|
factory = LLMAdapterFactory() |
|
|
|
# Test getting supported providers |
|
providers = factory.get_supported_providers() |
|
print(f"Supported providers: {providers}") |
|
|
|
# Test creating adapters |
|
for provider_name in providers.keys(): |
|
try: |
|
adapter = factory.create_adapter(provider_name) |
|
print(f"Successfully created adapter for {provider_name}") |
|
except Exception as e: |
|
print(f"Failed to create adapter for {provider_name}: {e}") |
|
|
|
print("LLM adapter factory test completed.") |
|
print("-" * 50) |
|
|
|
def test_rule_generator(): |
|
"""Test the rule generator.""" |
|
print("Testing rule generator...") |
|
|
|
rule_generator = RuleGenerator() |
|
|
|
# Test getting rule types |
|
rule_types = rule_generator.get_rule_types() |
|
print(f"Supported rule types: {[rt['id'] for rt in rule_types]}") |
|
|
|
# Test creating a basic rule without LLM |
|
try: |
|
rule = rule_generator._create_basic_rule( |
|
rule_type="Always", |
|
description="Test rule", |
|
content="This is a test rule content.", |
|
parameters={ |
|
"globs": "", |
|
"referenced_files": "@test-file.ts" |
|
} |
|
) |
|
print("Successfully created a basic rule:") |
|
print(rule) |
|
except Exception as e: |
|
print(f"Failed to create a basic rule: {e}") |
|
|
|
print("Rule generator test completed.") |
|
print("-" * 50) |
|
|
|
def main(): |
|
"""Run all tests.""" |
|
print("Starting backend functionality tests...") |
|
print("=" * 50) |
|
|
|
test_factory() |
|
test_rule_generator() |
|
|
|
print("=" * 50) |
|
print("All tests completed.") |
|
|
|
if __name__ == "__main__": |
|
main() |
|
EOL |
|
|
|
|
|
cat > /home/ubuntu/cursor-rules-generator/test_frontend.py << EOL |
|
""" |
|
Test script for Cursor Rules Generator frontend functionality. |
|
""" |
|
|
|
import os |
|
import sys |
|
import http.server |
|
import socketserver |
|
import threading |
|
import webbrowser |
|
import time |
|
|
|
def start_server(): |
|
"""Start a simple HTTP server to serve the frontend files.""" |
|
os.chdir("frontend") |
|
|
|
PORT = 8000 |
|
Handler = http.server.SimpleHTTPRequestHandler |
|
|
|
with socketserver.TCPServer(("", PORT), Handler) as httpd: |
|
print(f"Serving frontend at http://localhost:{PORT}") |
|
httpd.serve_forever() |
|
|
|
def main(): |
|
"""Run frontend tests.""" |
|
print("Starting frontend functionality tests...") |
|
print("=" * 50) |
|
|
|
# Check if frontend files exist |
|
if not os.path.exists("frontend/index.html"): |
|
print("Error: frontend/index.html not found.") |
|
return |
|
|
|
if not os.path.exists("frontend/css/styles.css"): |
|
print("Error: frontend/css/styles.css not found.") |
|
return |
|
|
|
if not os.path.exists("frontend/js/script.js"): |
|
print("Error: frontend/js/script.js not found.") |
|
return |
|
|
|
print("Frontend files found.") |
|
|
|
# Start the server in a separate thread |
|
server_thread = threading.Thread(target=start_server) |
|
server_thread.daemon = True |
|
server_thread.start() |
|
|
|
# Wait for the server to start |
|
time.sleep(1) |
|
|
|
# Open the browser |
|
print("Opening browser to test frontend...") |
|
webbrowser.open("http://localhost:8000") |
|
|
|
print("Frontend server started. Press Ctrl+C to stop.") |
|
|
|
try: |
|
while True: |
|
time.sleep(1) |
|
except KeyboardInterrupt: |
|
print("Server stopped.") |
|
|
|
print("=" * 50) |
|
print("Frontend test completed.") |
|
|
|
if __name__ == "__main__": |
|
main() |
|
EOL |
|
|
|
|
|
cat > /home/ubuntu/cursor-rules-generator/test_huggingface.py << EOL |
|
""" |
|
Test script for Cursor Rules Generator Hugging Face deployment. |
|
""" |
|
|
|
import os |
|
import sys |
|
import importlib.util |
|
|
|
def test_gradio_app(): |
|
"""Test the Gradio app for Hugging Face deployment.""" |
|
print("Testing Gradio app for Hugging Face deployment...") |
|
|
|
# Check if the app.py file exists |
|
if not os.path.exists("huggingface/app.py"): |
|
print("Error: huggingface/app.py not found.") |
|
return |
|
|
|
# Check if requirements.txt exists |
|
if not os.path.exists("huggingface/requirements.txt"): |
|
print("Error: huggingface/requirements.txt not found.") |
|
return |
|
|
|
# Check if README.md exists |
|
if not os.path.exists("huggingface/README.md"): |
|
print("Error: huggingface/README.md not found.") |
|
return |
|
|
|
# Check if DEPLOYMENT.md exists |
|
if not os.path.exists("huggingface/DEPLOYMENT.md"): |
|
print("Error: huggingface/DEPLOYMENT.md not found.") |
|
return |
|
|
|
print("All required files for Hugging Face deployment found.") |
|
|
|
# Try to import gradio to check if it's installed |
|
try: |
|
import gradio |
|
print("Gradio is installed.") |
|
except ImportError: |
|
print("Warning: Gradio is not installed. Cannot fully test the app.") |
|
print("To install Gradio, run: pip install gradio") |
|
return |
|
|
|
# Try to load the app module to check for syntax errors |
|
try: |
|
spec = importlib.util.spec_from_file_location("app", "huggingface/app.py") |
|
app_module = importlib.util.module_from_spec(spec) |
|
|
|
# We don't actually execute the module to avoid launching the app |
|
# spec.loader.exec_module(app_module) |
|
|
|
print("Hugging Face app module loaded successfully (syntax check passed).") |
|
except Exception as e: |
|
print(f"Error loading Hugging Face app module: {e}") |
|
|
|
print("Hugging Face deployment test completed.") |
|
print("-" * 50) |
|
|
|
def main(): |
|
"""Run all tests.""" |
|
print("Starting Hugging Face deployment tests...") |
|
print("=" * 50) |
|
|
|
test_gradio_app() |
|
|
|
print("=" * 50) |
|
print("All tests completed.") |
|
|
|
if __name__ == "__main__": |
|
main() |
|
EOL |
|
|
|
|
|
cat > /home/ubuntu/cursor-rules-generator/run_tests.py << EOL |
|
""" |
|
Main test script for Cursor Rules Generator. |
|
""" |
|
|
|
import os |
|
import sys |
|
import subprocess |
|
|
|
def run_test(test_script, description): |
|
"""Run a test script and print the result.""" |
|
print(f"Running {description}...") |
|
print("=" * 50) |
|
|
|
result = subprocess.run([sys.executable, test_script], capture_output=True, text=True) |
|
|
|
print(result.stdout) |
|
|
|
if result.returncode != 0: |
|
print(f"Error running {description}:") |
|
print(result.stderr) |
|
else: |
|
print(f"{description} completed successfully.") |
|
|
|
print("=" * 50) |
|
print() |
|
|
|
def main(): |
|
"""Run all tests.""" |
|
print("Starting Cursor Rules Generator tests...") |
|
print() |
|
|
|
# Test backend functionality |
|
run_test("test_backend.py", "backend functionality tests") |
|
|
|
# Test Hugging Face deployment |
|
run_test("test_huggingface.py", "Hugging Face deployment tests") |
|
|
|
# Note: We don't automatically run the frontend test as it opens a browser |
|
print("To test the frontend, run: python test_frontend.py") |
|
|
|
print("All tests completed.") |
|
|
|
if __name__ == "__main__": |
|
main() |
|
EOL |
|
|
|
echo "Test scripts created successfully." |
|
|