From e5739cc54518aaa94dd7e101f3ac158305fd52f5 Mon Sep 17 00:00:00 2001 From: "Babak K. Shandiz" Date: Thu, 18 Sep 2025 16:11:17 +0100 Subject: [PATCH] fix(agent-task/capi): add `WorkflowRunID` field to `Session` Signed-off-by: Babak K. Shandiz --- pkg/cmd/agent-task/capi/sessions.go | 3 + pkg/cmd/agent-task/capi/sessions_test.go | 106 +++++++++++++++++++++++ 2 files changed, 109 insertions(+) diff --git a/pkg/cmd/agent-task/capi/sessions.go b/pkg/cmd/agent-task/capi/sessions.go index db85825eb..a3989a862 100644 --- a/pkg/cmd/agent-task/capi/sessions.go +++ b/pkg/cmd/agent-task/capi/sessions.go @@ -43,6 +43,7 @@ type session struct { EventURL string `json:"event_url"` EventType string `json:"event_type"` PremiumRequests float64 `json:"premium_requests"` + WorkflowRunID uint64 `json:"workflow_run_id,omitempty"` Error *struct { Code string `json:"code"` Message string `json:"message"` @@ -87,6 +88,7 @@ type Session struct { EventURL string EventType string PremiumRequests float64 + WorkflowRunID uint64 Error *SessionError PullRequest *api.PullRequest @@ -467,6 +469,7 @@ func fromAPISession(s session) *Session { EventURL: s.EventURL, EventType: s.EventType, PremiumRequests: s.PremiumRequests, + WorkflowRunID: s.WorkflowRunID, } if s.Error != nil { result.Error = &SessionError{ diff --git a/pkg/cmd/agent-task/capi/sessions_test.go b/pkg/cmd/agent-task/capi/sessions_test.go index 8040cb413..daccbeaed 100644 --- a/pkg/cmd/agent-task/capi/sessions_test.go +++ b/pkg/cmd/agent-task/capi/sessions_test.go @@ -987,6 +987,112 @@ func TestListLatestSessionsForViewer(t *testing.T) { }, }, }, + { + name: "workflow run id is included", + limit: 10, + httpStubs: func(t *testing.T, reg *httpmock.Registry) { + reg.Register( + httpmock.WithHost( + httpmock.QueryMatcher("GET", "agents/sessions", url.Values{ + "page_number": {"1"}, + "page_size": {"50"}, + "sort": {"last_updated_at,desc"}, + }), + "api.githubcopilot.com", + ), + httpmock.StringResponse(heredoc.Docf(` + { + "sessions": [ + { + "id": "sessA", + "name": "Build artifacts", + "user_id": 1, + "agent_id": 2, + "logs": "", + "state": "failed", + "owner_id": 10, + "repo_id": 1000, + "resource_type": "pull", + "resource_id": 3000, + "created_at": "%[1]s", + "workflow_run_id": 9999 + } + ] + }`, + sampleDateString, + )), + ) + + // GraphQL hydration + reg.Register( + httpmock.GraphQL(`query FetchPRsAndUsersForAgentTaskSessions\b`), + httpmock.GraphQLQuery(heredoc.Docf(` + { + "data": { + "nodes": [ + { + "__typename": "PullRequest", + "id": "PR_node3000", + "fullDatabaseId": "3000", + "number": 100, + "title": "Improve docs", + "state": "OPEN", + "isDraft": true, + "url": "https://github.com/OWNER/REPO/pull/100", + "body": "", + "createdAt": "%[1]s", + "updatedAt": "%[1]s", + "repository": {"nameWithOwner": "OWNER/REPO"} + }, + { + "__typename": "User", + "login": "octocat", + "name": "Octocat", + "databaseId": 1 + } + ] + } + }`, + sampleDateString, + ), func(q string, vars map[string]interface{}) { + // Expected encoded node IDs for resource IDs 3000 and user octocat + assert.Equal(t, []interface{}{"PR_kwDNA-jNC7g", "U_kgAB"}, vars["ids"]) + }), + ) + }, + wantOut: []*Session{ + { + ID: "sessA", + Name: "Build artifacts", + UserID: 1, + AgentID: 2, + Logs: "", + State: "failed", + OwnerID: 10, + RepoID: 1000, + ResourceType: "pull", + ResourceID: 3000, + CreatedAt: sampleDate, + WorkflowRunID: 9999, + PullRequest: &api.PullRequest{ + ID: "PR_node3000", + FullDatabaseID: "3000", + Number: 100, + Title: "Improve docs", + State: "OPEN", + IsDraft: true, + URL: "https://github.com/OWNER/REPO/pull/100", + Body: "", + CreatedAt: sampleDate, + UpdatedAt: sampleDate, + Repository: &api.PRRepository{ + NameWithOwner: "OWNER/REPO", + }, + }, + User: &api.GitHubUser{Login: "octocat", Name: "Octocat", DatabaseID: 1}, + }, + }, + }, { name: "API error", limit: 10,