@@ -188,14 +188,14 @@ func TestGetJob(t *testing.T) {
188188func TestCreateJobRequiresRepoAndProblemStatement (t * testing.T ) {
189189 client := & CAPIClient {}
190190
191- _ , err := client .CreateJob (context .Background (), "" , "only-repo" , "" , "" )
191+ _ , err := client .CreateJob (context .Background (), "" , "only-repo" , "" , "" , "" )
192192 assert .EqualError (t , err , "owner and repo are required" )
193- _ , err = client .CreateJob (context .Background (), "only-owner" , "" , "" , "" )
193+ _ , err = client .CreateJob (context .Background (), "only-owner" , "" , "" , "" , "" )
194194 assert .EqualError (t , err , "owner and repo are required" )
195- _ , err = client .CreateJob (context .Background (), "" , "" , "" , "" )
195+ _ , err = client .CreateJob (context .Background (), "" , "" , "" , "" , "" )
196196 assert .EqualError (t , err , "owner and repo are required" )
197197
198- _ , err = client .CreateJob (context .Background (), "owner" , "repo" , "" , "" )
198+ _ , err = client .CreateJob (context .Background (), "owner" , "repo" , "" , "" , "" )
199199 assert .EqualError (t , err , "problem statement is required" )
200200}
201201
@@ -205,11 +205,12 @@ func TestCreateJob(t *testing.T) {
205205 require .NoError (t , err )
206206
207207 tests := []struct {
208- name string
209- baseBranch string
210- httpStubs func (* testing.T , * httpmock.Registry )
211- wantErr string
212- wantOut * Job
208+ name string
209+ baseBranch string
210+ customAgent string
211+ httpStubs func (* testing.T , * httpmock.Registry )
212+ wantErr string
213+ wantOut * Job
213214 }{
214215 {
215216 name : "success" ,
@@ -305,6 +306,56 @@ func TestCreateJob(t *testing.T) {
305306 UpdatedAt : sampleDate ,
306307 },
307308 },
309+ {
310+ name : "Success with custom agent" ,
311+ customAgent : "my-custom-agent" ,
312+ httpStubs : func (t * testing.T , reg * httpmock.Registry ) {
313+ reg .Register (
314+ httpmock .WithHost (httpmock .REST ("POST" , "agents/swe/v1/jobs/OWNER/REPO" ), "api.githubcopilot.com" ),
315+ httpmock .RESTPayload (201 ,
316+ heredoc .Docf (`
317+ {
318+ "job_id": "job123",
319+ "session_id": "sess1",
320+ "problem_statement": "Do the thing",
321+ "custom_agent": "my-custom-agent",
322+ "event_type": "foo",
323+ "content_filter_mode": "foo",
324+ "status": "foo",
325+ "result": "foo",
326+ "actor": {
327+ "id": 1,
328+ "login": "octocat"
329+ },
330+ "created_at": "%[1]s",
331+ "updated_at": "%[1]s"
332+ }
333+ ` , sampleDateString ),
334+ func (payload map [string ]interface {}) {
335+ assert .Equal (t , "Do the thing" , payload ["problem_statement" ])
336+ assert .Equal (t , "gh_cli" , payload ["event_type" ])
337+ assert .Equal (t , "my-custom-agent" , payload ["custom_agent" ])
338+ },
339+ ),
340+ )
341+ },
342+ wantOut : & Job {
343+ ID : "job123" ,
344+ SessionID : "sess1" ,
345+ ProblemStatement : "Do the thing" ,
346+ CustomAgent : "my-custom-agent" ,
347+ EventType : "foo" ,
348+ ContentFilterMode : "foo" ,
349+ Status : "foo" ,
350+ Result : "foo" ,
351+ Actor : & JobActor {
352+ ID : 1 ,
353+ Login : "octocat" ,
354+ },
355+ CreatedAt : sampleDate ,
356+ UpdatedAt : sampleDate ,
357+ },
358+ },
308359 {
309360 name : "API error, included in response body" ,
310361 httpStubs : func (t * testing.T , reg * httpmock.Registry ) {
@@ -317,7 +368,7 @@ func TestCreateJob(t *testing.T) {
317368 }` )),
318369 )
319370 },
320- wantErr : "failed to create job: some error" ,
371+ wantErr : "failed to create job: 500 Internal Server Error: some error" ,
321372 },
322373 {
323374 name : "API error" ,
@@ -327,7 +378,7 @@ func TestCreateJob(t *testing.T) {
327378 httpmock .StatusStringResponse (500 , `{}` ),
328379 )
329380 },
330- wantErr : "failed to create job: 500 Internal Server Error" ,
381+ wantErr : "failed to create job: 500 Internal Server Error: " ,
331382 },
332383 {
333384 name : "invalid JSON response, non-HTTP 200" ,
@@ -364,7 +415,7 @@ func TestCreateJob(t *testing.T) {
364415 cfg := config .NewBlankConfig ()
365416 capiClient := NewCAPIClient (httpClient , cfg .Authentication ())
366417
367- job , err := capiClient .CreateJob (context .Background (), "OWNER" , "REPO" , "Do the thing" , tt .baseBranch )
418+ job , err := capiClient .CreateJob (context .Background (), "OWNER" , "REPO" , "Do the thing" , tt .baseBranch , tt . customAgent )
368419
369420 if tt .wantErr != "" {
370421 require .EqualError (t , err , tt .wantErr )
0 commit comments