cue-lang / cue

The home of the CUE language! Validate and define text-based and dynamic configuration
https://cuelang.org
Apache License 2.0
5.01k stars 283 forks source link

cmd/cue: cmd workflows do not work (well) with embed #3297

Open myitcv opened 1 month ago

myitcv commented 1 month ago

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

$ cue version
cue version v0.0.0-20240712164527-719893f23850

go version go1.22.3
      -buildmode exe
       -compiler gc
  DefaultGODEBUG httplaxcontentlength=1,httpmuxgo121=1,tls10server=1,tlsrsakex=1,tlsunsafeekm=1
     CGO_ENABLED 1
          GOARCH arm64
            GOOS linux
             vcs git
    vcs.revision 719893f23850172d224720e6d1257586179ac895
        vcs.time 2024-07-12T16:45:27Z
    vcs.modified false
cue.lang.version v0.10.0

Does this issue reproduce with the latest release?

Yes

What did you do?

# Setup
env CUE_EXPERIMENT=embed

cd child

# cue eval
exec cue eval .
cmp stdout $WORK/eval.golden

# cue cmd print
exec cue cmd print
cmp stdout $WORK/print.golden

-- cue.mod/module.cue --
module: ""
language: {
    version: "v0.10.0"
}
-- parent.cue --
package fizz

foo: bar
-- print_tool.cue --
package fizz

import (
    "tool/cli"
)

command: print: {
    output: cli.Print & {
        text: foo
    }
}
-- child/child.cue --
@extern(embed)

package fizz

bar: _ @embed(file=hello.txt)
-- child/hello.txt --
hello world
-- eval.golden --
foo: """
    hello world

    """
bar: """
    hello world

    """
-- print.golden --
hello world

What did you expect to see?

Passing test.

What did you see instead?

# Setup (0.000s)
# cue eval (0.013s)
# cue cmd print (0.011s)
> exec cue cmd print
[stderr]
command.print.output.text: invalid string argument: non-concrete value string:
    ../print_tool.cue:8:2
    ../print_tool.cue:9:3
    tool/cli:4:3
    tool/cli:4:9
[exit status 1]
FAIL: /tmp/testscript795057461/repro.txtar/script.txtar:11: unexpected command failure

Thanks to @seankhliao for reporting.

myitcv commented 1 month ago

Thanks to @tvandinther for another repro:

env CUE_EXPERIMENT=embed

# export as yaml
exec cue export ./... --out yaml -e json
stdout '^foo: bar$'

# cmd dump
exec cue cmd dump
stdout '^foo: bar$'

-- test.cue --
@extern(embed)

package test

json: _ @embed(file=test.json)
-- test_tool.cue --
package test

import (
    "tool/cli"
    "encoding/yaml"
)

command: dump: {
    task: print: cli.Print & {
        text: yaml.Marshal(json)
    }
}
-- test.json --
{
    "foo": "bar"
}

This test should also pass, but currently fails with:

# export as yaml (0.012s)
# cmd dump (0.010s)
> exec cue cmd dump
[stderr]
command.dump.task.print.text: invalid string argument: non-concrete argument 0:
    ./test_tool.cue:9:8
    ./test_tool.cue:10:3
    ./test_tool.cue:10:9
    tool/cli:4:3
[exit status 1]
FAIL: /tmp/testscript382573103/repro.txtar/script.txtar:8: unexpected command failure