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

Code before:
		name             string
		stubs            func(*httpmock.Registry)
		baseRepoFunc     func() (ghrepo.Interface, error)
		problemStatement string
		wantStdout       string
		wantStdErr       string
		wantErr          string
	}{
		{
			name:             "get job API failure surfaces error",
			baseRepoFunc:     func() (ghrepo.Interface, error) { return ghrepo.New("OWNER", "REPO"), nil },
			problemStatement: "Do the thing",
			stubs: func(reg *httpmock.Registry) {
				reg.Register(
					httpmock.WithHost(httpmock.REST("POST", "agents/swe/v1/jobs/OWNER/REPO"), "api.githubcopilot.com"),
					httpmock.StatusStringResponse(201, createdJobTimeoutResponse),
				)
				reg.Register(
					httpmock.WithHost(httpmock.REST("GET", "agents/swe/v1/jobs/OWNER/REPO/jobABC"), "api.githubcopilot.com"),
					httpmock.StatusStringResponse(500, `{"error":{"message":"internal server error"}}`),
				)
			},
			wantStdErr: "failed to get job: 500 Internal Server Error\n",
			wantStdout: "job jobABC queued. View progress: https://github.com/copilot/agents\n",
		},
		{
			name:             "success with immediate PR",
			baseRepoFunc:     func() (ghrepo.Interface, error) { return ghrepo.New("OWNER", "REPO"), nil },
			problemStatement: "Do the thing",
			stubs: func(reg *httpmock.Registry) {
				reg.Register(
					httpmock.WithHost(httpmock.REST("POST", "agents/swe/v1/jobs/OWNER/REPO"), "api.githubcopilot.com"),
					httpmock.StatusStringResponse(201, createdJobSuccessWithPRResponse),
				)
			},
			wantStdout: "https://github.com/OWNER/REPO/pull/42/agent-sessions/sess1\n",
		},
		{
			name:             "success with delayed PR after polling",
			baseRepoFunc:     func() (ghrepo.Interface, error) { return ghrepo.New("OWNER", "REPO"), nil },
			problemStatement: "Do the thing",
			stubs: func(reg *httpmock.Registry) {
				reg.Register(
					httpmock.WithHost(httpmock.REST("POST", "agents/swe/v1/jobs/OWNER/REPO"), "api.githubcopilot.com"),
					httpmock.StatusStringResponse(201, createdJobSuccessResponse),
				)
				reg.Register(
					httpmock.WithHost(httpmock.REST("GET", "agents/swe/v1/jobs/OWNER/REPO/job123"), "api.githubcopilot.com"),
					httpmock.StringResponse(`{"job_id":"job123","pull_request":{"id":101,"number":42}}`),
				)
			},

Review comment (suggestion):
Maybe simpler like this:

```suggestion
						require.True(t, ok, "expected pull_request object in payload")
						assert.Equal(t, "refs/heads/feature", prRaw["base_ref"], "expected pull_request.base_ref to be 'refs/heads/feature'")
						assert.Equal(t, "Do the thing", payload["problem_statement"], "unexpected problem_statement value")
```

Code after:
		baseRepoFunc     func() (ghrepo.Interface, error)
		problemStatement string
		baseBranch       string
		wantStdout       string
		wantStdErr       string
		wantErr          string
	}{
		{
			name:             "base branch included in create payload",
			baseRepoFunc:     func() (ghrepo.Interface, error) { return ghrepo.New("OWNER", "REPO"), nil },
			problemStatement: "Do the thing",
			baseBranch:       "feature",
			stubs: func(reg *httpmock.Registry) {
				reg.Register(
					httpmock.WithHost(httpmock.REST("POST", "agents/swe/v1/jobs/OWNER/REPO"), "api.githubcopilot.com"),
					httpmock.RESTPayload(201, createdJobSuccessWithPRResponse, func(payload map[string]interface{}) {
						prRaw, ok := payload["pull_request"].(map[string]interface{})
						if !ok {
							require.FailNow(t, "expected pull_request object in payload")
						}
						if prRaw["base_ref"] != "refs/heads/feature" {
							require.FailNow(t, "expected pull_request.base_ref to be 'refs/heads/feature'")
						}
						if payload["problem_statement"] != "Do the thing" {
							require.FailNow(t, "unexpected problem_statement value")
						}
					}),
				)
			},
			wantStdout: "https://github.com/OWNER/REPO/pull/42/agent-sessions/sess1\n",
		},
		{
			name:             "get job API failure surfaces error",
			baseRepoFunc:     func() (ghrepo.Interface, error) { return ghrepo.New("OWNER", "REPO"), nil },
			problemStatement: "Do the thing",
			stubs: func(reg *httpmock.Registry) {
				reg.Register(
					httpmock.WithHost(httpmock.REST("POST", "agents/swe/v1/jobs/OWNER/REPO"), "api.githubcopilot.com"),
					httpmock.StatusStringResponse(201, createdJobTimeoutResponse),
				)
				reg.Register(
					httpmock.WithHost(httpmock.REST("GET", "agents/swe/v1/jobs/OWNER/REPO/jobABC"), "api.githubcopilot.com"),
					httpmock.StatusStringResponse(500, `{"error":{"message":"internal server error"}}`),
				)
			},
			wantStdErr: "failed to get job: 500 Internal Server Error\n",
			wantStdout: "job jobABC queued. View progress: https://github.com/copilot/agents\n",
		},
		{
			name:             "success with immediate PR",
			baseRepoFunc:     func() (ghrepo.Interface, error) { return ghrepo.New("OWNER", "REPO"), nil },