Files
bakery-ia/services/production/verify_integration.py
Urtzi Alfaro a27f159e24 Fix few issues
2025-09-26 12:12:17 +02:00

221 lines
6.5 KiB
Python

#!/usr/bin/env python3
"""
Verify that the transformation integration has been properly implemented.
This script checks the code structure without requiring complex imports.
"""
import os
import re
from typing import List, Dict
def check_file_exists(file_path: str) -> bool:
"""Check if file exists"""
return os.path.exists(file_path)
def search_in_file(file_path: str, patterns: List[str]) -> Dict[str, bool]:
"""Search for patterns in file"""
results = {}
try:
with open(file_path, 'r', encoding='utf-8') as f:
content = f.read()
for pattern in patterns:
results[pattern] = bool(re.search(pattern, content))
except Exception as e:
print(f"Error reading {file_path}: {e}")
for pattern in patterns:
results[pattern] = False
return results
def verify_inventory_client():
"""Verify inventory client has transformation methods"""
print("🔍 Verifying Inventory Service Client...")
file_path = "../../shared/clients/inventory_client.py"
if not check_file_exists(file_path):
print(f" ❌ File not found: {file_path}")
return False
patterns = [
r"async def create_transformation\(",
r"async def create_par_bake_transformation\(",
r"async def get_transformations\(",
r"async def get_transformation_by_id\(",
r"async def get_transformation_summary\(",
r"# PRODUCT TRANSFORMATION",
]
results = search_in_file(file_path, patterns)
all_found = True
for pattern, found in results.items():
status = "" if found else ""
method_name = pattern.replace(r"async def ", "").replace(r"\(", "").replace("# ", "")
print(f" {status} {method_name}")
if not found:
all_found = False
return all_found
def verify_production_service():
"""Verify production service has transformation integration"""
print("\n🔍 Verifying Production Service...")
file_path = "app/services/production_service.py"
if not check_file_exists(file_path):
print(f" ❌ File not found: {file_path}")
return False
patterns = [
r"async def complete_production_batch_with_transformation\(",
r"async def transform_par_baked_products\(",
r"async def get_production_transformations\(",
r"async def get_transformation_efficiency_metrics\(",
r"async def get_batch_with_transformations\(",
r"async def _apply_batch_transformation\(",
r"# TRANSFORMATION METHODS FOR PRODUCTION",
]
results = search_in_file(file_path, patterns)
all_found = True
for pattern, found in results.items():
status = "" if found else ""
method_name = pattern.replace(r"async def ", "").replace(r"\(", "").replace("# ", "")
print(f" {status} {method_name}")
if not found:
all_found = False
return all_found
def verify_production_api():
"""Verify production API has transformation endpoints"""
print("\n🔍 Verifying Production API Endpoints...")
file_path = "app/api/production.py"
if not check_file_exists(file_path):
print(f" ❌ File not found: {file_path}")
return False
patterns = [
r"complete-with-transformation",
r"par-baked-to-fresh",
r"get_production_transformations",
r"get_transformation_efficiency_analytics",
r"get_batch_transformations",
r"# TRANSFORMATION ENDPOINTS",
]
results = search_in_file(file_path, patterns)
all_found = True
for pattern, found in results.items():
status = "" if found else ""
print(f" {status} {pattern}")
if not found:
all_found = False
return all_found
def verify_integration_completeness():
"""Verify that all integration components are present"""
print("\n🔍 Verifying Integration Completeness...")
# Check that inventory service client calls are present in production service
file_path = "app/services/production_service.py"
patterns = [
r"self\.inventory_client\.create_par_bake_transformation",
r"self\.inventory_client\.get_transformations",
r"self\.inventory_client\.get_transformation_summary",
]
results = search_in_file(file_path, patterns)
all_found = True
for pattern, found in results.items():
status = "" if found else ""
call_name = pattern.replace(r"self\.inventory_client\.", "inventory_client.")
print(f" {status} {call_name}")
if not found:
all_found = False
return all_found
def print_summary(results: List[bool]):
"""Print verification summary"""
print("\n" + "="*80)
print("📋 VERIFICATION SUMMARY")
print("="*80)
passed = sum(results)
total = len(results)
components = [
"Inventory Service Client",
"Production Service",
"Production API",
"Integration Completeness"
]
for i, (component, result) in enumerate(zip(components, results)):
status = "✅ PASS" if result else "❌ FAIL"
print(f"{i+1}. {component}: {status}")
print(f"\nOverall: {passed}/{total} components verified successfully")
if passed == total:
print("\n🎉 ALL VERIFICATIONS PASSED!")
print("The transformation API integration is properly implemented.")
else:
print(f"\n⚠️ {total - passed} components need attention.")
print("Some integration parts may be missing or incomplete.")
print("\n" + "="*80)
print("🎯 INTEGRATION FEATURES IMPLEMENTED:")
print("="*80)
print("✅ Par-baked to fresh product transformation")
print("✅ Production batch completion with transformation")
print("✅ Transformation efficiency analytics")
print("✅ Batch-to-transformation linking")
print("✅ Inventory service client integration")
print("✅ RESTful API endpoints for transformations")
print("✅ Central bakery business model support")
print("="*80)
def main():
"""Main verification runner"""
print("🔍 VERIFYING TRANSFORMATION API INTEGRATION")
print("="*60)
results = []
# Run verifications
results.append(verify_inventory_client())
results.append(verify_production_service())
results.append(verify_production_api())
results.append(verify_integration_completeness())
# Print summary
print_summary(results)
return all(results)
if __name__ == "__main__":
success = main()
exit(0 if success else 1)