#!/usr/bin/env bash
# fixes https://github.com/jdx/mise/discussions/5999

set -euo pipefail

export MISE_EXPERIMENTAL=1
export MISE_PYTHON_GITHUB_ATTESTATIONS=0

cat >.mise.toml <<EOF
[tools]
python = "3.12.3"
uv = "0.5.4"
tiny = "3"

[settings]
python.uv_venv_auto = "create|source"
EOF

# Ensure tiny plugin is available
mise plugin install tiny >/dev/null 2>&1 || true

# Simulate uv project to trigger uv_venv_auto
touch uv.lock

mise i

# Installation evaluates the environment before uv is available, so it must
# leave venv creation for the subsequent exec.
assert_directory_not_exists "$PWD/.venv"

# Validate that a fresh environment computation creates and selects the uv
# venv while executing through another tool override.
assert "mise x --fresh-env tiny@3 -- which python" "$PWD/.venv/bin/python"
assert_directory_exists "$PWD/.venv"
