Skip to content

feat: enforce unique task name and other validation improvements#277

Open
JBBianchi wants to merge 4 commits into
serverlessworkflow:mainfrom
neuroglia-io:feat-taskllist-validation
Open

feat: enforce unique task name and other validation improvements#277
JBBianchi wants to merge 4 commits into
serverlessworkflow:mainfrom
neuroglia-io:feat-taskllist-validation

Conversation

@JBBianchi

Copy link
Copy Markdown
Member

Many thanks for submitting your Pull Request ❤️!

What this PR does / why we need it:
TLDR:

  1. Duplicate task-name validation
    New TaskListHooks.postValidation hook that rejects a TaskList containing duplicated task names, reporting every offending name.
  2. Structured validation errors
    New WorkflowValidationError base class carrying a path (RFC 6901 JSON Pointer to the offending node) and typeName. (Two subtypes: SchemaValidationError (AJV structural failures, retains raw schemaErrors) and DslValidationError (semantic/hook failures). )
  3. Recursive hook invocation
    validate now runs schema validation once at the root, then walks the whole subtree invoking each nested type's lifecycle hooks. So rules like duplicate-name detection fire on nested do blocks, not just the top level. Previously hooks only ran on the validated root.
  4. Generated navigation metadata
    New codegen (getChildTypes) emits a childTypes map describing each type's hydratable children (object / record / indexed / array / array-record). This drives the recursive walk and stays in lockstep with the constructor-hydration codegen. Notably it recurses into union-shared properties (e.g. do on both DoTask and ForTask) that the generic constructor doesn't hydrate.
  5. Tests
    Covering duplicate detection, nested tasks, and the error types/paths.

Copilot summary:

This pull request implements a robust, recursive validation framework for the Serverless Workflow SDK, introducing structured error types, lifecycle hooks for nested validation, and comprehensive test coverage. The main improvements include new error classes to distinguish schema and DSL validation failures, recursive invocation of validation hooks (including for nested structures like TaskList), and enhanced error reporting with precise JSON Pointer paths. These changes significantly improve the reliability and debuggability of workflow validation.

Validation Framework Enhancements:

  • Introduced new error types in src/lib/errors.ts (WorkflowValidationError, SchemaValidationError, DslValidationError) to provide structured, informative error handling for both schema and DSL validation failures. These errors include precise JSON Pointer paths and type names for better debugging.
  • Refactored src/lib/validation.ts to:
    • Run schema validation once at the root, then recursively invoke lifecycle hooks for all nested types using generated metadata.
    • Wrap DSL validation errors in DslValidationError with location context, and propagate WorkflowValidationError as-is.
    • Export new utility functions for pointer manipulation and error display, and update validation logic to use the new error types. [1] [2]

Lifecycle Hooks and TaskList Validation:

  • Added TaskListHooks in src/lib/hooks/task-list-hooks.ts to detect and throw errors on duplicate task names within a TaskList, and registered these hooks for recursive validation. [1] [2] [3] [4]
  • Updated exports to include the new error types in the SDK entry point.

Testing Improvements:

  • Added comprehensive tests in tests/validation/task-list-validation.spec.ts and extended tests/validation/workflow-validation.spec.ts to verify:
    • Duplicate task name detection at all nesting levels.
    • Proper error typing and path reporting for both schema and DSL errors.
    • Recursive validation of nested workflows and task lists. [1] [2] [3]

Code Generation Support:

  • Updated code generation tooling to support recursive validation by importing getChildTypes from reflection utilities.

These changes collectively provide a more maintainable, extensible, and debuggable validation system for workflows, with clear error reporting and robust support for complex, nested workflow structures.

Special notes for reviewers:

Additional information (if needed):

JBBianchi added 4 commits July 9, 2026 20:56
Signed-off-by: Jean-Baptiste Bianchi <jb.bianchi@neuroglia.io>
Signed-off-by: Jean-Baptiste Bianchi <jb.bianchi@neuroglia.io>
Signed-off-by: Jean-Baptiste Bianchi <jb.bianchi@neuroglia.io>
…on path

Signed-off-by: Jean-Baptiste Bianchi <jb.bianchi@neuroglia.io>
@JBBianchi JBBianchi requested a review from ricardozanini as a code owner July 10, 2026 10:42
@JBBianchi

Copy link
Copy Markdown
Member Author

@lornakelly @fantonangeli @handreyrc those changes impact the editor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant