mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: add display name field for tasks (#20856)
## Problem Tasks currently only expose a machine-friendly name field (e.g. `task-python-debug-a1b2`), but this value is primarily an identifier rather than a clean, descriptive label. We need a separate display-friendly name for use in the UI. This PR introduces a new `display_name` field and updates the task-name generation flow. The Claude system prompt was updated to return valid JSON with both `name` and `display_name`. The name generation logic follows a fallback chain (Anthropic > prompt sanitization > random fallback). To make task names more closely resemble their display names, the legacy `task-` prefix has been removed. For context, PR https://github.com/coder/coder/pull/20834 introduced a small Task icon to the workspace list to help identify workspaces associated to tasks. ## Changes - Database migration: Added `display_name` column to tasks table - Updated system prompt to generate both task name and display name as valid JSON - Task name generation now follows a fallback chain: Anthropic > prompt sanitization > random fallback - Removed `task-` prefix from task names to allow more descriptive names - Note: PR https://github.com/coder/coder/pull/20834 adds a Task icon to workspaces in the workspace list to distinguish task-created workspaces **Note:** UI changes will be addressed in a follow-up PR Related to: https://github.com/coder/coder/issues/20801
This commit is contained in:
+49
-7
@@ -1049,14 +1049,17 @@ func TestTasksCreate(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
taskName string
|
||||
expectFallbackName bool
|
||||
expectError string
|
||||
name string
|
||||
taskName string
|
||||
taskDisplayName string
|
||||
expectFallbackName bool
|
||||
expectFallbackDisplayName bool
|
||||
expectError string
|
||||
}{
|
||||
{
|
||||
name: "ValidName",
|
||||
taskName: "a-valid-task-name",
|
||||
name: "ValidName",
|
||||
taskName: "a-valid-task-name",
|
||||
expectFallbackDisplayName: true,
|
||||
},
|
||||
{
|
||||
name: "NotValidName",
|
||||
@@ -1066,8 +1069,37 @@ func TestTasksCreate(t *testing.T) {
|
||||
{
|
||||
name: "NoNameProvided",
|
||||
taskName: "",
|
||||
taskDisplayName: "A valid task display name",
|
||||
expectFallbackName: true,
|
||||
},
|
||||
{
|
||||
name: "ValidDisplayName",
|
||||
taskDisplayName: "A valid task display name",
|
||||
expectFallbackName: true,
|
||||
},
|
||||
{
|
||||
name: "NotValidDisplayName",
|
||||
taskDisplayName: "This is a task display name with a length greater than 64 characters.",
|
||||
expectError: "Display name must be 64 characters or less.",
|
||||
},
|
||||
{
|
||||
name: "NoDisplayNameProvided",
|
||||
taskName: "a-valid-task-name",
|
||||
taskDisplayName: "",
|
||||
expectFallbackDisplayName: true,
|
||||
},
|
||||
{
|
||||
name: "ValidNameAndDisplayName",
|
||||
taskName: "a-valid-task-name",
|
||||
taskDisplayName: "A valid task display name",
|
||||
},
|
||||
{
|
||||
name: "NoNameAndDisplayNameProvided",
|
||||
taskName: "",
|
||||
taskDisplayName: "",
|
||||
expectFallbackName: true,
|
||||
expectFallbackDisplayName: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
@@ -1098,6 +1130,7 @@ func TestTasksCreate(t *testing.T) {
|
||||
TemplateVersionID: template.ActiveVersionID,
|
||||
Input: "Some prompt",
|
||||
Name: tt.taskName,
|
||||
DisplayName: tt.taskDisplayName,
|
||||
})
|
||||
if tt.expectError == "" {
|
||||
require.NoError(t, err)
|
||||
@@ -1111,8 +1144,17 @@ func TestTasksCreate(t *testing.T) {
|
||||
if !tt.expectFallbackName {
|
||||
require.Equal(t, tt.taskName, task.Name)
|
||||
}
|
||||
|
||||
// Then: We expect the correct display name to have been picked.
|
||||
require.NotEmpty(t, task.DisplayName)
|
||||
if !tt.expectFallbackDisplayName {
|
||||
require.Equal(t, tt.taskDisplayName, task.DisplayName)
|
||||
}
|
||||
} else {
|
||||
require.ErrorContains(t, err, tt.expectError)
|
||||
var apiErr *codersdk.Error
|
||||
require.ErrorAs(t, err, &apiErr)
|
||||
require.Equal(t, http.StatusBadRequest, apiErr.StatusCode())
|
||||
require.Equal(t, apiErr.Message, tt.expectError)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user