MCPcopy Index your code
hub / github.com/cli/cli / Test_createRun

Function Test_createRun

pkg/cmd/agent-task/create/create_test.go:128–543  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

126}
127
128func Test_createRun(t *testing.T) {
129 tmpDir := t.TempDir()
130 taskDescFile := filepath.Join(tmpDir, "task-description.md")
131 emptyTaskDescFile := filepath.Join(tmpDir, "empty-task-description.md")
132 require.NoError(t, os.WriteFile(taskDescFile, []byte("task description from file"), 0600))
133 require.NoError(t, os.WriteFile(emptyTaskDescFile, []byte(" \n\n"), 0600))
134
135 sampleDateString := "2025-08-29T00:00:00Z"
136 sampleDate, err := time.Parse(time.RFC3339, sampleDateString)
137 require.NoError(t, err)
138
139 createdJobSuccess := capi.Job{
140 ID: "job123",
141 SessionID: "sess1",
142 Actor: &capi.JobActor{
143 ID: 1,
144 Login: "octocat",
145 },
146 CreatedAt: sampleDate,
147 UpdatedAt: sampleDate,
148 }
149 createdJobSuccessWithPR := capi.Job{
150 ID: "job123",
151 SessionID: "sess1",
152 Actor: &capi.JobActor{
153 ID: 1,
154 Login: "octocat",
155 },
156 CreatedAt: sampleDate,
157 UpdatedAt: sampleDate,
158 PullRequest: &capi.JobPullRequest{
159 ID: 101,
160 Number: 42,
161 },
162 }
163
164 tests := []struct {
165 name string
166 isTTY bool
167 opts *CreateOptions // input options (IO & BackOff set later)
168 capiStubs func(*testing.T, *capi.CapiClientMock)
169 logRendererStubs func(*testing.T, *shared.LogRendererMock)
170 wantStdout string
171 wantStdErr string
172 wantErr string
173 wantErrIs error
174 }{
175 {
176 name: "interactive, problem statement from arg",
177 isTTY: true,
178 opts: &CreateOptions{
179 BaseRepo: func() (ghrepo.Interface, error) { return ghrepo.New("OWNER", "REPO"), nil },
180 ProblemStatement: "task description from arg",
181 },
182 capiStubs: func(t *testing.T, m *capi.CapiClientMock) {
183 m.CreateJobFunc = func(ctx context.Context, owner, repo, problemStatement, baseBranch, customAgent string) (*capi.Job, error) {
184 require.Equal(t, "OWNER", owner)
185 require.Equal(t, "REPO", repo)

Callers

nothing calls this directly

Calls 14

NewFunction · 0.92
TestFunction · 0.92
fetcherStruct · 0.85
JoinMethod · 0.80
EqualMethod · 0.80
SetStdinTTYMethod · 0.80
SetStderrTTYMethod · 0.80
SetStdoutTTYMethod · 0.80
createRunFunction · 0.70
WriteMethod · 0.65
RunMethod · 0.65
LessMethod · 0.45

Tested by

no test coverage detected