refactor(testgen): enforce stricter rules in Go test prompt

Update the test generation prompt for Go to prohibit monkey-patching, global variable reassignments, and reflect tricks. Mandate use of only idiomatic Go with real function calls, table-driven tests, and simple happy/error path coverage. Simplify unit and live test structures for better production readiness.
This commit is contained in:
Greg Gauthier 2026-03-03 19:25:33 +00:00
parent fd9fbee655
commit fe0e3478b9

View File

@ -206,26 +206,29 @@ func getTestPrompt(lang string) string {
case "Go": case "Go":
return `You are an expert Go test writer. return `You are an expert Go test writer.
Generate a COMPLETE, production-ready *_test.go file that follows this modern Unit + Live test pattern: Generate a COMPLETE, production-ready *_test.go file using ONLY idiomatic Go.
1. Fast unit test (always runs on "go test"): STRICT RULES NEVER VIOLATE THESE:
- NO monkey-patching: never assign to runtime.GOOS, exec.Command, os.Stdout, os.Exit, or ANY package-level func/var
- NO global variable reassignment
- NO reflect tricks for mocking
- Use ONLY real function calls + table-driven tests
- For os.Exit or stdout testing, use simple smoke tests or pipes (no reassignment)
- Prefer simple happy-path + error-path tests
1. Fast unit test:
func TestXXX_Unit(t *testing.T) { func TestXXX_Unit(t *testing.T) {
t.Parallel() t.Parallel()
t.Log("✓ Fast XXX unit test") t.Log("✓ Fast XXX unit test")
// table-driven, real calls only
// Use table-driven tests with real function calls
// Cover happy path + error cases
// NO monkey-patching: never assign to runtime.GOOS, exec.Command, os/exec.Command, or any exported var/func
// Use only standard testing.T (no testify unless the project already imports it)
} }
2. Optional live integration test (skipped by default): 2. Optional live test:
func TestXXX_Live(t *testing.T) { func TestXXX_Live(t *testing.T) {
if !testing.Short() { if !testing.Short() {
t.Skip("skipping live integration test. Run with:\n go test -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 integration test...") t.Log("🧪 Running live integration test...")
// Real calls only
} }
Exact rules: Exact rules: