From 7295d11917f01f33a1f48ff71796da5bfe604bb0 Mon Sep 17 00:00:00 2001 From: Roger Peppe Date: Tue, 3 Sep 2024 12:32:16 +0100 Subject: [PATCH] internal/cueexperiment: prevent disabling modules experiment This change deprecates the modules experiment flag, meaning that modules will always be enabled. We do not yet remove the code to deal with disabled modules, meaning that it will be straightforward to revert this change if it turns out to be necessary. Signed-off-by: Roger Peppe Change-Id: I846ea4cdbe15c871c3cd92d40cbc5b8809b7b67d Dispatch-Trailer: {"type":"trybot","CL":1200580,"patchset":3,"ref":"refs/changes/80/1200580/3","targetBranch":"master"} --- cmd/cue/cmd/testdata/script/def_proto.txtar | 4 --- .../script/modinit_majorversion.txtar | 10 ++---- .../script/modinit_nomajorversion.txtar | 10 +++--- .../modpublish_registry_not_enabled.txtar | 2 +- .../script/modtidy_registry_not_enabled.txtar | 2 +- .../script/registry_modules_disabled.txtar | 36 ++----------------- .../registry_modules_disabled_warning.txtar | 14 -------- internal/cueexperiment/exp.go | 2 +- internal/cueexperiment/exp_test.go | 11 ++++-- 9 files changed, 21 insertions(+), 70 deletions(-) delete mode 100644 cmd/cue/cmd/testdata/script/registry_modules_disabled_warning.txtar diff --git a/cmd/cue/cmd/testdata/script/def_proto.txtar b/cmd/cue/cmd/testdata/script/def_proto.txtar index c5f207334..b57c4ce77 100644 --- a/cmd/cue/cmd/testdata/script/def_proto.txtar +++ b/cmd/cue/cmd/testdata/script/def_proto.txtar @@ -1,7 +1,3 @@ -env CUE_EXPERIMENT=modules=0 -exec cue def policy.proto -p api -I include -cmp stdout expect-stdout - env CUE_EXPERIMENT=modules exec cue def policy.proto -p api -I include cmp stdout expect-stdout diff --git a/cmd/cue/cmd/testdata/script/modinit_majorversion.txtar b/cmd/cue/cmd/testdata/script/modinit_majorversion.txtar index 7e0bb3da6..d51926b5e 100644 --- a/cmd/cue/cmd/testdata/script/modinit_majorversion.txtar +++ b/cmd/cue/cmd/testdata/script/modinit_majorversion.txtar @@ -1,14 +1,10 @@ env-fill want-module.cue env-fill want-module-experiment.cue -# Without the experiment, the major version is allowed, -# even though it's not particularly useful. -# It feels unnecessary to ask the user to re-run with the experiment. +# No way of disabling the modules experiment. env CUE_EXPERIMENT=modules=0 -exec cue mod init foo.com/bar@v1 -cmp cue.mod/module.cue want-module.cue -exists cue.mod/usr -exists cue.mod/pkg +! exec cue mod init foo.com/bar@v1 +stderr 'cannot change default value of deprecated flag "modules"' # With the experiment, it works as expected. env CUE_EXPERIMENT=modules diff --git a/cmd/cue/cmd/testdata/script/modinit_nomajorversion.txtar b/cmd/cue/cmd/testdata/script/modinit_nomajorversion.txtar index 04fc4fe87..11ddb5163 100644 --- a/cmd/cue/cmd/testdata/script/modinit_nomajorversion.txtar +++ b/cmd/cue/cmd/testdata/script/modinit_nomajorversion.txtar @@ -1,12 +1,10 @@ env-fill want-module.cue env-fill want-module-experiment.cue -# Without the experiment, we use the module path as-is. -env CUE_EXPERIMENT=modules=false -exec cue mod init foo.com/bar -cmp cue.mod/module.cue want-module.cue -exists cue.mod/usr -exists cue.mod/pkg +# No way of disabling the modules experiment. +env CUE_EXPERIMENT=modules=0 +! exec cue mod init foo.com/bar +stderr 'cannot change default value of deprecated flag "modules"' # With the experiment, although the major version will be implied # as v0, it's still omitted so that there's a possibility of compatibility diff --git a/cmd/cue/cmd/testdata/script/modpublish_registry_not_enabled.txtar b/cmd/cue/cmd/testdata/script/modpublish_registry_not_enabled.txtar index d75d45a6c..6dd990e89 100644 --- a/cmd/cue/cmd/testdata/script/modpublish_registry_not_enabled.txtar +++ b/cmd/cue/cmd/testdata/script/modpublish_registry_not_enabled.txtar @@ -2,4 +2,4 @@ env CUE_EXPERIMENT=modules=false ! exec cue mod publish v1.0.0 cmp stderr want-stderr -- want-stderr -- -modules experiment not enabled (enable with CUE_EXPERIMENT=modules) +cannot parse CUE_EXPERIMENT: cannot change default value of deprecated flag "modules" diff --git a/cmd/cue/cmd/testdata/script/modtidy_registry_not_enabled.txtar b/cmd/cue/cmd/testdata/script/modtidy_registry_not_enabled.txtar index 6df187a4c..ee508276e 100644 --- a/cmd/cue/cmd/testdata/script/modtidy_registry_not_enabled.txtar +++ b/cmd/cue/cmd/testdata/script/modtidy_registry_not_enabled.txtar @@ -3,4 +3,4 @@ env CUE_EXPERIMENT=modules=0 ! exec cue mod tidy cmp stderr want-stderr -- want-stderr -- -modules experiment not enabled (enable with CUE_EXPERIMENT=modules) +cannot parse CUE_EXPERIMENT: cannot change default value of deprecated flag "modules" diff --git a/cmd/cue/cmd/testdata/script/registry_modules_disabled.txtar b/cmd/cue/cmd/testdata/script/registry_modules_disabled.txtar index 1db0c773f..9dcf8892e 100644 --- a/cmd/cue/cmd/testdata/script/registry_modules_disabled.txtar +++ b/cmd/cue/cmd/testdata/script/registry_modules_disabled.txtar @@ -1,35 +1,5 @@ -# When CUE_EXPERIMENT is disabled, the CUE_REGISTRY -# variable is ignored, as are the new fields in module.cue +# When CUE_EXPERIMENT is disabled, we cannot use the cue command. env CUE_EXPERIMENT=modules=false -exec cue export . -cmp stdout expect-stdout - --- expect-stdout -- -"cue.mod/pkg source" --- main.cue -- -package main -import "example.com/e" - -e.foo - --- cue.mod/module.cue -- -module: "test.org" -language: version: "v0.9.0" -// This should be ignored. -deps: "example.com/e": v: "v0.0.1" --- cue.mod/pkg/example.com/e/cue.mod/module.cue -- -module: "example.com/e" -language: version: "v0.8.0" --- cue.mod/pkg/example.com/e/main.cue -- -package e -foo: "cue.mod/pkg source" - --- _registry/example.com_e_v0.0.1/cue.mod/module.cue -- -module: "example.com/e@v0" -language: version: "v0.8.0" - --- _registry/example.com_e_v0.0.1/main.cue -- -package e - -foo: "registry source" +! exec cue export . +stderr 'cannot change default value of deprecated flag "modules"' diff --git a/cmd/cue/cmd/testdata/script/registry_modules_disabled_warning.txtar b/cmd/cue/cmd/testdata/script/registry_modules_disabled_warning.txtar deleted file mode 100644 index 07d8b0379..000000000 --- a/cmd/cue/cmd/testdata/script/registry_modules_disabled_warning.txtar +++ /dev/null @@ -1,14 +0,0 @@ -env CUE_EXPERIMENT=modules=false -env CUE_REGISTRY=ignored.example.com -exec cue export . -cmp stdout expect-stdout -cmp stderr expect-stderr - --- expect-stdout -- -"ok" --- expect-stderr -- -warning: ignoring CUE_REGISTRY because modules experiment is not enabled. Set CUE_EXPERIMENT=modules to enable it. --- main.cue -- -package main - -"ok" diff --git a/internal/cueexperiment/exp.go b/internal/cueexperiment/exp.go index 535a636ad..698bf79d1 100644 --- a/internal/cueexperiment/exp.go +++ b/internal/cueexperiment/exp.go @@ -11,7 +11,7 @@ import ( // When adding, deleting, or modifying entries below, // update cmd/cue/cmd/help.go as well for `cue help environment`. var Flags struct { - Modules bool `envflag:"default:true"` + Modules bool `envflag:"deprecated,default:true"` // YAMLV3Decoder swaps the old internal/third_party/yaml decoder with the new // decoder implemented in internal/encoding/yaml on top of yaml.v3. diff --git a/internal/cueexperiment/exp_test.go b/internal/cueexperiment/exp_test.go index ff4e39070..8b0ce9b81 100644 --- a/internal/cueexperiment/exp_test.go +++ b/internal/cueexperiment/exp_test.go @@ -23,10 +23,15 @@ func TestInit(t *testing.T) { qt.Assert(t, qt.IsTrue(Flags.Modules)) qt.Assert(t, qt.IsTrue(Flags.YAMLV3Decoder)) - // Check that we can disable all experiments. - t.Setenv("CUE_EXPERIMENT", "modules=0,yamlv3decoder=0") + // Check that we can disable the YAML v3 experiment. + t.Setenv("CUE_EXPERIMENT", "yamlv3decoder=0") err = initAlways() qt.Assert(t, qt.IsNil(err)) - qt.Assert(t, qt.IsFalse(Flags.Modules)) + qt.Assert(t, qt.IsTrue(Flags.Modules)) qt.Assert(t, qt.IsFalse(Flags.YAMLV3Decoder)) + + // Check that we cannot disable the modules experiment. + t.Setenv("CUE_EXPERIMENT", "modules=0") + err = initAlways() + qt.Assert(t, qt.ErrorMatches(err, `cannot parse CUE_EXPERIMENT: cannot set deprecated flag "modules"`)) }