#!/usr/bin/env bash
# Regression test: a `--tool python@X` override must reach venv creation.
#
# `_.python.venv` rebuilds a python/uv-only toolset from the config files to avoid a circular wait
# during env resolution, so on its own it cannot see a CLI override — it would build the venv from
# the first `[tools] python` entry and then silently run every task under that interpreter.
# https://github.com/jdx/mise/discussions/5281

export MISE_PYTHON_GITHUB_ATTESTATIONS=0

cat >.mise.toml <<EOF
[tools]
python = ["3.13.14", "3.12.13"]
[env._.python]
venv = {path = "{{env.HOME}}/my_venv", create=true}
[tasks]
version = "python --version"
EOF

mise i

# no override: the first [tools] entry, unchanged
assert_contains "mise run version" "Python 3.13.14"

# the override decides which interpreter the venv is built from. A venv cannot be retargeted after
# creation, so remove it first — that is the same thing a per-version venv path would achieve.
rm -rf "$HOME/my_venv"
assert_contains "mise run --tool python@3.12.13 version" "Python 3.12.13"
