Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filters applied to arg or using arg in tests fail to resolve correctly #3778

Closed
bartsmykla opened this issue Dec 22, 2024 · 0 comments
Closed
Labels

Comments

@bartsmykla
Copy link

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           [email protected]:higebu/asdf-llvm.git#c527fd9
  kube-controller-tools  [email protected]:jimmidyson/asdf-kube-controller-tools.git#37526dc
  oapi-codegen           [email protected]:dylanrayboss/asdf-oapi-codegen.git#a988840

toolset:
  aqua:GoogleContainerTools/[email protected]
  aqua:etcd-io/[email protected]
  aqua:golangci/[email protected]
  aqua:helm/[email protected]
  aqua:jqlang/[email protected]
  aqua:koalaman/[email protected]
  aqua:kubernetes-sigs/[email protected]
  aqua:kubernetes/[email protected]
  aqua:norwoodj/[email protected]
  aqua:protocolbuffers/protobuf-go/[email protected]
  aqua:protocolbuffers/protobuf/[email protected]
  aqua:stackrox/[email protected]
  asdf:[email protected]
  asdf:[email protected]
  core:[email protected]
  go:github.com/envoyproxy/[email protected]
  go:github.com/google/osv-scanner/cmd/[email protected]
  go:github.com/onsi/ginkgo/v2/[email protected]
  go:github.com/pubg/[email protected]
  go:google.golang.org/grpc/cmd/[email protected]
  ubi:hadolint/[email protected]
  ubi:jdx/[email protected]
  ubi:k3d-io/[email protected]
  ubi:kubernetes-sigs/[email protected]
  ubi:mikefarah/[email protected]

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
@bartsmykla bartsmykla added the bug label Dec 22, 2024
Repository owner locked and limited conversation to collaborators Dec 22, 2024
@jdx jdx converted this issue into discussion #3780 Dec 22, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
Projects
None yet
Development

No branches or pull requests

1 participant