refactor(testgen): update Go prompt to enforce unit + live test pattern
- Modify user message to reference new pattern in system prompt - Revise Go test prompt for exact unit/live structure matching scaffold_test.go - Update testgen_test.go to match new prompt prefix
This commit is contained in:
parent
0ef58cb5a4
commit
d1eaa5234b
@ -124,8 +124,7 @@ func processTestgenFile(client *grok.Client, filePath, lang, systemPrompt, model
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": fmt.Sprintf("Source file %s (%s):\n```%s\n%s\n```\n\nGenerate the language-appropriate test file.", filepath.Base(filePath), lang, codeLang, cleanSrc),
|
||||
},
|
||||
"content": fmt.Sprintf("Source file %s (%s):\n```%s\n%s\n```\n\nGenerate the test file using the new Unit + Live integration pattern described in the system prompt.", filepath.Base(filePath), lang, codeLang, cleanSrc)},
|
||||
}
|
||||
|
||||
color.Yellow("🤖 Generating tests for %s → %s...", filepath.Base(filePath), filepath.Base(testPath))
|
||||
@ -193,21 +192,33 @@ func removeSourceComments(content, lang string) string {
|
||||
func getTestPrompt(lang string) string {
|
||||
switch lang {
|
||||
case "Go":
|
||||
return `You are an expert Go testing specialist. Generate COMPLETE, production-ready unit tests for the provided Go source:
|
||||
return `You are an expert Go test writer for the Grokkit project.
|
||||
|
||||
- Table-driven with t.Run(subtest, func(t *testing.T)) and t.Parallel()
|
||||
- Match exact style of gmgauthier/grokkit/internal/version/version_test.go
|
||||
- Use t.Context() for ctx-aware tests
|
||||
- Modern Go 1.24+: slices.Contains/IndexFunc, maps.Keys, errors.Is/Join, any, etc.
|
||||
- Cover ALL public funcs/methods/fields: happy path, edges, errors, panics, zero values
|
||||
- Realistic inputs, no external deps/mocks unless code requires
|
||||
- func TestXxx(t *testing.T) { ... } only
|
||||
Generate a COMPLETE, production-ready *_test.go file that follows this EXACT pattern:
|
||||
|
||||
Respond with ONLY the full *_test.go file:
|
||||
- Correct package name (infer from code)
|
||||
- Necessary imports
|
||||
- No benchmarks unless obvious perf func
|
||||
- NO prose, explanations, markdown, code blocks, or extra text. Pure Go test file.`
|
||||
1. Fast unit test(s) named TestXXX_Unit (or just TestXXX for the main test)
|
||||
- Zero API calls
|
||||
- Uses t.TempDir() + os.Chdir with proper defer restore (and error logging)
|
||||
- Uses testify/assert and require
|
||||
- Always runs instantly on "make test"
|
||||
|
||||
2. Optional live integration test named TestXXX_Live
|
||||
- Skipped by default with a clear t.Skip message showing the exact command to run it
|
||||
- Only runs when the user passes -short
|
||||
- Does real Grok API calls (exactly like the scaffold live test)
|
||||
- Includes t.Log messages so it never looks hung
|
||||
|
||||
Match the style of cmd/scaffold_test.go exactly:
|
||||
- Clear t.Logf messages
|
||||
- Table-driven where it makes sense
|
||||
- Proper temp-dir isolation
|
||||
- No unused imports
|
||||
- defer restore of working directory with error logging
|
||||
|
||||
Return ONLY the full Go test file. No explanations, no markdown, no backticks, no extra text whatsoever.
|
||||
|
||||
Current project style (match imports, helpers, error handling):
|
||||
{{.Context}}`
|
||||
case "Python":
|
||||
return `You are a pytest expert. Generate COMPLETE pytest unit tests for the Python source.
|
||||
|
||||
|
||||
@ -93,7 +93,7 @@ func TestGetTestPrompt(t *testing.T) {
|
||||
lang string
|
||||
wantPrefix string
|
||||
}{
|
||||
{"Go", "You are an expert Go testing specialist."},
|
||||
{"Go", "You are an expert Go test writer for the Grokkit project."},
|
||||
{"Python", "You are a pytest expert."},
|
||||
{"C", "You are a C unit testing expert using Check framework."},
|
||||
{"C++", "You are a Google Test expert."},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user