Skip to content

Add schema validation for BranchNode gRPC objects #248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 14, 2025

Conversation

devin-ai-integration[bot]
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot commented May 14, 2025

Add schema validation for BranchNode gRPC objects

Description

This PR implements schema validation for BranchNode gRPC objects to prevent malformed data from being accepted, which can cause deserialization failures when retrieving workflows.

Changes

  • Enhanced validation for BranchNode conditions to prevent malformed data
  • Added validation for condition ID, type, and condition structure
  • Note: Empty expressions in "if" conditions are allowed by design (as confirmed by existing tests)
  • Added unit tests for malformed data validation

Testing

Added unit tests to verify validation works correctly for various malformed data cases.

Related Issues

Fixes #140

Link to Devin run

https://app.devin.ai/sessions/aafc6baafac442cb88f6df9be82b1d29

Requested by

Chris Li (chris@avaprotocol.org)

Co-Authored-By: Chris Li <chris.li.2046@gmail.com>
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Co-Authored-By: Chris Li <chris.li.2046@gmail.com>
github-actions bot and others added 2 commits May 14, 2025 00:32
Formatted Go code using gofmt.
Co-Authored-By: Chris Li <chris.li.2046@gmail.com>
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds schema validation for BranchNode gRPC objects to prevent malformed data from being accepted during deserialization. Key changes include enhancing validation logic in the branch processor and adding comprehensive unit tests for various malformed condition cases.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
core/taskengine/vm_runner_branch.go Added validation for nil conditions, empty/invalid IDs and types, with logging for misplaced "else" conditions.
core/taskengine/vm_runner_branch_test.go Introduced unit tests to verify the schema validation behavior for branch node conditions.

return fmt.Errorf("condition at index %d has empty type", i)
}

if condition.Type != "if" && condition.Type != "else" {
Copy link
Preview

Copilot AI May 14, 2025

Choose a reason for hiding this comment

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

The PR description mentions schema validation for the condition expression, but no validation is implemented for the 'expression' field. Please either add validation for 'expression' or update the PR description to accurately reflect the implemented behavior.

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Thank you for the feedback! You're right that the PR description mentioned validation for expressions but our implementation doesn't reject empty expressions. This is intentional, as we found that existing tests (specifically TestBranchNodeEmptyConditionIsAPass) expect empty expressions to be allowed and treated as falsy. I've updated the PR description to clarify this design decision.

@chrisli30 chrisli30 merged commit a354403 into main May 14, 2025
14 checks passed
@chrisli30 chrisli30 deleted the devin/1747182290-add-grpc-schema-validation branch May 14, 2025 02:11
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