this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

cmd/cue: add sanity check that 'cue mod publish' is idempotent

https://cuelang.org/issue/3129 captures the fact the 'cue mod publish'
should be idempotent with respect to the contents of a module. It is
also the case that given the same "state" (with respect to source.kind),
'cue mod publish' should be idempotent.

Along with a rather large explanation on the expectations of the
in-memory OCI server, this CL adds a simple check that 'cue mod publish'
is idempotent for the two existing source.kind values, "self" and "git".

Fixes #3129.

Signed-off-by: Paul Jolly <paul@myitcv.io>
Change-Id: I131e58c7726912e656b2023626fe36a9792e7e55
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1195805
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>

+76
+76
cmd/cue/cmd/testdata/script/registry_publish_idempotent.txtar
··· 1 + # Check that cue mod publish is idempotent for all sources. 2 + # 3 + # We first perform the check on a 'source: kind: "self"' module, before reusing 4 + # that same module but with 'source: kind: "git"' for later versions. 5 + # 6 + # These checks rely on two critical properties of the in-memory OCI server: 7 + # 8 + # 1. the in-memory OCI server is run in immutable mode 9 + # 2. the in-memory OCI server accepts an attempt to publish a module under an 10 + # existing tag, but only in the case that the modules digest is identical. 11 + # 12 + # If point 1 were not true, then we would get a false positive from this check, 13 + # i.e. we would fail to detect that 'cue mod publish' is not idempotent. If, 14 + # separately, point 2 were not true, then we would get a failure as a result of 15 + # the follow 'republish' attempt, even if the published module digest were 16 + # identicial. 17 + # 18 + # We ensure point 1 is the case by asserting that we get an error when we 19 + # attempt to republish to an existing version of a module when we know the 20 + # contents to be different. 21 + # 22 + # If we fall foul of the failure as a result of point 2 not being true, this 23 + # series of tests will fail. We will then be forced to move this test to a 24 + # different place, which is perhaps where it belongs given the length of this 25 + # explanatory comment. 26 + 27 + memregistry MEMREGISTRY 28 + env CUE_REGISTRY=$MEMREGISTRY 29 + 30 + 31 + # v0.0.1 - source.kind == "self" 32 + cd $WORK/example 33 + cp $WORK/v0.0.1 $WORK/example/root.cue 34 + exec cue mod publish --json v0.0.1 35 + stdin stdout 36 + exec cue export -e files json: - 37 + cmp stdout $WORK/filelist.golden 38 + exec cue mod publish v0.0.1 39 + exec cue mod publish v0.0.1 # idempotent check 40 + 41 + 42 + # v0.0.2 - source.kind == "git" 43 + [!exec:git] skip 'no git command found' 44 + exec cue mod edit --source git 45 + cp $WORK/v0.0.2 $WORK/example/root.cue 46 + exec git init . 47 + exec git add . 48 + exec git -c user.name=noone -c user.email=noone@example.com commit -m 'initial commit' 49 + 50 + # Verify we cannot overwrite v0.0.1 with what we know is different module 51 + # contents. This ensures the in-memory OCI server is run in immutable mode. 52 + ! exec cue mod publish v0.0.1 53 + stderr 'cannot overwrite tag' 54 + 55 + exec cue mod publish --json v0.0.2 56 + stdin stdout 57 + exec cue export -e files json: - 58 + cmp stdout $WORK/filelist.golden 59 + exec cue mod publish v0.0.2 60 + exec cue mod publish v0.0.2 # idempotent check 61 + 62 + 63 + -- filelist.golden -- 64 + [ 65 + "cue.mod/module.cue", 66 + "root.cue" 67 + ] 68 + -- v0.0.1 -- 69 + package root 70 + v: "v0.0.1" 71 + -- v0.0.2 -- 72 + package root 73 + v: "v0.0.2" 74 + -- example/cue.mod/module.cue -- 75 + module: "x.example/root@v0" 76 + language: version: "v0.9.0-alpha.0"