this repo has no description
0
fork

Configure Feed

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

internal/mod/modload: skip over local module requirements in CheckTidy

A user reported that they were trying to publish a tidied module,
where the latest version of CUE made no changes via `cue mod tidy`,
yet the central registry responded with:

400 Bad Request: manifest invalid: module is not tidy

And indeed, it turns out this error came from `cue mod tidy --check`.
After a bit of digging, it seems like the cause was the module
contained packages in cue.mod/gen/ which were imported from the root
package in the module, and this causes --check to think the module's
requirements are not up to date, even though `cue mod tidy` is happy.

This makes `cue mod tidy --check` agree with `cue mod tidy`
in the case where the current module requires "local" modules
from cue.mod/*/ directories, as those are not written out
as dependencies in cue.mod/module.cue.

The added test case failed the newly added sanity check without the fix:

--- FAIL: TestTidy/testdata/tidy/cuemod-local.txtar (0.01s)
quicktest.go:22:
error:
got non-nil value
comment:
CheckTidy after a successful Tidy should not fail
got:
e"module is not tidy"
stack:
/home/mvdan/src/c/cue/internal/mod/modload/tidy_test.go:72
qt.Check(t, qt.IsNil(err), qt.Commentf("CheckTidy after a successful Tidy should not fail"))

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

+71 -1
+64
internal/mod/modload/testdata/tidy/cuemod-local.txtar
··· 1 + # This test checks that a mix of dependencies from a registry, 2 + # local modules from cue.mod/*/, and imports from the current module 3 + # all works and passes the tidy check. 4 + 5 + -- tidy-check-error -- 6 + module is not tidy: cannot find module providing package example.com@v0:main 7 + -- want -- 8 + module: "main.org@v0" 9 + language: { 10 + version: "v0.8.0" 11 + } 12 + deps: { 13 + "example.com@v0": { 14 + v: "v0.0.1" 15 + } 16 + } 17 + -- cue.mod/module.cue -- 18 + module: "main.org@v0" 19 + language: version: "v0.8.0" 20 + 21 + -- cue.mod/pkg/cuemodpkg.test/top.cue -- 22 + package cuemodpkg 23 + 24 + "cuemodpkg.test": "local" 25 + 26 + -- cue.mod/gen/cuemodgen.test/top.cue -- 27 + package cuemodgen 28 + 29 + "cuemodgen.test": "local" 30 + 31 + -- cue.mod/usr/cuemodusr.test/top.cue -- 32 + package cuemodusr 33 + 34 + "cuemodusr.test": "local" 35 + 36 + -- main.cue -- 37 + package main 38 + import ( 39 + "example.com@v0:main" 40 + "main.org/subpkg@v0" 41 + "cuemodpkg.test:cuemodpkg" 42 + "cuemodgen.test:cuemodgen" 43 + "cuemodusr.test:cuemodusr" 44 + ) 45 + 46 + main 47 + subpkg 48 + cuemodpkg 49 + cuemodgen 50 + cuemodusr 51 + 52 + -- subpkg/top.cue -- 53 + package subpkg 54 + 55 + "main.org@v0/sub": "current" 56 + 57 + -- _registry/example.com_v0.0.1/cue.mod/module.cue -- 58 + module: "example.com@v0" 59 + language: version: "v0.8.0" 60 + 61 + -- _registry/example.com_v0.0.1/top.cue -- 62 + package main 63 + 64 + "example.com@v0": "v0.0.1"
+7 -1
internal/mod/modload/tidy.go
··· 108 108 } 109 109 110 110 func equalRequirements(rs0, rs1 *modrequirements.Requirements) bool { 111 - return slices.Equal(rs0.RootModules(), rs1.RootModules()) && 111 + // Note that rs1.RootModules may include the unversioned local module 112 + // if the current module imports any packages under cue.mod/*/. 113 + // In such a case we want to skip over the local module when comparing, 114 + // just like modfileFromRequirements does when filling [modfile.File.Deps]. 115 + // Note that we clone the slice to not modify rs1's internal slice in-place. 116 + rs1RootMods := slices.DeleteFunc(slices.Clone(rs1.RootModules()), module.Version.IsLocal) 117 + return slices.Equal(rs0.RootModules(), rs1RootMods) && 112 118 maps.Equal(rs0.DefaultMajorVersions(), rs1.DefaultMajorVersions()) 113 119 } 114 120