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

feat(cli): warn user if setting autostart on workspace with template-level autostart#20454

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
mtojek merged 3 commits intomainfrom15619-warn-autostart
Oct 24, 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
16 changes: 16 additions & 0 deletionscli/schedule.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -176,6 +176,22 @@ func (r *RootCmd) scheduleStart() *serpent.Command {
}

schedStr = ptr.Ref(sched.String())

// Check if the template has autostart requirements that may conflict
// with the user's schedule.
template, err := client.Template(inv.Context(), workspace.TemplateID)
if err != nil {
return xerrors.Errorf("get template: %w", err)
}

if len(template.AutostartRequirement.DaysOfWeek) > 0 {
_, _ = fmt.Fprintf(
inv.Stderr,
"Warning: your workspace template restricts autostart to the following days: %s.\n"+
"Your workspace may only autostart on these days.\n",
strings.Join(template.AutostartRequirement.DaysOfWeek, ", "),
)
}
}

err = client.UpdateWorkspaceAutostart(inv.Context(), workspace.ID, codersdk.UpdateWorkspaceAutostartRequest{
Expand Down
64 changes: 64 additions & 0 deletionscli/schedule_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -373,3 +373,67 @@ func TestScheduleOverride(t *testing.T) {
})
}
}

//nolint:paralleltest // t.Setenv
func TestScheduleStart_TemplateAutostartRequirement(t *testing.T) {
t.Setenv("TZ", "UTC")
loc, err := tz.TimezoneIANA()
require.NoError(t, err)
require.Equal(t, "UTC", loc.String())

client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
user := coderdtest.CreateFirstUser(t, client)

version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID)
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)

// Update template to have autostart requirement
// Note: In AGPL, this will be ignored and all days will be allowed (enterprise feature).
template, err = client.UpdateTemplateMeta(context.Background(), template.ID, codersdk.UpdateTemplateMeta{
AutostartRequirement: &codersdk.TemplateAutostartRequirement{
DaysOfWeek: []string{"monday", "wednesday", "friday"},
},
})
require.NoError(t, err)

// Verify the template - in AGPL, AutostartRequirement will have all days (enterprise feature)
template, err = client.Template(context.Background(), template.ID)
require.NoError(t, err)
require.NotEmpty(t, template.AutostartRequirement.DaysOfWeek, "template should have autostart requirement days")

workspace := coderdtest.CreateWorkspace(t, client, template.ID)
coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, workspace.LatestBuild.ID)

t.Run("ShowsWarning", func(t *testing.T) {
// When: user sets autostart schedule
inv, root := clitest.New(t,
"schedule", "start", workspace.Name, "9:30AM", "Mon-Fri",
)
clitest.SetupConfig(t, client, root)
pty := ptytest.New(t).Attach(inv)
require.NoError(t, inv.Run())

// Then: warning should be shown
// In AGPL, this will show all days (enterprise feature defaults to all days allowed)
pty.ExpectMatch("Warning")
pty.ExpectMatch("may only autostart")
})

t.Run("NoWarningWhenManual", func(t *testing.T) {
// When: user sets manual schedule
inv, root := clitest.New(t,
"schedule", "start", workspace.Name, "manual",
)
clitest.SetupConfig(t, client, root)

var stderrBuf bytes.Buffer
inv.Stderr = &stderrBuf

require.NoError(t, inv.Run())

// Then: no warning should be shown on stderr
stderrOutput := stderrBuf.String()
require.NotContains(t, stderrOutput, "Warning")
})
}
Loading

[8]ページ先頭

©2009-2025 Movatter.jp