Skip to content

fix: prompt when parameter options are incompatible #9247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Aug 23, 2023
Prev Previous commit
Add test for disappeared option
  • Loading branch information
mtojek committed Aug 23, 2023
commit c03a58109379a4859c4c0616268531fbd382786d
1 change: 1 addition & 0 deletions cli/parameterresolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ func (pr *ParameterResolver) resolveWithInput(resolved []codersdk.WorkspaceBuild

firstTimeUse := pr.isFirstTimeUse(tvp.Name)
promptParameterOption := pr.isLastBuildParameterInvalidOption(tvp)

if (tvp.Ephemeral && pr.promptBuildOptions) ||
(action == WorkspaceCreate && tvp.Required) ||
(action == WorkspaceCreate && !tvp.Ephemeral) ||
Expand Down
66 changes: 66 additions & 0 deletions cli/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,72 @@ func TestUpdateValidateRichParameters(t *testing.T) {
<-doneChan
})

t.Run("ParameterOptionDisappeared", func(t *testing.T) {
t.Parallel()

// Create template and workspace
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
user := coderdtest.CreateFirstUser(t, client)

templateParameters := []*proto.RichParameter{
{Name: stringParameterName, Type: "string", Mutable: true, Required: true, Options: []*proto.RichParameterOption{
{Name: "First option", Description: "This is first option", Value: "1st"},
{Name: "Second option", Description: "This is second option", Value: "2nd"},
{Name: "Third option", Description: "This is third option", Value: "3rd"},
}},
}
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, prepareEchoResponses(templateParameters))
coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)

inv, root := clitest.New(t, "create", "my-workspace", "--yes", "--template", template.Name, "--parameter", fmt.Sprintf("%s=%s", stringParameterName, "2nd"))
clitest.SetupConfig(t, client, root)
err := inv.Run()
require.NoError(t, err)

// Update template - 2nd option disappeared, 4th option added
updatedTemplateParameters := []*proto.RichParameter{
{Name: stringParameterName, Type: "string", Mutable: true, Required: true, Options: []*proto.RichParameterOption{
{Name: "First option", Description: "This is first option", Value: "1st"},
{Name: "Third option", Description: "This is third option", Value: "3rd"},
{Name: "Fourth option", Description: "This is fourth option", Value: "4th"},
}},
}

updatedVersion := coderdtest.UpdateTemplateVersion(t, client, user.OrganizationID, prepareEchoResponses(updatedTemplateParameters), template.ID)
coderdtest.AwaitTemplateVersionJob(t, client, updatedVersion.ID)
err = client.UpdateActiveTemplateVersion(context.Background(), template.ID, codersdk.UpdateActiveTemplateVersion{
ID: updatedVersion.ID,
})
require.NoError(t, err)

// Update the workspace
inv, root = clitest.New(t, "update", "my-workspace")
clitest.SetupConfig(t, client, root)
doneChan := make(chan struct{})
pty := ptytest.New(t).Attach(inv)
go func() {
defer close(doneChan)
err := inv.Run()
assert.NoError(t, err)
}()

matches := []string{
stringParameterName, "Third option",
"Planning workspace...", "",
}
for i := 0; i < len(matches); i += 2 {
match := matches[i]
value := matches[i+1]
pty.ExpectMatch(match)

if value != "" {
pty.WriteLine(value)
}
}
<-doneChan
})

t.Run("ImmutableRequiredParameterExists_MutableRequiredParameterAdded", func(t *testing.T) {
t.Parallel()

Expand Down