Skip to content
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

fix: workflow step validation #3965

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from
Draft

Conversation

Kiryous
Copy link
Contributor

@Kiryous Kiryous commented Mar 11, 2025

Closes #3825

Copy link

vercel bot commented Mar 11, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
keep ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 13, 2025 2:34pm

@Kiryous Kiryous changed the title Fix/3825 workflow step validation fix: workflow step validation Mar 11, 2025
# Conflicts:
#	keep-ui/package-lock.json
#	keep-ui/package.json
@Kiryous
Copy link
Contributor Author

Kiryous commented Mar 13, 2025

@greptileai

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This PR implements comprehensive YAML validation for workflow steps to properly handle misplaced configuration keys like enrich_alert.

  • Added new validate-yaml.ts with position-aware error reporting using Zod schemas to catch misplaced keys in workflow definitions
  • Updated workflow validation to return arrays of errors with severity levels instead of single strings in validation.ts
  • Added getCurrentPath function in yaml-utils.ts to accurately identify YAML node locations for error reporting
  • Added useWorkflowJsonSchema hook and schema validation using Monaco editor integration for real-time validation feedback
  • Improved test coverage with new validation test cases in validateWorkflowYaml.test.ts and parser.test.ts

💡 (4/5) You can add custom instructions or style guidelines for the bot here!

29 file(s) reviewed, 21 comment(s)
Edit PR Review Bot Settings | Greptile

data: response,
filename: "topology-export.yaml",
contentType: "application/x-yaml",
});
} catch (error) {
console.log(error);
Copy link

Choose a reason for hiding this comment

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

style: Consider using toast.error here instead of console.log for consistency with error handling elsewhere in the file

Comment on lines +16 to +17
const path = getCurrentPath(doc, 69);
expect(path).toEqual(["workflow", "steps", 0, "provider", "type"]);
Copy link

Choose a reason for hiding this comment

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

style: Magic number 69 is used without explanation - unclear why this specific position maps to type field. Should test with actual character position calculation.

<Card className="h-[calc(100vh-12rem)] p-0 overflow-hidden">
<MonacoYAMLEditor
<Card className="h-[calc(100vh-12rem)] p-0">
<YAMLEditor
key={workflow.workflow_raw!}
Copy link

Choose a reason for hiding this comment

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

logic: key prop using non-null assertion (!), but workflow.workflow_raw could be undefined based on type

Suggested change
key={workflow.workflow_raw!}
key={workflow.workflow_raw ?? ''}

<Card className="h-[calc(100vh-12rem)] p-0 overflow-hidden">
<MonacoYAMLEditor
<Card className="h-[calc(100vh-12rem)] p-0">
<YAMLEditor
key={workflow.workflow_raw!}
workflowRaw={workflow.workflow_raw!}
Copy link

Choose a reason for hiding this comment

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

logic: same non-null assertion issue with workflowRaw prop

Suggested change
workflowRaw={workflow.workflow_raw!}
workflowRaw={workflow.workflow_raw ?? ''}

Comment on lines +335 to 336
expect(result).toEqual([["No test provider selected", "warning"]]);
});
Copy link

Choose a reason for hiding this comment

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

logic: Error message format changed from string to tuple with warning type. Ensure all error handlers in the codebase are updated to handle this new format.

result.forEach(([key, error]) => {
validationErrors.push([key, error, "error"]);
});
isValid = result.length === 0;
Copy link

Choose a reason for hiding this comment

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

logic: isValid logic is incorrect - should be false if any errors exist, not just if global validation has errors

Suggested change
isValid = result.length === 0;
isValid = false;

Comment on lines +39 to +52
[...step.branches.true, ...step.branches.false].forEach((branch) => {
const errors = validateStepPure(
branch,
providers,
installedProviders,
definition
);
if (errors.length > 0) {
errors.forEach(([error, type]) => {
validationErrors.push([branch.name || branch.id, error, type]);
});
isValid = false;
}
});
Copy link

Choose a reason for hiding this comment

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

logic: errors variable is being shadowed inside the forEach loop - could lead to confusion and bugs

loader.config({ monaco });

// In the docs, it is stated that there should only be one monaco yaml instance configured at a time
let monacoYamlInstance: MonacoYaml | undefined;
Copy link

Choose a reason for hiding this comment

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

logic: Global mutable state could cause issues in development with React strict mode's double-mounting. Consider using React context or refs instead.

@talboren talboren linked an issue Mar 19, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant