#!/usr/bin/env bash
# Test native GitHub attestations verification for aqua packages

set -euo pipefail

export MISE_EXPERIMENTAL=1
export MISE_AQUA_GITHUB_ATTESTATIONS=true

echo "=== Testing Native GitHub Attestations Verification ==="

# Test: Install goreleaser which has GitHub artifact attestations configured (v2.7.0+)
echo "Installing goreleaser with native GitHub attestations verification..."

# Capture the installation output to verify the native verification is being used
output=$(mise install aqua:goreleaser/goreleaser@latest 2>&1)
echo "$output"

# Verify the native GitHub attestations verification was used
if echo "$output" | grep -q "verify GitHub attestations"; then
	echo "✅ Native GitHub attestations verification was used"
else
	echo "❌ ERROR: GitHub attestations verification message not found in output"
	echo "Output was:"
	echo "$output"
	exit 1
fi

# Check if installation succeeded (it may fail due to async runtime issues but we still want to verify the verification step was called)
if echo "$output" | grep -q "✓ installed"; then
	echo "✓ goreleaser installed successfully"
	# Cleanup
	mise uninstall aqua:goreleaser/goreleaser@latest || true
else
	echo "⚠️ Installation failed (expected due to async runtime issue) but verification step was called"
fi

echo ""
echo "=== Native GitHub Attestations Verification Test Passed ✓ ==="
