From b82016028e6e64e4417f59ce93bd6bfe342c5d92 Mon Sep 17 00:00:00 2001 From: Greg Gauthier Date: Tue, 3 Mar 2026 18:06:13 +0000 Subject: [PATCH] refactor(testgen): refine Go test prompt to match scaffold style exactly - 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. --- cmd/testgen.go | 50 +++++++++++++++++++++++++-------------------- cmd/testgen_test.go | 15 ++++++++++++++ 2 files changed, 43 insertions(+), 22 deletions(-) diff --git a/cmd/testgen.go b/cmd/testgen.go index 24f58bf..73eb6b3 100644 --- a/cmd/testgen.go +++ b/cmd/testgen.go @@ -194,31 +194,37 @@ func getTestPrompt(lang string) string { case "Go": 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) - - 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" +1. Fast unit test (always runs on "make test"): + func TestXXX_Unit(t *testing.T) { // or just TestXXX if it fits better + t.Parallel() + t.Log("โœ“ Fast XXX unit test (no Grok API call)") -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 + // Zero API calls / network + // 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 + } -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 +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.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. - -Current project style (match imports, helpers, error handling): -{{.Context}}` +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 +- 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": 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 - Cover ALL functions: happy/edge/error cases -- Include #include ? Use Check std. +- Include #include - main() runner if needed. Respond ONLY full test_*.c: headers, suite funcs, main. Pure C.` diff --git a/cmd/testgen_test.go b/cmd/testgen_test.go index 6004bed..b0f1449 100644 --- a/cmd/testgen_test.go +++ b/cmd/testgen_test.go @@ -5,6 +5,21 @@ import ( "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) { t.Parallel()