@@ -710,6 +710,61 @@ func TestUpdateValidateRichParameters(t *testing.T) {
710
710
<- doneChan
711
711
})
712
712
713
+ t .Run ("ParameterOptionFailsMonotonicValidation" , func (t * testing.T ) {
714
+ t .Parallel ()
715
+
716
+ // Create template and workspace
717
+ client := coderdtest .New (t , & coderdtest.Options {IncludeProvisionerDaemon : true })
718
+ owner := coderdtest .CreateFirstUser (t , client )
719
+ member , _ := coderdtest .CreateAnotherUser (t , client , owner .OrganizationID )
720
+
721
+ const tempVal = "2"
722
+
723
+ templateParameters := []* proto.RichParameter {
724
+ {Name : numberParameterName , Type : "number" , Mutable : true , Required : true , Options : []* proto.RichParameterOption {
725
+ {Name : "First option" , Description : "This is first option" , Value : "1" },
726
+ {Name : "Second option" , Description : "This is second option" , Value : tempVal },
727
+ {Name : "Third option" , Description : "This is third option" , Value : "3" },
728
+ }, ValidationMonotonic : string (codersdk .MonotonicOrderIncreasing )},
729
+ }
730
+ version := coderdtest .CreateTemplateVersion (t , client , owner .OrganizationID , prepareEchoResponses (templateParameters ))
731
+ coderdtest .AwaitTemplateVersionJobCompleted (t , client , version .ID )
732
+ template := coderdtest .CreateTemplate (t , client , owner .OrganizationID , version .ID )
733
+
734
+ // Create new workspace
735
+ inv , root := clitest .New (t , "create" , "my-workspace" , "--yes" , "--template" , template .Name , "--parameter" , fmt .Sprintf ("%s=%s" , numberParameterName , tempVal ))
736
+ clitest .SetupConfig (t , member , root )
737
+ ptytest .New (t ).Attach (inv )
738
+ err := inv .Run ()
739
+ require .NoError (t , err )
740
+
741
+ // Update the workspace
742
+ inv , root = clitest .New (t , "update" , "my-workspace" , "--always-prompt=true" )
743
+ clitest .SetupConfig (t , member , root )
744
+
745
+ doneChan := make (chan struct {})
746
+ pty := ptytest .New (t ).Attach (inv )
747
+ go func () {
748
+ defer close (doneChan )
749
+ err := inv .Run ()
750
+ // TODO: improve validation so we catch this problem before it reaches the server
751
+ // but for now just validate that the server actually catches invalid monotonicity
752
+ assert .ErrorContains (t , err , fmt .Sprintf ("parameter value must be equal or greater than previous value: %s" , tempVal ))
753
+ }()
754
+
755
+ matches := []string {
756
+ // `cliui.Select` will automatically pick the first option, which will cause the validation to fail because
757
+ // "1" is less than "2" which was selected initially.
758
+ numberParameterName ,
759
+ }
760
+ for i := 0 ; i < len (matches ); i += 2 {
761
+ match := matches [i ]
762
+ pty .ExpectMatch (match )
763
+ }
764
+
765
+ <- doneChan
766
+ })
767
+
713
768
t .Run ("ImmutableRequiredParameterExists_MutableRequiredParameterAdded" , func (t * testing.T ) {
714
769
t .Parallel ()
715
770
0 commit comments