aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/email/patch_test.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2026-01-29 13:06:50 +0100
committerDmitry Vyukov <dvyukov@google.com>2026-01-30 11:03:40 +0000
commit6adbdcbe0a33024c6e70ffccd1c76f62a0179098 (patch)
treef5d07618387f400a5b56517282e0dc032d316820 /pkg/email/patch_test.go
parent5f1dd856122a81d1cf6bcad71da663f42484f321 (diff)
pkg/email: add patch FormatPatch function
Fixes #6673
Diffstat (limited to 'pkg/email/patch_test.go')
-rw-r--r--pkg/email/patch_test.go103
1 files changed, 103 insertions, 0 deletions
diff --git a/pkg/email/patch_test.go b/pkg/email/patch_test.go
index cffdebaec..2bc391103 100644
--- a/pkg/email/patch_test.go
+++ b/pkg/email/patch_test.go
@@ -4,7 +4,11 @@
package email
import (
+ "fmt"
"testing"
+
+ "github.com/google/syzkaller/pkg/aflow/ai"
+ "github.com/stretchr/testify/assert"
)
func TestParsePatch(t *testing.T) {
@@ -517,3 +521,102 @@ Diff
title: "test empty patch",
},
}
+
+func TestFormatPatch(t *testing.T) {
+ type Test struct {
+ description string
+ diff string
+ baseCommit string
+ authors []string
+ recipients []ai.Recipient
+ want string
+ }
+ tests := []Test{
+ {
+ description: `mm: fix something
+
+Something was broken. This fixes it.
+
+`,
+ diff: `diff --git a/mm/slub.c b/mm/slub.c
+index f77b7407c51b..9320daf2018f 100644
+--- a/mm/slub.c
++++ b/mm/slub.c
+@@ -250,7 +250,7 @@ struct partial_context {
+
+ static inline bool kmem_cache_debug(struct kmem_cache *s)
+ {
+- return kmem_cache_debug_flags(s, SLAB_DEBUG_FLAGS);
++ return kmem_cache_debug_flags(s, 0);
+ }
+`,
+ baseCommit: "f5e343a447510a663fbf6215584a9bf8e03bfd5c",
+ authors: []string{"syzbot@kernel.org"},
+ recipients: []ai.Recipient{
+ {Name: "Foo Bar", Email: "foobar@test.com", To: true},
+ {Email: "linux-kernel@vger.kernel.org"},
+ },
+ want: `mm: fix something
+
+Something was broken. This fixes it.
+
+Signed-off-by: syzbot@kernel.org
+To: "Foo Bar" <foobar@test.com>
+Cc: <linux-kernel@vger.kernel.org>
+---
+This patch was generated by Google Gemini LLM model.
+It was pre-reviewed and Signed-off-by a human, but please review carefully.
+
+diff --git a/mm/slub.c b/mm/slub.c
+index f77b7407c51b..9320daf2018f 100644
+--- a/mm/slub.c
++++ b/mm/slub.c
+@@ -250,7 +250,7 @@ struct partial_context {
+
+ static inline bool kmem_cache_debug(struct kmem_cache *s)
+ {
+- return kmem_cache_debug_flags(s, SLAB_DEBUG_FLAGS);
++ return kmem_cache_debug_flags(s, 0);
+ }
+
+base-commit: f5e343a447510a663fbf6215584a9bf8e03bfd5c
+`,
+ },
+
+ {
+ description: `mm: fix something
+
+Something was broken. This fixes it.
+
+`,
+ diff: `diff --git a/mm/slub.c b/mm/slub.c
+`,
+ baseCommit: "f5e343a447510a663fbf6215584a9bf8e03bfd5c",
+ authors: []string{"syzbot@kernel.org", `"Kernel Dev" <dev@kernel.org>`},
+ recipients: []ai.Recipient{
+ {Name: "Foo Bar", Email: "foobar@test.com", To: true},
+ },
+ want: `mm: fix something
+
+Something was broken. This fixes it.
+
+Signed-off-by: syzbot@kernel.org
+Signed-off-by: "Kernel Dev" <dev@kernel.org>
+To: "Foo Bar" <foobar@test.com>
+---
+This patch was generated by Google Gemini LLM model.
+It was pre-reviewed and Signed-off-by a human, but please review carefully.
+
+diff --git a/mm/slub.c b/mm/slub.c
+
+base-commit: f5e343a447510a663fbf6215584a9bf8e03bfd5c
+`,
+ },
+ }
+ for i, test := range tests {
+ t.Run(fmt.Sprint(i), func(t *testing.T) {
+ got := FormatPatch(test.description, test.diff, test.baseCommit, test.authors, test.recipients)
+ assert.Equal(t, test.want, got)
+ })
+ }
+}