jdx/mise

Filters applied to `arg` or using `arg` in tests fail to resolve correctly

Closed this issue · 0 comments

Describe the bug
Applying filters to arg or using it in tests in TOML tasks fails to work as expected in some cases. Filters do not apply correctly, and arguments appear as placeholder strings (MISE_TASK_ARG) instead of resolving to their values.

To Reproduce

  1. Example 1: Using arg in tasks with conditionals

    ["generate:policy"]
    env.___POLICIES_DIR = "{{ env.POLICIES_DIR | default(value='pkg/plugins/policies') }}"
    
    depends = ["generate:tools:policy-gen"]
    
    run = """
    {% set policy_name = arg(name='policy-name') %}
    {% set plugin_dir = env.___POLICIES_DIR ~ '/' ~ policy_name %}
    
    {% if not plugin_dir is exists %}
    {{ throw(message=plugin_dir ~ " doesn't exist") }}
    {% endif %}
    """

    Running the task with mise run generate:policy circuit-breaker results in the following error:

    [generate:policy] panic in task: panicked at src/task/task_script_parser.rs:281:59:
    called `Result::unwrap()` on an `Err` value: Error { kind: Msg("Failed to render '__tera_one_off'"), source: Some(Error { kind: CallFunction("throw"), source: Some(Error { kind: Msg("pkg/plugins/policies/MISE_TASK_ARG:policy-name:MISE_TASK_ARG doesn't exist"), source: None }) }) }
    
  2. Example 2: Applying filters to arg

    ["generate:policy"]
    env.___POLICIES_DIR = "{{ env.POLICIES_DIR | default(value='pkg/plugins/policies') }}"
    
    depends = ["generate:tools:policy-gen"]
    
    run = """
    {% set policy_name = arg(name='policy-name') | upper %}
    {% set plugin_dir = env.___POLICIES_DIR ~ '/' ~ policy_name %}
    """

    Running the task with mise run generate:policy circuit-breaker results in the policy_name variable being incorrectly evaluated as MISE_TASK_ARG:POLICY-NAME:MISE_TASK_ARG, causing paths to be constructed incorrectly:

    [generate:policy] $ policy-gen core-resource --plugin-dir pkg/plugins/policies/MISE_TASK_ARG:POLICY-NAME:MISE_TASK_ARG --gomodule github.com/kumahq/kuma
    Error: stat pkg/plugins/policies/MISE_TASK_ARG:POLICY-NAME:MISE_TASK_ARG/api/v1alpha1/MISE_TASK_ARG:POLICY-NAME:MISE_TASK_ARG.go: no such file or directory
    [generate:policy] ERROR task failed
    

Expected behavior

  • The arg function should resolve to the actual argument passed to the task (e.g., circuit-breaker).
  • Filters like upper should apply correctly to the resolved argument value.
  • Conditional checks should properly evaluate paths based on resolved arguments.

mise doctor output

version: 2024.12.17 macos-arm64 (6abef71 2024-12-21)
activated: yes
shims_on_path: no

build_info:
  Target: aarch64-apple-darwin
  Features: DEFAULT, NATIVE_TLS, OPENSSL
  Built: Sat, 21 Dec 2024 16:00:07 +0000
  Rust Version: rustc 1.83.0 (90b35a623 2024-11-26)
  Profile: release

shell:
  /opt/homebrew/bin/fish
  fish, version 3.7.1

dirs:
  cache: ~/Library/Caches/mise
  config: ~/.config/mise
  data: ~/.local/share/mise
  shims: ~/.local/share/mise/shims
  state: ~/.local/state/mise

config_files:
  ~/.config/mise/config.toml
  ~/foo/mise.toml

ignored_config_files: (none)

backends:
  aqua
  asdf
  cargo
  core
  dotnet
  gem
  go
  npm
  pipx
  spm
  ubi
  vfox

plugins:
  clang-format           git@github.com:higebu/asdf-llvm.git#c527fd9
  kube-controller-tools  git@github.com:jimmidyson/asdf-kube-controller-tools.git#37526dc
  oapi-codegen           git@github.com:dylanrayboss/asdf-oapi-codegen.git#a988840

toolset:
  aqua:GoogleContainerTools/container-structure-test@1.19.3
  aqua:etcd-io/etcd@3.5.17
  aqua:golangci/golangci-lint@1.62.0
  aqua:helm/helm@3.16.4
  aqua:jqlang/jq@1.7.1
  aqua:koalaman/shellcheck@0.10.0
  aqua:kubernetes-sigs/kubebuilder@4.3.1
  aqua:kubernetes/kubectl@1.32.0
  aqua:norwoodj/helm-docs@1.11.0
  aqua:protocolbuffers/protobuf-go/protoc-gen-go@1.28.1
  aqua:protocolbuffers/protobuf/protoc@3.20.0
  aqua:stackrox/kube-linter@0.6.5
  asdf:kube-controller-tools@0.16.5
  asdf:oapi-codegen@2.4.1
  core:go@1.23.4
  go:github.com/envoyproxy/protoc-gen-validate@v1.1.0
  go:github.com/google/osv-scanner/cmd/osv-scanner@1.9.1
  go:github.com/onsi/ginkgo/v2/ginkgo@2.22.0
  go:github.com/pubg/protoc-gen-jsonschema@0.6.2
  go:google.golang.org/grpc/cmd/protoc-gen-go-grpc@1.1.0
  ubi:hadolint/hadolint@2.12.0
  ubi:jdx/usage@1.7.2
  ubi:k3d-io/k3d@5.7.5
  ubi:kubernetes-sigs/kind@0.26.0
  ubi:mikefarah/yq@4.30.8

path:
  ~/.local/share/mise/installs/container-structure-test/1.19.3
  ~/.local/share/mise/installs/etcd/3.5.17/etcd-v3.5.17-darwin-amd64
  ~/.local/share/mise/installs/go/1.23.4/bin
  ~/.local/share/mise/installs/ginkgo/2.22.0/bin
  ~/.local/share/mise/installs/golangci-lint/1.62.0/golangci-lint-1.62.0-darwin-arm64
  ~/.local/share/mise/installs/hadolint/2.12.0/bin
  ~/.local/share/mise/installs/helm/3.16.4/darwin-arm64
  ~/.local/share/mise/installs/helm-docs/1.11.0
  ~/.local/share/mise/installs/jq/1.7.1
  ~/.local/share/mise/installs/k3d/5.7.5/bin
  ~/.local/share/mise/installs/kind/0.26.0/bin
  ~/.local/share/mise/installs/kube-controller-tools/0.16.5/bin
  ~/.local/share/mise/installs/kube-linter/0.6.5
  ~/.local/share/mise/installs/kubebuilder/4.3.1
  ~/.local/share/mise/installs/kubectl/1.32.0
  ~/.local/share/mise/installs/oapi-codegen/2.4.1/bin
  ~/.local/share/mise/installs/osv-scanner/1.9.1/bin
  ~/.local/share/mise/installs/protoc/3.20.0/bin
  ~/.local/share/mise/installs/protoc-gen-go/1.28.1
  ~/.local/share/mise/installs/protoc-gen-go-grpc/1.1.0/bin
  ~/.local/share/mise/installs/protoc-gen-jsonschema/0.6.2/bin
  ~/.local/share/mise/installs/protoc-gen-validate/v1.1.0/bin
  ~/.local/share/mise/installs/shellcheck/0.10.0/shellcheck-v0.10.0
  ~/.local/share/mise/installs/yq/4.30.8/bin
  ~/.local/share/mise/installs/usage/1.7.2/bin
  ~/.local/share/mise/installs/go/1.23.4/bin
  ~/.local/bin
  /opt/homebrew/bin
  /opt/homebrew/sbin
  /opt/homebrew/opt/make/libexec/gnubin
  /opt/homebrew/opt/coreutils/libexec/gnubin
  ~/.cargo/bin
  /bin
  ~/go/bin
  ~/bin
  /usr/local/opt/libiconv/bin
  /usr/local/sbin
  /usr/local/opt/ruby/bin
  /usr/local/opt/curl/bin
  /usr/local/opt/fzf/bin
  /opt/homebrew/opt/fzf/bin
  /usr/local/bin
  /System/Cryptexes/App/usr/bin
  /usr/bin
  /usr/sbin
  /sbin
  /Library/Apple/usr/bin
  /usr/local/MacGPG2/bin
  /Applications/Wireshark.app/Contents/MacOS

env_vars:
  MISE_SHELL=fish

settings:
  experimental  true ~/.config/mise/config.toml
  experimental  true ~/foo/mise.toml

No problems found