Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
5 changes: 0 additions & 5 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,3 @@ archives:

checksum:
name_template: checksums.txt

release:
github:
owner: ory
name: lumen
27 changes: 26 additions & 1 deletion scripts/run.bat
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,32 @@ set "BINARY=%PLUGIN_ROOT%\bin\lumen-windows-%ARCH%.exe"

:: Download on first run if binary is missing
if not exist "%BINARY%" (
set "REPO=ory/lumen"
if defined LUMEN_RELEASE_REPO (
set "REPO=%LUMEN_RELEASE_REPO%"
) else (
set "REPO="
set "ORIGIN_URL="
for /f "delims=" %%u in ('git -C "%PLUGIN_ROOT%" remote get-url origin 2^>nul') do (
if not defined ORIGIN_URL set "ORIGIN_URL=%%u"
)
if defined ORIGIN_URL (
set "CANDIDATE="
set "_TMP=!ORIGIN_URL!"
if /I "!_TMP:~0,19!"=="https://github.com/" (
set "CANDIDATE=!_TMP:~19!"
) else if /I "!_TMP:~0,15!"=="git@github.com:" (
set "CANDIDATE=!_TMP:~15!"
) else if /I "!_TMP:~0,21!"=="ssh://git@github.com/" (
set "CANDIDATE=!_TMP:~21!"
)
if defined CANDIDATE (
if "!CANDIDATE:~-4!"==".git" set "CANDIDATE=!CANDIDATE:~0,-4!"
echo !CANDIDATE! | findstr /r "^[^/][^/]*/[^/][^/]*$" >nul 2>&1
if not errorlevel 1 set "REPO=!CANDIDATE!"
)
)
if not defined REPO set "REPO=ory/lumen"
)
Comment thread
coderabbitai[bot] marked this conversation as resolved.

:: Always use the version pinned in the manifest — keeps plugin and binary in sync
set "MANIFEST=%PLUGIN_ROOT%\.release-please-manifest.json"
Expand Down
32 changes: 31 additions & 1 deletion scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,36 @@ set -euo pipefail
# OpenCode, and direct local invocation.
PLUGIN_ROOT="${CLAUDE_PLUGIN_ROOT:-${CURSOR_PLUGIN_ROOT:-$(cd "$(dirname "$0")/.." && pwd)}}"

release_repo_from_remote_url() {
local url="$1" repo
case "$url" in
https://github.com/*/*.git) repo="${url#https://github.com/}"; echo "${repo%.git}" ;;
https://github.com/*/*) echo "${url#https://github.com/}" ;;
git@github.com:*/*.git) repo="${url#git@github.com:}"; echo "${repo%.git}" ;;
git@github.com:*/*) echo "${url#git@github.com:}" ;;
ssh://git@github.com/*/*.git) repo="${url#ssh://git@github.com/}"; echo "${repo%.git}" ;;
ssh://git@github.com/*/*) echo "${url#ssh://git@github.com/}" ;;
*) echo "" ;;
esac
}

resolve_release_repo() {
if [ -n "${LUMEN_RELEASE_REPO:-}" ]; then
echo "$LUMEN_RELEASE_REPO"
return
fi

local remote_url repo
remote_url="$(git -C "$PLUGIN_ROOT" remote get-url origin 2>/dev/null || true)"
repo="$(release_repo_from_remote_url "$remote_url")"
if [ -n "$repo" ]; then
echo "$repo"
return
fi

echo "ory/lumen"
}

# Platform detection
OS="$(uname -s | tr '[:upper:]' '[:lower:]')"
ARCH="$(uname -m)"
Expand All @@ -29,7 +59,7 @@ done
if [ -z "$BINARY" ]; then
BINARY="${PLUGIN_ROOT}/bin/lumen-${OS}-${ARCH}"

REPO="ory/lumen"
REPO="$(resolve_release_repo)"

# Always use the version pinned in the manifest — keeps plugin and binary in sync
MANIFEST="${PLUGIN_ROOT}/.release-please-manifest.json"
Expand Down
55 changes: 54 additions & 1 deletion scripts/test_run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,37 @@ assert_eq "Windows amd64 URL" \
"https://github.com/ory/lumen/releases/download/v0.0.1-alpha.4/lumen-0.0.1-alpha.4-windows-amd64.exe" \
"$(download_url "$REPO" "$VERSION" "windows" "amd64")"

echo ""
echo "=== release repository resolution tests ==="

release_repo_from_remote_url() {
local url="$1" repo
case "$url" in
https://github.com/*/*.git) repo="${url#https://github.com/}"; echo "${repo%.git}" ;;
https://github.com/*/*) echo "${url#https://github.com/}" ;;
git@github.com:*/*.git) repo="${url#git@github.com:}"; echo "${repo%.git}" ;;
git@github.com:*/*) echo "${url#git@github.com:}" ;;
ssh://git@github.com/*/*.git) repo="${url#ssh://git@github.com/}"; echo "${repo%.git}" ;;
ssh://git@github.com/*/*) echo "${url#ssh://git@github.com/}" ;;
*) echo "" ;;
esac
}

assert_eq "parse HTTPS origin with .git" "def324/lumen" \
"$(release_repo_from_remote_url "https://github.com/def324/lumen.git")"
assert_eq "parse HTTPS origin without .git" "def324/lumen" \
"$(release_repo_from_remote_url "https://github.com/def324/lumen")"
assert_eq "parse SSH origin with .git" "def324/lumen" \
"$(release_repo_from_remote_url "git@github.com:def324/lumen.git")"
assert_eq "parse ssh:// origin with .git" "def324/lumen" \
"$(release_repo_from_remote_url "ssh://git@github.com/def324/lumen.git")"
assert_eq "parse SSH origin without .git" "def324/lumen" \
"$(release_repo_from_remote_url "git@github.com:def324/lumen")"
assert_eq "parse ssh:// origin without .git" "def324/lumen" \
"$(release_repo_from_remote_url "ssh://git@github.com/def324/lumen")"
assert_eq "ignore non-GitHub origin" "" \
"$(release_repo_from_remote_url "git@example.com:def324/lumen.git")"

echo ""
echo "=== arch normalisation tests ==="
assert_eq "x86_64 → amd64" "amd64" "$(normalise_arch "x86_64")"
Expand Down Expand Up @@ -165,6 +196,7 @@ echo "=== stdio download-on-first-run integration test ==="
_SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
_TMPROOT="$(mktemp -d)"
_FAKE_CURL_DIR="$(mktemp -d)"
_URL_LOG="${_TMPROOT}/curl-urls.txt"
trap 'rm -rf "$_TMPROOT" "$_FAKE_CURL_DIR"' EXIT

OS="$(uname -s | tr '[:upper:]' '[:lower:]')"
Expand All @@ -181,6 +213,7 @@ echo "=== stdio download-on-first-run integration test ==="
while [ $# -gt 0 ]; do
case "$1" in
-o) mkdir -p "$(dirname "$2")"; printf '#!/usr/bin/env bash\nexit 0\n' > "$2"; chmod +x "$2"; shift 2 ;;
https://*) printf '%s\n' "$1" >> "$LUMEN_CURL_URL_LOG"; shift ;;
*) shift ;;
esac
done
Expand All @@ -189,7 +222,10 @@ FAKECURL
chmod +x "${_FAKE_CURL_DIR}/curl"

EXIT_CODE=0
CLAUDE_PLUGIN_ROOT="${_TMPROOT}" PATH="${_FAKE_CURL_DIR}:${PATH}" \
CLAUDE_PLUGIN_ROOT="${_TMPROOT}" \
LUMEN_RELEASE_REPO="def324/lumen" \
LUMEN_CURL_URL_LOG="${_URL_LOG}" \
PATH="${_FAKE_CURL_DIR}:${PATH}" \
bash "${_SCRIPT_DIR}/run.sh" stdio >/dev/null 2>&1 || EXIT_CODE=$?

if [ "$EXIT_CODE" -ne 0 ]; then
Expand All @@ -200,6 +236,12 @@ FAKECURL
echo " FAIL: run.sh stdio should have downloaded binary to ${_EXPECTED_BINARY}"
exit 1
fi
if ! grep -q "https://github.com/def324/lumen/releases/download/v0.0.1/" "${_URL_LOG}"; then
echo " FAIL: run.sh stdio should use LUMEN_RELEASE_REPO for download URL"
echo " URLs:"
sed 's/^/ /' "${_URL_LOG}"
exit 1
fi
echo " PASS: run.sh stdio downloads binary and execs it on first install"
) && PASS=$((PASS + 1)) || FAIL=$((FAIL + 1))

Expand Down Expand Up @@ -301,6 +343,7 @@ echo "=== stdio first-install MCP handshake test ==="
_TMPROOT="$(mktemp -d)"
_FAKE_CURL_DIR="$(mktemp -d)"
_MOCK_BIN_DIR="$(mktemp -d)"
_URL_LOG="${_TMPROOT}/curl-urls.txt"
trap 'rm -rf "$_TMPROOT" "$_FAKE_CURL_DIR" "$_MOCK_BIN_DIR"' EXIT

_OS="$(uname -s | tr '[:upper:]' '[:lower:]')"
Expand All @@ -321,13 +364,16 @@ echo "=== stdio first-install MCP handshake test ==="

printf '{\n ".": "0.0.1"\n}\n' > "${_TMPROOT}/.release-please-manifest.json"
mkdir -p "${_TMPROOT}/bin"
git -C "${_TMPROOT}" init -q
git -C "${_TMPROOT}" remote add origin git@github.com:def324/lumen.git

# Stub curl: parse -o <target> and copy the prebuilt mock into place.
cat > "${_FAKE_CURL_DIR}/curl" <<'FAKECURL'
#!/usr/bin/env bash
while [ $# -gt 0 ]; do
case "$1" in
-o) mkdir -p "$(dirname "$2")"; cp "$LUMEN_MOCK_BINARY" "$2"; chmod +x "$2"; shift 2 ;;
https://*) printf '%s\n' "$1" >> "$LUMEN_CURL_URL_LOG"; shift ;;
*) shift ;;
esac
done
Expand All @@ -343,6 +389,7 @@ FAKECURL
printf '%s\n' "$_INIT_REQ" | \
CLAUDE_PLUGIN_ROOT="${_TMPROOT}" \
PATH="${_FAKE_CURL_DIR}:${PATH}" \
LUMEN_CURL_URL_LOG="${_URL_LOG}" \
LUMEN_MOCK_BINARY="${_MOCK_BIN}" \
bash "${_SCRIPT_DIR}/run.sh" stdio >"${_STDOUT}" 2>"${_STDERR}" \
|| EXIT_CODE=$?
Expand All @@ -357,6 +404,12 @@ FAKECURL
echo " FAIL: run.sh stdio did not place artefact at ${_EXPECTED_BINARY}"
exit 1
fi
if ! grep -q "https://github.com/def324/lumen/releases/download/v0.0.1/" "${_URL_LOG}"; then
echo " FAIL: run.sh stdio should derive release repo from plugin root origin"
echo " URLs:"
sed 's/^/ /' "${_URL_LOG}"
exit 1
fi
if ! grep -q '"jsonrpc":"2.0"' "${_STDOUT}"; then
echo " FAIL: MCP initialize produced no JSON-RPC 2.0 response on stdout"
echo " stdout:"
Expand Down
Loading
Loading