diff --git a/cmd/testgen.go b/cmd/testgen.go index 8452368..b9855e1 100644 --- a/cmd/testgen.go +++ b/cmd/testgen.go @@ -32,6 +32,8 @@ Examples: modelFlag, _ := cmd.Flags().GetString("model") model := config.GetModel("testgen", modelFlag) + color.Cyan("๐Ÿ”ง testgen using model: %s (override with -m flag)", model) + logger.Info("testgen started", "num_files", len(args), "model", model, "auto_apply", yesFlag) client := grok.NewClient() @@ -129,9 +131,19 @@ func processTestgenFile(client *grok.Client, filePath, lang, systemPrompt, model color.Yellow("๐Ÿค– Generating tests for %s โ†’ %s...", filepath.Base(filePath), filepath.Base(testPath)) rawResponse := client.StreamSilent(messages, model) - newTestCode := grok.CleanCodeResponse(rawResponse) + // โ† NEW: detailed debugging when the model returns nothing useful + newTestCode := grok.CleanCodeResponse(rawResponse) if len(newTestCode) == 0 || strings.TrimSpace(newTestCode) == "" { + color.Red("โŒ Cleaned response is empty") + color.Red(" Raw AI response length : %d characters", len(rawResponse)) + if len(rawResponse) > 0 { + previewLen := 300 + if len(rawResponse) < previewLen { + previewLen = len(rawResponse) + } + color.Red(" Raw preview (first %d chars):\n%s", previewLen, rawResponse[:previewLen]) + } return fmt.Errorf("empty generation response") } @@ -197,15 +209,14 @@ func getTestPrompt(lang string) string { Generate a COMPLETE, production-ready *_test.go file that follows this modern Unit + Live test pattern: 1. Fast unit test (always runs on "go test"): - func TestXXX_Unit(t *testing.T) { // or TestCreateIniFile if it fits better + func TestXXX_Unit(t *testing.T) { t.Parallel() t.Log("โœ“ Fast XXX unit test") - // Zero external calls - // Use t.TempDir() + os.Chdir with proper defer restore + error logging - // 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 + // 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): @@ -214,16 +225,18 @@ Generate a COMPLETE, production-ready *_test.go file that follows this modern Un t.Skip("skipping live integration test. Run with:\n go test -run TestXXX_Live -short -v") } t.Log("๐Ÿงช Running live integration test...") - // Real behavior (file I/O, exec, API calls, etc.) - // Use t.Logf messages so it never looks hung + // Real calls only } Exact rules: -- 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 +- Derive test names from functions (e.g. isInstalled โ†’ TestIsInstalled_Unit) +- The XXX in t.Skip MUST exactly match the live function name - 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.` +- Keep tests simple and idiomatic Go +- Return ONLY the full test file. No explanations, no markdown, no backticks.` + + // Python/C/C++ prompts unchanged case "Python": return `You are a pytest expert. Generate COMPLETE pytest unit tests for the Python source.