- 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
69 lines
1.7 KiB
Go
69 lines
1.7 KiB
Go
package cmd
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"gmgauthier.com/grokkit/internal/linter"
|
|
)
|
|
|
|
func TestBuildLintFixMessages(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
result *linter.LintResult
|
|
code string
|
|
wantLen int
|
|
sysCheck string
|
|
usrCheck []string
|
|
}{
|
|
{
|
|
name: "go file with issues",
|
|
result: &linter.LintResult{
|
|
Language: "Go",
|
|
LinterUsed: "golangci-lint",
|
|
Output: "line 5: unused variable x",
|
|
},
|
|
code: "package main\nfunc main() { x := 1 }",
|
|
wantLen: 2,
|
|
sysCheck: "code quality",
|
|
usrCheck: []string{"Go", "golangci-lint", "unused variable x", "package main"},
|
|
},
|
|
{
|
|
name: "python file with issues",
|
|
result: &linter.LintResult{
|
|
Language: "Python",
|
|
LinterUsed: "flake8",
|
|
Output: "E501 line too long",
|
|
},
|
|
code: "def foo():\n pass",
|
|
wantLen: 2,
|
|
sysCheck: "code quality",
|
|
usrCheck: []string{"Python", "flake8", "E501 line too long", "def foo"},
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
msgs := buildLintFixMessages(tt.result, tt.code)
|
|
|
|
if len(msgs) != tt.wantLen {
|
|
t.Fatalf("expected %d messages, got %d", tt.wantLen, 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)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|