[One Workflow] 🐞 Improving detection of steps in the yaml#249274
Conversation
…-breaking-the-yaml
…he-yaml' of github.com:yngrdyn/kibana into 14310-bug-step-snippet-inserted-on-same-line-breaking-the-yaml
…-breaking-the-yaml
There was a problem hiding this comment.
Pull request overview
This PR improves the detection and insertion of workflow steps and triggers in YAML documents, fixing bugs related to cursor position handling and various edge cases when using the actions menu.
Changes:
- Enhanced step/trigger insertion logic to handle cursor position on
steps:/triggers:line, comment lines, empty lines, and existing steps - Replaced flow-style empty arrays (
[]) and empty items with proper step/trigger definitions - Extracted shared utilities for snippet insertion to reduce code duplication
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| workflow_yaml_editor.tsx | Removed redundant null check for yamlDocument before step insertion |
| snippet_insertion_utils.ts | New shared utility module containing helper functions for snippet insertion logic |
| insert_trigger_snippet.ts | Refactored to use shared utilities from snippet_insertion_utils.ts |
| insert_step_snippet.ts | Complete rewrite with improved cursor position handling and edge case support |
| insert_step_snippet.test.ts | Added comprehensive test coverage for all cursor position scenarios and edge cases |
Comments suppressed due to low confidence (1)
src/platform/plugins/shared/workflows_management/public/widgets/workflow_yaml_editor/lib/snippets/snippet_insertion_utils.ts:1
- The magic number
10(allowed range after step) lacks explanation. Consider extracting this to a named constant likeMAX_LINES_AFTER_STEP_FOR_CURSOR_INSERTwith a comment explaining why this specific value was chosen.
/*
There was a problem hiding this comment.
Thanks for working on this! While manually testing, I found that if the cursor is right at the end of a step, it works great; if I put a newline after a step or place the cursor on the same line as "steps:", the snippet gets inserted in the wrong position, or ignores the indent of nested steps.
Please see attached screencasts:
- As a user I expect, new step will be inserted as a second step in if.steps, not under "else".
after-steps-before-else.mov
- As a user I expect that if I place cursor after "steps:", the new step will be inserted inside this section; and if I added a new line after nested step, I expect new step to appear with the same indentation after the step I focused on currently.
after-else.mov
| let document: Document; | ||
| try { | ||
| document = yamlDocument || parseDocument(model.getValue()); | ||
| } catch (error) { |
There was a problem hiding this comment.
The parseDocument call could throw an exception if the YAML is malformed, but the error is caught and silently swallowed at line 460. This makes debugging difficult. Consider logging the error or providing feedback about the parse failure.
| } catch (error) { | |
| } catch (error) { | |
| // Swallowing YAML parse errors here makes debugging difficult; log with context. | |
| // eslint-disable-next-line no-console | |
| console.error('Failed to parse YAML document in insertStepSnippet', error); |
⏳ Build in-progress, with failures
Failed CI Steps
Test Failures
History
cc @yngrdyn |
edda587 to
860084c
Compare
…-breaking-the-yaml
Kiryous
left a comment
There was a problem hiding this comment.
LGTM! Thanks for addressing edge cases ❤️
Thinking out loud: for future, given we'll have a visual editor, we might consider refactoring this logic into a YAML-AST based approach - e.g. "insert step at path steps[0].steps[1]" rather than relying on Monaco line/column positions. This would make the core logic more testable and reusable across editors. But that's a bigger refactor for another day!
…-breaking-the-yaml
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
26 similar comments
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
Closes https://github.com/elastic/security-team/issues/14310
Close https://github.com/elastic/security-team/issues/14570
Closes https://github.com/elastic/security-team/issues/15440
Summary
This PR fixes bugs related to
actions menu+stepsand account for the following behaviour:steps:line → Insert step on the following line[]is replaced by selected stepTechnical Changes
insert_step_snippet.tsby extracting helper functions for better maintainabilitysnippet_insertion_utils.ts) to reduce code duplication between step and trigger insertionTesting
Added comprehensive test coverage for all cursor position scenarios and edge cases.