#!/usr/bin/env bash

cargo init --name hello_cargo

#################################################################################
# Test remote tasks with no ref
#################################################################################

cat <<EOF >mise.toml
[tasks.remote_lint_https_latest]
file  = "git::https://github.com/jdx/mise.git//xtasks/lint/clippy"
EOF

assert_contains "mise tasks" "remote_lint_https_latest"
assert_succeed "mise run remote_lint_https_latest" # Remote task should be downloaded

mise cache clear # Clear cache to force redownload

assert_succeed "MISE_TASK_REMOTE_NO_CACHE=true mise run remote_lint_https_latest" # Remote task should be redownloaded

assert_succeed "mise run remote_lint_https_latest --no-cache" # Remote task should be redownloaded

assert_succeed "mise run remote_lint_https_latest" # Cache should be used

#################################################################################
# Test remote tasks with with ref
#################################################################################

cat <<EOF >mise.toml
[tasks.remote_lint_https_ref]
file  = "git::https://github.com/jdx/mise.git//xtasks/lint/clippy?ref=v2025.1.17"
EOF

assert_contains "mise tasks" "remote_lint_https_ref"
assert_succeed "mise run remote_lint_https_ref" # Remote task should be downloaded

mise cache clear # Clear cache to force redownload

assert_succeed "MISE_TASK_REMOTE_NO_CACHE=true mise run remote_lint_https_ref" # Remote task should be redownloaded

assert_succeed "mise run remote_lint_https_ref --no-cache" # Remote task should be redownloaded

assert_succeed "mise run remote_lint_https_ref" # Cache should be used
