The new home of the CUE language! Validate and define text-based and dynamic configuration

Go Reference Github GolangCI Go 1.14+ platforms

The CUE Data Constraint Language

Configure, Unify, Execute

CUE is an open source data constraint language which aims to simplify tasks involving defining and using data.

It is a superset of JSON, allowing users familiar with JSON to get started quickly.

What is it for?

You can use CUE to

  • define a detailed validation schema for your data (manually or automatically from data)
  • reduce boilerplate in your data (manually or automatically from schema)
  • extract a schema from code
  • generate type definitions and validation code
  • merge JSON in a principled way
  • define and run declarative scripts

How?

CUE merges the notion of schema and data. The same CUE definition can simultaneously be used for validating data and act as a template to reduce boilerplate. Schema definition is enriched with fine-grained value definitions and default values. At the same time, data can be simplified by removing values implied by such detailed definitions. The merging of these two concepts enables many tasks to be handled in a principled way.

Constraints provide a simple and well-defined, yet powerful, alternative to inheritance, a common source of complexity with configuration languages.

CUE Scripting

The CUE scripting layer defines declarative scripting, expressed in CUE, on top of data. This solves three problems: working around the closedness of CUE definitions (we say CUE is hermetic), providing an easy way to share common scripts and workflows for using data, and giving CUE the knowledge of how data is used to optimize validation.

There are many tools that interpret data or use a specialized language for a specific domain (Kustomize, Ksonnet). This solves dealing with data on one level, but the problem it solves may repeat itself at a higher level when integrating other systems in a workflow. CUE scripting is generic and allows users to define any workflow.

Tooling

CUE is designed for automation. Some aspects of this are:

  • convert existing YAML and JSON
  • automatically simplify configurations
  • rich APIs designed for automated tooling
  • formatter
  • arbitrary-precision arithmetic
  • generate CUE templates from source code
  • generate source code from CUE definitions (TODO)

Download and Install

Release builds

Download the latest release from GitHub.

Install using Homebrew

Using Homebrew, you can install using the CUE Homebrew tap:

brew install cuelang/tap/cue

Install from Source

If you already have Go installed, the short version is:

GO111MODULE=on go get cuelang.org/go/cmd/cue

Or, if you are using Go 1.16:

go install cuelang.org/go/cmd/[email protected]

This will install the cue command line tool.

For more details see Installing CUE.

Learning CUE

The fastest way to learn the basics is to follow the tutorial on basic language constructs.

A more elaborate tutorial demonstrating of how to convert and restructure an existing set of Kubernetes configurations is available in written form.

References

Contributing

Our canonical Git repository is located at https://review.gerrithub.io/q/project:cue-lang%252Fcue.

To contribute, please read the Contribution Guide.

To report issues or make a feature request, use the issue tracker.

Changes can be contributed using Gerrit or Github pull requests.

Contact

You can get in touch with the cuelang community in the following ways:


Unless otherwise noted, the CUE source files are distributed under the Apache 2.0 license found in the LICENSE file.

This is not an officially supported Google product.

Comments
  • cue: use dots as a separator for folding instead of spaces?

    cue: use dots as a separator for folding instead of spaces?

    Originally opened by @ghost in https://github.com/cuelang/cue/issues/60

    This input:

    outer middle inner: 3
    

    produces this with CUE

    {
       "outer": {
          "middle": {
             "inner": 3
          }
       }
    }
    

    and this with YAML:

    {
       "outer middle inner": 3
    }
    

    this seems like too much sugar to be worth it

    https://github.com/cuelang/cue/blob/master/doc/tutorial/basics/fold.md

  • Add an option to quote all strings in YAML

    Add an option to quote all strings in YAML

    Currently, exporting to YAML is a mine field, because most things well defined as strings in a CUE file will be exported unquoted in YAML.

    Of course, because YAML interprets magically most unquoted things, this leads to plenty of issues. E.G:

    • dates can be wrongly interpreted: https://github.com/cue-lang/cue/issues/1076
    • the norway problem: https://hitchdev.com/strictyaml/why/implicit-typing-removed/
    • the python 3.10 problem: https://github.com/actions/setup-python/issues/160

    I think quoting all the strings in the resulting YAML should be the default behavior. However, this would probably cause a lot of troubles now that the old behavior is used everywhere.

    Alternatively, a nice solution would be to provide an option to force cue to quote everything. This option could be turned on with either:

    • a cli --flag
    • an env var
    • a directive in the cue file
  • cmd/cue: reference error in value imported from a package lost during export

    cmd/cue: reference error in value imported from a package lost during export

    Originally opened by @uhthomas in https://github.com/cuelang/cue/issues/854

    What version of CUE are you using (cue version)?

    $ cue version
    cue version v0.3.0-beta.7 linux/amd64
    

    Does this issue reproduce with the latest release?

    Yes.

    What did you do?

    ! exec cue export
    cmp stderr stderr.golden
    
    -- a.cue --
    package a
    
    import "mod.com/b"
    
    theb: b.name
    -- b/b.cue --
    package b
    
    import "mod.com/c"
    
    b: c.c & {
    	other: "name"
    }
    
    name: b.other
    -- c/c.cue --
    package c
    -- cue.mod/module.cue --
    module: "mod.com"
    -- stderr.golden --
    b: undefined field c:
        ./b/b.cue:5:6
    

    With beta.3 this test passes; with beta.4 (or indeed any commit including bedb047a988217bab040c29eeb8a51988ce23b76) fails with:

    > ! exec cue export
    [stdout]
    {
        "theb": "name"
    }
    FAIL: /tmp/testscript235319619/repro.txt/script.txt:1: unexpected command success
    

    What did you expect to see?

    A passing test.

    What did you see instead?

    Per above; a failing test, because cue export succeeds where it should not.

    Edit: updated description to the contents of https://github.com/cuelang/cue/issues/854#issuecomment-808683933 for ease of reference.

  • How to set up per-environment configs

    How to set up per-environment configs

    Originally opened by @vikstrous in https://github.com/cuelang/cue/issues/190

    I'm trying to set up per-environment configs with cue, but I'm running into a bug.

    ... in paths doesn't work with symlinks.

    Repro:

    tree
    .
    ├── cue.mod
    │   ├── module.cue
    │   ├── pkg
    │   └── usr
    ├── environments
    │   ├── development
    │   │   ├── development.cue
    │   │   └── services -> ../../services/
    │   └── production
    │       ├── production.cue
    │       └── services -> ../../services/
    └── services
        └── frontend
            └── frontend.cue
    
    10 directories, 4 files
    
    cat environments/development/development.cue
    package service
    
    Environment:: "development"
    
    cat environments/production/production.cue
    package service
    
    Environment:: "production"
    
    cat services/frontend/frontend.cue
    package service
    
    main: "hello \(Environment)"
    
    cue eval ./environments/development/services/frontend/
    Environment :: "development"
    main:          "hello development"
    

    Expected:

    cue eval ./environments/development/services/...
    Environment :: "development"
    main:          "hello development"
    

    Actual:

    cue eval ./environments/development/services/...
    cue: "./environments/development/services/..." matched no packages
    

    If there's any info about how to customize configs for different environments or any best practices, please let me know. I've read all of the docs and I didn't see anything mentioning this issue.

  • doc: update README to explain how CUE differs from jsonnet?

    doc: update README to explain how CUE differs from jsonnet?

    Originally opened by @ngrilly in https://github.com/cuelang/cue/issues/33

    How is CUE different from jsonnet, both coming from Google, and the latter being largely promoted especially in the context of Kubernetes?

  • ci: update Go versions

    ci: update Go versions

    Update Release go version to at least 1.16 so that darwin arm64 target binaries can be released

    Issue for PR #1223 that sparked more conversation

    @myitcv commented:

    There are a few things we probably want to address here:    
    - expanding the build matrix to include Go 1.17
    - building CUE release artefacts with the latest version of Go
    - expanding the release matrix to include new Go ports
    - testing all the above (somewhat related to goreleaser test goreleaser/goreleaser#2355))
    

    @myitcv to @verdverm:

    we used to build with the latest version of Go. Looks like when I updated our build matrix from 
    1.16.0-rc1 to 1.16 I didn't flip to define 1.16 (at the time) as the latest stable version of Go. We 
    can fix that in whatever changes come from this discussion.
    

    @verdverm:

    another update in 1.17 I was thinking might be helpful for API users is the dependency pruning. 
    That would require updating the Go directive in go.mod. Thoughts?
    
    Another thought, is there preference for including (or not) the patch version in the workflows? (i.e. 1.16 vs 1.16.5)
    Any implications on reproducibility, like a new patch version released between final commit testing and tagging for a release?
    
  • Memory leak in core/adt

    Memory leak in core/adt

    Originally opened by @samalba in https://github.com/cuelang/cue/issues/661

    What version of CUE are you using (cue version)?

    $ cue version
    0.3.0-beta.2
    

    Does this issue reproduce with the latest release?

    Yes. I also reproduced it as well with master (c58e0ffc4c74d1b3cffe6467b7f144b9dde631b7) - same result than beta.2.

    What did you do?

    Cannot give a repro as it's happening with blocklayer's runtime, using the Cue Go API. In few seconds, the binary is consuming several gigs of RAM (stays stable at around 34MB with 0.3.0-alpha6).

    As @myitcv suggested, I enabled pprof and gathered this attached heap profile.

    heap.out.gz

    Here are the top consumers:

    (pprof) top
    Showing nodes accounting for 1023.36MB, 87.95%!o(MISSING)f 1163.57MB total
    Dropped 82 nodes (cum <= 5.82MB)
    Showing top 10 nodes out of 84
          flat  flat%!s(MISSING)um%!c(MISSING)um   cum%!
    (MISSING)
      322.54MB 27.72%   322.54MB 27.72%!c(MISSING)uelang.org/go/internal/core/adt.(*Vertex).GetArc
      158.51MB 13.62%   158.51MB 13.62%!c(MISSING)uelang.org/go/internal/core/adt.(*Vertex).addConjunct
      136.02MB 11.69%   136.02MB 11.69%!c(MISSING)uelang.org/go/internal/core/adt.(*nodeContext).createDisjunct
      113.01MB  9.71%   666.57MB 57.29%!c(MISSING)uelang.org/go/internal/core/adt.(*nodeContext).addStruct
       91.51MB  7.86%    91.51MB  7.86%!c(MISSING)uelang.org/go/internal/core/adt.updateCyclic
       75.50MB  6.49%    75.50MB  6.49%!c(MISSING)uelang.org/go/internal/core/adt.(*Vertex).AddStruct
       44.76MB  3.85%    50.27MB  4.32%!c(MISSING)uelang.org/go/pkg/encoding/json.Marshal
          39MB  3.35%    78.51MB  6.75%!c(MISSING)uelang.org/go/internal/core/adt.(*StructInfo).MatchAndInsert
          24MB  2.06%       24MB  2.06%!c(MISSING)uelang.org/go/internal/core/adt.clone
       18.50MB  1.59%    18.50MB  1.59%!c(MISSING)uelang.org/go/internal/core/adt.CloseInfo.SpawnRef (inline)
    
  • Panic during cue eval

    Panic during cue eval

    Originally opened by @verdverm in https://github.com/cuelang/cue/issues/598

    What version of CUE are you using (cue version)?

    master @ 6c49cf0

    the previous commit(s) do not have this panic

    panic: runtime error: invalid memory address or nil pointer dereference [recovered]
            panic: runtime error: invalid memory address or nil pointer dereference
    [signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x6d7017]
    
    goroutine 1 [running]:
    cuelang.org/go/cmd/cue/cmd.recoverError(0xc000723ec0)
            /home/tony/cue/cue/cmd/cue/cmd/root.go:221 +0x95
    panic(0xbcfac0, 0x11a5f00)
            /usr/local/go/src/runtime/panic.go:969 +0x1b9
    cuelang.org/go/internal/core/adt.(*Vertex).Default(0x0, 0xd9e0e0)
            /home/tony/cue/cue/internal/core/adt/default.go:46 +0x37
    cuelang.org/go/internal/core/adt.(*OpContext).node(0xc0002cd6c0, 0xd99420, 0xc0003d0cd0, 0x40bc01, 0xc000020000)
            /home/tony/cue/cue/internal/core/adt/context.go:676 +0x1cc
    cuelang.org/go/internal/core/adt.(*SelectorExpr).resolve(0xc00044f0e0, 0xc0002cd6c0, 0xc000390c30)
            /home/tony/cue/cue/internal/core/adt/expr.go:588 +0x54
    cuelang.org/go/internal/core/adt.(*OpContext).Resolve(0xc0002cd6c0, 0xc0001df9f0, 0xd93660, 0xc00044f0e0, 0xc00044f0e0, 0x1)
            /home/tony/cue/cue/internal/core/adt/context.go:331 +0xdb
    cuelang.org/go/internal/core/eval.(*nodeContext).evalExpr(0xc0000cf980, 0xc0001df9f0, 0xd8bc40, 0xc00044f100, 0x0)
            /home/tony/cue/cue/internal/core/eval/eval.go:1144 +0x49e
    cuelang.org/go/internal/core/eval.(*nodeContext).addExprConjunct(0xc0000cf980, 0xc0001df9f0, 0xd8bc40, 0xc00044f100, 0x7ea800000000)
            /home/tony/cue/cue/internal/core/eval/eval.go:1114 +0xaa
    cuelang.org/go/internal/core/eval.(*Evaluator).evalVertex(0xc000345e60, 0xc0002cd6c0, 0xc000340360, 0x4, 0x0, 0x0, 0x0)
            /home/tony/cue/cue/internal/core/eval/eval.go:408 +0x2d8
    cuelang.org/go/internal/core/eval.(*Evaluator).UnifyAccept(0xc000345e60, 0xc0002cd6c0, 0xc000340360, 0x719804, 0x0, 0x0)
            /home/tony/cue/cue/internal/core/eval/eval.go:283 +0xa7
    cuelang.org/go/internal/core/eval.(*Evaluator).Unify(0xc000345e60, 0xc0002cd6c0, 0xc000340360, 0xc0001d4a04)
            /home/tony/cue/cue/internal/core/eval/eval.go:257 +0x50
    cuelang.org/go/internal/core/eval.(*nodeContext).completeArcs(0xc0000cf380, 0xc000130004)
            /home/tony/cue/cue/internal/core/eval/eval.go:620 +0xc8
    cuelang.org/go/internal/core/eval.(*nodeContext).postDisjunct(0xc0000cf380, 0xbdb004)
            /home/tony/cue/cue/internal/core/eval/eval.go:599 +0x470
    cuelang.org/go/internal/core/eval.(*nodeContext).updateResult(0xc0000cf380, 0xc0005b6904, 0x3)
            /home/tony/cue/cue/internal/core/eval/disjunct.go:132 +0x4c
    cuelang.org/go/internal/core/eval.(*nodeContext).tryDisjuncts(0xc0000cf380, 0xc000510704, 0xd8bc40)
            /home/tony/cue/cue/internal/core/eval/disjunct.go:203 +0x1a7
    cuelang.org/go/internal/core/eval.(*Evaluator).evalVertex(0xc000345e60, 0xc0002cd6c0, 0xc000132240, 0xc000785704, 0x0, 0x0, 0x0)
            /home/tony/cue/cue/internal/core/eval/eval.go:438 +0x3b5
    ...
    

    fmt.Printf("nil node: %!v(MISSING)\n", v)

    ...
    nil node: &adt.BasicType{Src:(*ast.Ident)(nil), K: 0xff}
    nil node: &adt.BasicType{Src:(*ast.Ident)(nil), K: 0xff}
    nil node: &adt.BasicType{Src:(*ast.Ident)(nil), K: 0xff}
    nil node: &adt.BasicType{Src:(*ast.Ident)(nil), K: 0xff}
    nil node: &adt.Bottom{Src:(*ast.SelectorExpr)( 0xc000343260), Err:errors.list{(*adt.ValueError)( 0xc000674d20), (*adt.ValueError)( 0xc000674d90)}, Code: 4, HasRecursive:false, ChildError:false, Value:adt.Value(nil)}
    nil node: &adt.Bottom{Src:ast.Node(nil), Err:(*errors.posError)( 0xc000094660), Code: 4, HasRecursive:false, ChildError:false, Value:adt.Value(nil)}
    nil node: &adt.BasicType{Src:(*ast.Ident)(nil), K: 0xff}
    nil node: &adt.BasicType{Src:(*ast.Ident)(nil), K: 0xff}
    nil node: &adt.BasicType{Src:(*ast.Ident)(nil), K: 0xff}
    nil node: &adt.BasicType{Src:(*ast.Ident)(nil), K: 0xff}
    nil node: &adt.Bottom{Src:(*ast.SelectorExpr)( 0xc000343260), Err:errors.list{(*adt.ValueError)( 0xc000675340), (*adt.ValueError)( 0xc0006753b0)}, Code: 4, HasRecursive:false, ChildError:false, Value:adt.Value(nil)}
    nil node: &adt.BasicType{Src:(*ast.Ident)(nil), K: 0xff}
    nil node: &adt.BasicType{Src:(*ast.Ident)(nil), K: 0xff}
    nil node: &adt.BasicType{Src:(*ast.Ident)(nil), K: 0xff}
    nil node: &adt.BasicType{Src:(*ast.Ident)(nil), K: 0xff}
    nil node: &adt.Bottom{Src:(*ast.SelectorExpr)( 0xc000343260), Err:errors.list{(*adt.ValueError)( 0xc0006758f0), (*adt.ValueError)( 0xc000675960)}, Code: 4, HasRecursive:false, ChildError:false, Value:adt.Value(nil)}
    nil node: &adt.Bottom{Src:ast.Node(nil), Err:(*errors.posError)( 0xc000094660), Code: 4, HasRecursive:false, ChildError:false, Value:adt.Value(nil)}
    nil node: &adt.BasicType{Src:(*ast.Ident)(nil), K: 0xff}
    nil node: &adt.BasicType{Src:(*ast.Ident)(nil), K: 0xff}
    nil node: &adt.BasicType{Src:(*ast.Ident)(nil), K: 0xff}
    nil node: &adt.BasicType{Src:(*ast.Ident)(nil), K: 0xff}
    nil node: &adt.Bottom{Src:(*ast.SelectorExpr)( 0xc000343260), Err:errors.list{(*adt.ValueError)( 0xc000675f10), (*adt.ValueError)( 0xc000675f80)}, Code: 4, HasRecursive:false, ChildError:false, Value:adt.Value(nil)}
    nil node: &adt.BasicType{Src:(*ast.Ident)(nil), K: 0xff}
    nil node: &adt.BasicType{Src:(*ast.Ident)(nil), K: 0xff}
    nil node: &adt.BasicType{Src:(*ast.Ident)(nil), K: 0xff}
    nil node: &adt.BasicType{Src:(*ast.Ident)(nil), K: 0xff}
    nil node: &adt.Bottom{Src:(*ast.SelectorExpr)( 0xc000343260), Err:errors.list{(*adt.ValueError)( 0xc0006804d0), (*adt.ValueError)( 0xc000680540)}, Code: 4, HasRecursive:false, ChildError:false, Value:adt.Value(nil)}
    nil node: &adt.StructMarker{NeedClose:false}
    
  • Document usage of intstr.IntOrString in the k8s tutorial

    Document usage of intstr.IntOrString in the k8s tutorial

    Originally opened by @grantzvolsky in https://github.com/cuelang/cue/issues/148

    The kubernetes tutorial shows how to Extract CUE templates directly from Go source.

    The generated Cue templates include intstr.

    The question is how to use this struct with Cue.

    How could one e.g. configure a service targetPort? Neither of the configurations below work.

     service "backend" spec ports: [{
       port:       80
       targetPort: "backend-http" // Error 1
       targetPort: intstr.FromString("backend-http") // Error 2
       targetPort: { Type: 1, IntVal: 0, StrVal: "backend-http" } // Yields invalid output
     }]
    

    Error 1:

    service."backend".spec.ports.0.targetPort: conflicting values IntOrString and "backend-http" (mismatched types struct and string):
        ./cue/backend-overlays-local.cue:10:15
        ./pkg/k8s.io/api/core/v1/types_go_gen.cue:4389:15
    terminating because of errors
    

    Error 2:

    service."backend".spec.ports.0.targetPort: undefined field "FromString":
        ./cue/backend-overlays-local.cue:10:15
    a
    

    Invalid output (yaml dump):

      ports:
      - name: 80-http
        port: 80
        protocol: TCP
        targetPort:
          IntVal: 0
          StrVal: backend-http
          Type: 1
    

    A possible workaround would be to define IntOrString as IntOrString :: int | string, but that would go against the instructions in the template ("// Code generated by cue get go. DO NOT EDIT.").

  • panic: getNodeContext: nodeContext out of sync

    panic: getNodeContext: nodeContext out of sync

    Originally opened by @binarylogic in https://github.com/cuelang/cue/issues/633

    What version of CUE are you using (cue version)?

    ➜ cue version
    cue version 0.3.0-beta.1 darwin/amd64
    

    Does this issue reproduce with the latest release?

    Yes

    What did you do?

    We use Cue over at Vector to maintain project metadata (such as configuration) for our docs. Up until 0.3.0-beta.1 everything has worked fine.

    1. git clone [email protected]:timberio/vector.git
    2. cd vector
    3. cue export docs/**/*.cue

    What did you expect to see?

    The normal JSON document generated from our cue files.

    What did you see instead?

    panic: getNodeContext: nodeContext out of sync
      panic: freeNode: nodeContext out of sync [recovered]
      panic: freeNode: nodeContext out of sync
    
    goroutine 1 [running]:
    cuelang.org/go/cmd/cue/cmd.recoverError(0xc00221fec0)
      /Users/mpvl/Documents/dev/release/cue/cmd/cue/cmd/root.go:221 +0x95
    panic(0x17996c0, 0x19760a0)
      /usr/local/go/src/runtime/panic.go:969 +0x1b9
    cuelang.org/go/internal/core/adt.(*Vertex).freeNode(0xc0043726c0, 0xc004337180)
      /Users/mpvl/Documents/dev/release/cue/internal/core/adt/eval.go:799 +0x132
    panic(0x17996c0, 0x1976080)
      /usr/local/go/src/runtime/panic.go:975 +0x47a
    cuelang.org/go/internal/core/adt.(*Vertex).getNodeContext(0xc00438c2d0, 0xc000329450, 0xc00438c240)
      /Users/mpvl/Documents/dev/release/cue/internal/core/adt/eval.go:785 +0xd6
    cuelang.org/go/internal/core/adt.(*Unifier).Unify(0xc000329468, 0xc000329450, 0xc00438c2d0, 0x180e905)
      /Users/mpvl/Documents/dev/release/cue/internal/core/adt/eval.go:207 +0x92
    cuelang.org/go/internal/core/adt.(*nodeContext).completeArcs(0xc004337880, 0x5)
      /Users/mpvl/Documents/dev/release/cue/internal/core/adt/eval.go:577 +0x136
    cuelang.org/go/internal/core/adt.(*nodeContext).postDisjunct(0xc004337880, 0x605)
      /Users/mpvl/Documents/dev/release/cue/internal/core/adt/eval.go:548 +0x4fb
    cuelang.org/go/internal/core/adt.(*nodeContext).expandDisjuncts(0xc004337880, 0xc0038dbe05, 0xc004337180, 0x0, 0x1)
      /Users/mpvl/Documents/dev/release/cue/internal/core/adt/disjunct.go:137 +0x1008
    cuelang.org/go/internal/core/adt.(*nodeContext).expandDisjuncts(0xc004337180, 0xc004372603, 0xc004337180, 0x0, 0x0)
      /Users/mpvl/Documents/dev/release/cue/internal/core/adt/disjunct.go:213 +0x408
    cuelang.org/go/internal/core/adt.(*Unifier).Unify(0xc000329468, 0xc000329450, 0xc0043726c0, 0x12ccb03)
      /Users/mpvl/Documents/dev/release/cue/internal/core/adt/eval.go:315 +0x4a8
    cuelang.org/go/internal/core/adt.(*Unifier).evaluate(0xc000329468, 0xc000329450, 0xc0043726c0, 0x810a303, 0xc0015a64b0, 0x1)
      /Users/mpvl/Documents/dev/release/cue/internal/core/adt/eval.go:139 +0x8c
    cuelang.org/go/internal/core/adt.(*OpContext).evalState(0xc000329450, 0x199a300, 0xc0015a64b0, 0xc00389d603, 0x0, 0x0)
      /Users/mpvl/Documents/dev/release/cue/internal/core/adt/context.go:585 +0x247
    cuelang.org/go/internal/core/adt.(*OpContext).node(0xc000329450, 0x198d340, 0xc001aad4a0, 0x199a300, 0xc0015a64b0, 0x180e801, 0x1)
      /Users/mpvl/Documents/dev/release/cue/internal/core/adt/context.go:725 +0x5f
    cuelang.org/go/internal/core/adt.(*SelectorExpr).resolve(0xc001aad4a0, 0xc000329450, 0xc001aad4a0)
      /Users/mpvl/Documents/dev/release/cue/internal/core/adt/expr.go:698 +0x65
    cuelang.org/go/internal/core/adt.(*OpContext).evalState(0xc000329450, 0x199a5c0, 0xc001aad4a0, 0x1807002, 0x0, 0x0)
      /Users/mpvl/Documents/dev/release/cue/internal/core/adt/context.go:577 +0x1fd
    cuelang.org/go/internal/core/adt.(*OpContext).Evaluate(0xc000329450, 0xc0038db1d0, 0x199a5c0, 0xc001aad4a0, 0xc001a93280, 0x199ecc0, 0xc001a93280)
      /Users/mpvl/Documents/dev/release/cue/internal/core/adt/context.go:507 +0x105
    cuelang.org/go/internal/core/adt.(*OpContext).Concrete(0xc000329450, 0xc0038db1d0, 0x199a5c0, 0xc001aad4a0, 0x17cce20, 0x1d6fe78, 0x1009eff, 0xc00001e000, 0x17e5a40)
      /Users/mpvl/Documents/dev/release/cue/internal/core/adt/context.go:445 +0x53
    cuelang.org/go/internal/core/adt.(*BinaryExpr).evaluate(0xc0019bb3e0, 0xc000329450, 0xc0019bb3e0, 0x86731d8)
      /Users/mpvl/Documents/dev/release/cue/internal/core/adt/expr.go:961 +0x285
    cuelang.org/go/internal/core/adt.(*OpContext).evalState(0xc000329450, 0x1999fc0, 0xc0019bb3e0, 0x2, 0x0, 0x0)
      /Users/mpvl/Documents/dev/release/cue/internal/core/adt/context.go:573 +0x38c
    cuelang.org/go/internal/core/adt.(*OpContext).value(0xc000329450, 0x1999fc0, 0xc0019bb3e0, 0xc003d2d500, 0xc0019bb470)
      /Users/mpvl/Documents/dev/release/cue/internal/core/adt/context.go:537 +0x48
    cuelang.org/go/internal/core/adt.(*IfClause).yield(0xc0019bb410, 0xc000329450, 0xc003d2d500)
      /Users/mpvl/Documents/dev/release/cue/internal/core/adt/expr.go:1417 +0x46
    cuelang.org/go/internal/core/adt.(*OpContext).Yield(0xc000329450, 0xc0038db1d0, 0x19944c0, 0xc0019bb410, 0xc003d2d500, 0x19944c0)
      /Users/mpvl/Documents/dev/release/cue/internal/core/adt/context.go:433 +0xf9
    cuelang.org/go/internal/core/adt.(*nodeContext).injectEmbedded(0xc004328000, 0xc004328200, 0x0)
      /Users/mpvl/Documents/dev/release/cue/internal/core/adt/eval.go:1799 +0x14f
    cuelang.org/go/internal/core/adt.(*nodeContext).expandOne(0xc004328000, 0xc004348360)
      /Users/mpvl/Documents/dev/release/cue/internal/core/adt/eval.go:1722 +0xc5
    cuelang.org/go/internal/core/adt.(*Unifier).Unify(0xc000329468, 0xc000329450, 0xc004348360, 0x180e905)
      /Users/mpvl/Documents/dev/release/cue/internal/core/adt/eval.go:277 +0x3c5
    cuelang.org/go/internal/core/adt.(*nodeContext).completeArcs(0xc0041d7880, 0x5)
      /Users/mpvl/Documents/dev/release/cue/internal/core/adt/eval.go:577 +0x136
    cuelang.org/go/internal/core/adt.(*nodeContext).postDisjunct(0xc0041d7880, 0x5)
      /Users/mpvl/Documents/dev/release/cue/internal/core/adt/eval.go:548 +0x4fb
    cuelang.org/go/internal/core/adt.(*nodeContext).expandDisjuncts(0xc0041d7880, 0xc00431f805, 0xc0041d7880, 0x0, 0x0)
      /Users/mpvl/Documents/dev/release/cue/internal/core/adt/disjunct.go:137 +0x1008
    cuelang.org/go/internal/core/adt.(*Unifier).Unify(0xc000329468, 0xc000329450, 0xc00431f8c0, 0x180e905)
      /Users/mpvl/Documents/dev/release/cue/internal/core/adt/eval.go:315 +0x4a8
    cuelang.org/go/internal/core/adt.(*nodeContext).completeArcs(0xc000037c00, 0x5)
      /Users/mpvl/Documents/dev/release/cue/internal/core/adt/eval.go:577 +0x136
    cuelang.org/go/internal/core/adt.(*nodeContext).postDisjunct(0xc000037c00, 0x1829805)
      /Users/mpvl/Documents/dev/release/cue/internal/core/adt/eval.go:548 +0x4fb
    cuelang.org/go/internal/core/adt.(*nodeContext).expandDisjuncts(0xc000037c00, 0xc0014ab305, 0xc000037c00, 0x0, 0x0)
      /Users/mpvl/Documents/dev/release/cue/internal/core/adt/disjunct.go:137 +0x1008
    cuelang.org/go/internal/core/adt.(*Unifier).Unify(0xc000329468, 0xc000329450, 0xc0014ab320, 0x180e905)
      /Users/mpvl/Documents/dev/release/cue/internal/core/adt/eval.go:315 +0x4a8
    cuelang.org/go/internal/core/adt.(*nodeContext).completeArcs(0xc000282a80, 0x5)
      /Users/mpvl/Documents/dev/release/cue/internal/core/adt/eval.go:577 +0x136
    cuelang.org/go/internal/core/adt.(*nodeContext).postDisjunct(0xc000282a80, 0x5)
      /Users/mpvl/Documents/dev/release/cue/internal/core/adt/eval.go:548 +0x4fb
    cuelang.org/go/internal/core/adt.(*nodeContext).expandDisjuncts(0xc000282a80, 0xc001448605, 0xc000282a80, 0x0, 0x0)
      /Users/mpvl/Documents/dev/release/cue/internal/core/adt/disjunct.go:137 +0x1008
    cuelang.org/go/internal/core/adt.(*Unifier).Unify(0xc000329468, 0xc000329450, 0xc001448630, 0x180e905)
      /Users/mpvl/Documents/dev/release/cue/internal/core/adt/eval.go:315 +0x4a8
    cuelang.org/go/internal/core/adt.(*nodeContext).completeArcs(0xc000282380, 0x5)
      /Users/mpvl/Documents/dev/release/cue/internal/core/adt/eval.go:577 +0x136
    cuelang.org/go/internal/core/adt.(*nodeContext).postDisjunct(0xc000282380, 0xc00088bc05)
      /Users/mpvl/Documents/dev/release/cue/internal/core/adt/eval.go:548 +0x4fb
    cuelang.org/go/internal/core/adt.(*nodeContext).expandDisjuncts(0xc000282380, 0xc000fabb05, 0xc000282380, 0x0, 0x0)
      /Users/mpvl/Documents/dev/release/cue/internal/core/adt/disjunct.go:137 +0x1008
    cuelang.org/go/internal/core/adt.(*Unifier).Unify(0xc000329468, 0xc000329450, 0xc000fabb00, 0x180e905)
      /Users/mpvl/Documents/dev/release/cue/internal/core/adt/eval.go:315 +0x4a8
    cuelang.org/go/internal/core/adt.(*nodeContext).completeArcs(0xc000282000, 0x5)
      /Users/mpvl/Documents/dev/release/cue/internal/core/adt/eval.go:577 +0x136
    cuelang.org/go/internal/core/adt.(*nodeContext).postDisjunct(0xc000282000, 0x5)
      /Users/mpvl/Documents/dev/release/cue/internal/core/adt/eval.go:548 +0x4fb
    cuelang.org/go/internal/core/adt.(*nodeContext).expandDisjuncts(0xc000282000, 0xc00182e505, 0xc000282000, 0x0, 0x0)
      /Users/mpvl/Documents/dev/release/cue/internal/core/adt/disjunct.go:137 +0x1008
    cuelang.org/go/internal/core/adt.(*Unifier).Unify(0xc000329468, 0xc000329450, 0xc00182e510, 0xc000329405)
      /Users/mpvl/Documents/dev/release/cue/internal/core/adt/eval.go:315 +0x4a8
    cuelang.org/go/internal/core/adt.(*Vertex).Finalize(...)
      /Users/mpvl/Documents/dev/release/cue/internal/core/adt/composite.go:401
    cuelang.org/go/cue.(*Instance).Value(0xc00188a700, 0x6, 0xc00031fea0)
      /Users/mpvl/Documents/dev/release/cue/cue/instance.go:271 +0x6c
    cuelang.org/go/cmd/cue/cmd.buildInstances(0xc00031fea0, 0xc0017e7898, 0x1, 0x1, 0x17c8180, 0xc000321d40, 0xc0002c3b58)
      /Users/mpvl/Documents/dev/release/cue/cmd/cue/cmd/common.go:552 +0x131
    cuelang.org/go/cmd/cue/cmd.(*buildPlan).instances(0xc000178180, 0x0, 0x0)
      /Users/mpvl/Documents/dev/release/cue/cmd/cue/cmd/common.go:156 +0x58
    cuelang.org/go/cmd/cue/cmd.runExport(0xc00031fea0, 0xc00036c600, 0x10d, 0x10d, 0x0, 0x0)
      /Users/mpvl/Documents/dev/release/cue/cmd/cue/cmd/export.go:114 +0x1be
    cuelang.org/go/cmd/cue/cmd.mkRunE.func1(0xc000344000, 0xc00036c600, 0x10d, 0x10d, 0x0, 0x0)
      /Users/mpvl/Documents/dev/release/cue/cmd/cue/cmd/root.go:46 +0x6c
    github.com/spf13/cobra.(*Command).execute(0xc000344000, 0xc00036b300, 0x10d, 0x130, 0xc000344000, 0xc00036b300)
      /Users/mpvl/go/pkg/mod/github.com/spf13/[email protected]/command.go:842 +0x47c
    github.com/spf13/cobra.(*Command).ExecuteC(0xc000281080, 0x0, 0x0, 0x0)
      /Users/mpvl/go/pkg/mod/github.com/spf13/[email protected]/command.go:950 +0x375
    github.com/spf13/cobra.(*Command).Execute(...)
      /Users/mpvl/go/pkg/mod/github.com/spf13/[email protected]/command.go:887
    cuelang.org/go/cmd/cue/cmd.(*Command).Run(0xc00031fea0, 0x1997f00, 0xc00003a0b8, 0x0, 0x0)
      /Users/mpvl/Documents/dev/release/cue/cmd/cue/cmd/root.go:206 +0x65
    cuelang.org/go/cmd/cue/cmd.mainErr(0x1997f00, 0xc00003a0b8, 0xc000031310, 0x10e, 0x12f, 0x18da528, 0xc0002c3f48)
      /Users/mpvl/Documents/dev/release/cue/cmd/cue/cmd/root.go:145 +0x8a
    cuelang.org/go/cmd/cue/cmd.Main(0xc000100058)
      /Users/mpvl/Documents/dev/release/cue/cmd/cue/cmd/root.go:127 +0x9c
    main.main()
      /Users/mpvl/Documents/dev/release/cue/cmd/cue/main.go:24 +0x25
    
  • cue get go does not work consistently

    cue get go does not work consistently

    Originally opened by @verdverm in https://github.com/cuelang/cue/issues/621

    ceu get go does not load its own interfaces when a go vendor directory is present and CUE is not in the dependencies.

    The error is in initInterfaces() (https://github.com/cuelang/cue/blob/master/cmd/cue/cmd/get_go.go#L287)

    packages.Load does not return an error, but there are errors in p[0].Errors

    We should be checking for these errors where this function is used.


    repro:

    mkdir intstr && cd intstr
    go mod init foo.bar/intstr
    cue mod init foo.bar/intstr
    cat << EOF > repro.go
    package intstr
    import (
            "k8s.io/apimachinery/pkg/util/intstr"
    )
    _ = intstr.IntOrString
    EOF
    go mod vendor
    cue get go k8s.io/apimachinery/pkg/util/intstr
    

    possible resolutions:

    1. check for the errors and return better messages
    2. modify the Config passed to packages.Load
    3. embed and load the toTop and toText interfaces

    (1) I'd generally prefer to have a solution that does not require the user to have Cue as a dependency. This seems like unpleasant DX, essentially telling them they need to have an artificial dependency via overly complex instructions.

    (2) could be an easy solution. However, I'm leery of modifying the Config so that Cue code is fetched automatically. This might make some SecOps people unhappy / break in corp intranets.

    (3) Config has an Overlay we could use to embed these files as strings. This seems like the best way to go.

    We will also want to catch the errors in the other locations and provide an error message there.

    What do others think?

  • Can I write the Fibonacci sequence in cue?

    Can I write the Fibonacci sequence in cue?

    What version of CUE are you using (cue version)?

    $ cue version
    cue version v0.4.3 darwin/amd64
    

    Does this issue reproduce with the latest release?

    Yes

    What did you do?

    For the following code snippet (fib.cue), I run with cue export fib.cue

    #Fib: {
        n: int,
        if n <= 2 {
            value: 1
        }
        if n > 2 {
            _n1: #Fib & {
                n: n - 1
            },
            _n2: #Fib & {
                n: n - 2
            }
            value: _n1.value + _n2.value
        }
    }
    fib8: #Fib & {
        n: 8
    }
    
    

    What did you expect to see?

    {
        "fib8": {
            "n": 8,
            "value": 21
        }
    }
    

    What did you see instead?

    cycle error:
        ../fib.cue:3:8
    cycle error:
        ../fib.cue:6:8
    

    It seems that for #Fib in different positions, cue treats them as the same instance?

  • Enable the OpenSSF Scorecard Github Action

    Enable the OpenSSF Scorecard Github Action

    Hello, I am Joyce and I'm working on behalf of Google and the Open Source Security Foundation to help essential open-source projects improve their supply-chain security. Given the CUE Language relevance and impact in many projects, the OpenSSF has identified it as one of the 100 most critical open source projects.

    Is your feature request related to a problem? Please describe. According to Open Source Security and Risk Analysis Report, 84% of all codebases have at least one vulnerability, with an average of 158 per codebase. The majority have been in the code for more than 2 years and have documented solutions available.

    Even in large tech companies, the tedious process of reviewing code for vulnerabilities falls down the priority list, and there is little insight into known vulnerabilities and solutions that companies can draw on.

    That’s where the OpenSSF tool called Scorecards is helping. Its focus is to understand the security posture of a project and assess the risks that the dependencies could introduce.

    Describe the solution you'd like

    Scorecards runs dozens of automated security checks to help maintainers better understand their project's supply-chain security posture. It is developed by the OpenSSF, in partnership with GitHub.

    To simplify maintainers' lives, the OpenSSF has also developed the Scorecard GitHub Action. It is very lightweight and runs on every change to the repository's main branch. The results of its checks are available on the project's security dashboard, and include suggestions on how to solve any issues (see examples in the Additional context). The Action does not run or interact with any workflows, but merely parses them to identify possible vulnerabilities. This Action has been adopted by 1800+ projects already.

    This way, the OpenSSF Scorecard Github Action could help you to increase the security of the repository, providing some guarantee that it is (mostly) safe from malicious sabotage.

    Would you be interested in a PR which adds this Action? Optionally, it can also publish your results to the OpenSSF REST API, which allows a badge with the project's score to be added to its README, which is a great way to show off your hard work to improve security best practices and to help raising the collective level of open source security.

    Any concerns or doubts please let me know.

    Additional context Code scanning dashboard with multiple alerts, including Code-Review and Token-Permissions

    Detail of a Token-Permissions alert, indicating the specific file and remediation steps

  • Introducing pattern constraint causes

    Introducing pattern constraint causes "cue export" to spin indefinitely

    What version of CUE are you using (cue version)?

    cue version v0.4.4-0.20220915174651-ad253ed099e9
    
           -compiler gc
         CGO_ENABLED 1
              GOARCH amd64
                GOOS darwin
             GOAMD64 v1

    Does this issue reproduce with the latest release?

    Yes, both in version 0.4.3 and the tip as of today (ad253ed099e94ddcffd07e6f73a76735a96cfaf8).

    What did you do?

    I wrote a few definitions as described in preceding discussion in the "language" channel of the "CUE" Slack workspace, involving a recursive definition as part of describing Terraform's JSON output format. Building up from there, I wrote definitions for types, values of any type, values of a particular type, and documents with fields bearing values of those types.

    Most of this works fine, up until when I try to use a pattern constraint to define that general document schema, where each of the field must bear one of these values. When I try, the cue export command spins using 2.5 CPUs for as long as twenty minutes. That's the longest I've let it run so far before killing it.

    I'll share the definitions that I've written so far, together with a small JSON file that shows input data against which I'd unify these definitions.

    CUE definitions
    #ValueType:
    	// See https://github.com/zclconf/go-cty/blob/3792a7b5328c364b10c6d642e3ea0d9761338740/cty/json.go#L16-L89.
    	"bool" | // Primitive types
    	"number" |
    	"string" |
    	["list", #ValueType] |
    	["map", #ValueType] | // Complex types
    	["object", {[string]: #ValueType}] |
    	["object", {[string]: #ValueType}, [...string]] |
    	["set", #ValueType] |
    	["tuple", [...#ValueType]] |
    	"dynamic" // Pseudo-type
    
    #OutputValue: {
    	type:         #ValueType
    	sensitive:    bool
    	description?: string
    	value:        _
    }
    
    // Make defining schemas more convenient.
    #BoolTypedOutputValue: #OutputValue & {
    	type:  "bool"
    	value: bool
    }
    #NumberTypedOutputValue: #OutputValue & {
    	type:  "number"
    	value: number
    }
    #StringTypedOutputValue: #OutputValue & {
    	type:  "string"
    	value: string
    }
    let compositeTypedOutputValue = #OutputValue & {
    	#collectionType: "list" | "map" | "object" | "set" | "tuple"
    	{
    		type: [#collectionType, ...]
    	}
    }
    #ListTypedOutputValue: compositeTypedOutputValue & {
    	#collectionType: "list"
    	value: [...]
    }
    #MapTypedOutputValue: compositeTypedOutputValue & {
    	#collectionType: "map"
    	value: [string]: _
    }
    #ObjectTypedOutputValue: compositeTypedOutputValue & {
    	#collectionType: "object"
    	value: [string]: _
    }
    #SetTypedOutputValue: compositeTypedOutputValue & {
    	#collectionType: "set"
    	value: [...]
    }
    #TupleTypedOutputValue: compositeTypedOutputValue & {
    	#collectionType: "tuple"
    	value: [...]
    }
    
    // Output defines the schema for data emitted by the "terraform output -json" command.
    // THIS IS THE PROBLEM.
    //#Output: [string]: #OutputValue
    // Loosen the schema just to compare the behavior.
    #Output: [string]: _
    
    _#AWSTFOutput: #Output & {
    	let hostedZones = #TupleTypedOutputValue & {
    		value: [...{
    			id:   string // More elaborate in actual code.
    			name: string // More elaborate in actual code.
    		}]
    	}
    
    	acme_dns_challenge_prover_iam_role:   #ObjectTypedOutputValue
    	assume_dns_record_publisher_iam_role: #ObjectTypedOutputValue
    	external_dns_route_53_hosted_zones:   hostedZones
    	iam_users:                            #ObjectTypedOutputValue
    	iam_users: value: [string]: {
    		arn:       string // More elaborate in actual code.
    		unique_id: string // More elaborate in actual code.
    	}
    	route_53_hosted_zones: hostedZones
    }
    
    // Example use of these definitions unified with real input data
    example: _#AWSTFOutput & {
    	// NB: This is a JSON object pasted in, redacted in places.
    	"acme_dns_challenge_prover_iam_role": {
    		"sensitive": false
    		"type": [
    			"object",
    			{
    				"arn":       "string"
    				"name":      "string"
    				"unique_id": "string"
    			},
    		]
    		"value": {
    			"arn":       "arn:aws:iam::123456789012:role/some/path/acme-dns-challenge-prover"
    			"name":      "acme-dns-challenge-prover"
    			"unique_id": "AROAZWV55UJHHXTZOPWHI"
    		}
    	}
    	"assume_dns_record_publisher_iam_role": {
    		"sensitive": false
    		"type": [
    			"object",
    			{
    				"arn":       "string"
    				"name":      "string"
    				"unique_id": "string"
    			},
    		]
    		"value": {
    			"arn":       "arn:aws:iam::123456789012:role/some/path/dns-record-publisher"
    			"name":      "dns-record-publisher"
    			"unique_id": "AROAZWV55UJHO5BPDUMOB"
    		}
    	}
    	"external_dns_route_53_hosted_zones": {
    		"sensitive": false
    		"type": [
    			"tuple",
    			[
    				[
    					"object",
    					{
    						"id":   "string"
    						"name": "string"
    					},
    				],
    				[
    					"object",
    					{
    						"id":   "string"
    						"name": "string"
    					},
    				],
    			],
    		]
    		"value": [
    			{
    				"id":   "ZBIUQ9J8XHK3M"
    				"name": "example.com"
    			},
    			{
    				"id":   "Z08962273OP4H9PT589NQ"
    				"name": "example-1.com"
    			},
    		]
    	}
    	"iam_users": {
    		"sensitive": false
    		"type": [
    			"object",
    			{
    				"ExternalDNS": [
    					"object",
    					{
    						"arn":       "string"
    						"unique_id": "string"
    					},
    				]
    				"cert-manager": [
    					"object",
    					{
    						"arn":       "string"
    						"unique_id": "string"
    					},
    				]
    			},
    		]
    		"value": {
    			"daExternalDNS": {
    				"arn":       "arn:aws:iam::123456789012:user/some/path/ExternalDNS"
    				"unique_id": "AIDAZWV55UJ0123456789"
    			}
    			"dacert-manager": {
    				"arn":       "arn:aws:iam::123456789012:user/some/path/cert-manager"
    				"unique_id": "AIDAZWV55UJ0123456789"
    			}
    		}
    	}
    	"route_53_hosted_zones": {
    		"sensitive": false
    		"type": [
    			"tuple",
    			[
    				[
    					"object",
    					{
    						"id":   "string"
    						"name": "string"
    					},
    				],
    			],
    		]
    		"value": [
    			{
    				"id":   "ZBI0123456789"
    				"name": "example.com"
    			},
    		]
    	}
    }
    

    Note the comment in the source that reads "THIS IS THE PROBLEM." If I uncomment the line after it to read as follows, cue export gets stuck:

    #Output: [string]: #OutputValue
    

    The same problem arises if I write the following:

    _#AWSTFOutput: [string]: #OutputValue
    

    That is, I'd like to express that _#AWSTFOutput is a JSON document produced by terraform output -json with a particular set of output values, such that each field in the JSON object must bear a value that conforms to #OutputValue.

    Relaxing that pattern constraint to the following allows cue export to proceed:

    #Output: [string]: _
    

    However, that fails to satisfy my goal of describing a valid JSON object, as these values could be of any type.

    What did you expect to see?

    cue export should emit the JSON document as it was, very quickly, without complaining about any schema violations.

    What did you see instead?

    cue export consumes several CPUs for as long as I'll allow it to run, while emitting no output.

  • Error importing gitlab json schema

    Error importing gitlab json schema

    What version of CUE are you using (cue version)?

    $ cue version
    cue version v0.4.3 darwin/arm64
    

    Does this issue reproduce with the latest release?

    Yep

    What did you do?

    curl -JLO https://gitlab.com/gitlab-org/gitlab/-/raw/master/app/assets/javascripts/editor/schema/ci.json
    cue import -f -l "#CISpec:" -p gitlab ci.json
    

    Permalink to latest commit: https://gitlab.com/gitlab-org/gitlab/-/blob/7cac80c74d52cce38faa8a0068305a370a417ebd/app/assets/javascripts/editor/schema/ci.json

    What did you expect to see?

    The schema converted to CUE

    What did you see instead?

    constraint not allowed because type string is excluded:
        ./ci.json:116:33
    constraint not allowed because type string is excluded:
        ./ci.json:703:25
    

    Lines 116 and 703 for reference

  • cmd/cue: cue fmt silently fails to work when there are missing imports

    cmd/cue: cue fmt silently fails to work when there are missing imports

    What version of CUE are you using (cue version)?

    $ cue version
    cue version v0.0.0-20220915174651-ad253ed099e9
    
           -compiler gc
         CGO_ENABLED 1
              GOARCH amd64
                GOOS linux
             GOAMD64 v1
                 vcs git
        vcs.revision ad253ed099e94ddcffd07e6f73a76735a96cfaf8
            vcs.time 2022-09-15T17:46:51Z
        vcs.modified false
    
    

    Does this issue reproduce with the latest release?

    No, the error isn't silent under v0.4.3.

    What did you do?

    I ran this testscript file:

    exec cue fmt x1/x1.cue x2/x2.cue
    cmp x1/x1.cue expectx1.cue
    cmp x2/x2.cue expectx2.cue
    
    -- x1/x1.cue --
    package x
    
    import _ "github.com/foo/bar"
    -- x2/x2.cue --
    package y
    
    	needsFormat: int
    
    -- expectx1.cue --
    package x
    
    import _ "github.com/foo/bar"
    -- expectx2.cue --
    package y
    
    needsFormat: int
    

    What did you expect to see?

    A passing test.

    What did you see instead?

    > exec cue fmt x1/x1.cue x2/x2.cue
    > cmp x1/x1.cue expectx1.cue
    > cmp x2/x2.cue expectx2.cue
    --- x2/x2.cue
    +++ expectx2.cue
    @@ -1,4 +1,3 @@
     package y
     
    -	needsFormat: int
    -
    +needsFormat: int
    
    FAIL: /tmp/testscript1726192439/x.txtar/script.txtar:3: x2/x2.cue and expectx2.cue differ
    

    That is, the cue fmt command appears to succeed but doesn't actually format all the files.

    Under v0.4.3 I see this instead:

    found packages "x" (x1.cue) and y (x2.cue) in "$WORK"
    import failed: cannot find package "github.com/foo/bar":
        ./x1/x1.cue:3:8
    

    I would argue that both these failures are spurious. If I give cue fmt an explicit list of CUE files, I think it should probably format them independently and regardless of unresolved imports.

  • evaluator: comprehension cycle reported where previously this was allowed

    evaluator: comprehension cycle reported where previously this was allowed

    What version of CUE are you using (cue version)?

    $ cue version
    cue version v0.0.0-20220915134846-df148ee6b613
    
           -compiler gc
         CGO_ENABLED 1
              GOARCH arm64
                GOOS linux
                 vcs git
        vcs.revision df148ee6b6133e0466f7964eec027f2e0349cdbe
            vcs.time 2022-09-15T13:48:46Z
        vcs.modified true
    

    Does this issue reproduce with the latest release?

    Yes

    What did you do?

    exec cue export x.cue
    cmp stdout stdout.golden
    
    -- x.cue --
    package preguide
    
    #Guide: {
    	// Scenarios defines the set of scenarios this guide should cover.
    	Scenarios: [name=string]: #Scenario & {
    		Name: name
    	}
    
    	// Terminals declares the required terminals for this guide.
    	Terminals: [name=string]: #Terminal & {
    		Name: name
    	}
    
    	// This for loop templates to ensure that terminal declares an
    	// image for every scenario.
    	for scenario, _ in Scenarios for terminal, _ in Terminals {
    		Terminals: "\(terminal)": Scenarios: "\(scenario)": #TerminalScenario
    	}
    
    }
    
    #Terminal: {
    	Name: string
    	Scenarios: [string]: #TerminalScenario
    }
    
    #TerminalScenario: {
    	Image: string
    }
    
    #Scenario: {
    	Name:        string
    	Description: string
    }
    
    g1: #Guide & {
    	Terminals: term1: #Terminal & {
    		Scenarios: go115: Image: "this_will_never_be_used"
    	}
    
    	Scenarios: go115: {
    		Description: "Go 1.15"
    	}
    }
    -- stdout.golden --
    {
        "g1": {
            "Scenarios": {
                "go115": {
                    "Name": "go115",
                    "Description": "Go 1.15"
                }
            },
            "Terminals": {
                "term1": {
                    "Name": "term1",
                    "Scenarios": {
                        "go115": {
                            "Image": "this_will_never_be_used"
                        }
                    }
                }
            }
        }
    }
    

    What did you expect to see?

    Passing test. This passes with v0.4.1.

    What did you see instead?

    With tip (df148ee6):

    > exec cue export x.cue
    [stderr]
    cycle error:
        ./x.cue:16:50
    [exit status 1]
    FAIL: /tmp/testscript1377975653/repro.txtar/script.txtar:1: unexpected command failure
    

    What's interesting is that this got broken in be2ee9b62d2d9326fe025bed40215d7b5104a662. However the output against that commit is different to tip:

    > exec cue export x.cue
    [stderr]
    g1: cannot add field Terminals: was already used:
        ./x.cue:17:3
    [exit status 1]
    FAIL: /tmp/testscript2841319868/repro.txtar/script.txtar:1: unexpected command failure
    
Related tags
Lithia is an experimental functional programming language with an implicit but strong and dynamic type system.

Lithia is an experimental functional programming language with an implicit but strong and dynamic type system. Lithia is designed around a few core concepts in mind all language features contribute to.

Jun 14, 2022
Vocabular checker JetBrains Academy home work Read file with bad words

Vocabulary Checker JetBrains Academy home work Read file with bad words and replace them on * in the next entered text until exitVocabulary Checker JetBrains Academy home work Read file with bad words and replace them on * in the next entered text until exit

Jan 14, 2022
customer.io full stack engineer take home project
customer.io full stack engineer take home project

customer.io full stack engineer take home project

Jan 21, 2022
The kprobe package allows construction of dynamic struct based on kprobe event format descriptions.

The kprobe package allows construction of dynamic struct based on kprobe event format descriptions.

Oct 27, 2021
A modern and intuitive terminal-based text editor
A modern and intuitive terminal-based text editor

micro is a terminal-based text editor that aims to be easy to use and intuitive, while also taking advantage of the capabilities of modern terminals.

Sep 21, 2022
Repo Tugas Problem Solving Paradigm (Greedy, D&C, Dynamic Programming) ALTA Immersive BE5
Repo Tugas Problem Solving Paradigm (Greedy, D&C, Dynamic Programming) ALTA Immersive BE5

Cara mengerjakan tugas clone project ini, melalui git clone https://github.com/ALTA-Immersive-BE5/Problem-Solving-Paradigm.git setelah clone selesai,

Dec 23, 2021
This Go based project of Aadhyarupam Innovators demonstrate the code examples for building microservices, integration with cloud services (Google Cloud Firestore), application configuration management (Viper) etc.

This Go based project of Aadhyarupam Innovators demonstrate the code examples for building microservices, integration with cloud services (Google Cloud Firestore), application configuration management (Viper) etc.

Jan 31, 2022
Day-1 is apart of my 6 days of Christmas challenge where i write in two new languages everyday, and make something weird out of it.

Day-1 is apart of my 6 days of Christmas challenge where i write in two new languages everyday, and make something weird out of it. today was a HTTP server written with PostGreSQL using Golang, R, and shell script read more

Dec 21, 2021
🏃‍♂️ A new way to execute commands and manipulate command output in Go

??‍♂️ A new way to execute commands and manipulate command output in Go

Jul 18, 2022
Phalanx is a cloud-native full-text search and indexing server written in Go built on top of Bluge that provides endpoints through gRPC and traditional RESTful API.

Phalanx Phalanx is a cloud-native full-text search and indexing server written in Go built on top of Bluge that provides endpoints through gRPC and tr

Sep 23, 2022
Gec is a minimal stack-based programming language

Gec is a minimal stack-based programming language

May 22, 2022
A minimalist Go PDF writer in 1982 lines. Draws text, images and shapes. Helps understand the PDF format. Used in production for reports.
A minimalist Go PDF writer in 1982 lines. Draws text, images and shapes. Helps understand the PDF format. Used in production for reports.

one-file-pdf - A minimalist PDF generator in <2K lines and 1 file The main idea behind this project was: "How small can I make a PDF generator for it

Sep 22, 2022
API and a set of tools to manage Netbox configuration declaratively

declarative-netbox An experimental project to explore the idea of managing the N

Jan 24, 2022
Enrich `go test` outputs with text decorations.
Enrich `go test` outputs with text decorations.

richgo Rich-Go will enrich go test outputs with text decorations Installation (go get): go get -u github.com/kyoh86/richgo (homebrew): brew tap kyoh8

Sep 21, 2022
Tool to easily rename or move a bunch of files with a text editor of your choice
Tool to easily rename or move a bunch of files with a text editor of your choice

batch-rename With batch-rename you can utilize your favorite text editor to rename or move a bunch of files at once. It doesn't come with any features

Sep 11, 2022
Insert German umlauts in the clipboard text.

Trying to write German on an English keyboard proves to be hard. Entering umlauts like ä and ß is not easy. This program will insert umlauts in your c

Feb 7, 2022
Knit is an inline code generation tool that combines the power of Go's text/template package with automatic spec file loading.

Knit Knit is an inline code generation tool that combines the power of Go's text/template package with automatic spec file loading. Example openapi: "

Sep 15, 2022
The phylosophy behind readyGo is "A Simple configuration should give a working project.".
The phylosophy behind readyGo is

The phylosophy behind readyGo is "A Simple configuration should give a working project.". readyGo is a command line interface( probably the name of re

Oct 30, 2021
Configuration agent for BFE control plane

conf-agent conf-agent 说明 conf-agent 从 api-server 获取最新的配置并触发bfe热加载。 获取方式 获取 conf-agent 工具。获取 conf-agent 有多种方式: 在 releases 页面下载对应平台的可执行文件 通过 go get 工具本地

Mar 29, 2022