#!/usr/bin/env bash

# Regression test for https://github.com/jdx/mise/discussions/8880
# Current config options must override stale install-manifest options for HTTP
# version listings.

VERSION_LIST_DIR="$TMPDIR/http-version-list-opts"
mkdir -p "$VERSION_LIST_DIR"
cat <<'JSON' >"$VERSION_LIST_DIR/versions.json"
{"old":["0.1.0"],"current":["1.0.0","2.0.0"]}
JSON

start_http_server --dir "$VERSION_LIST_DIR"

mkdir -p "$MISE_DATA_DIR/installs"
cat <<EOF >"$MISE_DATA_DIR/installs/.mise-installs.toml"
[http-tool-opts]
short = "http:tool-opts"
full = "http:tool-opts"
explicit_backend = true

[http-tool-opts.opts]
version_list_url = "http://localhost:$HTTP_PORT/versions.json"
version_json_path = ".old"
EOF

cat <<EOF >mise.toml
[tools."http:tool-opts"]
version = "1.0.0"
version_list_url = "http://localhost:$HTTP_PORT/versions.json"
version_json_path = ".current"
EOF

assert "mise ls-remote http:tool-opts" "1.0.0
2.0.0"
