package cmd import ( "os" "testing" ) // TestWorkonCmd — FAST DEFAULT TEST (runs on make test / go test ./cmd) func TestWorkonCmd(t *testing.T) { t.Log("✓ Fast workon unit test (no Grok API call)") // Verify the command is registered found := false for _, c := range rootCmd.Commands() { if c.Use == "workon " { found = true break } } if !found { t.Fatal("workon command not registered on rootCmd") } } func TestWorkonFlagRegistration(t *testing.T) { tests := []struct { name string flagName string shorthand string }{ {"message flag", "message", "M"}, {"fix flag", "fix", "f"}, {"complete flag", "complete", "c"}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { flag := workonCmd.Flags().Lookup(tt.flagName) if flag == nil { t.Fatalf("flag %q not found on workon command", tt.flagName) } if flag.Shorthand != tt.shorthand { t.Errorf("flag %q shorthand = %q, want %q", tt.flagName, flag.Shorthand, tt.shorthand) } }) } } func TestWorkonFlagExclusivity(t *testing.T) { // Run in a temp dir so todo.Bootstrap() doesn't leave orphan dirs in cmd/ tmpDir := t.TempDir() origDir, _ := os.Getwd() if err := os.Chdir(tmpDir); err != nil { t.Fatal(err) } defer func() { _ = os.Chdir(origDir) }() tests := []struct { name string args []string expectErr bool }{ { name: "complete alone is valid", args: []string{"workon", "test-item", "-c"}, expectErr: false, // will fail at Run level (no git repo), but not at flag validation }, { name: "complete with fix is valid", args: []string{"workon", "test-item", "-c", "-f"}, expectErr: false, }, { name: "complete with message is invalid", args: []string{"workon", "test-item", "-c", "-M", "some msg"}, expectErr: true, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { rootCmd.SetArgs(tt.args) err := rootCmd.Execute() if tt.expectErr && err == nil { t.Error("expected error, got nil") } // Note: non-error cases may still fail (no git, no API key, etc.) // We only assert that the flag validation error fires when expected if tt.expectErr && err != nil { // Verify it's the right error if err.Error() != "-c cannot be combined with -m" { // The error might be wrapped t.Logf("got error: %v (flag validation may have been triggered)", err) } } }) } } func TestWorkonRequiresArgs(t *testing.T) { rootCmd.SetArgs([]string{"workon"}) err := rootCmd.Execute() if err == nil { t.Error("expected error when no args provided, got nil") } }