Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions e2e/backend/test_http_ls_remote_current_opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/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

HTTP_PORT_FILE="$TMPDIR/http_version_list_port"
python3 -c "
import http.server, socketserver
s = socketserver.TCPServer(('', 0), lambda *a: http.server.SimpleHTTPRequestHandler(*a, directory='$VERSION_LIST_DIR'))
with open('$HTTP_PORT_FILE', 'w') as f:
f.write(str(s.server_address[1]))
s.serve_forever()
" &
HTTP_SERVER_PID=$!

wait_for_file "$HTTP_PORT_FILE" "HTTP test server port file" 30 "$HTTP_SERVER_PID"
HTTP_PORT=$(cat "$HTTP_PORT_FILE")

Comment thread
greptile-apps[bot] marked this conversation as resolved.
cleanup() {
kill $HTTP_SERVER_PID 2>/dev/null || true
}
trap cleanup EXIT
Comment on lines +21 to +29

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 The trap cleanup EXIT is registered after wait_for_file, so if wait_for_file fails (e.g., the server crashes before writing the port file) and calls exit 1, the trap is never registered and the Python server process is orphaned. Moving the trap registration to immediately after HTTP_SERVER_PID=$! ensures cleanup always runs on exit, matching the pattern used in test_http_compressed_binaries.

Suggested change
HTTP_SERVER_PID=$!
wait_for_file "$HTTP_PORT_FILE" "HTTP test server port file" 30 "$HTTP_SERVER_PID"
HTTP_PORT=$(cat "$HTTP_PORT_FILE")
cleanup() {
kill $HTTP_SERVER_PID 2>/dev/null || true
}
trap cleanup EXIT
HTTP_SERVER_PID=$!
cleanup() {
kill $HTTP_SERVER_PID 2>/dev/null || true
}
trap cleanup EXIT
wait_for_file "$HTTP_PORT_FILE" "HTTP test server port file" 30 "$HTTP_SERVER_PID"
HTTP_PORT=$(cat "$HTTP_PORT_FILE")


if ! curl --retry 5 --retry-connrefused --retry-delay 1 -fsS "http://localhost:$HTTP_PORT/versions.json" >/dev/null; then
fail "HTTP server failed to respond"
fi

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"
Loading