Compare commits

...

3 Commits

Author SHA1 Message Date
Atif Ali a822e303e9 fix(cli): remove problematic pty.Output() call from test
The pty.Output() call was causing an error after the command completed.
The test already verifies the output format with ExpectMatchContext,
so we only need to verify the version was created in the database.
2025-12-09 16:24:08 +00:00
Atif Ali cb2d0add26 fix(cli): update test expectation for new version output format
The test was expecting the old output format "Updated version at" but
the new format is "Updated version {name} at". Updated the test to
match the beginning of the output string.
2025-12-09 16:03:07 +00:00
Atif Ali d53c8d8d05 fix(cli): display template version name in push output
Previously, when running `coder templates push` without specifying a
`--name` flag, the backend would autogenerate a version name (e.g.,
"kind_nightingale"), but the CLI never displayed this name to the user.
This made it difficult to reference the version later.

This change updates the success message to include the version name,
whether it was autogenerated or user-specified.

Output changes from:
  "Updated version at Jan 2 15:04:05!"
to:
  "Updated version kind_nightingale at Jan 2 15:04:05!"

Closes #21111

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-09 15:50:25 +00:00
2 changed files with 85 additions and 2 deletions
+3 -1
View File
@@ -204,7 +204,9 @@ func (r *RootCmd) templatePush() *serpent.Command {
}
}
_, _ = fmt.Fprintf(inv.Stdout, "Updated version at %s!\n", pretty.Sprint(cliui.DefaultStyles.DateTimeStamp, time.Now().Format(time.Stamp)))
_, _ = fmt.Fprintf(inv.Stdout, "Updated version %s at %s!\n",
pretty.Sprint(cliui.DefaultStyles.Keyword, job.Name),
pretty.Sprint(cliui.DefaultStyles.DateTimeStamp, time.Now().Format(time.Stamp)))
return nil
},
}
+82 -1
View File
@@ -106,7 +106,7 @@ func TestTemplatePush(t *testing.T) {
inv = inv.WithContext(ctx)
w := clitest.StartWithWaiter(t, inv)
pty.ExpectNoMatchBefore(ctx, "Template message is longer than 72 characters", "Updated version at")
pty.ExpectNoMatchBefore(ctx, "Template message is longer than 72 characters", "Updated version")
w.RequireSuccess()
@@ -1302,6 +1302,87 @@ cli_overrides_file_var: from-file`)
require.Equal(t, "from-cli-override", varMap["cli_overrides_file_var"])
})
})
t.Run("DisplayAutogeneratedVersionName", func(t *testing.T) {
t.Parallel()
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
owner := coderdtest.CreateFirstUser(t, client)
templateAdmin, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID, rbac.RoleTemplateAdmin())
version := coderdtest.CreateTemplateVersion(t, client, owner.OrganizationID, nil)
_ = coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID)
template := coderdtest.CreateTemplate(t, client, owner.OrganizationID, version.ID)
// Test the cli command without --name flag (autogenerated name).
source := clitest.CreateTemplateVersionSource(t, &echo.Responses{
Parse: echo.ParseComplete,
ProvisionApply: echo.ApplyComplete,
})
inv, root := clitest.New(t, "templates", "push", template.Name, "--directory", source, "--test.provisioner", string(database.ProvisionerTypeEcho), "--yes")
clitest.SetupConfig(t, templateAdmin, root)
pty := ptytest.New(t).Attach(inv)
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitMedium)
defer cancel()
inv = inv.WithContext(ctx)
w := clitest.StartWithWaiter(t, inv)
// Expect the output to contain "Updated version" followed by the version name.
pty.ExpectMatchContext(ctx, "Updated version")
w.RequireSuccess()
// Verify the autogenerated template version was created.
templateVersions, err := client.TemplateVersionsByTemplate(context.Background(), codersdk.TemplateVersionsByTemplateRequest{
TemplateID: template.ID,
})
require.NoError(t, err)
assert.Len(t, templateVersions, 2)
assert.NotEqual(t, template.ActiveVersionID, templateVersions[1].ID)
// Verify the autogenerated name is not empty (it should be something like "fervent_austin5").
assert.NotEmpty(t, templateVersions[1].Name)
})
t.Run("DisplayUserSpecifiedVersionName", func(t *testing.T) {
t.Parallel()
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
owner := coderdtest.CreateFirstUser(t, client)
templateAdmin, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID, rbac.RoleTemplateAdmin())
version := coderdtest.CreateTemplateVersion(t, client, owner.OrganizationID, nil)
_ = coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID)
template := coderdtest.CreateTemplate(t, client, owner.OrganizationID, version.ID)
// Test the cli command with --name flag.
source := clitest.CreateTemplateVersionSource(t, &echo.Responses{
Parse: echo.ParseComplete,
ProvisionApply: echo.ApplyComplete,
})
versionName := "my-custom-version"
inv, root := clitest.New(t, "templates", "push", template.Name, "--directory", source, "--test.provisioner", string(database.ProvisionerTypeEcho), "--name", versionName, "--yes")
clitest.SetupConfig(t, templateAdmin, root)
pty := ptytest.New(t).Attach(inv)
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitMedium)
defer cancel()
inv = inv.WithContext(ctx)
w := clitest.StartWithWaiter(t, inv)
// Expect the output to contain "Updated version my-custom-version".
pty.ExpectMatchContext(ctx, "Updated version "+versionName)
w.RequireSuccess()
// Assert that the template version has the correct name.
templateVersions, err := client.TemplateVersionsByTemplate(context.Background(), codersdk.TemplateVersionsByTemplateRequest{
TemplateID: template.ID,
})
require.NoError(t, err)
assert.Len(t, templateVersions, 2)
require.Equal(t, versionName, templateVersions[1].Name)
})
}
func createEchoResponsesWithTemplateVariables(templateVariables []*proto.TemplateVariable) *echo.Responses {