MCPcopy Index your code
hub / github.com/coder/coder / TestWorkspaceFilterHasAITask

Function TestWorkspaceFilterHasAITask

coderd/workspaces_test.go:5358–5467  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

5356}
5357
5358func TestWorkspaceFilterHasAITask(t *testing.T) {
5359 t.Parallel()
5360
5361 db, pubsub := dbtestutil.NewDB(t)
5362 client := coderdtest.New(t, &coderdtest.Options{
5363 Database: db,
5364 Pubsub: pubsub,
5365 IncludeProvisionerDaemon: true,
5366 })
5367 user := coderdtest.CreateFirstUser(t, client)
5368
5369 version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
5370 coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID)
5371 template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
5372
5373 ctx := testutil.Context(t, testutil.WaitLong)
5374
5375 // Helper function to create workspace with optional task.
5376 createWorkspace := func(jobCompleted, createTask bool, prompt string) uuid.UUID {
5377 // TODO(mafredri): The bellow comment is based on deprecated logic and
5378 // kept only present to test that the old observable behavior works as
5379 // intended.
5380 //
5381 // When a provisioner job uses these tags, no provisioner will match it.
5382 // We do this so jobs will always be stuck in "pending", allowing us to
5383 // exercise the intermediary state when has_ai_task is nil and we
5384 // compensate by looking at pending provisioning jobs.
5385 // See GetWorkspaces clauses.
5386 unpickableTags := database.StringMap{"custom": "true"}
5387
5388 ws := dbgen.Workspace(t, db, database.WorkspaceTable{
5389 OwnerID: user.UserID,
5390 OrganizationID: user.OrganizationID,
5391 TemplateID: template.ID,
5392 })
5393
5394 jobConfig := database.ProvisionerJob{
5395 OrganizationID: user.OrganizationID,
5396 InitiatorID: user.UserID,
5397 Tags: unpickableTags,
5398 }
5399 if jobCompleted {
5400 jobConfig.CompletedAt = sql.NullTime{Time: time.Now(), Valid: true}
5401 }
5402 job := dbgen.ProvisionerJob(t, db, pubsub, jobConfig)
5403 res := dbgen.WorkspaceResource(t, db, database.WorkspaceResource{JobID: job.ID})
5404 agnt := dbgen.WorkspaceAgent(t, db, database.WorkspaceAgent{ResourceID: res.ID})
5405 taskApp := dbgen.WorkspaceApp(t, db, database.WorkspaceApp{AgentID: agnt.ID})
5406 build := dbgen.WorkspaceBuild(t, db, database.WorkspaceBuild{
5407 WorkspaceID: ws.ID,
5408 TemplateVersionID: version.ID,
5409 InitiatorID: user.UserID,
5410 JobID: job.ID,
5411 BuildNumber: 1,
5412 })
5413
5414 if createTask {
5415 task := dbgen.Task(t, db, database.TaskTable{

Callers

nothing calls this directly

Calls 15

NewDBFunction · 0.92
NewFunction · 0.92
CreateFirstUserFunction · 0.92
CreateTemplateVersionFunction · 0.92
CreateTemplateFunction · 0.92
ContextFunction · 0.92
WorkspaceFunction · 0.92
ProvisionerJobFunction · 0.92
WorkspaceResourceFunction · 0.92
WorkspaceAgentFunction · 0.92
WorkspaceAppFunction · 0.92

Tested by

no test coverage detected