#!/usr/bin/env bash

# The version of a registry package reaches the package manager as
# `<name>@<version>`, which it parses as a full package spec. A version that
# is a path must not install that directory in place of the registry package.
mkdir -p payload
cat >payload/package.json <<'EOF'
{"name": "left-pad", "version": "1.3.0", "bin": {"left-pad": "cli.sh"}}
EOF
printf '#!/bin/sh\necho payload\n' >payload/cli.sh
chmod +x payload/cli.sh

# An absolute path is refused when the version is parsed, before the backend
# sees it; either layer may report it.
assert_fail_matches "mise install 'npm:left-pad@$PWD/payload'" "must not start with '/'|is not a version, range or dist-tag"
# These pass the generic version rules, so the npm backend's own check refuses them.
assert_fail "mise install npm:left-pad@./payload" "is not a version, range or dist-tag"
assert_fail "mise install npm:left-pad@stevemao/left-pad" "is not a version, range or dist-tag"
# None of them installed anything.
mkdir -p "$MISE_DATA_DIR/installs"
assert_empty "find '$MISE_DATA_DIR/installs' -path '*npm-left-pad*' -name node_modules"
