grokkit/cmd/history_test.go

54 lines
1.3 KiB
Go
Raw Normal View History

package cmd
import (
"strings"
"testing"
)
func TestBuildHistoryMessages(t *testing.T) {
tests := []struct {
name string
log string
sysCheck string
usrCheck string
}{
{
name: "with recent commits",
log: "abc1234 feat: add new feature\ndef5678 fix: resolve bug",
sysCheck: "git history",
usrCheck: "abc1234 feat: add new feature",
},
{
name: "empty log",
log: "",
sysCheck: "git history",
usrCheck: "",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
msgs := buildHistoryMessages(tt.log)
if len(msgs) != 2 {
t.Fatalf("expected 2 messages, got %d", len(msgs))
}
if msgs[0]["role"] != "system" {
t.Errorf("first message role = %q, want %q", msgs[0]["role"], "system")
}
if msgs[1]["role"] != "user" {
t.Errorf("second message role = %q, want %q", msgs[1]["role"], "user")
}
if !strings.Contains(strings.ToLower(msgs[0]["content"]), strings.ToLower(tt.sysCheck)) {
t.Errorf("system prompt missing %q; got: %s", tt.sysCheck, msgs[0]["content"])
}
if tt.usrCheck != "" && !strings.Contains(msgs[1]["content"], tt.usrCheck) {
t.Errorf("user content missing %q", tt.usrCheck)
}
if msgs[1]["content"] != tt.log {
t.Errorf("user content = %q, want %q", msgs[1]["content"], tt.log)
}
})
}
}