Fix workflow test flake8 violations

This commit is contained in:
Eliad Shahar
2025-09-30 23:31:36 +03:00
parent f5e0536846
commit 778be2ed40

View File

@@ -8,7 +8,13 @@ import json
from pathlib import Path from pathlib import Path
from typing import Any, Dict, Iterable, List from typing import Any, Dict, Iterable, List
DEFAULT_CATEGORIES: List[str] = ['Manual', 'Webhook', 'Schedule', 'Http', 'Code'] DEFAULT_CATEGORIES: List[str] = [
'Manual',
'Webhook',
'Schedule',
'Http',
'Code',
]
def _load_workflow_samples(categories: Iterable[str]) -> List[Dict[str, Any]]: def _load_workflow_samples(categories: Iterable[str]) -> List[Dict[str, Any]]:
@@ -21,7 +27,8 @@ def _load_workflow_samples(categories: Iterable[str]) -> List[Dict[str, Any]]:
if not category_path.exists(): if not category_path.exists():
continue continue
workflow_files = list(category_path.glob('*.json'))[:2] # Test first 2 from each category # Test first 2 workflows from each category to limit CI runtime
workflow_files = list(category_path.glob('*.json'))[:2]
for workflow_file in workflow_files: for workflow_file in workflow_files:
try: try:
@@ -31,27 +38,34 @@ def _load_workflow_samples(categories: Iterable[str]) -> List[Dict[str, Any]]:
# Validate basic structure # Validate basic structure
has_name = 'name' in data and bool(data['name']) has_name = 'name' in data and bool(data['name'])
has_nodes = 'nodes' in data and isinstance(data['nodes'], list) has_nodes = 'nodes' in data and isinstance(data['nodes'], list)
has_connections = 'connections' in data and isinstance(data['connections'], dict) has_connections = (
'connections' in data
and isinstance(data['connections'], dict)
)
samples.append({ samples.append(
'file': str(workflow_file), {
'name': data.get('name', 'Unnamed'), 'file': str(workflow_file),
'nodes': len(data.get('nodes', [])), 'name': data.get('name', 'Unnamed'),
'connections': len(data.get('connections', {})), 'nodes': len(data.get('nodes', [])),
'has_name': has_name, 'connections': len(data.get('connections', {})),
'has_nodes': has_nodes, 'has_name': has_name,
'has_connections': has_connections, 'has_nodes': has_nodes,
'valid': has_name and has_nodes and has_connections, 'has_connections': has_connections,
'category': category 'valid': has_name and has_nodes and has_connections,
}) 'category': category,
}
)
except Exception as e: # pragma: no cover - defensive logging except Exception as e: # pragma: no cover - defensive logging
samples.append({ samples.append(
'file': str(workflow_file), {
'error': str(e), 'file': str(workflow_file),
'valid': False, 'error': str(e),
'category': category 'valid': False,
}) 'category': category,
}
)
return samples return samples
@@ -70,9 +84,13 @@ def _print_summary(samples: List[Dict[str, Any]]) -> tuple[int, int]:
) )
valid_count += 1 valid_count += 1
else: else:
print(f"{sample['file']} - Error: {sample.get('error', 'Invalid structure')}") error = sample.get('error', 'Invalid structure')
print(f"{sample['file']} - Error: {error}")
print(f"\n🎯 Result: {valid_count}/{len(samples)} workflows are valid and ready!") print(
"\n🎯 Result: "
f"{valid_count}/{len(samples)} workflows are valid and ready!"
)
# Category breakdown # Category breakdown
category_stats: Dict[str, Dict[str, int]] = {} category_stats: Dict[str, Dict[str, int]] = {}
@@ -84,10 +102,17 @@ def _print_summary(samples: List[Dict[str, Any]]) -> tuple[int, int]:
if sample['valid']: if sample['valid']:
category_stats[category]['valid'] += 1 category_stats[category]['valid'] += 1
print(f"\n📁 Category Breakdown:") print("\n📁 Category Breakdown:")
for category, stats in category_stats.items(): for category, stats in category_stats.items():
success_rate = (stats['valid'] / stats['total']) * 100 if stats['total'] > 0 else 0 success_rate = (
print(f" {category}: {stats['valid']}/{stats['total']} ({success_rate:.1f}%)") (stats['valid'] / stats['total']) * 100
if stats['total'] > 0
else 0
)
print(
f" {category}: {stats['valid']}/{stats['total']} "
f"({success_rate:.1f}%)"
)
return valid_count, len(samples) return valid_count, len(samples)
@@ -117,8 +142,14 @@ if __name__ == "__main__":
if total_count == 0: if total_count == 0:
print("\n⚠️ No workflows found to validate.") print("\n⚠️ No workflows found to validate.")
elif valid_count == total_count: elif valid_count == total_count:
print(f"\n🎉 ALL SAMPLE WORKFLOWS ARE VALID! 🎉") print("\n🎉 ALL SAMPLE WORKFLOWS ARE VALID! 🎉")
elif valid_count > total_count * 0.8: elif valid_count > total_count * 0.8:
print(f"\n✅ Most workflows are valid ({valid_count}/{total_count})") print(
"\n✅ Most workflows are valid "
f"({valid_count}/{total_count})"
)
else: else:
print(f"\n⚠️ Some workflows need attention ({valid_count}/{total_count})") print(
"\n⚠️ Some workflows need attention "
f"({valid_count}/{total_count})"
)