#!/usr/bin/env bash
# Test that tool_alias with asset_pattern uses the alias-specific options
# Regression test for https://github.com/jdx/mise/discussions/8847
# Regression test for https://github.com/jdx/mise/discussions/9074
# When both the original tool and an aliased tool are configured with different
# asset_pattern values, each should use its own pattern. Distinct aliases that
# resolve to the same backend/version must also be scheduled as distinct installs.

cat <<'EOF' >mise.toml
[tool_alias]
hw1 = "github:jdx/mise-test-fixtures"
hw2 = "github:jdx/mise-test-fixtures"

[tools.hw1]
version = "1.0.0"
asset_pattern = "hello-world-1.0.0.tar.gz"
bin_path = "hello-world-1.0.0/bin"
postinstall = "chmod +x $MISE_TOOL_INSTALL_PATH/hello-world-1.0.0/bin/hello-world"

[tools.hw2]
version = "1.0.0"
asset_pattern = "hello-world-2.0.0.tar.gz"
bin_path = "hello-world-2.0.0/bin"
postinstall = "chmod +x $MISE_TOOL_INSTALL_PATH/hello-world-2.0.0/bin/hello-world"
EOF

mise install
# Both should install successfully with the correct asset
assert_contains "mise x -- hello-world" "hello world"
# Both aliases should have installed using their own asset patterns
assert "test -d ~/.local/share/mise/installs/hw1/1.0.0/hello-world-1.0.0"
assert "test -d ~/.local/share/mise/installs/hw2/1.0.0/hello-world-2.0.0"
