Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions e2e/tasks/test_task_global_config_dedup
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/usr/bin/env bash

mkdir -p "$HOME/global-config"

marker="$MISE_TMP_DIR/global-config-render-count"
: >"$marker"
cat >"$HOME/global-config/config.toml" <<EOF
[tasks.render-once]
description = "{{ exec(command='echo rendered >> $marker') }}"
run = "echo render-once"
EOF

# A path listed as both user-global and system config is one physical config and
# must render once. Task rendering can execute templates, so duplicate loading
# is observable even when the final task map deduplicates the name.
MISE_GLOBAL_CONFIG_FILE="$HOME/global-config/config.toml" \
MISE_SYSTEM_CONFIG_FILE="$HOME/global-config/config.toml" \
mise tasks >/dev/null
assert "wc -l < '$marker' | tr -d ' '" "1"

linked_marker="$MISE_TMP_DIR/linked-global-config-render-count"
: >"$linked_marker"
cat >"$HOME/global-config/linked-config.toml" <<EOF
[tasks.render-linked-once]
description = "{{ exec(command='echo rendered >> $linked_marker') }}"
run = "echo render-linked-once"
EOF
ln -s "linked-config.toml" "$HOME/global-config/config-link.toml"
MISE_GLOBAL_CONFIG_FILE="$HOME/global-config/linked-config.toml" \
MISE_SYSTEM_CONFIG_FILE="$HOME/global-config/config-link.toml" \
mise tasks >/dev/null
assert "wc -l < '$linked_marker' | tr -d ' '" "1"

shared_marker="$MISE_TMP_DIR/shared-global-task-render-count"
: >"$shared_marker"
shared_toml_marker="$MISE_TMP_DIR/shared-global-toml-render-count"
: >"$shared_toml_marker"
mkdir -p "$HOME/shared-global-tasks"
cat >"$HOME/shared-global-tasks/render-shared-once" <<EOF
#!/usr/bin/env bash
#MISE description="{{ exec(command='echo rendered >> $shared_marker') }}"
echo render-shared-once
EOF
chmod +x "$HOME/shared-global-tasks/render-shared-once"
cat >"$HOME/shared-global-tasks/shared.toml" <<EOF
[render-shared-toml-once]
description = "{{ exec(command='echo rendered >> $shared_toml_marker') }}"
run = "echo render-shared-toml-once"
EOF
ln -s "shared-global-tasks" "$HOME/shared-global-tasks-link"
cat >"$HOME/global-config/user.toml" <<EOF
[task_config]
includes = ["$HOME/shared-global-tasks"]
EOF
cat >"$HOME/global-config/system.toml" <<EOF
[task_config]
includes = ["$HOME/shared-global-tasks-link"]
EOF

# Distinct global configs may reach the same physical script or TOML task file
# through different path spellings. Reuse the higher-precedence rendered tasks
# instead of evaluating either template again.
MISE_GLOBAL_CONFIG_FILE="$HOME/global-config/user.toml" \
MISE_SYSTEM_CONFIG_FILE="$HOME/global-config/system.toml" \
mise tasks >/dev/null
assert "wc -l < '$shared_marker' | tr -d ' '" "1"
assert "wc -l < '$shared_toml_marker' | tr -d ' '" "1"

mkdir -p "$HOME/include-order-tasks"
cat >"$HOME/include-order-tasks/include-winner" <<'EOF'
#!/usr/bin/env bash
echo "$MISE_TASK_FILE"
EOF
chmod +x "$HOME/include-order-tasks/include-winner"
ln -s "include-order-tasks" "$HOME/first-global-tasks"
ln -s "include-order-tasks" "$HOME/second-global-tasks"
cat >"$HOME/global-config/include-order.toml" <<EOF
[task_config]
includes = ["$HOME/first-global-tasks", "$HOME/second-global-tasks"]
EOF

# Reuse is limited to earlier global config units. Within one config the
# documented later-include-wins rule still controls the task's source context.
assert \
"MISE_GLOBAL_CONFIG_FILE='$HOME/global-config/include-order.toml' MISE_SYSTEM_CONFIG_FILE='$HOME/global-config/missing.toml' mise run include-winner" \
"$HOME/second-global-tasks/include-winner"
33 changes: 31 additions & 2 deletions e2e/tasks/test_task_ls_global
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,29 @@ cat <<'EOF' >~/.config/mise/tasks/myglobalfile
echo myglobalfile
EOF
chmod +x ~/.config/mise/tasks/myglobalfile
mkdir -p ~/.config/mise/conf.d
cat <<'TOML' >~/.config/mise/conf.d/relative-overlay.toml
[task_config]
includes = ["empty-global-tasks"]

[tasks.relative-meta]
file = ".config/mise/tasks/relative-meta"
env = { RELATIVE_OVERLAY = "applied" }

[tasks.templated-meta]
file = "{{config_root}}/.config/mise/tasks/templated-meta"
env = { TEMPLATED_OVERLAY = "applied" }
TOML
cat <<'EOF' >~/.config/mise/tasks/relative-meta
#!/usr/bin/env bash
echo "RELATIVE_OVERLAY=${RELATIVE_OVERLAY:-<unset>}"
EOF
chmod +x ~/.config/mise/tasks/relative-meta
cat <<'EOF' >~/.config/mise/tasks/templated-meta
#!/usr/bin/env bash
echo "TEMPLATED_OVERLAY=${TEMPLATED_OVERLAY:-<unset>}"
EOF
chmod +x ~/.config/mise/tasks/templated-meta
mkdir -p ~/dotfiles/tasks
cat <<'EOF' >~/dotfiles/tasks/customglobalfile
#!/usr/bin/env bash
Expand All @@ -35,11 +58,17 @@ assert "mise tasks" "customglobalfile
myglobal
myglobalfile
mylocal
systemglobalfile"
relative-meta
systemglobalfile
templated-meta"
assert "mise tasks --local" "mylocal"
assert "mise tasks --global" "customglobalfile
myglobal
myglobalfile
systemglobalfile"
relative-meta
systemglobalfile
templated-meta"
assert "mise run customglobalfile" "PROJECT_ROOT=$PWD"
assert "mise run systemglobalfile" "PROJECT_ROOT=$PWD"
assert "mise run relative-meta" "RELATIVE_OVERLAY=applied"
assert "mise run templated-meta" "TEMPLATED_OVERLAY=applied"
23 changes: 23 additions & 0 deletions e2e/tasks/test_task_monorepo_config_dedup
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

export MISE_EXPERIMENTAL=1

marker="$MISE_TMP_DIR/monorepo-config-render-count"
mkdir -p apps/example

cat <<'EOF' >mise.toml
monorepo_root = true

[monorepo]
config_roots = ["apps/*"]
EOF

cat >apps/example/mise.toml <<EOF
[tasks.render-once]
description = "{{ exec(command='echo rendered >> $marker') }}"
run = "echo render-once"
EOF
ln -s mise.toml apps/example/mise.local.toml

mise tasks --all >/dev/null
assert "wc -l < '$marker' | tr -d ' '" "1"
63 changes: 63 additions & 0 deletions e2e/tasks/test_task_source_comparison_no_exec
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env bash

mkdir -p "$HOME/.config/mise/conf.d" "$HOME/.config/mise/tasks"

marker="$MISE_TMP_DIR/source-comparison-exec-marker"
script="$HOME/.config/mise/tasks/same"

cat <<'EOF' >"$script"
#!/usr/bin/env bash
echo same-script
EOF
chmod +x "$script"
cat <<'EOF' >"$HOME/.config/mise/tasks/same-hash"
#!/usr/bin/env bash
echo same-hash-script
EOF
chmod +x "$HOME/.config/mise/tasks/same-hash"
cat <<'EOF' >"$HOME/.config/mise/tasks/same-vars"
#!/usr/bin/env bash
echo "LOWER_OVERLAY=${LOWER_OVERLAY:-<unset>}"
EOF
chmod +x "$HOME/.config/mise/tasks/same-vars"
cat <<'EOF' >"$HOME/other-vars-script"
#!/usr/bin/env bash
echo other-vars-script
EOF
chmod +x "$HOME/other-vars-script"

cat >"$HOME/.config/mise/config.toml" <<EOF
[task_config]
includes = [".config/mise/tasks"]

[vars]
comparison_path = "$HOME/.config/mise/tasks/same-vars"
EOF

cat >"$HOME/.config/mise/conf.d/lower.toml" <<EOF
[task_config]
includes = ["empty-global-tasks"]

[tasks.same]
file = "{{ exec(command='printf $script; printf x >> $marker') }}"
env = { LOWER_OVERLAY = "must-not-render-for-comparison" }
vars = { SIDE_EFFECT = "{{ exec(command='printf y >> $marker') }}" }

[tasks.same-hash]
file = "{{ '/definitely/missing' | hash_file }}"

Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
[tasks.same-vars]
file = "{{ vars.comparison_path }}"
vars = { comparison_path = "$HOME/other-vars-script" }
env = { LOWER_OVERLAY = "must-not-apply" }
EOF

mise tasks >/dev/null
if [[ -e $marker ]]; then
fail "task source comparison executed a deferred file template"
fi

# The active config's vars must not resolve a different task's deferred file
# path. The task-local value points elsewhere, so treating this as the same
# source would incorrectly apply the lower overlay to the discovered script.
assert "mise run same-vars" "LOWER_OVERLAY=<unset>"
Loading