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

Function setupCLITaskTest

cli/task_test.go:291–340  ·  view source on GitHub ↗
(ctx context.Context, t *testing.T, agentAPIHandlers map[string]http.HandlerFunc)

Source from the content-addressed store, hash-verified

289}
290
291func 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.
343func pauseTask(ctx context.Context, t *testing.T, client *codersdk.Client, task codersdk.Task) {

Callers 4

TestExpTaskResumeFunction · 0.85
Test_TaskLogs_GoldenFunction · 0.85
Test_TaskSendFunction · 0.85
TestExpTaskPauseFunction · 0.85

Calls 15

NewFunction · 0.92
CreateFirstUserFunction · 0.92
CreateAnotherUserFunction · 0.92
NewFunction · 0.92
WithFixedTokenFunction · 0.92
NewFunction · 0.92
NewWorkspaceAgentWaiterFunction · 0.92
startFakeAgentAPIFunction · 0.85
createAITaskTemplateFunction · 0.85
withSidebarURLFunction · 0.85
withAgentTokenFunction · 0.85

Tested by

no test coverage detected