From 4a196ddf1d944f757cd31b809a43f6912fdbaed2 Mon Sep 17 00:00:00 2001 From: Kynan Ware <47394200+BagToad@users.noreply.github.com> Date: Sun, 29 Mar 2026 17:48:09 -0600 Subject: [PATCH] test: add regression test for issue-only fields in FieldsToEditSurvey Verifies Type and Parent only appear in the interactive picker when Allowed is explicitly set. Prevents regression where issue-only fields leak into gh pr edit's interactive mode. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- pkg/cmd/pr/shared/survey_test.go | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/pkg/cmd/pr/shared/survey_test.go b/pkg/cmd/pr/shared/survey_test.go index 384e54895..5b84548a2 100644 --- a/pkg/cmd/pr/shared/survey_test.go +++ b/pkg/cmd/pr/shared/survey_test.go @@ -260,3 +260,38 @@ func TestTitleSurvey(t *testing.T) { }) } } + +func TestFieldsToEditSurvey_IssueOnlyFields(t *testing.T) { + t.Run("without Allowed flags omits Type and Parent", func(t *testing.T) { + pm := prompter.NewMockPrompter(t) + pm.RegisterMultiSelect("What would you like to edit?", []string{}, + // Type and Parent should NOT appear here + []string{"Title", "Body", "Assignees", "Labels", "Projects", "Milestone"}, + func(_ string, _, _ []string) ([]int, error) { + return []int{0}, nil + }) + + editable := &Editable{} + err := FieldsToEditSurvey(pm, editable) + require.NoError(t, err) + assert.True(t, editable.Title.Edited) + }) + + t.Run("with Allowed flags includes Type and Parent", func(t *testing.T) { + pm := prompter.NewMockPrompter(t) + pm.RegisterMultiSelect("What would you like to edit?", []string{}, + // Type and Parent should appear between Labels and Projects + []string{"Title", "Body", "Assignees", "Labels", "Type", "Parent", "Projects", "Milestone"}, + func(_ string, _, _ []string) ([]int, error) { + return []int{4, 5}, nil // select Type and Parent + }) + + editable := &Editable{} + editable.IssueType.Allowed = true + editable.Parent.Allowed = true + err := FieldsToEditSurvey(pm, editable) + require.NoError(t, err) + assert.True(t, editable.IssueType.Edited) + assert.True(t, editable.Parent.Edited) + }) +}