grokkit/cmd/review_test.go
Greg Gauthier 0aa806be70
Some checks failed
CI / Test (push) Failing after 25s
CI / Lint (push) Has been skipped
CI / Build (push) Has been skipped
feat(cmd): add AI documentation generation and command tests
- Implemented `grokkit docs` command for generating language-specific documentation comments (godoc, PEP 257, Doxygen, etc.) with previews, backups, and auto-apply option
- Extracted message builder functions for commit, history, pr-describe, and review commands
- Added comprehensive unit tests for all command message builders (commit_test.go, docs_test.go, history_test.go, lint_test.go, prdescribe_test.go, review_test.go)
- Enforced 70% test coverage threshold in CI workflow
- Added .golangci.yml configuration with linters like govet, errcheck, staticcheck
- Updated Makefile to include -race in tests and add help target
- Updated README.md with new docs command details, workflows, and quality features
- Added .claude/ to .gitignore
- Configured default model for docs command in config.go
2026-03-02 20:13:50 +00:00

56 lines
1.3 KiB
Go

package cmd
import (
"strings"
"testing"
)
func TestBuildReviewMessages(t *testing.T) {
tests := []struct {
name string
status string
diff string
sysCheck string
usrCheck []string
}{
{
name: "with status and diff",
status: "M main.go",
diff: "diff --git a/main.go b/main.go\n+func foo() {}",
sysCheck: "code reviewer",
usrCheck: []string{"M main.go", "diff --git a/main.go"},
},
{
name: "empty diff",
status: "",
diff: "",
sysCheck: "code reviewer",
usrCheck: []string{"Git status:", "Git diff:"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
msgs := buildReviewMessages(tt.status, tt.diff)
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"])
}
for _, check := range tt.usrCheck {
if !strings.Contains(msgs[1]["content"], check) {
t.Errorf("user prompt missing %q", check)
}
}
})
}
}