Add test demonstrating lock file issue and implement partial fix for --skip-charts case

Co-authored-by: yxxhero <11087727+yxxhero@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2025-08-19 01:09:50 +00:00
parent 6482956281
commit 19ede56a51
2 changed files with 95 additions and 1 deletions

View File

@ -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 {

View File

@ -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)
})
}
}