diff --git a/internal/cmd/credentialcmd/credentialcmd.go b/internal/cmd/credentialcmd/credentialcmd.go index cded1ee..3f5a7b9 100644 --- a/internal/cmd/credentialcmd/credentialcmd.go +++ b/internal/cmd/credentialcmd/credentialcmd.go @@ -1574,8 +1574,8 @@ func editInteractiveInitSecretsManagement(_ *cobra.Command, opts *root.Options, func (p huhInitMenuPrompter) ChooseAction(prompt initMenuPrompt) (initMenuAction, error) { action := initMenuInitialAction(prompt) options := []huh.Option[initMenuAction]{ - huh.NewOption(fmt.Sprintf("Configure reviewer entities (%d)", prompt.ReviewerEntityCount), initMenuActionReviewerEntities), huh.NewOption(fmt.Sprintf("Configure LLM runtimes (%d)", prompt.LLMRuntimeCount), initMenuActionLLMRuntimes), + huh.NewOption(fmt.Sprintf("Configure reviewer entities (%d)", prompt.ReviewerEntityCount), initMenuActionReviewerEntities), huh.NewOption(fmt.Sprintf("Configure review profiles (%d)", prompt.ReviewProfileCount), initMenuActionReviewProfiles), huh.NewOption("Configure global settings", initMenuActionGlobalSettings), huh.NewOption("Configure secrets management", initMenuActionSecretsManagement), @@ -1616,12 +1616,12 @@ func (p huhInitMenuPrompter) ChooseAction(prompt initMenuPrompt) (initMenuAction } func initMenuInitialAction(prompt initMenuPrompt) initMenuAction { - if prompt.CanConfigureReviewer { - return initMenuActionReviewerEntities - } if prompt.CanConfigureLLM { return initMenuActionLLMRuntimes } + if prompt.CanConfigureReviewer { + return initMenuActionReviewerEntities + } return initMenuActionReviewProfiles } diff --git a/internal/cmd/credentialcmd/credentialcmd_test.go b/internal/cmd/credentialcmd/credentialcmd_test.go index c6bcca0..305e5d2 100644 --- a/internal/cmd/credentialcmd/credentialcmd_test.go +++ b/internal/cmd/credentialcmd/credentialcmd_test.go @@ -11325,8 +11325,8 @@ func TestHuhInitMenuPrompterAccessibleShowsMenuEntries(t *testing.T) { } out := stderr.String() for _, want := range []string{ - "Configure reviewer entities (3)", "Configure LLM runtimes (2)", + "Configure reviewer entities (3)", "Configure review profiles (1)", "Configure global settings", "Configure secrets management", @@ -11344,11 +11344,13 @@ func TestHuhInitMenuPrompterAccessibleShowsMenuEntries(t *testing.T) { t.Fatalf("stderr = %q, want temporary v2 menu item removed", out) } assertContentOrder(t, out, - "Configure reviewer entities (3)", "Configure LLM runtimes (2)", + "Configure reviewer entities (3)", "Configure review profiles (1)", "Configure global settings", "Configure secrets management", + "Commit staged changes and exit", + "Discard staged changes and exit", ) } @@ -11396,8 +11398,25 @@ func TestHuhInitMenuPrompterDefaultStartsAtTopWhenProfileIsActive(t *testing.T) if err != nil { t.Fatalf("ChooseAction: %v", err) } + if action != initMenuActionLLMRuntimes { + t.Fatalf("action = %q, want LLM runtimes as first active-workspace configuration item", action) + } +} + +func TestInitMenuInitialActionFallsBackToReviewerWhenLLMDisabled(t *testing.T) { + action := initMenuInitialAction(initMenuPrompt{ + HasWorkspace: true, + CanConfigureReviewer: true, + }) if action != initMenuActionReviewerEntities { - t.Fatalf("action = %q, want first main-menu configuration item", action) + t.Fatalf("action = %q, want reviewer entities when LLM runtimes are disabled", action) + } +} + +func TestInitMenuInitialActionStartsAtReviewProfilesBeforeWorkspace(t *testing.T) { + action := initMenuInitialAction(initMenuPrompt{}) + if action != initMenuActionReviewProfiles { + t.Fatalf("action = %q, want review profiles before workspace-dependent actions are enabled", action) } } @@ -11447,7 +11466,7 @@ func TestHuhInitMenuPrompterAccessibleRejectsDisabledLLMUntilProfileExists(t *te var stderr bytes.Buffer prompter := huhInitMenuPrompter{ stdin: strings.NewReader(strings.Join([]string{ - "2", // Configure LLM runtimes (disabled) + "1", // Configure LLM runtimes (disabled) "7", // Discard staged changes and exit "", }, "\n")), @@ -11465,6 +11484,29 @@ func TestHuhInitMenuPrompterAccessibleRejectsDisabledLLMUntilProfileExists(t *te } } +func TestHuhInitMenuPrompterAccessibleRejectsDisabledReviewerUntilProfileExists(t *testing.T) { + t.Setenv("TERM", "dumb") + var stderr bytes.Buffer + prompter := huhInitMenuPrompter{ + stdin: strings.NewReader(strings.Join([]string{ + "2", // Configure reviewer entities (disabled) + "7", // Discard staged changes and exit + "", + }, "\n")), + stderr: &stderr, + } + action, err := prompter.ChooseAction(initMenuPrompt{}) + if err != nil { + t.Fatalf("ChooseAction: %v", err) + } + if action == initMenuActionReviewerEntities { + t.Fatalf("action = %q, want disabled reviewer selection to be rejected", action) + } + if !strings.Contains(stderr.String(), "configure a review profile before editing reviewer entities") { + t.Fatalf("stderr = %q, want disabled-reviewer validation message", stderr.String()) + } +} + func TestHuhInitMenuPrompterAccessibleSelectsReviewProfiles(t *testing.T) { t.Setenv("TERM", "dumb") var stderr bytes.Buffer