@@ -373,3 +373,67 @@ func TestScheduleOverride(t *testing.T) {
373373})
374374}
375375}
376+
377+ //nolint:paralleltest // t.Setenv
378+ func TestScheduleStart_TemplateAutostartRequirement (t * testing.T ) {
379+ t .Setenv ("TZ" ,"UTC" )
380+ loc ,err := tz .TimezoneIANA ()
381+ require .NoError (t ,err )
382+ require .Equal (t ,"UTC" ,loc .String ())
383+
384+ client := coderdtest .New (t ,& coderdtest.Options {IncludeProvisionerDaemon :true })
385+ user := coderdtest .CreateFirstUser (t ,client )
386+
387+ version := coderdtest .CreateTemplateVersion (t ,client ,user .OrganizationID ,nil )
388+ coderdtest .AwaitTemplateVersionJobCompleted (t ,client ,version .ID )
389+ template := coderdtest .CreateTemplate (t ,client ,user .OrganizationID ,version .ID )
390+
391+ // Update template to have autostart requirement
392+ // Note: In AGPL, this will be ignored and all days will be allowed (enterprise feature).
393+ template ,err = client .UpdateTemplateMeta (context .Background (),template .ID , codersdk.UpdateTemplateMeta {
394+ AutostartRequirement :& codersdk.TemplateAutostartRequirement {
395+ DaysOfWeek : []string {"monday" ,"wednesday" ,"friday" },
396+ },
397+ })
398+ require .NoError (t ,err )
399+
400+ // Verify the template - in AGPL, AutostartRequirement will have all days (enterprise feature)
401+ template ,err = client .Template (context .Background (),template .ID )
402+ require .NoError (t ,err )
403+ require .NotEmpty (t ,template .AutostartRequirement .DaysOfWeek ,"template should have autostart requirement days" )
404+
405+ workspace := coderdtest .CreateWorkspace (t ,client ,template .ID )
406+ coderdtest .AwaitWorkspaceBuildJobCompleted (t ,client ,workspace .LatestBuild .ID )
407+
408+ t .Run ("ShowsWarning" ,func (t * testing.T ) {
409+ // When: user sets autostart schedule
410+ inv ,root := clitest .New (t ,
411+ "schedule" ,"start" ,workspace .Name ,"9:30AM" ,"Mon-Fri" ,
412+ )
413+ clitest .SetupConfig (t ,client ,root )
414+ pty := ptytest .New (t ).Attach (inv )
415+ require .NoError (t ,inv .Run ())
416+
417+ // Then: warning should be shown
418+ // In AGPL, this will show all days (enterprise feature defaults to all days allowed)
419+ pty .ExpectMatch ("Warning" )
420+ pty .ExpectMatch ("may only autostart" )
421+ })
422+
423+ t .Run ("NoWarningWhenManual" ,func (t * testing.T ) {
424+ // When: user sets manual schedule
425+ inv ,root := clitest .New (t ,
426+ "schedule" ,"start" ,workspace .Name ,"manual" ,
427+ )
428+ clitest .SetupConfig (t ,client ,root )
429+
430+ var stderrBuf bytes.Buffer
431+ inv .Stderr = & stderrBuf
432+
433+ require .NoError (t ,inv .Run ())
434+
435+ // Then: no warning should be shown on stderr
436+ stderrOutput := stderrBuf .String ()
437+ require .NotContains (t ,stderrOutput ,"Warning" )
438+ })
439+ }