@@ -114,22 +114,66 @@ func Test_ActionsList_ListWorkflows(t *testing.T) {
114114 }
115115}
116116
117+ func unsafeWorkflowRunFixture () * github.WorkflowRun {
118+ return & github.WorkflowRun {
119+ ID : github .Ptr (int64 (12345 )),
120+ Name : github .Ptr (baselineUnsafeText ),
121+ DisplayTitle : github .Ptr (baselineUnsafeText ),
122+ HeadBranch : github .Ptr ("feature/exact<script>" ),
123+ HeadSHA : github .Ptr ("abc123" ),
124+ HeadCommit : & github.HeadCommit {
125+ Message : github .Ptr (baselineUnsafeText ),
126+ Author : & github.CommitAuthor {
127+ Name : github .Ptr (baselineUnsafeText ),
128+ Email : github .Ptr ("author@example.com" ),
129+ },
130+ Added : []string {"src/exact<script>.go" },
131+ },
132+ PullRequests : []* github.PullRequest {{
133+ Title : github .Ptr (baselineUnsafeText ),
134+ Body : github .Ptr (baselineUnsafeText ),
135+ Labels : []* github.Label {{Name : github .Ptr (baselineUnsafeText ), Description : github .Ptr (baselineUnsafeText )}},
136+ Milestone : & github.Milestone {Title : github .Ptr (baselineUnsafeText ), Description : github .Ptr (baselineUnsafeText )},
137+ Head : & github.PullRequestBranch {Repo : & github.Repository {Description : github .Ptr (baselineUnsafeText )}},
138+ Base : & github.PullRequestBranch {Repo : & github.Repository {Description : github .Ptr (baselineUnsafeText )}},
139+ }},
140+ Repository : & github.Repository {Description : github .Ptr (baselineUnsafeText )},
141+ HeadRepository : & github.Repository {Description : github .Ptr (baselineUnsafeText )},
142+ Status : github .Ptr ("completed" ),
143+ Conclusion : github .Ptr ("success" ),
144+ }
145+ }
146+
147+ func assertSanitizedWorkflowRun (t * testing.T , run * github.WorkflowRun ) {
148+ t .Helper ()
149+ expected := sanitizeOutputText (baselineUnsafeText )
150+ assert .Equal (t , expected , run .GetName ())
151+ assert .Equal (t , expected , run .GetDisplayTitle ())
152+ assert .Equal (t , expected , run .HeadCommit .GetMessage ())
153+ assert .Equal (t , expected , run .HeadCommit .Author .GetName ())
154+ assert .Equal (t , "author@example.com" , run .HeadCommit .Author .GetEmail ())
155+ assert .Equal (t , []string {"src/exact<script>.go" }, run .HeadCommit .Added )
156+ assert .Equal (t , expected , run .PullRequests [0 ].GetTitle ())
157+ assert .Equal (t , expected , run .PullRequests [0 ].Labels [0 ].GetName ())
158+ assert .Equal (t , expected , run .PullRequests [0 ].Milestone .GetTitle ())
159+ assert .Equal (t , expected , run .PullRequests [0 ].Head .Repo .GetDescription ())
160+ assert .Equal (t , expected , run .PullRequests [0 ].Base .Repo .GetDescription ())
161+ assert .Equal (t , expected , run .Repository .GetDescription ())
162+ assert .Equal (t , expected , run .HeadRepository .GetDescription ())
163+ assert .Equal (t , "feature/exact<script>" , run .GetHeadBranch ())
164+ assert .Equal (t , "abc123" , run .GetHeadSHA ())
165+ }
166+
117167func Test_ActionsList_ListWorkflowRuns (t * testing.T ) {
118168 toolDef := ActionsList (translations .NullTranslationHelper )
119169
120170 t .Run ("successful workflow runs list" , func (t * testing.T ) {
171+ workflowRun := unsafeWorkflowRunFixture ()
121172 mockedClient := MockHTTPClientWithHandlers (map [string ]http.HandlerFunc {
122173 GetReposActionsWorkflowsRunsByOwnerByRepoByWorkflowID : http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
123174 runs := & github.WorkflowRuns {
124- TotalCount : github .Ptr (1 ),
125- WorkflowRuns : []* github.WorkflowRun {
126- {
127- ID : github .Ptr (int64 (123 )),
128- Name : github .Ptr ("CI" ),
129- Status : github .Ptr ("completed" ),
130- Conclusion : github .Ptr ("success" ),
131- },
132- },
175+ TotalCount : github .Ptr (1 ),
176+ WorkflowRuns : []* github.WorkflowRun {workflowRun },
133177 }
134178 w .WriteHeader (http .StatusOK )
135179 _ = json .NewEncoder (w ).Encode (runs )
@@ -158,6 +202,9 @@ func Test_ActionsList_ListWorkflowRuns(t *testing.T) {
158202 err = json .Unmarshal ([]byte (textContent .Text ), & response )
159203 require .NoError (t , err )
160204 assert .NotNil (t , response .TotalCount )
205+ require .Len (t , response .WorkflowRuns , 1 )
206+ assertSanitizedWorkflowRun (t , response .WorkflowRuns [0 ])
207+ assert .Equal (t , baselineUnsafeText , workflowRun .GetName ())
161208 })
162209
163210 t .Run ("list all workflow runs without resource_id" , func (t * testing.T ) {
@@ -209,6 +256,55 @@ func Test_ActionsList_ListWorkflowRuns(t *testing.T) {
209256 })
210257}
211258
259+ func Test_ActionsList_ListWorkflowJobs (t * testing.T ) {
260+ toolDef := ActionsList (translations .NullTranslationHelper )
261+ workflowJob := & github.WorkflowJob {
262+ ID : github .Ptr (int64 (123 )),
263+ Name : github .Ptr (baselineUnsafeText ),
264+ WorkflowName : github .Ptr (baselineUnsafeText ),
265+ RunnerName : github .Ptr (baselineUnsafeText ),
266+ RunnerGroupName : github .Ptr (baselineUnsafeText ),
267+ Steps : []* github.TaskStep {{Name : github .Ptr (baselineUnsafeText )}},
268+ }
269+ mockedClient := MockHTTPClientWithHandlers (map [string ]http.HandlerFunc {
270+ GetReposActionsRunsJobsByOwnerByRepoByRunID : http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
271+ w .WriteHeader (http .StatusOK )
272+ _ = json .NewEncoder (w ).Encode (& github.Jobs {
273+ TotalCount : github .Ptr (1 ),
274+ Jobs : []* github.WorkflowJob {workflowJob },
275+ })
276+ }),
277+ })
278+
279+ client := mustNewGHClient (t , mockedClient )
280+ deps := BaseDeps {Client : client }
281+ handler := toolDef .Handler (deps )
282+ request := createMCPRequest (map [string ]any {
283+ "method" : "list_workflow_jobs" ,
284+ "owner" : "owner" ,
285+ "repo" : "repo" ,
286+ "resource_id" : "123" ,
287+ })
288+ result , err := handler (ContextWithDeps (context .Background (), deps ), & request )
289+ require .NoError (t , err )
290+ require .False (t , result .IsError )
291+
292+ var response struct {
293+ Jobs * github.Jobs `json:"jobs"`
294+ }
295+ require .NoError (t , json .Unmarshal ([]byte (getTextResult (t , result ).Text ), & response ))
296+ require .NotNil (t , response .Jobs )
297+ require .Len (t , response .Jobs .Jobs , 1 )
298+ returnedJob := response .Jobs .Jobs [0 ]
299+ assert .Equal (t , sanitizeOutputText (baselineUnsafeText ), returnedJob .GetName ())
300+ assert .Equal (t , sanitizeOutputText (baselineUnsafeText ), returnedJob .GetWorkflowName ())
301+ assert .Equal (t , baselineUnsafeText , returnedJob .GetRunnerName ())
302+ assert .Equal (t , baselineUnsafeText , returnedJob .GetRunnerGroupName ())
303+ assert .Equal (t , sanitizeOutputText (baselineUnsafeText ), returnedJob .Steps [0 ].GetName ())
304+ assert .Equal (t , baselineUnsafeText , workflowJob .GetName ())
305+ assert .Equal (t , baselineUnsafeText , workflowJob .GetRunnerName ())
306+ }
307+
212308func Test_ActionsGet (t * testing.T ) {
213309 // Verify tool definition once
214310 toolDef := ActionsGet (translations .NullTranslationHelper )
@@ -271,16 +367,11 @@ func Test_ActionsGet_GetWorkflowRun(t *testing.T) {
271367 toolDef := ActionsGet (translations .NullTranslationHelper )
272368
273369 t .Run ("successful workflow run get" , func (t * testing.T ) {
370+ workflowRun := unsafeWorkflowRunFixture ()
274371 mockedClient := MockHTTPClientWithHandlers (map [string ]http.HandlerFunc {
275372 GetReposActionsRunsByOwnerByRepoByRunID : http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
276- run := & github.WorkflowRun {
277- ID : github .Ptr (int64 (12345 )),
278- Name : github .Ptr ("CI" ),
279- Status : github .Ptr ("completed" ),
280- Conclusion : github .Ptr ("success" ),
281- }
282373 w .WriteHeader (http .StatusOK )
283- _ = json .NewEncoder (w ).Encode (run )
374+ _ = json .NewEncoder (w ).Encode (workflowRun )
284375 }),
285376 })
286377
@@ -307,6 +398,8 @@ func Test_ActionsGet_GetWorkflowRun(t *testing.T) {
307398 require .NoError (t , err )
308399 assert .NotNil (t , response .ID )
309400 assert .Equal (t , int64 (12345 ), * response .ID )
401+ assertSanitizedWorkflowRun (t , & response )
402+ assert .Equal (t , baselineUnsafeText , workflowRun .GetName ())
310403 })
311404}
312405
0 commit comments