Spiritual_Health_Project / scripts /cleanup_test_data.py
DocUA's picture
feat: Complete prompt optimization system implementation
24214fc
#!/usr/bin/env python3
"""
Cleanup script to remove test data from prompt management system.
This script removes any test indicators, templates, or rules that may have been
added during testing and restores the system to clean production state.
"""
import sys
import json
from pathlib import Path
def cleanup_indicators():
"""Remove test indicators from indicators.json."""
indicators_file = Path("src/config/prompt_management/data/indicators.json")
if not indicators_file.exists():
print("❌ indicators.json not found")
return False
try:
with open(indicators_file, 'r', encoding='utf-8') as f:
data = json.load(f)
original_count = len(data.get('indicators', []))
# Remove test indicators
clean_indicators = []
for indicator in data.get('indicators', []):
if isinstance(indicator, dict):
name = indicator.get('name', '')
# Skip test indicators
if not any(test_pattern in name for test_pattern in [
'load_test_indicator',
'test_indicator',
'example_indicator'
]):
clean_indicators.append(indicator)
data['indicators'] = clean_indicators
with open(indicators_file, 'w', encoding='utf-8') as f:
json.dump(data, f, indent=2, ensure_ascii=False)
removed_count = original_count - len(clean_indicators)
print(f"βœ… Cleaned indicators: removed {removed_count} test indicators, kept {len(clean_indicators)} real ones")
return True
except Exception as e:
print(f"❌ Error cleaning indicators: {e}")
return False
def cleanup_templates():
"""Remove test templates from templates.json."""
templates_file = Path("src/config/prompt_management/data/templates.json")
if not templates_file.exists():
print("❌ templates.json not found")
return False
try:
with open(templates_file, 'r', encoding='utf-8') as f:
data = json.load(f)
original_count = len(data.get('templates', []))
# Remove invalid/test templates
clean_templates = []
for template in data.get('templates', []):
if isinstance(template, dict):
template_id = template.get('template_id', '')
name = template.get('name', '')
content = template.get('content', '')
# Skip test/invalid templates
if (template_id and name and content and
not any(test_pattern in template_id.lower() for test_pattern in [
'test', '000', 'example'
]) and
not any(invalid_char in template_id for invalid_char in [
'ⳇ', 'Δ›', 's', 'Ś', 'Γ«', 'Ę', 'Δ—', 'Δ„', 'Ε‚', 'Δ³', 'Ε€'
]) and
len(content) > 10 and content != "0000000000"):
clean_templates.append(template)
data['templates'] = clean_templates
with open(templates_file, 'w', encoding='utf-8') as f:
json.dump(data, f, indent=2, ensure_ascii=False)
removed_count = original_count - len(clean_templates)
print(f"βœ… Cleaned templates: removed {removed_count} invalid templates, kept {len(clean_templates)} valid ones")
return True
except Exception as e:
print(f"❌ Error cleaning templates: {e}")
return False
def cleanup_rules():
"""Remove test rules from rules.json."""
rules_file = Path("src/config/prompt_management/data/rules.json")
if not rules_file.exists():
print("❌ rules.json not found")
return False
try:
with open(rules_file, 'r', encoding='utf-8') as f:
data = json.load(f)
original_count = len(data.get('rules', []))
# Remove test rules
clean_rules = []
for rule in data.get('rules', []):
if isinstance(rule, dict):
rule_id = rule.get('rule_id', '')
description = rule.get('description', '')
# Skip test rules
if (rule_id and description and
not any(test_pattern in rule_id.lower() for test_pattern in [
'test', 'example', 'load_test'
])):
clean_rules.append(rule)
data['rules'] = clean_rules
with open(rules_file, 'w', encoding='utf-8') as f:
json.dump(data, f, indent=2, ensure_ascii=False)
removed_count = original_count - len(clean_rules)
print(f"βœ… Cleaned rules: removed {removed_count} test rules, kept {len(clean_rules)} valid ones")
return True
except Exception as e:
print(f"❌ Error cleaning rules: {e}")
return False
def main():
"""Main cleanup function."""
print("🧹 Cleaning up test data from prompt management system...")
print("=" * 60)
success = True
# Cleanup each component
success &= cleanup_indicators()
success &= cleanup_templates()
success &= cleanup_rules()
print("=" * 60)
if success:
print("πŸŽ‰ Cleanup completed successfully!")
print("\nπŸ“‹ Next steps:")
print(" 1. Restart the application to load clean data")
print(" 2. Check the Edit Prompts interface")
print(" 3. Verify prompts contain only relevant information")
else:
print("❌ Some cleanup operations failed. Check the errors above.")
return 1
return 0
if __name__ == "__main__":
sys.exit(main())