From 78de014b7dd8eaf05afdc7342a255a977363d53b Mon Sep 17 00:00:00 2001 From: Bruno Albuquerque Date: Wed, 25 Mar 2026 09:57:37 -0400 Subject: [PATCH] fix(engine): delegate customDiffPatch.summary() to inner patch's Summary() Previously the method returned a hardcoded "CustomPatch" string. It now performs a type assertion against a local summarizer interface and calls Summary() on the inner patch when available, falling back to "CustomPatch" otherwise. Adds tests for both branches. --- internal/engine/patch_ops.go | 6 ++++++ internal/engine/patch_test.go | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/internal/engine/patch_ops.go b/internal/engine/patch_ops.go index fce4f46..708db0e 100644 --- a/internal/engine/patch_ops.go +++ b/internal/engine/patch_ops.go @@ -1630,5 +1630,11 @@ func (p *customDiffPatch) toJSONPatch(path string) []map[string]any { } func (p *customDiffPatch) summary(path string) string { + type summarizer interface { + Summary() string + } + if s, ok := p.patch.(summarizer); ok { + return s.Summary() + } return "CustomPatch" } diff --git a/internal/engine/patch_test.go b/internal/engine/patch_test.go index b2aafcf..0863a09 100644 --- a/internal/engine/patch_test.go +++ b/internal/engine/patch_test.go @@ -322,6 +322,26 @@ func TestCustomDiffPatch_ToJSONPatch(t *testing.T) { } } +func TestCustomDiffPatch_Summary(t *testing.T) { + t.Run("delegates to inner Summary", func(t *testing.T) { + custom := &customDiffPatch{patch: summarizerFunc("Text update")} + if got := custom.summary(""); got != "Text update" { + t.Errorf("expected %q, got %q", "Text update", got) + } + }) + + t.Run("falls back to CustomPatch when no Summary method", func(t *testing.T) { + custom := &customDiffPatch{patch: struct{}{}} + if got := custom.summary(""); got != "CustomPatch" { + t.Errorf("expected %q, got %q", "CustomPatch", got) + } + }) +} + +type summarizerFunc string + +func (s summarizerFunc) Summary() string { return string(s) } + func TestPatch_Summary(t *testing.T) { type Config struct { Name string