From 76536e45aa4d9ea531e635df7380f729d81bc541 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 23 Apr 2026 00:03:58 +0000 Subject: [PATCH] test(state): harden chartify skip-schema flag detection Agent-Logs-Url: https://github.com/helmfile/helmfile/sessions/a695cbff-c37a-403a-9658-09f4fdaa65d0 Co-authored-by: yxxhero <11087727+yxxhero@users.noreply.github.com> --- pkg/state/issue_2549_test.go | 18 ++++++++++++++---- pkg/state/state.go | 22 +++++++++++++++++----- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/pkg/state/issue_2549_test.go b/pkg/state/issue_2549_test.go index 66fd9830..0c90da06 100644 --- a/pkg/state/issue_2549_test.go +++ b/pkg/state/issue_2549_test.go @@ -1,6 +1,10 @@ package state -import "testing" +import ( + "testing" + + "github.com/stretchr/testify/require" +) func TestAppendSkipSchemaValidationFlagToChartifyTemplateArgs(t *testing.T) { enable := true @@ -43,6 +47,14 @@ func TestAppendSkipSchemaValidationFlagToChartifyTemplateArgs(t *testing.T) { templateArgs: "--skip-schema-validation --kube-context default", want: "--skip-schema-validation --kube-context default", }, + { + name: "does not treat similar flag values as existing flag", + release: &ReleaseSpec{ + SkipSchemaValidation: &enable, + }, + templateArgs: "--set name=foo--skip-schema-validation", + want: "--set name=foo--skip-schema-validation --skip-schema-validation", + }, { name: "does not add flag when disabled", release: &ReleaseSpec{}, @@ -60,9 +72,7 @@ func TestAppendSkipSchemaValidationFlagToChartifyTemplateArgs(t *testing.T) { } got := st.appendSkipSchemaValidationFlagToChartifyTemplateArgs(tt.templateArgs, tt.release) - if got != tt.want { - t.Fatalf("appendSkipSchemaValidationFlagToChartifyTemplateArgs() = %q, want %q", got, tt.want) - } + require.Equal(t, tt.want, got) }) } } diff --git a/pkg/state/state.go b/pkg/state/state.go index 488d6de2..36e111da 100644 --- a/pkg/state/state.go +++ b/pkg/state/state.go @@ -1637,15 +1637,27 @@ func (st *HelmState) processChartification(chartification *Chartify, release *Re } func (st *HelmState) appendSkipSchemaValidationFlagToChartifyTemplateArgs(templateArgs string, release *ReleaseSpec) string { - if !st.shouldSkipSchemaValidation(release, false) || strings.Contains(templateArgs, "--skip-schema-validation") { + if !st.shouldSkipSchemaValidation(release, false) || hasTemplateArg(templateArgs, "--skip-schema-validation") { return templateArgs } - if templateArgs == "" { - return "--skip-schema-validation" - } + return appendTemplateArg(templateArgs, "--skip-schema-validation") +} - return templateArgs + " --skip-schema-validation" +func hasTemplateArg(templateArgs, arg string) bool { + for _, token := range strings.Fields(templateArgs) { + if token == arg || strings.HasPrefix(token, arg+"=") { + return true + } + } + return false +} + +func appendTemplateArg(templateArgs, arg string) string { + if templateArgs == "" { + return arg + } + return templateArgs + " " + arg } // processLocalChart handles local chart processing