#!/usr/bin/env bash
# Test that `mise install` warns when installing tools not in any config file

set -euo pipefail
export RUST_BACKTRACE=0
export MISE_FRIENDLY_ERROR=1

# Test: Installing a tool not in config should show a "mise use" hint
assert_contains "mise install tiny@3.1.0 2>&1" "not activated"
assert_contains "mise install tiny@3.1.0 2>&1" "mise use tiny"

# Test: Installing a tool that IS in config should NOT show the hint
mise use dummy@1.0.0
assert_not_contains "mise install dummy 2>&1" "not activated"

# Test: Installing TOOL@VERSION for a tool that IS in config should NOT show
# the hint (regression test for #9501 — CLI args were overriding the config
# source in the merged tool request set, falsely flagging configured tools as
# inactive).
assert_not_contains "mise install dummy@1.0.0 2>&1" "not activated"
assert_not_contains "mise install dummy@latest 2>&1" "not activated"

# Clean up
mise use --rm dummy

# Test: Installing a tool that's only configured via MISE_<TOOL>_VERSION env
# var should NOT show the hint (regression test for #9522 review feedback —
# the config-files-only check was missing env-var-configured tools).
INSTALL_ENV_LOG="$TMPDIR/mise-install-env.log"
MISE_DUMMY_VERSION=1.0.0 mise install dummy 2>&1 | tee "$INSTALL_ENV_LOG"
assert_not_contains "cat '$INSTALL_ENV_LOG'" "not activated"
MISE_DUMMY_VERSION=1.0.0 mise install dummy@1.0.0 2>&1 | tee "$INSTALL_ENV_LOG"
assert_not_contains "cat '$INSTALL_ENV_LOG'" "not activated"
# (Backend-alias coverage for env-var-configured tools — e.g. that
# MISE_NODEJS_VERSION matches `node` — lives in the tool_env_vars unit test
# in src/toolset/tool_request_set.rs; we don't repeat it here because
# installing node in e2e is expensive and `--dry-run` returns before the
# inactive-tool warning would fire.)
