Skip to content

Commit 2a96988

Browse files
committed
cmd/cue: add a forwards compatibility test case for bugfix releases
When loading a CUE module which uses a higher language.version than the current language version supported by cmd/cue, it does not matter whether the version is higher due to a higher bugfix number or a higher minor or even major number. We treat the language.version version as a hard version minimum, even though the language spec should not change in bugfix releases, for the sake of consistent and intuitive behavior. language.version also affects the module.cue file schema to use, and that can indeed change in bugfix releases from time to time. We already had a test case for a CUE module with a higher minor number in its language.version; add one with a higher bugfix number as well. While here, move "cd" testscript commands to be next to the top-level comment which describes each test case set up via txtar. For #3197. Signed-off-by: Daniel Martí <[email protected]> Change-Id: Ied3603b95662656fa45063421f730e7788646b8e Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1196300 TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Paul Jolly <[email protected]> Reviewed-by: Roger Peppe <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
1 parent 6056916 commit 2a96988

File tree

3 files changed

+60
-3
lines changed

3 files changed

+60
-3
lines changed

cmd/cue/cmd/script_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import (
4747
"cuelang.org/go/cue/parser"
4848
"cuelang.org/go/internal/cuetest"
4949
"cuelang.org/go/internal/cueversion"
50+
"cuelang.org/go/internal/mod/semver"
5051
"cuelang.org/go/internal/registrytest"
5152
)
5253

@@ -257,7 +258,11 @@ func TestScript(t *testing.T) {
257258
e.Vars = append(e.Vars,
258259
"GOPROXY="+srv.URL,
259260
"GONOSUMDB=*", // GOPROXY is a private proxy
261+
262+
// The current language version which would be added by `cue mod init`, e.g. v0.10.0.
260263
"CUE_LANGUAGE_VERSION="+cueversion.LanguageVersion(),
264+
// A later language version which only increases the bugfix release, e.g. v0.10.99.
265+
"CUE_LANGUAGE_VERSION_BUGFIX="+semver.MajorMinor(cueversion.LanguageVersion())+".99",
261266
)
262267
entries, err := os.ReadDir(e.WorkDir)
263268
if err != nil {

cmd/cue/cmd/testdata/script/module_compatibility_backwards.txtar

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ env CUE_REGISTRY=$MEMREGISTRY+insecure
1717

1818
# A module that was created before the modules experiment,
1919
# without a major version suffix nor a language version.
20+
cd ${WORK}/premodules
2021

2122
# Downstream consumption via cue.mod/*/ works.
2223
# Downstream consumption via a registry is not possible as its module path lacks a major version suffix.
23-
cd ${WORK}/premodules
2424
exec cue export
2525
stdout '"downstream": "hello from premodules.example"'
2626

@@ -56,11 +56,11 @@ exec cue mod publish v0.0.2
5656

5757

5858
# A module that was created with a language.version of v0.8.0.
59+
cd ${WORK}/v0.8.0-downstream-deps
5960

6061
# Downstream consumption via a registry works.
6162
# Note that we need to point CUE_REGISTRY back to the contents inside _registry/ below.
6263
env CUE_REGISTRY=${ORIG_CUE_REGISTRY}
63-
cd ${WORK}/v0.8.0-downstream-deps
6464
exec cue export
6565
stdout '"downstream": "hello from v0.8.0.example"'
6666
env CUE_REGISTRY=$MEMREGISTRY+insecure

cmd/cue/cmd/testdata/script/module_compatibility_forwards.txtar

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,43 @@
99
# cover scenarios where just one of them is too new,
1010
# as we should allow downstream consumption when only the module schema version is too new.
1111

12-
# A module that was created with a language.version of v0.99.0 in the far future.
12+
# A module that was created with a language.version of ${CUE_LANGUAGE_VERSION_BUGFIX},
13+
# which is like the current ${CUE_LANGUAGE_VERSION} but with a higher bugfix release.
14+
# For example, if ${CUE_LANGUAGE_VERSION} is v0.10.0 or v0.10.5, ${CUE_LANGUAGE_VERSION_BUGFIX} is v0.10.99.
15+
# Even though the language spec should not change in bugfix releases,
16+
# we still treat the language version as a hard minimum following semver.
17+
cd ${WORK}/bugfix-newer
18+
env-fill cue.mod/pkg/bugfix-newer.example/cue.mod/module.cue
1319

1420
# TODO(mvdan): downstream consumption via cue.mod/*/ works when it should not,
1521
# because we do not yet use language.version as a minimum for parsing or evaluating CUE.
22+
exec cue export
23+
stdout '"downstream": "hello from bugfix-newer.example"'
24+
25+
# TODO(mvdan): test downstream consumption via a registry; note that _registry/ complains
26+
# because it is unable to parse the module.cue file with a schema that is too new.
27+
28+
# Continue inside the module's own directory as if we had cloned it directly.
29+
cd ${WORK}
30+
mv bugfix-newer/cue.mod/pkg/bugfix-newer.example bugfix-newer-downstream-direct
31+
cd bugfix-newer-downstream-direct
32+
33+
# Downstream consumption via `cue export` does not work as we don't support the language spec version.
34+
! exec cue export
35+
cmp stderr ${WORK}/bugfix-newer-toonew.stderr
36+
37+
# Upstream development and publishing is forbidden as we don't have or understand the schema.
38+
! exec cue mod tidy --check
39+
cmp stderr ${WORK}/bugfix-newer-toonew.stderr
40+
! exec cue mod publish v0.0.2
41+
cmp stderr ${WORK}/bugfix-newer-toonew.stderr
42+
43+
44+
# A module that was created with a language.version of v0.99.0 in the far future.
1645
cd ${WORK}/v0.99.0
46+
47+
# TODO(mvdan): downstream consumption via cue.mod/*/ works when it should not,
48+
# because we do not yet use language.version as a minimum for parsing or evaluating CUE.
1749
exec cue export
1850
stdout '"downstream": "hello from v0.99.0.example"'
1951

@@ -35,6 +67,26 @@ cmp stderr ${WORK}/v0.99.0-toonew.stderr
3567
! exec cue mod publish v0.0.2
3668
cmp stderr ${WORK}/v0.99.0-toonew.stderr
3769

70+
-- bugfix-newer-toonew.stderr --
71+
language version "v0.10.99" declared in module.cue is too new for current language version "v0.10.0"
72+
-- bugfix-newer/cue.mod/module.cue --
73+
module: "downstream.example"
74+
language: version: "v0.9.0"
75+
-- bugfix-newer/downstream.cue --
76+
package downstream
77+
import "bugfix-newer.example:root"
78+
downstream: root
79+
-- bugfix-newer/cue.mod/pkg/bugfix-newer.example/cue.mod/module.cue --
80+
module: "bugfix-newer.example"
81+
language: version: "${CUE_LANGUAGE_VERSION_BUGFIX}"
82+
-- bugfix-newer/cue.mod/pkg/bugfix-newer.example/root.cue --
83+
package root
84+
import "bugfix-newer.example/subpkg"
85+
subpkg
86+
-- bugfix-newer/cue.mod/pkg/bugfix-newer.example/subpkg/subpkg.cue --
87+
package subpkg
88+
"hello from bugfix-newer.example"
89+
3890
-- v0.99.0-toonew.stderr --
3991
language version "v0.99.0" declared in module.cue is too new for current language version "v0.10.0"
4092
-- v0.99.0/cue.mod/module.cue --

0 commit comments

Comments
 (0)