(ctx context.Context, t *testing.T, agentAPIHandlers map[string]http.HandlerFunc)
| 289 | } |
| 290 | |
| 291 | func setupCLITaskTest(ctx context.Context, t *testing.T, agentAPIHandlers map[string]http.HandlerFunc) setupCLITaskTestResult { |
| 292 | t.Helper() |
| 293 | |
| 294 | ownerClient := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true}) |
| 295 | owner := coderdtest.CreateFirstUser(t, ownerClient) |
| 296 | userClient, _ := coderdtest.CreateAnotherUser(t, ownerClient, owner.OrganizationID) |
| 297 | |
| 298 | fakeAPI := startFakeAgentAPI(t, agentAPIHandlers) |
| 299 | |
| 300 | authToken := uuid.NewString() |
| 301 | template := createAITaskTemplate(t, ownerClient, owner.OrganizationID, withSidebarURL(fakeAPI.URL()), withAgentToken(authToken)) |
| 302 | |
| 303 | wantPrompt := "test prompt" |
| 304 | task, err := userClient.CreateTask(ctx, codersdk.Me, codersdk.CreateTaskRequest{ |
| 305 | TemplateVersionID: template.ActiveVersionID, |
| 306 | Input: wantPrompt, |
| 307 | Name: "test-task", |
| 308 | }) |
| 309 | require.NoError(t, err) |
| 310 | |
| 311 | // Wait for the task's underlying workspace to be built. |
| 312 | require.True(t, task.WorkspaceID.Valid, "task should have a workspace ID") |
| 313 | workspace, err := userClient.Workspace(ctx, task.WorkspaceID.UUID) |
| 314 | require.NoError(t, err) |
| 315 | coderdtest.AwaitWorkspaceBuildJobCompleted(t, userClient, workspace.LatestBuild.ID) |
| 316 | |
| 317 | agentClient := agentsdk.New(userClient.URL, agentsdk.WithFixedToken(authToken)) |
| 318 | agt := agenttest.New(t, userClient.URL, authToken, func(o *agent.Options) { |
| 319 | o.Client = agentClient |
| 320 | }) |
| 321 | |
| 322 | coderdtest.NewWorkspaceAgentWaiter(t, userClient, workspace.ID). |
| 323 | WaitFor(coderdtest.AgentsReady) |
| 324 | |
| 325 | // Report the task app as idle so that waitForTaskIdle can proceed. |
| 326 | err = agentClient.PatchAppStatus(ctx, agentsdk.PatchAppStatus{ |
| 327 | AppSlug: "task-sidebar", |
| 328 | State: codersdk.WorkspaceAppStatusStateIdle, |
| 329 | Message: "ready", |
| 330 | }) |
| 331 | require.NoError(t, err) |
| 332 | |
| 333 | return setupCLITaskTestResult{ |
| 334 | ownerClient: ownerClient, |
| 335 | userClient: userClient, |
| 336 | task: task, |
| 337 | agentToken: authToken, |
| 338 | agent: agt, |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | // pauseTask pauses the task and waits for the stop build to complete. |
| 343 | func pauseTask(ctx context.Context, t *testing.T, client *codersdk.Client, task codersdk.Task) { |
no test coverage detected