From 7366759c2014d9be2017f4bb12edc04345e577ac Mon Sep 17 00:00:00 2001 From: Zhaochen Li Date: Mon, 28 Jul 2025 15:26:49 +1000 Subject: [PATCH] Fix bug with workspace devfile event command not defined --- .../devfile_operations/restrictions_enforcer.rb | 13 ++++++++++++- ...rt-event-nonexistent-command-devfile.yaml.erb | 16 ++++++++++++++++ .../restrictions_enforcer_spec.rb | 1 + locale/gitlab.pot | 3 +++ 4 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 ee/spec/fixtures/remote_development/example.invalid-poststart-event-nonexistent-command-devfile.yaml.erb diff --git a/ee/lib/remote_development/devfile_operations/restrictions_enforcer.rb b/ee/lib/remote_development/devfile_operations/restrictions_enforcer.rb index 62c11d37de99ba..ac01916e4ad757 100644 --- a/ee/lib/remote_development/devfile_operations/restrictions_enforcer.rb +++ b/ee/lib/remote_development/devfile_operations/restrictions_enforcer.rb @@ -359,8 +359,19 @@ def self.validate_events(context) # ===== postStart specific validations ===== - # Check if the referenced command is an exec command referenced_command = commands.find { |cmd| cmd[:id] == command_name } + # Check if referenced command is defined in the command section + unless referenced_command.is_a?(Hash) + append_err( + format(_("PostStart event references command '%{command}' which has no command definition."), + command: command_name + ), + context + ) + next + end + + # Check if the referenced command is an exec command next if referenced_command[:exec].present? append_err( diff --git a/ee/spec/fixtures/remote_development/example.invalid-poststart-event-nonexistent-command-devfile.yaml.erb b/ee/spec/fixtures/remote_development/example.invalid-poststart-event-nonexistent-command-devfile.yaml.erb new file mode 100644 index 00000000000000..8c656d1c2db285 --- /dev/null +++ b/ee/spec/fixtures/remote_development/example.invalid-poststart-event-nonexistent-command-devfile.yaml.erb @@ -0,0 +1,16 @@ +--- +schemaVersion: 2.2.0 +components: + - name: example-valid-component + attributes: + gl/inject-editor: true + container: + image: quay.io/mloriedo/universal-developer-image:ubi8-dw-demo +commands: + - id: valid-command + exec: + component: example-valid-component + commandLine: echo "valid command" +events: + postStart: + - nonexistent-command diff --git a/ee/spec/lib/remote_development/devfile_operations/restrictions_enforcer_spec.rb b/ee/spec/lib/remote_development/devfile_operations/restrictions_enforcer_spec.rb index 0df59d47461e9f..49c3ca9d4e0704 100644 --- a/ee/spec/lib/remote_development/devfile_operations/restrictions_enforcer_spec.rb +++ b/ee/spec/lib/remote_development/devfile_operations/restrictions_enforcer_spec.rb @@ -112,6 +112,7 @@ "example.invalid-unsupported-command-exec-options-devfile.yaml.erb" | "Unsupported options 'unsupportedOption' for exec command 'unsupported-options'. Only 'commandLine, component, label, hotReloadCapable' are supported." "example.invalid-unsupported-command-type-devfile.yaml.erb" | "Command 'composite-command' must have one of the supported command types: exec, apply" "example.invalid-unsupported-command-type-poststart-event-devfile.yaml.erb" | "PostStart event references command 'apply-command' which is not an exec command. Only exec commands are supported in postStart events" + "example.invalid-poststart-event-nonexistent-command-devfile.yaml.erb" | "PostStart event references command 'nonexistent-command' which has no command definition." "example.invalid-unsupported-component-container-dedicated-pod-devfile.yaml.erb" | "Property 'dedicatedPod' of component 'example' is not yet supported" "example.invalid-unsupported-component-type-image-devfile.yaml.erb" | "Component type 'image' is not yet supported" "example.invalid-unsupported-component-type-kubernetes-devfile.yaml.erb" | "Component type 'kubernetes' is not yet supported" diff --git a/locale/gitlab.pot b/locale/gitlab.pot index bffbc7381cead2..6cc73ecc98468d 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -47353,6 +47353,9 @@ msgstr "" msgid "Possible to override in each project." msgstr "" +msgid "PostStart event references command '%{command}' which has no command definition." +msgstr "" + msgid "PostStart event references command '%{command}' which is not an exec command. Only exec commands are supported in postStart events" msgstr "" -- GitLab