diff --git a/internal/commands/prime.go b/internal/commands/prime.go index 322b7dcb..ee1ca10c 100644 --- a/internal/commands/prime.go +++ b/internal/commands/prime.go @@ -2,11 +2,10 @@ package commands import ( _ "embed" - "os" "text/template" - "github.com/spf13/cobra" "github.com/hmans/beans/pkg/config" + "github.com/spf13/cobra" ) //go:embed prompt.tmpl @@ -26,20 +25,6 @@ var primeCmd = &cobra.Command{ Long: `Outputs a prompt that primes AI coding agents on how to use the beans CLI to manage project issues.`, Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - // If no explicit path given, check if a beans project exists by searching - // upward for a .beans.yml config file - if beansPath == "" && configPath == "" { - cwd, err := os.Getwd() - if err != nil { - return nil // Silently exit on error - } - configFile, err := config.FindConfig(cwd) - if err != nil || configFile == "" { - // No config file found - silently exit - return nil - } - } - tmpl, err := template.New("prompt").Parse(agentPromptTemplate) if err != nil { return err @@ -52,7 +37,7 @@ var primeCmd = &cobra.Command{ Priorities: config.DefaultPriorities, } - return tmpl.Execute(os.Stdout, data) + return tmpl.Execute(cmd.OutOrStdout(), data) }, } diff --git a/internal/commands/prime_test.go b/internal/commands/prime_test.go new file mode 100644 index 00000000..22409d94 --- /dev/null +++ b/internal/commands/prime_test.go @@ -0,0 +1,45 @@ +package commands + +import ( + "bytes" + "os" + "strings" + "testing" +) + +func TestPrimeOutputsPromptWithoutBeansProject(t *testing.T) { + oldBeansPath, oldConfigPath := beansPath, configPath + beansPath, configPath = "", "" + t.Cleanup(func() { + beansPath, configPath = oldBeansPath, oldConfigPath + }) + + oldCwd, err := os.Getwd() + if err != nil { + t.Fatalf("Getwd() error = %v", err) + } + + tmpDir := t.TempDir() + if err := os.Chdir(tmpDir); err != nil { + t.Fatalf("Chdir(%q) error = %v", tmpDir, err) + } + t.Cleanup(func() { + _ = os.Chdir(oldCwd) + }) + + cmd := *primeCmd + var stdout bytes.Buffer + cmd.SetOut(&stdout) + + if err := cmd.RunE(&cmd, nil); err != nil { + t.Fatalf("prime RunE() error = %v", err) + } + + if stdout.Len() == 0 { + t.Fatal("expected prime to write prompt output, got empty output") + } + + if !strings.Contains(stdout.String(), "# Beans Usage Guide for Agents") { + t.Fatalf("expected prompt heading in output, got %q", stdout.String()) + } +}