#!/usr/bin/env bash

# Create system "tools" that always fail and push them to the front of PATH
cat >"$HOME/bin/fail" <<'EOF'
#!/usr/bin/env bash
echo "CALL TO SYSTEM $(basename $0)! args: $*" >&2
exit 1
EOF
chmod +x "$HOME"/bin/fail
ln -s fail "$HOME/bin/go"
export PATH="$HOME/bin:$PATH"

# Just to be sure...
assert_fail go

cat >>.mise.toml <<EOF
[tools]
go = "prefix:1.22"
"go:github.com/golangci/golangci-lint/cmd/golangci-lint" = "latest"
[settings]
experimental = true
EOF

mise install go
mise install

eval "$(mise activate bash --shims)"

assert "mise x go:github.com/DarthSim/hivemind@1.1.0 -- hivemind --version" "Hivemind version 1.1.0"
assert "mise x go:github.com/go-task/task/v3/cmd/task@3.34.1 -- task --version" "Task version: v3.34.1 (h1:yAAxUM54zoaHv+OtDnGgkWSVeiRuaOCn1lPUXPQQA0o=)"
# See https://github.com/jdx/mise/issues/1667
assert "mise x go:github.com/jdx/go-example@e16a340 -- go-example" "hello world"

# Required to properly cleanup as go installs read-only sources
chmod -R +w ~/go
