Repository: cli/cli
File: pkg/cmd/agent-task/create/create_test.go (Go)

Code before:
					require.Equal(t, "REPO", repo)
					require.Equal(t, "Enter the task description+From editor", problemStatement)
					return &createdJobSuccessWithPR, nil
				}
			},
			wantStdout: "https://github.com/OWNER/REPO/pull/42/agent-sessions/sess1\n",
		},
		{
			name: "interactively rejecting confirmation prompt aborts task creation",
			opts: &CreateOptions{
				BaseRepo:         func() (ghrepo.Interface, error) { return ghrepo.New("OWNER", "REPO"), nil },
				ProblemStatement: "",
				Prompter: &prompter.PrompterMock{
					MarkdownEditorFunc: func(prompt, defaultValue string, blankAllowed bool) (string, error) {
						require.Equal(t, "Enter the task description", prompt)
						return "From editor", nil
					},
					ConfirmFunc: func(message string, defaultValue bool) (bool, error) {
						require.Equal(t, "Submit agent task", message)
						return false, nil
					},
				},
			},
			isTTY:      true,
			wantErr:    "SilentError",
			wantStdErr: "",
		},
		{
			name:  "interactively entering task description with editor, no file",
			isTTY: true,
			opts: &CreateOptions{
				BaseRepo: func() (ghrepo.Interface, error) {
					return ghrepo.New("OWNER", "REPO"), nil
				},
				ProblemStatement: "",
				Prompter: &prompter.PrompterMock{
					MarkdownEditorFunc: func(prompt, defaultValue string, blankAllowed bool) (string, error) {
						require.Equal(t, "Enter the task description", prompt)
						return "From editor", nil
					},
					ConfirmFunc: func(message string, defaultValue bool) (bool, error) {
						require.Equal(t, "Submit agent task", message)
						return true, nil
					},
				},
			},
			capiStubs: func(t *testing.T, m *capi.CapiClientMock) {
				m.CreateJobFunc = func(ctx context.Context, owner, repo, problemStatement, baseBranch string) (*capi.Job, error) {
					require.Equal(t, "From editor", problemStatement)
					return &createdJobSuccessWithPR, nil
				}

Review comment (suggestion):
What we want here to is to make sure error is the right type. I suggest adding a `wantErrIs` of type `error`, and assert it using `require.ErrorIs` function. We have already done that in `capi_test.go`:

https://github.com/cli/cli/blob/deee0c61eda2a897dc25faa21a2828611d5748e9/pkg/cmd/agent-task/capi/sessions_test.go#L1488-L1492

https://github.com/cli/cli/blob/deee0c61eda2a897dc25faa21a2828611d5748e9/pkg/cmd/agent-task/capi/sessions_test.go#L1729-L1737

Code after:
				ProblemStatement: "",
				Prompter: &prompter.PrompterMock{
					MarkdownEditorFunc: func(prompt, defaultValue string, blankAllowed bool) (string, error) {
						require.Equal(t, "Enter the task description", prompt)
						return "From editor", nil
					},
					ConfirmFunc: func(message string, defaultValue bool) (bool, error) {
						require.Equal(t, "Submit agent task", message)
						return true, nil
					},
				},
			},
			capiStubs: func(t *testing.T, m *capi.CapiClientMock) {
				m.CreateJobFunc = func(ctx context.Context, owner, repo, problemStatement, baseBranch string) (*capi.Job, error) {
					require.Equal(t, "From editor", problemStatement)
					return &createdJobSuccessWithPR, nil
				}
			},
			wantStdout: "https://github.com/OWNER/REPO/pull/42/agent-sessions/sess1\n",
		},
		{
			name:  "empty task description from interactive prompt returns error",
			isTTY: true,
			opts: &CreateOptions{
				BaseRepo: func() (ghrepo.Interface, error) {
					return ghrepo.New("OWNER", "REPO"), nil
				},
				Prompter: &prompter.PrompterMock{
					MarkdownEditorFunc: func(prompt, defaultValue string, blankAllowed bool) (string, error) {
						return "   ", nil
					},
				},
			},
			wantErr:    "SilentError",
			wantErrIs:  cmdutil.SilentError,
			wantStdErr: "a task description is required.\n",
		},
		{
			name: "problem statement loaded from file non-interactively doesn't prompt or return error",
			opts: &CreateOptions{
				BaseRepo:             func() (ghrepo.Interface, error) { return ghrepo.New("OWNER", "REPO"), nil },
				ProblemStatement:     "",
				ProblemStatementFile: taskDescFile,
			},
			capiStubs: func(t *testing.T, m *capi.CapiClientMock) {
				m.CreateJobFunc = func(ctx context.Context, owner, repo, problemStatement, baseBranch string) (*capi.Job, error) {
					require.Equal(t, "OWNER", owner)
					require.Equal(t, "REPO", repo)
					require.Equal(t, "task description from file", problemStatement)
					return &createdJobSuccessWithPR, nil
				}