refactor(testgen): refine Go test prompt to match scaffold style exactly
All checks were successful
CI / Test (push) Successful in 28s
CI / Lint (push) Successful in 18s
CI / Build (push) Successful in 15s

- Updated getTestPrompt for Go to enforce exact test structure: unit with t.Parallel() and logs, optional live with precise skip message.
- Ensured test name derivation, no unused imports, and pure output.
- Added example TestTestgenCmd_Unit and _Live in testgen_test.go to demonstrate the new pattern.
- Minor fixes to Python and C prompts for consistency.
This commit is contained in:
Greg Gauthier 2026-03-03 18:06:13 +00:00
parent d1eaa5234b
commit b82016028e
2 changed files with 43 additions and 22 deletions

View File

@ -194,31 +194,37 @@ func getTestPrompt(lang string) string {
case "Go": case "Go":
return `You are an expert Go test writer for the Grokkit project. return `You are an expert Go test writer for the Grokkit project.
Generate a COMPLETE, production-ready *_test.go file that follows this EXACT pattern: Generate a COMPLETE, production-ready *_test.go file that follows this EXACT pattern from cmd/scaffold_test.go:
1. Fast unit test(s) named TestXXX_Unit (or just TestXXX for the main test) 1. Fast unit test (always runs on "make test"):
- Zero API calls func TestXXX_Unit(t *testing.T) { // or just TestXXX if it fits better
- Uses t.TempDir() + os.Chdir with proper defer restore (and error logging) t.Parallel()
- Uses testify/assert and require t.Log("✓ Fast XXX unit test (no Grok API call)")
- Always runs instantly on "make test"
2. Optional live integration test named TestXXX_Live // Zero API calls / network
- Skipped by default with a clear t.Skip message showing the exact command to run it // Use t.TempDir() + os.Chdir with proper defer restore + error logging
- Only runs when the user passes -short // testify/assert + require
- Does real Grok API calls (exactly like the scaffold live test) // Table-driven where sensible
- Includes t.Log messages so it never looks hung // Cover main functions in the source file
}
Match the style of cmd/scaffold_test.go exactly: 2. Optional live integration test (skipped by default):
- Clear t.Logf messages func TestXXX_Live(t *testing.T) {
- Table-driven where it makes sense if !testing.Short() {
- Proper temp-dir isolation t.Skip("skipping live Grok integration test. Run with:\n go test ./cmd -run TestXXX_Live -short -v")
- No unused imports }
- defer restore of working directory with error logging t.Log("🧪 Running live Grok integration test...")
// Real Grok API calls via grok.NewClient()
// t.Logf messages so it never looks hung
}
Return ONLY the full Go test file. No explanations, no markdown, no backticks, no extra text whatsoever. Exact rules:
- Derive test name from source filename (e.g. client.go TestClient_Unit / TestClient_Live)
Current project style (match imports, helpers, error handling): - The XXX in the t.Skip command MUST match the live test function name you actually created
{{.Context}}` - Match Grokkit style exactly: imports, helpers, error handling, cwd restore
- 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.`
case "Python": case "Python":
return `You are a pytest expert. Generate COMPLETE pytest unit tests for the Python source. return `You are a pytest expert. Generate COMPLETE pytest unit tests for the Python source.
@ -235,7 +241,7 @@ Respond ONLY with full test_*.py file: imports, fixtures, tests. Pure Python tes
- Use Check suite: Suite, tcase_begin/end, ck_assert_* macros - Use Check suite: Suite, tcase_begin/end, ck_assert_* macros
- Cover ALL functions: happy/edge/error cases - Cover ALL functions: happy/edge/error cases
- Include #include <check.h> <minunit.h>? Use Check std. - Include #include <check.h>
- main() runner if needed. - main() runner if needed.
Respond ONLY full test_*.c: headers, suite funcs, main. Pure C.` Respond ONLY full test_*.c: headers, suite funcs, main. Pure C.`

View File

@ -5,6 +5,21 @@ import (
"testing" "testing"
) )
// New scaffold-style dual tests (fast unit + optional live)
// These are exactly the pattern used in scaffold_test.go
func TestTestgenCmd(t *testing.T) {
t.Parallel()
t.Log("✓ Fast testgen unit test (no Grok API call)")
}
func TestTestgenCmd_Live(t *testing.T) {
if !testing.Short() {
t.Skip("skipping live Grok integration test. Run with:\n go test ./cmd -run TestTestgenCmd_Live -short -v")
}
t.Log("🧪 Running live testgen integration test with real Grok API...")
// TODO: expand later (e.g. create temp source + call processTestgenFile + verify output)
}
func TestRemoveSourceComments(t *testing.T) { func TestRemoveSourceComments(t *testing.T) {
t.Parallel() t.Parallel()