diff --git a/coderd/autobuild/executor/lifecycle_executor.go b/coderd/autobuild/executor/lifecycle_executor.go index 1993742cce1fa..40d5ccbdc6626 100644 --- a/coderd/autobuild/executor/lifecycle_executor.go +++ b/coderd/autobuild/executor/lifecycle_executor.go @@ -295,7 +295,7 @@ func build(ctx context.Context, store database.Store, workspace database.Workspa CreatedAt: now, UpdatedAt: now, WorkspaceID: workspace.ID, - TemplateVersionID: priorHistory.TemplateVersionID, + TemplateVersionID: template.ActiveVersionID, BuildNumber: priorBuildNumber + 1, ProvisionerState: priorHistory.ProvisionerState, InitiatorID: workspace.OwnerID, diff --git a/coderd/autobuild/executor/lifecycle_executor_test.go b/coderd/autobuild/executor/lifecycle_executor_test.go index 4e53246213e1e..8b3e6b89fd4ed 100644 --- a/coderd/autobuild/executor/lifecycle_executor_test.go +++ b/coderd/autobuild/executor/lifecycle_executor_test.go @@ -99,14 +99,14 @@ func TestExecutorAutostartTemplateUpdated(t *testing.T) { close(tickCh) }() - // Then: the workspace should be started using the previous template version, and not the updated version. + // Then: the workspace is started using the new template version, not the old one. stats := <-statsCh assert.NoError(t, stats.Error) assert.Len(t, stats.Transitions, 1) assert.Contains(t, stats.Transitions, workspace.ID) assert.Equal(t, database.WorkspaceTransitionStart, stats.Transitions[workspace.ID]) ws := coderdtest.MustWorkspace(t, client, workspace.ID) - assert.Equal(t, workspace.LatestBuild.TemplateVersionID, ws.LatestBuild.TemplateVersionID, "expected workspace build to be using the old template version") + assert.Equal(t, newVersion.ID, ws.LatestBuild.TemplateVersionID, "expected workspace build to be using the new template version") } func TestExecutorAutostartAlreadyRunning(t *testing.T) {