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