refactor(testgen): generalize Go test generation prompt
All checks were successful
CI / Test (push) Successful in 28s
CI / Lint (push) Successful in 19s
CI / Build (push) Successful in 15s

- Remove Grokkit-specific references to make the prompt more versatile.
- Update unit and live test patterns for broader applicability, including standard testing.T usage.
- Adjust test name derivation and skip messages for consistency.
- Sync test assertions in testgen_test.go with the updated prompt.
This commit is contained in:
Greg Gauthier 2026-03-03 18:27:49 +00:00
parent b82016028e
commit b76aa6f800
2 changed files with 16 additions and 17 deletions

View File

@ -192,36 +192,35 @@ func removeSourceComments(content, lang string) string {
func getTestPrompt(lang string) string { func getTestPrompt(lang string) string {
switch lang { switch lang {
case "Go": case "Go":
return `You are an expert Go test writer for the Grokkit project. return `You are an expert Go test writer.
Generate a COMPLETE, production-ready *_test.go file that follows this EXACT pattern from cmd/scaffold_test.go: Generate a COMPLETE, production-ready *_test.go file that follows this modern Unit + Live test pattern:
1. Fast unit test (always runs on "make test"): 1. Fast unit test (always runs on "go test"):
func TestXXX_Unit(t *testing.T) { // or just TestXXX if it fits better func TestXXX_Unit(t *testing.T) { // or TestCreateIniFile if it fits better
t.Parallel() t.Parallel()
t.Log("✓ Fast XXX unit test (no Grok API call)") t.Log("✓ Fast XXX unit test")
// Zero API calls / network // Zero external calls
// Use t.TempDir() + os.Chdir with proper defer restore + error logging // Use t.TempDir() + os.Chdir with proper defer restore + error logging
// testify/assert + require // Use standard testing.T (add testify/assert only if the project already uses it)
// Table-driven where sensible // Cover happy path, errors, edge cases
// Cover main functions in the source file // Table-driven where it makes sense
} }
2. Optional live integration test (skipped by default): 2. Optional live integration test (skipped by default):
func TestXXX_Live(t *testing.T) { func TestXXX_Live(t *testing.T) {
if !testing.Short() { if !testing.Short() {
t.Skip("skipping live Grok integration test. Run with:\n go test ./cmd -run TestXXX_Live -short -v") t.Skip("skipping live integration test. Run with:\n go test -run TestXXX_Live -short -v")
} }
t.Log("🧪 Running live Grok integration test...") t.Log("🧪 Running live integration test...")
// Real Grok API calls via grok.NewClient() // Real behavior (file I/O, exec, API calls, etc.)
// t.Logf messages so it never looks hung // Use t.Logf messages so it never looks hung
} }
Exact rules: Exact rules:
- Derive test name from source filename (e.g. client.go TestClient_Unit / TestClient_Live) - Derive sensible test names from the source filename and functions (e.g. filer.go TestCreateIniFile_Unit / TestCreateIniFile_Live)
- The XXX in the t.Skip command MUST match the live test function name you actually created - The XXX in the t.Skip command MUST exactly match the live test function name you created
- Match Grokkit style exactly: imports, helpers, error handling, cwd restore
- t.Parallel() on unit tests only - t.Parallel() on unit tests only
- NO unused imports - NO unused imports
- Return ONLY the full test file. No explanations, no markdown, no backticks, no extra text whatsoever.` - Return ONLY the full test file. No explanations, no markdown, no backticks, no extra text whatsoever.`

View File

@ -108,7 +108,7 @@ func TestGetTestPrompt(t *testing.T) {
lang string lang string
wantPrefix string wantPrefix string
}{ }{
{"Go", "You are an expert Go test writer for the Grokkit project."}, {"Go", "You are an expert Go test writer."}, // ← updated to match the new generalized prompt
{"Python", "You are a pytest expert."}, {"Python", "You are a pytest expert."},
{"C", "You are a C unit testing expert using Check framework."}, {"C", "You are a C unit testing expert using Check framework."},
{"C++", "You are a Google Test expert."}, {"C++", "You are a Google Test expert."},