fix: unify pre-execution validation with --validate-only (fixes #66)#67
Conversation
Previously, normal workflow execution used weaker validation (schema-only via validate_ir) while --validate-only used full WorkflowValidator. This caused unknown node types to show ugly tracebacks instead of clean error messages. Changes: - Add _validate_before_execution() using full WorkflowValidator with real params - Remove _validate_workflow_structure() and _validate_and_handle_workflow_errors() - Remove unused validate_ir import from main.py - Add validation call after _prepare_execution_environment() in execute_json_workflow() - Update tests to patch WorkflowValidator.validate instead of removed validate_ir Benefits: - Consistent validation across all modes (normal, --validate-only, --auto-repair) - Clean error messages for unknown node types - Validation happens BEFORE any nodes execute - Removed ~65 lines of duplicate validation logic Fixes #66
- Remove unused metrics_collector parameter from _validate_before_execution() - Remove overly broad except Exception block that was hiding potential bugs (let WorkflowValidator exceptions propagate naturally)
Code ReviewThis PR successfully unifies validation behavior between normal execution and Critical — Must Fix Before Merge1. Registry Instantiation in Validation PathLocation: registry = Registry()Issue: Creating a fresh Fix: Follow the existing pattern in
Recommendation: Add an optional def _validate_before_execution(
ctx: click.Context,
ir_data: dict[str, Any],
execution_params: dict[str, Any],
output_format: str,
verbose: bool,
metrics_collector: Any | None,
registry: Registry | None = None, # Allow caller to provide
) -> None:
...
if registry is None:
registry = Registry()
...Then pass the registry from the caller if available. 2. Unused
|
Response to ReviewThanks for the thorough review! I've addressed the critical issues. Fixed ✅Critical #2: Unused
Critical #3: Bare
Not Addressed (by design)Critical #1: Registry instantiation
Warning #4: Test helper function
Warnings #5-9: Low priority, can be addressed in future cleanup PRs The PR is ready for merge after CI passes. |
Summary
Unifies validation behavior between normal workflow execution and
--validate-onlymode. Previously, normal execution used weaker schema-only validation while--validate-onlyused fullWorkflowValidator. This caused unknown node types to show ugly tracebacks instead of clean error messages.Changes
_validate_before_execution()function using fullWorkflowValidatorwith real execution params_validate_workflow_structure()and_validate_and_handle_workflow_errors()(dead code)validate_irimport frommain.py_prepare_execution_environment()but beforeexecute_workflow()WorkflowValidator.validateinstead of removedvalidate_irtest_validation_before_execution.pywith 5 testsExplanation
The CLI had two different validation paths:
validate_ir()(schema only)WorkflowValidator.validate()(full)--validate-onlyWorkflowValidator.validate()(full)WorkflowValidator.validate()(full)--auto-repairWorkflowValidator.validate()(full)WorkflowValidator.validate()(full)The key insight was that validation should happen AFTER
_prepare_execution_environment()createsenhanced_params, so we can validate with real params instead of dummy placeholders. This provides better template validation than--validate-onlymode.Before (ugly traceback):
After (clean error):
Testing
make checkpasses (linting, type checking)--validate-onlyand normal executionRun
make testto verify all tests pass.🤖 Implemented by Claude