@@ -279,34 +279,37 @@ func TestTasks(t *testing.T) {
279279t .Run ("Get" ,func (t * testing.T ) {
280280t .Parallel ()
281281
282- t .Skip ("TODO(mafredri): Remove, fixed down-stack!" )
283-
284282var (
285283client ,db = coderdtest .NewWithDatabase (t ,& coderdtest.Options {IncludeProvisionerDaemon :true })
286284ctx = testutil .Context (t ,testutil .WaitLong )
287285user = coderdtest .CreateFirstUser (t ,client )
288286template = createAITemplate (t ,client ,user )
289- // Create a workspace (task) with a specific prompt.
290287wantPrompt = "review my code"
291- workspace = coderdtest .CreateWorkspace (t ,client ,template .ID ,func (req * codersdk.CreateWorkspaceRequest ) {
292- req .RichParameterValues = []codersdk.WorkspaceBuildParameter {
293- {Name :codersdk .AITaskPromptParameterName ,Value :wantPrompt },
294- }
295- })
288+ exp = codersdk .NewExperimentalClient (client )
296289)
297290
298- coderdtest .AwaitWorkspaceBuildJobCompleted (t ,client ,workspace .LatestBuild .ID )
299- ws := coderdtest .MustWorkspace (t ,client ,workspace .ID )
291+ task ,err := exp .CreateTask (ctx ,"me" , codersdk.CreateTaskRequest {
292+ TemplateVersionID :template .ActiveVersionID ,
293+ Input :wantPrompt ,
294+ })
295+ require .NoError (t ,err )
296+ require .True (t ,task .WorkspaceID .Valid )
297+
298+ // Get the workspace and wait for it to be ready.
299+ ws ,err := client .Workspace (ctx ,task .WorkspaceID .UUID )
300+ require .NoError (t ,err )
301+ coderdtest .AwaitWorkspaceBuildJobCompleted (t ,client ,ws .LatestBuild .ID )
302+ ws = coderdtest .MustWorkspace (t ,client ,task .WorkspaceID .UUID )
300303// Assert invariant: the workspace has exactly one resource with one agent with one app.
301304require .Len (t ,ws .LatestBuild .Resources ,1 )
302305require .Len (t ,ws .LatestBuild .Resources [0 ].Agents ,1 )
303306agentID := ws .LatestBuild .Resources [0 ].Agents [0 ].ID
304307taskAppID := ws .LatestBuild .Resources [0 ].Agents [0 ].Apps [0 ].ID
305308
306309// Insert an app status for the workspace
307- _ ,err : =db .InsertWorkspaceAppStatus (dbauthz .AsSystemRestricted (ctx ), database.InsertWorkspaceAppStatusParams {
310+ _ ,err = db .InsertWorkspaceAppStatus (dbauthz .AsSystemRestricted (ctx ), database.InsertWorkspaceAppStatusParams {
308311ID :uuid .New (),
309- WorkspaceID :workspace . ID ,
312+ WorkspaceID :task . WorkspaceID . UUID ,
310313CreatedAt :dbtime .Now (),
311314AgentID :agentID ,
312315AppID :taskAppID ,
@@ -316,31 +319,33 @@ func TestTasks(t *testing.T) {
316319require .NoError (t ,err )
317320
318321// Fetch the task by ID via experimental API and verify fields.
319- exp := codersdk .NewExperimentalClient (client )
320- task ,err := exp .TaskByID (ctx ,workspace .ID )
322+ updated ,err := exp .TaskByID (ctx ,task .ID )
321323require .NoError (t ,err )
322324
323- assert .Equal (t ,workspace .ID ,task .ID ,"task ID should match workspace ID" )
324- assert .Equal (t ,workspace .Name ,task .Name ,"task name should map from workspace name" )
325- assert .Equal (t ,wantPrompt ,task .InitialPrompt ,"task prompt should match the AI Prompt parameter" )
326- assert .Equal (t ,workspace .ID ,task .WorkspaceID .UUID ,"workspace id should match" )
327- assert .NotEmpty (t ,task .WorkspaceStatus ,"task status should not be empty" )
325+ assert .Equal (t ,task .ID ,updated .ID ,"task ID should match" )
326+ assert .Equal (t ,task .Name ,updated .Name ,"task name should match" )
327+ assert .Equal (t ,wantPrompt ,updated .InitialPrompt ,"task prompt should match the AI Prompt parameter" )
328+ assert .Equal (t ,task .WorkspaceID .UUID ,updated .WorkspaceID .UUID ,"workspace id should match" )
329+ assert .Equal (t ,ws .LatestBuild .BuildNumber ,updated .WorkspaceBuildNumber ,"workspace build number should match" )
330+ assert .Equal (t ,agentID ,updated .WorkspaceAgentID .UUID ,"workspace agent id should match" )
331+ assert .Equal (t ,taskAppID ,updated .WorkspaceAppID .UUID ,"workspace app id should match" )
332+ assert .NotEmpty (t ,updated .WorkspaceStatus ,"task status should not be empty" )
328333
329334// Stop the workspace
330- coderdtest .MustTransitionWorkspace (t ,client ,workspace . ID ,codersdk .WorkspaceTransitionStart ,codersdk .WorkspaceTransitionStop )
335+ coderdtest .MustTransitionWorkspace (t ,client ,task . WorkspaceID . UUID ,codersdk .WorkspaceTransitionStart ,codersdk .WorkspaceTransitionStop )
331336
332337// Verify that the previous status still remains
333- updated ,err : =exp .TaskByID (ctx ,workspace .ID )
338+ updated ,err = exp .TaskByID (ctx ,task .ID )
334339require .NoError (t ,err )
335340assert .NotNil (t ,updated .CurrentState ,"current state should not be nil" )
336341assert .Equal (t ,"all done" ,updated .CurrentState .Message )
337342assert .Equal (t ,codersdk .TaskStateComplete ,updated .CurrentState .State )
338343
339344// Start the workspace again
340- coderdtest .MustTransitionWorkspace (t ,client ,workspace . ID ,codersdk .WorkspaceTransitionStop ,codersdk .WorkspaceTransitionStart )
345+ coderdtest .MustTransitionWorkspace (t ,client ,task . WorkspaceID . UUID ,codersdk .WorkspaceTransitionStop ,codersdk .WorkspaceTransitionStart )
341346
342347// Verify that the status from the previous build is no longer present
343- updated ,err = exp .TaskByID (ctx ,workspace .ID )
348+ updated ,err = exp .TaskByID (ctx ,task .ID )
344349require .NoError (t ,err )
345350assert .Nil (t ,updated .CurrentState ,"current state should be nil" )
346351})