Skip to content

feat: implement default route validation to prevent multiple default routes per node#814

Open
hanorik wants to merge 2 commits into
google:wolo/workflowsfrom
hanorik:fallback_validator
Open

feat: implement default route validation to prevent multiple default routes per node#814
hanorik wants to merge 2 commits into
google:wolo/workflowsfrom
hanorik:fallback_validator

Conversation

@hanorik
Copy link
Copy Markdown
Contributor

@hanorik hanorik commented May 11, 2026

This PR introduces validation to ensure that a node in a workflow graph does not have more than one default route.

Key Changes:

  • Default Route Validation: Added validateDefaultRoute in validation.go to ensure each node has at most one outgoing edge with Default route. It returns a new error ErrMultipleDefaultRoutes if a violation is found.
  • Unit Tests: Added TestDefaultRoute in validation_test.go to verify the behavior with both valid and invalid configurations.

@hanorik hanorik requested review from anFatum and wolo-lab May 11, 2026 18:08
Copy link
Copy Markdown

@wolo-lab wolo-lab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, only minor changes.

Comment thread workflow/validation.go
}

// validateWorkflow executes a set of workflow validation checks.
func validateWorkflow(workflow *Workflow) error {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not used anywhere. Please build chains from your PRs so it will be easier to merge them.
We could have something like

validateNodes(edges []Edge) error {
   if err := validateSthn(...); err != nul {return err ]
   \+ adding more checks like the new one here
}

Comment thread workflow/validation.go
for node, edges := range workflow.edges {
hasDefault := false
for _, edge := range edges {
if edge.Route == Default && !hasDefault {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit (optional): consider if this is more readable

if edge.Route != Default {
  continue
}
if hasDefault {
  return fmt.Errof(...)
}
hasDefault = true

Comment thread workflow/validation_test.go Outdated
if err := validateDefaultRoute(&Workflow{edges: map[Node][]Edge{nodeA: tc.edges}}); err != nil && !tc.expectErr {
t.Errorf("got an error %v, expected none", err)
} else if err == nil && tc.expectErr {
t.Errorf("expected an error, got none")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe let's check if we got the proper error type (errors.IS)?

@hanorik hanorik force-pushed the fallback_validator branch from 450cc4e to 390b879 Compare May 13, 2026 09:13
@hanorik hanorik force-pushed the fallback_validator branch from 390b879 to d3897d4 Compare May 13, 2026 09:25
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.

2 participants