@@ -274,34 +274,37 @@ func TestTasks(t *testing.T) {
274274t .Run ("Get" ,func (t * testing.T ) {
275275t .Parallel ()
276276
277- t .Skip ("TODO(mafredri): Remove, fixed down-stack!" )
278-
279277var (
280278client ,db = coderdtest .NewWithDatabase (t ,& coderdtest.Options {IncludeProvisionerDaemon :true })
281279ctx = testutil .Context (t ,testutil .WaitLong )
282280user = coderdtest .CreateFirstUser (t ,client )
283281template = createAITemplate (t ,client ,user )
284- // Create a workspace (task) with a specific prompt.
285282wantPrompt = "review my code"
286- workspace = coderdtest .CreateWorkspace (t ,client ,template .ID ,func (req * codersdk.CreateWorkspaceRequest ) {
287- req .RichParameterValues = []codersdk.WorkspaceBuildParameter {
288- {Name :codersdk .AITaskPromptParameterName ,Value :wantPrompt },
289- }
290- })
283+ exp = codersdk .NewExperimentalClient (client )
291284)
292285
293- coderdtest .AwaitWorkspaceBuildJobCompleted (t ,client ,workspace .LatestBuild .ID )
294- ws := coderdtest .MustWorkspace (t ,client ,workspace .ID )
286+ task ,err := exp .CreateTask (ctx ,"me" , codersdk.CreateTaskRequest {
287+ TemplateVersionID :template .ActiveVersionID ,
288+ Input :wantPrompt ,
289+ })
290+ require .NoError (t ,err )
291+ require .True (t ,task .WorkspaceID .Valid )
292+
293+ // Get the workspace and wait for it to be ready.
294+ ws ,err := client .Workspace (ctx ,task .WorkspaceID .UUID )
295+ require .NoError (t ,err )
296+ coderdtest .AwaitWorkspaceBuildJobCompleted (t ,client ,ws .LatestBuild .ID )
297+ ws = coderdtest .MustWorkspace (t ,client ,task .WorkspaceID .UUID )
295298// Assert invariant: the workspace has exactly one resource with one agent with one app.
296299require .Len (t ,ws .LatestBuild .Resources ,1 )
297300require .Len (t ,ws .LatestBuild .Resources [0 ].Agents ,1 )
298301agentID := ws .LatestBuild .Resources [0 ].Agents [0 ].ID
299302taskAppID := ws .LatestBuild .Resources [0 ].Agents [0 ].Apps [0 ].ID
300303
301304// Insert an app status for the workspace
302- _ ,err : =db .InsertWorkspaceAppStatus (dbauthz .AsSystemRestricted (ctx ), database.InsertWorkspaceAppStatusParams {
305+ _ ,err = db .InsertWorkspaceAppStatus (dbauthz .AsSystemRestricted (ctx ), database.InsertWorkspaceAppStatusParams {
303306ID :uuid .New (),
304- WorkspaceID :workspace . ID ,
307+ WorkspaceID :task . WorkspaceID . UUID ,
305308CreatedAt :dbtime .Now (),
306309AgentID :agentID ,
307310AppID :taskAppID ,
@@ -311,31 +314,33 @@ func TestTasks(t *testing.T) {
311314require .NoError (t ,err )
312315
313316// Fetch the task by ID via experimental API and verify fields.
314- exp := codersdk .NewExperimentalClient (client )
315- task ,err := exp .TaskByID (ctx ,workspace .ID )
317+ updated ,err := exp .TaskByID (ctx ,task .ID )
316318require .NoError (t ,err )
317319
318- assert .Equal (t ,workspace .ID ,task .ID ,"task ID should match workspace ID" )
319- assert .Equal (t ,workspace .Name ,task .Name ,"task name should map from workspace name" )
320- assert .Equal (t ,wantPrompt ,task .InitialPrompt ,"task prompt should match the AI Prompt parameter" )
321- assert .Equal (t ,workspace .ID ,task .WorkspaceID .UUID ,"workspace id should match" )
322- assert .NotEmpty (t ,task .WorkspaceStatus ,"task status should not be empty" )
320+ assert .Equal (t ,task .ID ,updated .ID ,"task ID should match" )
321+ assert .Equal (t ,task .Name ,updated .Name ,"task name should match" )
322+ assert .Equal (t ,wantPrompt ,updated .InitialPrompt ,"task prompt should match the AI Prompt parameter" )
323+ assert .Equal (t ,task .WorkspaceID .UUID ,updated .WorkspaceID .UUID ,"workspace id should match" )
324+ assert .Equal (t ,ws .LatestBuild .BuildNumber ,updated .WorkspaceBuildNumber ,"workspace build number should match" )
325+ assert .Equal (t ,agentID ,updated .WorkspaceAgentID .UUID ,"workspace agent id should match" )
326+ assert .Equal (t ,taskAppID ,updated .WorkspaceAppID .UUID ,"workspace app id should match" )
327+ assert .NotEmpty (t ,updated .WorkspaceStatus ,"task status should not be empty" )
323328
324329// Stop the workspace
325- coderdtest .MustTransitionWorkspace (t ,client ,workspace . ID ,codersdk .WorkspaceTransitionStart ,codersdk .WorkspaceTransitionStop )
330+ coderdtest .MustTransitionWorkspace (t ,client ,task . WorkspaceID . UUID ,codersdk .WorkspaceTransitionStart ,codersdk .WorkspaceTransitionStop )
326331
327332// Verify that the previous status still remains
328- updated ,err : =exp .TaskByID (ctx ,workspace .ID )
333+ updated ,err = exp .TaskByID (ctx ,task .ID )
329334require .NoError (t ,err )
330335assert .NotNil (t ,updated .CurrentState ,"current state should not be nil" )
331336assert .Equal (t ,"all done" ,updated .CurrentState .Message )
332337assert .Equal (t ,codersdk .TaskStateComplete ,updated .CurrentState .State )
333338
334339// Start the workspace again
335- coderdtest .MustTransitionWorkspace (t ,client ,workspace . ID ,codersdk .WorkspaceTransitionStop ,codersdk .WorkspaceTransitionStart )
340+ coderdtest .MustTransitionWorkspace (t ,client ,task . WorkspaceID . UUID ,codersdk .WorkspaceTransitionStop ,codersdk .WorkspaceTransitionStart )
336341
337342// Verify that the status from the previous build is no longer present
338- updated ,err = exp .TaskByID (ctx ,workspace .ID )
343+ updated ,err = exp .TaskByID (ctx ,task .ID )
339344require .NoError (t ,err )
340345assert .Nil (t ,updated .CurrentState ,"current state should be nil" )
341346})