feat: 提交详情能看 diff,也能丢给 AI 审这一次改动。文件检查可单独排除路径,TODO 只认大写,避免把 todo 表和模块当成待办标记。
热力图按容器宽度铺满一年,不再横向滚动。托盘右键换成可换皮肤的弹层;更新下载显示进度,退出后再由脚本拉起安装器,避免还占着 exe。
This commit is contained in:
68
service/git_patch_test.go
Normal file
68
service/git_patch_test.go
Normal file
@@ -0,0 +1,68 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
"view/model"
|
||||
)
|
||||
|
||||
func TestParseCommitPatches(t *testing.T) {
|
||||
raw := `diff --git a/main.go b/main.go
|
||||
index 111..222 100644
|
||||
--- a/main.go
|
||||
+++ b/main.go
|
||||
@@ -1,2 +1,3 @@
|
||||
package main
|
||||
+// feature
|
||||
`
|
||||
got := parseCommitPatches(raw)
|
||||
p, ok := got["main.go"]
|
||||
if !ok || p.Binary || p.Text == "" {
|
||||
t.Fatalf("patch=%#v", got)
|
||||
}
|
||||
if !strings.Contains(p.Text, "+// feature") {
|
||||
t.Fatalf("missing added line: %q", p.Text)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseCommitPatchesBinaryAndDelete(t *testing.T) {
|
||||
raw := `diff --git a/logo.png b/logo.png
|
||||
index 111..222 100644
|
||||
Binary files a/logo.png and b/logo.png differ
|
||||
diff --git a/gone.go b/gone.go
|
||||
deleted file mode 100644
|
||||
index 111..000
|
||||
--- a/gone.go
|
||||
+++ /dev/null
|
||||
@@ -1 +0,0 @@
|
||||
-package gone
|
||||
`
|
||||
got := parseCommitPatches(raw)
|
||||
if !got["logo.png"].Binary {
|
||||
t.Fatalf("binary not marked: %#v", got["logo.png"])
|
||||
}
|
||||
if got["gone.go"].Text == "" || got["gone.go"].Binary {
|
||||
t.Fatalf("deleted file patch=%#v", got["gone.go"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormatCommitDiffForAI(t *testing.T) {
|
||||
d := model.GitCommitDetail{
|
||||
GitCommit: model.GitCommit{Hash: "abc123", Author: "Ann", Email: "a@b.c", Date: "2026-08-19", Message: "add feature", Added: 2, Deleted: 1},
|
||||
Files: []model.GitFileChange{
|
||||
{Path: "main.go", Status: "modified", Added: 2, Deleted: 1, Patch: "+// feature\n-old"},
|
||||
{Path: "logo.png", Status: "modified", Binary: true},
|
||||
},
|
||||
}
|
||||
text := FormatCommitDiffForAI(d, 0)
|
||||
if !strings.Contains(text, "add feature") || !strings.Contains(text, "main.go") || !strings.Contains(text, "+// feature") {
|
||||
t.Fatalf("unexpected prompt:\n%s", text)
|
||||
}
|
||||
if !strings.Contains(text, "[binary]") {
|
||||
t.Fatal("binary file should be listed")
|
||||
}
|
||||
tiny := FormatCommitDiffForAI(d, 80)
|
||||
if !strings.Contains(tiny, "因过长未纳入") && !strings.Contains(tiny, "add feature") {
|
||||
t.Fatalf("truncated prompt:\n%s", tiny)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user