Skip to content

[One Workflow] 🐞 Improving detection of steps in the yaml#249274

Merged
yngrdyn merged 14 commits into
elastic:mainfrom
yngrdyn:14310-bug-step-snippet-inserted-on-same-line-breaking-the-yaml
Feb 6, 2026
Merged

[One Workflow] 🐞 Improving detection of steps in the yaml#249274
yngrdyn merged 14 commits into
elastic:mainfrom
yngrdyn:14310-bug-step-snippet-inserted-on-same-line-breaking-the-yaml

Conversation

@yngrdyn
Copy link
Copy Markdown
Contributor

@yngrdyn yngrdyn commented Jan 15, 2026

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+ steps and account for the following behaviour:

  • Cursor on steps: line → Insert step on the following line
  • Cursor on comment line → Insert step on the following line (after the comment)
  • Cursor on empty line → Replace the empty line with the new step
  • Cursor on existing step → Insert after that step
  • No cursor → Insert at the end (default behavior)
  • empty YAML → Step section is created and step is added
  • flow-style[] is replaced by selected step
  • empty items → empty item is replaced by selected step

Technical Changes

  • Simplified insert_step_snippet.ts by extracting helper functions for better maintainability
  • Created shared utilities (snippet_insertion_utils.ts) to reduce code duplication between step and trigger insertion

Testing

Added comprehensive test coverage for all cursor position scenarios and edge cases.

@yngrdyn yngrdyn self-assigned this Jan 15, 2026
@yngrdyn yngrdyn requested a review from a team as a code owner January 15, 2026 17:10
@yngrdyn yngrdyn added backport:version Backport to applied version labels Team:One Workflow Team label for One Workflow (Workflow automation) v9.3.0 labels Jan 15, 2026
@yngrdyn yngrdyn changed the title [One Workflow] :ladybug: Improving detection of steps in the yaml [One Workflow] 🐞 Improving detection of steps in the yaml Jan 15, 2026
@yngrdyn yngrdyn added the release_note:skip Skip the PR/issue when compiling release notes label Jan 15, 2026
@Kiryous Kiryous requested a review from Copilot January 19, 2026 19:27
Copy link
Copy Markdown
Contributor

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 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 like MAX_LINES_AFTER_STEP_FOR_CURSOR_INSERT with a comment explaining why this specific value was chosen.
/*

Copy link
Copy Markdown
Contributor

@Kiryous Kiryous left a comment

Choose a reason for hiding this comment

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

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:

  1. 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
  1. 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

@yngrdyn yngrdyn requested review from Kiryous and Copilot February 4, 2026 13:09
Copy link
Copy Markdown
Contributor

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

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

let document: Document;
try {
document = yamlDocument || parseDocument(model.getValue());
} catch (error) {
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
} 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);

Copilot uses AI. Check for mistakes.
@elasticmachine
Copy link
Copy Markdown
Contributor

⏳ Build in-progress, with failures

Failed CI Steps

Test Failures

  • [job] [logs] Jest Tests #9 / insertTriggerSnippet when triggers section exists but is empty should insert trigger when triggers section has multiple comments
  • [job] [logs] Jest Tests #9 / insertTriggerSnippet when triggers section exists but is empty should insert trigger when triggers section has multiple comments
  • [job] [logs] Scout: [ platform / streams_app-serverless-oblt ] plugin / serverless-oblt - Stream data processing - data sources management - should allow adding a new kql data source
  • [job] [logs] Scout: [ platform / streams_app-stateful ] plugin / should allow adding a new kql data source
  • [job] [logs] Scout: [ platform / streams_app-serverless-oblt ] plugin / should allow adding a new kql data source
  • [job] [logs] Scout: [ platform / streams_app-stateful ] plugin / stateful - Stream data processing - data sources management - should allow adding a new kql data source

History

cc @yngrdyn

@yngrdyn yngrdyn force-pushed the 14310-bug-step-snippet-inserted-on-same-line-breaking-the-yaml branch from edda587 to 860084c Compare February 4, 2026 15:55
Copy link
Copy Markdown
Contributor

@Kiryous Kiryous left a comment

Choose a reason for hiding this comment

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

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!

@kibanamachine
Copy link
Copy Markdown
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 249274 locally
cc: @yngrdyn

26 similar comments
@kibanamachine
Copy link
Copy Markdown
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 249274 locally
cc: @yngrdyn

@kibanamachine
Copy link
Copy Markdown
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 249274 locally
cc: @yngrdyn

@kibanamachine
Copy link
Copy Markdown
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 249274 locally
cc: @yngrdyn

@kibanamachine
Copy link
Copy Markdown
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 249274 locally
cc: @yngrdyn

@kibanamachine
Copy link
Copy Markdown
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 249274 locally
cc: @yngrdyn

@kibanamachine
Copy link
Copy Markdown
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 249274 locally
cc: @yngrdyn

@kibanamachine
Copy link
Copy Markdown
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 249274 locally
cc: @yngrdyn

@kibanamachine
Copy link
Copy Markdown
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 249274 locally
cc: @yngrdyn

@kibanamachine
Copy link
Copy Markdown
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 249274 locally
cc: @yngrdyn

@kibanamachine
Copy link
Copy Markdown
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 249274 locally
cc: @yngrdyn

@kibanamachine
Copy link
Copy Markdown
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 249274 locally
cc: @yngrdyn

@kibanamachine
Copy link
Copy Markdown
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 249274 locally
cc: @yngrdyn

@kibanamachine
Copy link
Copy Markdown
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 249274 locally
cc: @yngrdyn

@kibanamachine
Copy link
Copy Markdown
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 249274 locally
cc: @yngrdyn

@kibanamachine
Copy link
Copy Markdown
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 249274 locally
cc: @yngrdyn

@kibanamachine
Copy link
Copy Markdown
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 249274 locally
cc: @yngrdyn

@kibanamachine
Copy link
Copy Markdown
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 249274 locally
cc: @yngrdyn

@kibanamachine
Copy link
Copy Markdown
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 249274 locally
cc: @yngrdyn

@kibanamachine
Copy link
Copy Markdown
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 249274 locally
cc: @yngrdyn

@kibanamachine
Copy link
Copy Markdown
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 249274 locally
cc: @yngrdyn

@kibanamachine
Copy link
Copy Markdown
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 249274 locally
cc: @yngrdyn

@kibanamachine
Copy link
Copy Markdown
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 249274 locally
cc: @yngrdyn

@kibanamachine
Copy link
Copy Markdown
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 249274 locally
cc: @yngrdyn

@kibanamachine
Copy link
Copy Markdown
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 249274 locally
cc: @yngrdyn

@kibanamachine
Copy link
Copy Markdown
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 249274 locally
cc: @yngrdyn

@kibanamachine
Copy link
Copy Markdown
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 249274 locally
cc: @yngrdyn

@yngrdyn yngrdyn added the backport:skip This PR does not require backporting label Jun 1, 2026
@kibanamachine kibanamachine removed the backport missing Added to PRs automatically when the are determined to be missing a backport. label Jun 1, 2026
@yngrdyn yngrdyn removed the backport:version Backport to applied version labels label Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team:One Workflow Team label for One Workflow (Workflow automation) v9.3.0 v9.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants