# Test that cue mod publish refuses to publish a module whose module.cue is
# stale relative to cue.mod/local-module.cue: the local view selects a higher
# version of a dependency (via a directory replace declared at v0.2.0) than the
# published module.cue advertises (v0.1.0), so a full 'cue mod tidy' would
# update module.cue. Publishing must reject this even though local-module.cue
# itself is never published.

memregistry MEMREGISTRY
env ORIG_CUE_REGISTRY=$CUE_REGISTRY
env CUE_REGISTRY=main.org=$MEMREGISTRY+insecure,$CUE_REGISTRY
cd m

! exec cue mod publish v0.1.0
stderr '^module is not tidy, use ''cue mod tidy''$'

-- m/cue.mod/module.cue --
module: "main.org@v0"
language: version: "v0.17.0"
source: kind: "self"
deps: {
	"example.com/e@v0": v: "v0.1.0"
}
-- m/cue.mod/local-module.cue --
deps: {
	"example.com/e@v0": {
		v:       "v0.2.0"
		replaceWith: "./local_e"
	}
}
-- m/main.cue --
package main

import "example.com/e@v0:e"

out: e.value
-- m/local_e/cue.mod/module.cue --
module: "example.com/e@v0"
language: version: "v0.9.0"
-- m/local_e/e.cue --
package e

value: "from local directory v0.2.0"
-- _registry/example.com_e_v0.1.0/cue.mod/module.cue --
module: "example.com/e@v0"
language: version: "v0.9.0"
-- _registry/example.com_e_v0.1.0/e.cue --
package e

value: "from registry v0.1.0"
