Open verdverm opened 1 year ago
Thanks for the report, @verdverm. Looks like a bug to me. Here is a simpler example which is a bit easier to understand:
go mod tidy
go run .
cmp stdout stdout.golden
-- cue.mod/module.cue --
module: "hof.io/repro"
-- cue.mod/pkg/hof.io/dep/main.cue --
package dep
Model: {
Name: string
}
-- go.mod --
module hof.io/repro
go 1.19
require cuelang.org/go v0.5.0-beta.5
-- input.cue --
package main
import (
"hof.io/dep"
)
MyModels: {
Models: dep.Model
}
-- main.go --
package main
import (
"fmt"
"cuelang.org/go/cue"
"cuelang.org/go/cue/cuecontext"
"cuelang.org/go/cue/format"
"cuelang.org/go/cue/load"
)
func main() {
ctx := cuecontext.New()
bis := load.Instances([]string{"input.cue"}, nil)
val := ctx.BuildInstance(bis[0])
formatVal := func() []byte {
syn := val.Syntax(cue.InlineImports(true))
src, err := format.Node(syn)
if err != nil {
panic(err)
}
return src
}
fmt.Printf("======== pre fill ==========\n%s\n", formatVal())
val = val.FillPath(cue.ParsePath("MyModels.ID"), "abc123")
fmt.Printf("======== post fill =========\n%s\n", formatVal())
}
-- stdout.golden --
======== pre fill ==========
package main
MyModels: {
Models: {
Name: string
}
}
======== post fill =========
package main
MyModels: {
Models: {
Name: string
}
ID: "abc123"
}
Passing test
> go mod tidy
> go run .
[stdout]
======== pre fill ==========
package main
MyModels: {
Models: {
Name: string
}
}
======== post fill =========
import "hof.io/dep"
MyModels: {
Models: dep.Model
ID: "abc123"
}
> cmp stdout stdout.golden
--- stdout
+++ stdout.golden
@@ -8,10 +8,12 @@
}
======== post fill =========
-import "hof.io/dep"
+package main
MyModels: {
- Models: dep.Model
+ Models: {
+ Name: string
+ }
ID: "abc123"
}
FAIL: /tmp/testscript574378884/repro.txtar/script.txtar:3: stdout and stdout.golden differ
Marking as v0.7.0 to prevent delaying v0.6.0, but @verdverm please say if this is a pressing issue.
The goal here is to programmaticly add a field to Value and then write it out with InlineImports.
What version of CUE are you using (
cue version
)?Does this issue reproduce with the latest stable release?
n/a ImportPaths is only in beta
What did you do?
What did you see instead?
The full output looks like this, you can see the difference more clearly here