@@ -163,6 +163,10 @@ func (c *Client) GetConnectionReports() []*agentproto.ReportConnectionRequest {
163
163
return c .fakeAgentAPI .GetConnectionReports ()
164
164
}
165
165
166
+ func (c * Client )GetSubAgents () []* agentproto.SubAgent {
167
+ return c .fakeAgentAPI .GetSubAgents ()
168
+ }
169
+
166
170
type FakeAgentAPI struct {
167
171
sync.Mutex
168
172
t testing.TB
@@ -177,6 +181,7 @@ type FakeAgentAPI struct {
177
181
metadata map [string ]agentsdk.Metadata
178
182
timings []* agentproto.Timing
179
183
connectionReports []* agentproto.ReportConnectionRequest
184
+ subAgents map [uuid.UUID ]* agentproto.SubAgent
180
185
181
186
getAnnouncementBannersFunc func () ([]codersdk.BannerConfig ,error )
182
187
getResourcesMonitoringConfigurationFunc func () (* agentproto.GetResourcesMonitoringConfigurationResponse ,error )
@@ -365,16 +370,86 @@ func (f *FakeAgentAPI) GetConnectionReports() []*agentproto.ReportConnectionRequ
365
370
return slices .Clone (f .connectionReports )
366
371
}
367
372
368
- func (* FakeAgentAPI )CreateSubAgent (_ context.Context ,_ * agentproto.CreateSubAgentRequest ) (* agentproto.CreateSubAgentResponse ,error ) {
369
- panic ("unimplemented" )
373
+ func (f * FakeAgentAPI )CreateSubAgent (ctx context.Context ,req * agentproto.CreateSubAgentRequest ) (* agentproto.CreateSubAgentResponse ,error ) {
374
+ f .Lock ()
375
+ defer f .Unlock ()
376
+
377
+ f .logger .Debug (ctx ,"create sub agent called" ,slog .F ("req" ,req ))
378
+
379
+ // Generate IDs for the new sub-agent.
380
+ subAgentID := uuid .New ()
381
+ authToken := uuid .New ()
382
+
383
+ // Create the sub-agent proto object.
384
+ subAgent := & agentproto.SubAgent {
385
+ Id :subAgentID [:],
386
+ Name :req .Name ,
387
+ AuthToken :authToken [:],
388
+ }
389
+
390
+ // Store the sub-agent in our map.
391
+ if f .subAgents == nil {
392
+ f .subAgents = make (map [uuid.UUID ]* agentproto.SubAgent )
393
+ }
394
+ f .subAgents [subAgentID ]= subAgent
395
+
396
+ // For a fake implementation, we don't create workspace apps.
397
+ // Real implementations would handle req.Apps here.
398
+ return & agentproto.CreateSubAgentResponse {
399
+ Agent :subAgent ,
400
+ AppCreationErrors :nil ,
401
+ },nil
402
+ }
403
+
404
+ func (f * FakeAgentAPI )DeleteSubAgent (ctx context.Context ,req * agentproto.DeleteSubAgentRequest ) (* agentproto.DeleteSubAgentResponse ,error ) {
405
+ f .Lock ()
406
+ defer f .Unlock ()
407
+
408
+ f .logger .Debug (ctx ,"delete sub agent called" ,slog .F ("req" ,req ))
409
+
410
+ subAgentID ,err := uuid .FromBytes (req .Id )
411
+ if err != nil {
412
+ return nil ,err
413
+ }
414
+
415
+ // Remove the sub-agent from our map.
416
+ if f .subAgents != nil {
417
+ delete (f .subAgents ,subAgentID )
418
+ }
419
+
420
+ return & agentproto.DeleteSubAgentResponse {},nil
370
421
}
371
422
372
- func (* FakeAgentAPI )DeleteSubAgent (_ context.Context ,_ * agentproto.DeleteSubAgentRequest ) (* agentproto.DeleteSubAgentResponse ,error ) {
373
- panic ("unimplemented" )
423
+ func (f * FakeAgentAPI )ListSubAgents (ctx context.Context ,req * agentproto.ListSubAgentsRequest ) (* agentproto.ListSubAgentsResponse ,error ) {
424
+ f .Lock ()
425
+ defer f .Unlock ()
426
+
427
+ f .logger .Debug (ctx ,"list sub agents called" ,slog .F ("req" ,req ))
428
+
429
+ var agents []* agentproto.SubAgent
430
+ if f .subAgents != nil {
431
+ agents = make ([]* agentproto.SubAgent ,0 ,len (f .subAgents ))
432
+ for _ ,agent := range f .subAgents {
433
+ agents = append (agents ,agent )
434
+ }
435
+ }
436
+
437
+ return & agentproto.ListSubAgentsResponse {
438
+ Agents :agents ,
439
+ },nil
374
440
}
375
441
376
- func (* FakeAgentAPI )ListSubAgents (_ context.Context ,_ * agentproto.ListSubAgentsRequest ) (* agentproto.ListSubAgentsResponse ,error ) {
377
- panic ("unimplemented" )
442
+ func (f * FakeAgentAPI )GetSubAgents () []* agentproto.SubAgent {
443
+ f .Lock ()
444
+ defer f .Unlock ()
445
+ var agents []* agentproto.SubAgent
446
+ if f .subAgents != nil {
447
+ agents = make ([]* agentproto.SubAgent ,0 ,len (f .subAgents ))
448
+ for _ ,agent := range f .subAgents {
449
+ agents = append (agents ,agent )
450
+ }
451
+ }
452
+ return agents
378
453
}
379
454
380
455
func NewFakeAgentAPI (t testing.TB ,logger slog.Logger ,manifest * agentproto.Manifest ,statsCh chan * agentproto.Stats )* FakeAgentAPI {