From 19ede56a51598169595ac2671a7c17dd97004ad4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 19 Aug 2025 01:09:50 +0000 Subject: [PATCH] Add test demonstrating lock file issue and implement partial fix for --skip-charts case Co-authored-by: yxxhero <11087727+yxxhero@users.noreply.github.com> --- pkg/app/app.go | 12 ++++- pkg/app/app_list_lock_test.go | 84 +++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 pkg/app/app_list_lock_test.go diff --git a/pkg/app/app.go b/pkg/app/app.go index 19024459..06371275 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -605,7 +605,17 @@ func (a *App) ListReleases(c ListConfigProvider) error { stateReleases = rel }) } else { - stateReleases, err = a.list(run) + // Even when skipping charts, we should still resolve dependencies from the lock file + // to show the locked versions instead of the version constraints from helmfile.yaml + resolvedState, resolveErr := run.state.ResolveDeps() + if resolveErr != nil { + err = resolveErr + } else { + // Create a new run with the resolved state to get the correct versions + resolvedRun := *run + resolvedRun.state = resolvedState + stateReleases, err = a.list(&resolvedRun) + } } if err != nil { diff --git a/pkg/app/app_list_lock_test.go b/pkg/app/app_list_lock_test.go new file mode 100644 index 00000000..55f605df --- /dev/null +++ b/pkg/app/app_list_lock_test.go @@ -0,0 +1,84 @@ +package app + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "go.uber.org/zap" + + ffs "github.com/helmfile/helmfile/pkg/filesystem" + "github.com/helmfile/helmfile/pkg/testutil" +) + +// TestListReflectsLockedVersions tests that helmfile list shows versions from +// the lock file when available, both with and without --skip-charts +func TestListReflectsLockedVersions(t *testing.T) { + testCases := []struct { + name string + skipCharts bool + }{ + { + name: "with skipCharts=false", + skipCharts: false, + }, + { + name: "with skipCharts=true", + skipCharts: true, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + // Mock files: helmfile.yaml with a chart dependency and helmfile.lock with resolved version + files := map[string]string{ + "/path/to/helmfile.yaml": ` +repositories: +- name: bitnami + url: https://charts.bitnami.com/bitnami + +releases: +- name: redis + chart: bitnami/redis + version: "*" +`, + "/path/to/helmfile.lock": ` +version: v0.170.1 +dependencies: +- name: redis + repository: https://charts.bitnami.com/bitnami + version: 18.1.5 +digest: sha256:abcd1234 +generated: "2023-01-01T00:00:00Z" +`, + } + + logger := zap.NewNop().Sugar() + + app := appWithFs(&App{ + OverrideHelmBinary: DefaultHelmBinary, + fs: ffs.DefaultFileSystem(), + OverrideKubeContext: "default", + Env: "default", + Logger: logger, + FileOrDir: "/path/to/helmfile.yaml", + }, files) + + expectNoCallsToHelm(app) + + cfg := configImpl{ + skipCharts: tc.skipCharts, + output: "json", + } + + out, err := testutil.CaptureStdout(func() { + listErr := app.ListReleases(cfg) + assert.NoError(t, listErr) + }) + assert.NoError(t, err) + + // The output should contain the locked version (18.1.5) not the constraint (*) + assert.Contains(t, out, "18.1.5", "Expected to see locked version 18.1.5 in output, but got: %s", out) + assert.NotContains(t, out, `"version":"*"`, "Should not see version constraint in output, but got: %s", out) + }) + } +} \ No newline at end of file