Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(cli/templatepush): only implicitly read from stdin if the directory flag is unset#19681

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ethanndickson merged 1 commit intomainfromethan/fix-unintentional-stdin
Sep 4, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletionscli/templatepush.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -309,8 +309,9 @@ func (pf *templateUploadFlags) stdin(inv *serpent.Invocation) (out bool) {
inv.Logger.Info(inv.Context(), "uploading tar read from stdin")
}
}()
// We let the directory override our isTTY check
return pf.directory == "-" || (!isTTYIn(inv) && pf.directory == ".")
// We read a tar from stdin if the directory is "-" or if we're not in a
// TTY and the directory flag is unset.
return pf.directory == "-" || (!isTTYIn(inv) && !inv.ParsedFlags().Lookup("directory").Changed)
}

func (pf *templateUploadFlags) upload(inv *serpent.Invocation, client *codersdk.Client) (*codersdk.UploadResponse, error) {
Expand Down
40 changes: 40 additions & 0 deletionscli/templatepush_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -339,6 +339,7 @@ func TestTemplatePush(t *testing.T) {
inv, root := clitest.New(t, "templates", "push",
"--test.provisioner", string(database.ProvisionerTypeEcho),
"--test.workdir", source,
"--force-tty",
)
clitest.SetupConfig(t, templateAdmin, root)
pty := ptytest.New(t).Attach(inv)
Expand DownExpand Up@@ -1075,6 +1076,45 @@ func TestTemplatePush(t *testing.T) {
require.Equal(t, templateName, template.Name)
require.NotEqual(t, uuid.Nil, template.ActiveVersionID)
})

t.Run("NoStdinWithCurrentDirectory", 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)

source := clitest.CreateTemplateVersionSource(t, &echo.Responses{
Parse: echo.ParseComplete,
ProvisionApply: echo.ApplyComplete,
})

inv, root := clitest.New(t, "templates", "push", template.Name,
"--directory", ".",
"--test.provisioner", string(database.ProvisionerTypeEcho),
"--test.workdir", source,
"--name", "example",
"--yes")
clitest.SetupConfig(t, templateAdmin, root)

inv.Stdin = strings.NewReader("invalid tar content that would cause failure")

ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitMedium)
defer cancel()

err := inv.WithContext(ctx).Run()
require.NoError(t, err, "Should succeed without reading from stdin")

templateVersions, err := client.TemplateVersionsByTemplate(ctx, codersdk.TemplateVersionsByTemplateRequest{
TemplateID: template.ID,
})
require.NoError(t, err)
require.Len(t, templateVersions, 2)
require.Equal(t, "example", templateVersions[1].Name)
})
})
}

Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp