fix: reduce agentfake manager startup time (#25669)

Signed-off-by: Callum Styan <callumstyan@gmail.com>
Co-authored-by: Mux <noreply@coder.com>
This commit is contained in:
Callum Styan
2026-06-04 15:28:13 -07:00
committed by GitHub
co-authored by Mux
parent 6dedae4858
commit 4627b01415
14 changed files with 918 additions and 155 deletions
+14
View File
@@ -3457,6 +3457,20 @@ func (q *querier) GetEnabledMCPServerConfigs(ctx context.Context) ([]database.MC
return q.db.GetEnabledMCPServerConfigs(ctx)
}
// GetExternalAgentTokensByTemplateID is used for scaletesting purposes; the
// scaletest agentfake path calls this query directly via a connection to the
// database. There is no production code path that uses this method, and it is
// deliberately not exposed over HTTP. The query filters for running
// workspaces only (latest build has transition=start and job_status=succeeded).
func (q *querier) GetExternalAgentTokensByTemplateID(ctx context.Context, arg database.GetExternalAgentTokensByTemplateIDParams) ([]database.GetExternalAgentTokensByTemplateIDRow, error) {
// ResourceSystem is used because the query spans multiple workspaces
// with no single RBAC object to check.
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceSystem); err != nil {
return nil, err
}
return q.db.GetExternalAgentTokensByTemplateID(ctx, arg)
}
func (q *querier) GetExternalAuthLink(ctx context.Context, arg database.GetExternalAuthLinkParams) (database.ExternalAuthLink, error) {
return fetchWithAction(q.log, q.auth, policy.ActionReadPersonal, q.db.GetExternalAuthLink)(ctx, arg)
}
+6
View File
@@ -3137,6 +3137,12 @@ func (s *MethodTestSuite) TestUser() {
dbm.EXPECT().UpdateGitSSHKey(gomock.Any(), arg).Return(key, nil).AnyTimes()
check.Args(arg).Asserts(key, policy.ActionUpdatePersonal).Returns(key)
}))
s.Run("GetExternalAgentTokensByTemplateID", s.Mocked(func(dbm *dbmock.MockStore, faker *gofakeit.Faker, check *expects) {
arg := database.GetExternalAgentTokensByTemplateIDParams{TemplateID: uuid.New(), OwnerID: uuid.Nil}
row := testutil.Fake(s.T(), faker, database.GetExternalAgentTokensByTemplateIDRow{})
dbm.EXPECT().GetExternalAgentTokensByTemplateID(gomock.Any(), arg).Return([]database.GetExternalAgentTokensByTemplateIDRow{row}, nil).AnyTimes()
check.Args(arg).Asserts(rbac.ResourceSystem, policy.ActionRead).Returns(slice.New(row))
}))
s.Run("GetExternalAuthLink", s.Mocked(func(dbm *dbmock.MockStore, faker *gofakeit.Faker, check *expects) {
link := testutil.Fake(s.T(), faker, database.ExternalAuthLink{})
arg := database.GetExternalAuthLinkParams{ProviderID: link.ProviderID, UserID: link.UserID}