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 {
switch lang {
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"):
func TestXXX_Unit(t *testing.T) { // or just TestXXX if it fits better
1. Fast unit test (always runs on "go test"):
func TestXXX_Unit(t *testing.T) { // or TestCreateIniFile if it fits better
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
// testify/assert + require
// Table-driven where sensible
// Cover main functions in the source file
// Use standard testing.T (add testify/assert only if the project already uses it)
// Cover happy path, errors, edge cases
// Table-driven where it makes sense
}
2. Optional live integration test (skipped by default):
func TestXXX_Live(t *testing.T) {
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...")
// Real Grok API calls via grok.NewClient()
// t.Logf messages so it never looks hung
t.Log("🧪 Running live integration test...")
// Real behavior (file I/O, exec, API calls, etc.)
// Use t.Logf messages so it never looks hung
}
Exact rules:
- Derive test name from source filename (e.g. client.go TestClient_Unit / TestClient_Live)
- The XXX in the t.Skip command MUST match the live test function name you actually created
- Match Grokkit style exactly: imports, helpers, error handling, cwd restore
- 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 exactly match the live test function name you created
- t.Parallel() on unit tests only
- NO unused imports
- 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
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."},
{"C", "You are a C unit testing expert using Check framework."},
{"C++", "You are a Google Test expert."},