mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: set codersdk.Task current_state during task initialization (#20692)
## Problem With the new tasks data model, a task starts with an `initializing` status. However, the API returns `current_state: null` to represent the agent state, causing the frontend to display "No message available". This PR updates `codersdk.Task` to return a `current_state` when the task is initializing with meaningful messages about what's happening during task initialization. **Previous message** <img width="2764" height="288" alt="Screenshot 2025-11-07 at 09 06 13" src="https://github.com/user-attachments/assets/feec9f15-91ca-4378-8565-5f9de062d11a" /> **New message** <img width="2726" height="226" alt="Screenshot 2025-11-12 at 11 00 15" src="https://github.com/user-attachments/assets/2f9bee3e-7ac4-4382-b1c3-1d06bbc2906e" /> ## Changes - Populate `current_state` with descriptive initialization messages when task status is `initializing` and no valid app status exists for the current build - **dbfake**: Fix `WorkspaceBuild` builder to properly handle pending/running jobs by linking tasks without requiring agent/app resources **Note:** UI Storybook changes to reflect these new messages will be addressed in a follow-up PR. Closes: https://github.com/coder/internal/issues/1063
This commit is contained in:
@@ -240,14 +240,18 @@ func TestTasks(t *testing.T) {
|
||||
assert.NotNil(t, updated.CurrentState, "current state should not be nil")
|
||||
assert.Equal(t, "all done", updated.CurrentState.Message)
|
||||
assert.Equal(t, codersdk.TaskStateComplete, updated.CurrentState.State)
|
||||
previousCurrentState := updated.CurrentState
|
||||
|
||||
// Start the workspace again
|
||||
coderdtest.MustTransitionWorkspace(t, client, task.WorkspaceID.UUID, codersdk.WorkspaceTransitionStop, codersdk.WorkspaceTransitionStart)
|
||||
|
||||
// Verify that the status from the previous build is no longer present
|
||||
// Verify that the status from the previous build has been cleared
|
||||
// and replaced by the agent initialization status.
|
||||
updated, err = exp.TaskByID(ctx, task.ID)
|
||||
require.NoError(t, err)
|
||||
assert.Nil(t, updated.CurrentState, "current state should be nil")
|
||||
assert.NotEqual(t, previousCurrentState, updated.CurrentState)
|
||||
assert.Equal(t, codersdk.TaskStateWorking, updated.CurrentState.State)
|
||||
assert.NotEqual(t, "all done", updated.CurrentState.Message)
|
||||
})
|
||||
|
||||
t.Run("Delete", func(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user