#!/usr/bin/env bash
# A lazy tool is installed on first use, so doctor must not report it as a problem.
# https://github.com/jdx/mise/issues/15018

cat >mise.toml <<'EOF'
[tools]
dummy = { version = "1.0.0", lazy = true }
EOF

assert_not_contains "mise doctor 2>&1 || true" "tool dummy@1.0.0 is not installed"
assert_contains "mise doctor 2>&1 || true" "(lazy)"
doctor_json=$(mise doctor --json 2>/dev/null || true)
assert_not_contains_text "$doctor_json" "is not installed"
dummy_flags=$(jq -c '.toolset.dummy[0] | [.missing, .lazy]' <<<"$doctor_json")
assert_contains_text "$dummy_flags" "[true,true]"

# Ordinary missing tools are still reported.
cat >mise.toml <<'EOF'
[tools]
tiny = "1.0.0"
EOF
assert_contains "mise doctor 2>&1 || true" "vfox:jdx/vfox-tiny@1.0.0 is not installed"

# A lazy tool with no registry bin metadata must declare lazy_bins; doctor reports
# the configuration error rather than treating the tool as intentionally missing.
cat >mise.toml <<'EOF'
[tools]
"github:jdx/mise-test-fixtures" = { version = "1.0.0", lazy = true }
EOF
assert_contains "mise doctor 2>&1 || true" "set lazy_bins explicitly"
cat >mise.toml <<'EOF'
[tools]
"github:jdx/mise-test-fixtures" = { version = "1.0.0", lazy = true, lazy_bins = ["fixture"] }
EOF
assert_not_contains "mise doctor 2>&1 || true" "set lazy_bins explicitly"
