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 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]]:
@@ -21,7 +27,8 @@ def _load_workflow_samples(categories: Iterable[str]) -> List[Dict[str, Any]]:
if not category_path.exists():
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:
try:
@@ -31,27 +38,34 @@ def _load_workflow_samples(categories: Iterable[str]) -> List[Dict[str, Any]]:
# Validate basic structure
has_name = 'name' in data and bool(data['name'])
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({
'file': str(workflow_file),
'name': data.get('name', 'Unnamed'),
'nodes': len(data.get('nodes', [])),
'connections': len(data.get('connections', {})),
'has_name': has_name,
'has_nodes': has_nodes,
'has_connections': has_connections,
'valid': has_name and has_nodes and has_connections,
'category': category
})
samples.append(
{
'file': str(workflow_file),
'name': data.get('name', 'Unnamed'),
'nodes': len(data.get('nodes', [])),
'connections': len(data.get('connections', {})),
'has_name': has_name,
'has_nodes': has_nodes,
'has_connections': has_connections,
'valid': has_name and has_nodes and has_connections,
'category': category,
}
)
except Exception as e: # pragma: no cover - defensive logging
samples.append({
'file': str(workflow_file),
'error': str(e),
'valid': False,
'category': category
})
samples.append(
{
'file': str(workflow_file),
'error': str(e),
'valid': False,
'category': category,
}
)
return samples
@@ -70,9 +84,13 @@ def _print_summary(samples: List[Dict[str, Any]]) -> tuple[int, int]:
)
valid_count += 1
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_stats: Dict[str, Dict[str, int]] = {}
@@ -84,10 +102,17 @@ def _print_summary(samples: List[Dict[str, Any]]) -> tuple[int, int]:
if sample['valid']:
category_stats[category]['valid'] += 1
print(f"\n📁 Category Breakdown:")
print("\n📁 Category Breakdown:")
for category, stats in category_stats.items():
success_rate = (stats['valid'] / stats['total']) * 100 if stats['total'] > 0 else 0
print(f" {category}: {stats['valid']}/{stats['total']} ({success_rate:.1f}%)")
success_rate = (
(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)
@@ -117,8 +142,14 @@ if __name__ == "__main__":
if total_count == 0:
print("\n⚠️ No workflows found to validate.")
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:
print(f"\n✅ Most workflows are valid ({valid_count}/{total_count})")
print(
"\n✅ Most workflows are valid "
f"({valid_count}/{total_count})"
)
else:
print(f"\n⚠️ Some workflows need attention ({valid_count}/{total_count})")
print(
"\n⚠️ Some workflows need attention "
f"({valid_count}/{total_count})"
)