@@ -416,25 +416,26 @@ func TestTasks(t *testing.T) {
416
416
t .Run ("Send" ,func (t * testing.T ) {
417
417
t .Parallel ()
418
418
419
- t .Run ("OK " ,func (t * testing.T ) {
419
+ t .Run ("IntegrationOK " ,func (t * testing.T ) {
420
420
t .Parallel ()
421
421
422
422
client ,_ ,api := coderdtest .NewWithAPI (t ,& coderdtest.Options {IncludeProvisionerDaemon :true })
423
423
owner := coderdtest .CreateFirstUser (t ,client )
424
424
userClient ,_ := coderdtest .CreateAnotherUser (t ,client ,owner .OrganizationID )
425
425
426
- // Start a fake AgentAPI that accepts POST /message with 200 OK.
426
+ // Start a fake AgentAPI that accepts GET /status and POST /message.
427
+ statusResponse := `{"body":{"status":"stable"}}`
427
428
srv := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter ,r * http.Request ) {
428
429
if r .Method == http .MethodGet && r .URL .Path == "/status" {
429
- _ ,_ = fmt .Fprintln (w ,`{"body":{"status":"stable"}}` )
430
+ _ ,_ = fmt .Fprint (w ,statusResponse )
430
431
w .WriteHeader (http .StatusOK )
431
432
return
432
433
}
433
434
if r .Method == http .MethodPost && r .URL .Path == "/message" {
434
435
w .WriteHeader (http .StatusOK )
435
436
return
436
437
}
437
- w .WriteHeader (http .StatusOK )
438
+ w .WriteHeader (http .StatusInternalServerError )
438
439
}))
439
440
defer srv .Close ()
440
441
@@ -474,19 +475,40 @@ func TestTasks(t *testing.T) {
474
475
}
475
476
require .NotEqual (t ,uuid .Nil ,sidebarAppID )
476
477
477
- // Make the sidebar apphealthy for this test .
478
+ // Make the sidebar appunhealthy initially .
478
479
err = api .Database .UpdateWorkspaceAppHealthByID (dbauthz .AsSystemRestricted (ctx ), database.UpdateWorkspaceAppHealthByIDParams {
479
480
ID :sidebarAppID ,
480
- Health :database .WorkspaceAppHealthHealthy ,
481
+ Health :database .WorkspaceAppHealthUnhealthy ,
481
482
})
482
483
require .NoError (t ,err )
483
484
484
- // Send task input to the tasks sidebar app and expect 204.
485
485
exp := codersdk .NewExperimentalClient (userClient )
486
486
err = exp .TaskSend (ctx ,"me" ,ws .ID , codersdk.TaskSendRequest {
487
487
Input :"Hello, Agent!" ,
488
488
})
489
+ require .Error (t ,err ,"wanted error due to unhealthy sidebar app" )
490
+
491
+ // Make the sidebar app healthy.
492
+ err = api .Database .UpdateWorkspaceAppHealthByID (dbauthz .AsSystemRestricted (ctx ), database.UpdateWorkspaceAppHealthByIDParams {
493
+ ID :sidebarAppID ,
494
+ Health :database .WorkspaceAppHealthHealthy ,
495
+ })
489
496
require .NoError (t ,err )
497
+
498
+ statusResponse = `{"body":{"status":"bad"}}`
499
+
500
+ err = exp .TaskSend (ctx ,"me" ,ws .ID , codersdk.TaskSendRequest {
501
+ Input :"Hello, Agent!" ,
502
+ })
503
+ require .Error (t ,err ,"wanted error due to bad status" )
504
+
505
+ statusResponse = `{"body":{"status":"stable"}}`
506
+
507
+ // Send task input to the tasks sidebar app and expect 204.e
508
+ err = exp .TaskSend (ctx ,"me" ,ws .ID , codersdk.TaskSendRequest {
509
+ Input :"Hello, Agent!" ,
510
+ })
511
+ require .NoError (t ,err ,"wanted no error due to healthy sidebar app and stable status" )
490
512
})
491
513
492
514
t .Run ("MissingContent" ,func (t * testing.T ) {