From 3d794a5db429e57f527746051a381c064b0af422 Mon Sep 17 00:00:00 2001 From: zjncs <18910855655@163.com> Date: Fri, 4 Sep 2026 15:45:11 +0800 Subject: [PATCH] fix(v3): restore the error check inverted in processDependencyConditions When converting the type assertion to errors.AsType in 025418291, the negation was dropped, so the "real error" warning fired for the normal missing-condition case (ErrNoValue) and genuine PathValue errors were silenced instead. This diverges from the v2 implementation the code was based on. Restore the negation and add a regression test. Signed-off-by: zjncs <18910855655@163.com> --- internal/chart/v3/util/dependencies.go | 8 +++---- internal/chart/v3/util/dependencies_test.go | 25 +++++++++++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/internal/chart/v3/util/dependencies.go b/internal/chart/v3/util/dependencies.go index 8b84ef428..49486826b 100644 --- a/internal/chart/v3/util/dependencies.go +++ b/internal/chart/v3/util/dependencies.go @@ -53,10 +53,10 @@ func processDependencyConditions(reqs []*chart.Dependency, cvals common.Values, break } slog.Warn("returned non-bool value", "path", c, "chart", r.Name) - } else if _, ok := errors.AsType[common.ErrNoValue](err); ok { - // this is a real error - slog.Warn("the method PathValue returned error", slog.Any("error", err)) - } + } else if _, ok := errors.AsType[common.ErrNoValue](err); !ok { + // this is a real error + slog.Warn("the method PathValue returned error", slog.Any("error", err)) + } } } } diff --git a/internal/chart/v3/util/dependencies_test.go b/internal/chart/v3/util/dependencies_test.go index 45693ef46..4f62898b5 100644 --- a/internal/chart/v3/util/dependencies_test.go +++ b/internal/chart/v3/util/dependencies_test.go @@ -15,6 +15,8 @@ limitations under the License. package util import ( + "bytes" + "log/slog" "os" "path/filepath" "sort" @@ -55,6 +57,29 @@ func TestLoadDependency(t *testing.T) { check(c.Lock.Dependencies) } +// An absent condition path is the normal case for every unset condition and +// must not be reported as a PathValue error, matching the v2 implementation. +func TestProcessDependencyConditionsAbsentPathNoWarning(t *testing.T) { + prev := slog.Default() + t.Cleanup(func() { slog.SetDefault(prev) }) + + var logBuf bytes.Buffer + slog.SetDefault(slog.New(slog.NewJSONHandler(&logBuf, nil))) + + reqs := []*chart.Dependency{ + {Name: "subchart1", Condition: "subchart1.enabled"}, + {Name: "subchart2", Condition: "not.in.values"}, + } + v := common.Values{"subchart1": map[string]any{"enabled": true}} + + processDependencyConditions(reqs, v, "") + + assert.True(t, reqs[0].Enabled, "expected the present condition to be applied") + assert.False(t, reqs[1].Enabled, "expected the absent condition to leave the dependency disabled") + assert.NotContains(t, logBuf.String(), "PathValue returned error", + "an absent condition path is not a PathValue error and must not be warned about") +} + func TestDependencyEnabled(t *testing.T) { type M = map[string]any tests := []struct {