setupCLITaskTestWithSnapshot creates a task in the specified status with a log snapshot. Note: We do not use IncludeProvisionerDaemon because these tests use dbfake to directly set up database state and don't need actual provisioning. This also avoids potential interference from the provisioner daem
(ctx context.Context, t *testing.T, status codersdk.TaskStatus, messages []agentapisdk.Message)
| 365 | // set up database state and don't need actual provisioning. This also avoids potential |
| 366 | // interference from the provisioner daemon polling for jobs. |
| 367 | func setupCLITaskTestWithSnapshot(ctx context.Context, t *testing.T, status codersdk.TaskStatus, messages []agentapisdk.Message) (*codersdk.Client, codersdk.Task) { |
| 368 | t.Helper() |
| 369 | |
| 370 | ownerClient, db := coderdtest.NewWithDatabase(t, nil) |
| 371 | owner := coderdtest.CreateFirstUser(t, ownerClient) |
| 372 | userClient, user := coderdtest.CreateAnotherUser(t, ownerClient, owner.OrganizationID) |
| 373 | |
| 374 | ownerUser, err := ownerClient.User(ctx, owner.UserID.String()) |
| 375 | require.NoError(t, err) |
| 376 | ownerSubject := coderdtest.AuthzUserSubject(ownerUser) |
| 377 | |
| 378 | task := createTaskInStatus(t, db, owner.OrganizationID, user.ID, status) |
| 379 | |
| 380 | // Create snapshot envelope with agentapi format. |
| 381 | envelope := coderd.TaskLogSnapshotEnvelope{ |
| 382 | Format: "agentapi", |
| 383 | Data: agentapisdk.GetMessagesResponse{ |
| 384 | Messages: messages, |
| 385 | }, |
| 386 | } |
| 387 | snapshotJSON, err := json.Marshal(envelope) |
| 388 | require.NoError(t, err) |
| 389 | |
| 390 | // Insert snapshot into database. |
| 391 | snapshotTime := time.Now() |
| 392 | err = db.UpsertTaskSnapshot(dbauthz.As(ctx, ownerSubject), database.UpsertTaskSnapshotParams{ |
| 393 | TaskID: task.ID, |
| 394 | LogSnapshot: json.RawMessage(snapshotJSON), |
| 395 | LogSnapshotCreatedAt: snapshotTime, |
| 396 | }) |
| 397 | require.NoError(t, err) |
| 398 | |
| 399 | return userClient, task |
| 400 | } |
| 401 | |
| 402 | // setupCLITaskTestWithoutSnapshot creates a task in the specified status without a log snapshot. |
| 403 | // Note: We do not use IncludeProvisionerDaemon because these tests use dbfake to directly |
no test coverage detected