Same agent Smaller bill. The tools and infrastructure to get more work from your AI. Fewer tokens. Less compute. Lower cost.
TypeScript agent-harnessagent-harness-engineeringai-engineeringai-observabilityamd-gpuclaude-codeclickhousecodexcoding-agentcoding-agentscursorgenaigpu-monitoringllm-observabilityllmopsnvidia-smiobservabilityopen-sourceopenaiopentelemetry
fix(cli): resolve the newest cli-* release instead of /releases/latest (#1617)
BASIL K AJId1156bd612f8
diff --git a/.github/workflows/ci-cli.yml b/.github/workflows/ci-cli.ymlindex 0186df9c..3626dd7e 100644--- a/.github/workflows/ci-cli.yml+++ b/.github/workflows/ci-cli.yml@@ -1,6 +1,7 @@name: CI / CLI-# Runs go-test + the plugin-tree drift check for the openlit CLI.+# Runs go-test, the installer release-resolution check, and the+# plugin-tree drift check for the openlit CLI.# Splits out from release-cli.yml so test failures don't have to wait# for a tag push: every PR that touches cli/ or plugins/ gets the# same signal the release workflow would.@@ -39,6 +40,11 @@ jobs:- uses: actions/checkout@v7with:ref: ${{ inputs.ref || github.sha }}+ # Offline. Runs before setup-go so a broken installer does not wait+ # on the toolchain. release-cli.yml calls this workflow, so a CLI+ # release runs the same check.+ - name: Test installer release resolution+ run: sh cli/scripts/install_resolve_test.sh- uses: actions/setup-go@v6with:go-version-file: cli/go.moddiff --git a/cli/scripts/install.ps1 b/cli/scripts/install.ps1index b5a936e1..d9c65faa 100644--- a/cli/scripts/install.ps1+++ b/cli/scripts/install.ps1@@ -12,7 +12,10 @@# $env:OPENLIT_INSTALL_DIR Target install directory.# Default: $env:USERPROFILE\.openlit\bin# $env:OPENLIT_VERSION Release tag WITHOUT the `cli-` prefix,-# e.g. `1.2.0`. Default: `latest`.+# e.g. `1.2.0`. Default: `latest`, resolved to+# the newest `cli-*` tag through the releases+# API - NOT through /releases/latest, which+# points at whichever component shipped last.$ErrorActionPreference = 'Stop'@@ -42,14 +45,66 @@ if ($archEnv -eq 'ARM64') {Stop-OpenLit "unsupported architecture: $archEnv (the CLI is 64-bit only)"}+# Before any GitHub request. Older Windows PowerShell defaults to TLS 1.0,+# which GitHub rejects. The zip download used to be the only request; the+# release lookup is one too, so this has to be set first or `latest` fails+# on those hosts while a pinned OPENLIT_VERSION still installs.+[Net.ServicePointManager]::SecurityProtocol = `+ [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12+# --- Resolve the asset URL --------------------------------------------------+# `/releases/latest` cannot be used here. This repository releases many+# components from one tree - openlit-*, py-*, ts-*, controller-*,+# otel-gpu-collector-* - and GitHub's "latest" is whichever of them was+# published most recently, regardless of component. That release does not+# carry the CLI archives, so the download 404s (#1596). Resolve the newest+# `cli-*` tag instead; the releases API returns newest first. Both+# installers use that rule; do not skip prereleases here unless install.sh+# does too.$asset = "openlit-windows-$arch.zip"-$url = if ($Version -eq 'latest') {- "https://github.com/$Repo/releases/latest/download/$asset"+if ($Version -eq 'latest') {+ Write-OpenLit 'Resolving the latest CLI release'+ $releasesApi = "https://api.github.com/repos/$Repo/releases"+ # Page, rather than reading only the first 100. The CLI is one component+ # among many, so its newest tag will not stay on page 1. Walk until a+ # cli-* tag is found, the list ends, or a ten-page cap. The cap stops a+ # repository with no cli-* release from walking every page before failing.+ # A thrown request fails the install in the catch below; it does not+ # look like an empty page. Unauthenticated calls are rate limited+ # (60/hour per IP).+ $tag = $null+ # Resolve once. Windows PowerShell 5.1 and PowerShell 6+ do not accept+ # the same User-Agent spelling, and -UseBasicParsing is not universal.+ $irm = Get-Command Invoke-RestMethod+ for ($page = 1; $page -le 10 -and -not $tag; $page++) {+ $irmParams = @{ Uri = "${releasesApi}?per_page=100&page=$page" }+ if ($irm.Parameters.Keys -contains 'UseBasicParsing') {+ $irmParams.UseBasicParsing = $true+ }+ # 5.1 sets User-Agent through Headers. PowerShell 6+ rejects that+ # restricted header and requires -UserAgent.+ if ($irm.Parameters.Keys -contains 'UserAgent') {+ $irmParams.UserAgent = 'openlit-installer'+ } else {+ $irmParams.Headers = @{ 'User-Agent' = 'openlit-installer' }+ }+ try {+ $releases = Invoke-RestMethod @irmParams+ } catch {+ Stop-OpenLit "could not reach $releasesApi ($($_.Exception.Message)). Set `$env:OPENLIT_VERSION to a published CLI version (for example 0.0.1) and re-run."+ }+ if (-not $releases -or $releases.Count -eq 0) { break }+ $tag = ($releases | Where-Object { $_.tag_name -like 'cli-*' } | Select-Object -First 1).tag_name+ }+ if (-not $tag) {+ Stop-OpenLit "could not resolve the latest cli-* release from $releasesApi. Set `$env:OPENLIT_VERSION to a published CLI version (for example 0.0.1) and re-run."+ }+ Write-OpenLit "Latest CLI release is $tag"} else {- "https://github.com/$Repo/releases/download/cli-$Version/$asset"+ $tag = "cli-$Version"}+$url = "https://github.com/$Repo/releases/download/$tag/$asset"Write-OpenLit "Downloading $asset"@@ -60,13 +115,6 @@ New-Item -ItemType Directory -Path $tmpDir | Out-Nulltry {$zipPath = Join-Path $tmpDir $asset- # Use TLS 1.2 explicitly for older Windows PowerShell builds that- # default to TLS 1.0; GitHub disabled that years ago and the- # download would fail with a misleading "could not create SSL/TLS- # secure channel" otherwise.- [Net.ServicePointManager]::SecurityProtocol = `- [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12-Invoke-WebRequest -Uri $url -OutFile $zipPath -UseBasicParsingExpand-Archive -Path $zipPath -DestinationPath $tmpDir -Forcediff --git a/cli/scripts/install.sh b/cli/scripts/install.shindex 814a18bf..685e0883 100755--- a/cli/scripts/install.sh+++ b/cli/scripts/install.sh@@ -13,8 +13,10 @@# OPENLIT_INSTALL_DIR Target install directory.# Default: $HOME/.openlit/bin# OPENLIT_VERSION Release tag WITHOUT the `cli-` prefix, e.g.-# `1.2.0`. Default: `latest` (resolved by-# GitHub Releases' /latest redirect).+# `1.2.0`. Default: `latest`, resolved to the+# newest `cli-*` tag through the releases API —+# NOT through /releases/latest, which points at+# whichever component shipped most recently.## Exit codes:# 0 Installed (or already present).@@ -36,6 +38,11 @@ need() {need curlneed tarneed uname+# The release lookup below parses the releases JSON with grep/sed/head.+# Fail here, before any download, if one of them is missing.+need grep+need sed+need head# `sha256sum` lives on Linux, `shasum` on macOS — fall back gracefully# below. We don't fatal on missing either: if neither tool is present,@@ -68,13 +75,73 @@ esac# --- Resolve the asset URL --------------------------------------------------# The release-cli.yml workflow uploads one tarball per OS/arch named-# openlit-<os>-<arch>.tar.gz. Latest is a redirect; pinned versions-# use the `cli-X.Y.Z` tag layout that the workflow keys off of.+# openlit-<os>-<arch>.tar.gz, on a `cli-X.Y.Z` tag.+#+# `/releases/latest` cannot be used to find it. This repository releases+# many components from one tree — openlit-*, py-*, ts-*, controller-*,+# otel-gpu-collector-* — and GitHub's "latest" is whichever of them was+# published most recently, regardless of component. That release does not+# carry the CLI archives, so the download 404s (#1596).+#+# Resolve the newest `cli-*` tag explicitly. The releases API returns+# newest first, so the first match is the one we want. Both installers+# use that rule; do not skip prereleases here unless install.ps1 does too.asset="openlit-${os}-${arch}.tar.gz"if [ "$OPENLIT_VERSION" = "latest" ]; then- url="https://github.com/${OPENLIT_REPO}/releases/latest/download/${asset}"+ info "Resolving the latest CLI release"+ releases_api="https://api.github.com/repos/${OPENLIT_REPO}/releases"+ # Page, rather than reading only the first 100. The CLI is one+ # component among many, so its newest tag will not stay on page 1.+ # Walk until a cli-* tag is found, the list ends, or a ten-page cap.+ # The cap stops a repository with no cli-* release from reading every+ # page before it fails.+ #+ # A failed call is not the end of the list. Treating it as one reports+ # "no cli-* release" when the request never succeeded, including on a+ # later page after earlier pages held only other components.+ # Unauthenticated calls are rate limited (60/hour per IP).+ tag=""+ page=1+ while [ "$page" -le 10 ]; do+ if ! body=$(curl -fsSL --retry 3 --retry-delay 1 \+ -H "Accept: application/vnd.github+json" \+ -H "User-Agent: openlit-installer" \+ "${releases_api}?per_page=100&page=${page}"); then+ fatal "could not reach ${releases_api} (network error or GitHub rate limit). \+Set OPENLIT_VERSION to a published CLI version (for example OPENLIT_VERSION=0.0.1) and re-run."+ fi+ # grep -o first, so each tag_name lands on its own line before+ # anything tries to pick one. A lone sed would depend on the API+ # pretty-printing one tag_name per line: on a compact body the+ # leading .* is greedy and walks to the LAST cli-* on the line,+ # which is the oldest release rather than the newest.+ tag=$(printf '%s' "$body" \+ | grep -o '"tag_name"[[:space:]]*:[[:space:]]*"cli-[^"]*"' \+ | sed -n 's/.*"\(cli-[^"]*\)"/\1/p' \+ | head -n 1)+ [ -n "$tag" ] && break+ # HTTP 200 with no tag_name is the end of the list. A page of+ # other components still has tag_name and has to be turned.+ printf '%s' "$body" | grep -q '"tag_name"' || break+ page=$((page + 1))+ done+ if [ -z "$tag" ]; then+ fatal "could not resolve the latest cli-* release from ${releases_api}. \+Set OPENLIT_VERSION to a published CLI version (for example OPENLIT_VERSION=0.0.1) and re-run."+ fi+ info "Latest CLI release is ${tag}"else- url="https://github.com/${OPENLIT_REPO}/releases/download/cli-${OPENLIT_VERSION}/${asset}"+ tag="cli-${OPENLIT_VERSION}"+fi+url="https://github.com/${OPENLIT_REPO}/releases/download/${tag}/${asset}"++# Test hook. cli/scripts/install_resolve_test.sh sets this so it can+# read the tag the real installer chose without downloading. Unset for+# a normal install. curl | sh only fetches this file, so the lookup+# cannot live in a sibling the test imports.+if [ "${OPENLIT_PRINT_TAG:-}" = "1" ]; then+ printf '%s\n' "$tag"+ exit 0fiinfo "Downloading ${asset}"diff --git a/cli/scripts/install_resolve_test.sh b/cli/scripts/install_resolve_test.shnew file mode 100755index 00000000..0901244e--- /dev/null+++ b/cli/scripts/install_resolve_test.sh@@ -0,0 +1,204 @@+#!/usr/bin/env sh+# Hermetic checks for the CLI installer's release lookup.+#+# curl | sh downloads install.sh alone, so the lookup stays in that file+# (and the matching block in install.ps1). This test executes install.sh+# with a fake curl on PATH. It does not reimplement the parser.+#+# install.ps1 cannot run on the Linux CI image. The checks at the bottom+# lock the two Windows failure modes that have no shell equivalent:+# TLS 1.2 must cover the release request, and User-Agent must follow+# whichever parameter that host's Invoke-RestMethod actually has.+#+# sh cli/scripts/install_resolve_test.sh+# INSTALL_SHELL=/bin/dash sh cli/scripts/install_resolve_test.sh++set -eu++ROOT=$(CDPATH= cd -- "$(dirname "$0")" && pwd)+INSTALL="$ROOT/install.sh"+PS1="$ROOT/install.ps1"+SHELL_BIN=${INSTALL_SHELL:-/bin/sh}++WORKDIR=$(mktemp -d -t openlit-install-test-XXXXXX)+trap 'rm -rf "$WORKDIR"' EXIT INT TERM+BIN="$WORKDIR/bin"+mkdir -p "$BIN"++fail=0+rc=0++say() { printf '%s\n' "$*"; }+ok() { say "ok $1"; }+bad() {+ printf 'FAIL %s\n' "$1" >&2+ fail=1+}++write_curl() {+ cat > "$BIN/curl"+ chmod +x "$BIN/curl"+}++run_install() {+ if "$SHELL_BIN" "$INSTALL" >"$WORKDIR/out" 2>"$WORKDIR/err"; then+ rc=0+ else+ rc=$?+ fi+}++tag_of() {+ tail -n 1 "$WORKDIR/out"+}++expect_tag() {+ name=$1+ want=$2+ got=$(tag_of)+ if [ "$rc" -ne 0 ] || [ "$got" != "$want" ]; then+ bad "$name: rc=$rc got='${got:-}' want='$want'"+ cat "$WORKDIR/err" >&2 || true+ return+ fi+ ok "$name"+}++expect_fail() {+ name=$1+ must=$2+ forbid=$3+ if [ "$rc" -eq 0 ]; then+ bad "$name: expected a failing install"+ return+ fi+ if ! grep -q "$must" "$WORKDIR/err"; then+ bad "$name: stderr missing '$must'"+ cat "$WORKDIR/err" >&2 || true+ return+ fi+ if grep -q "$forbid" "$WORKDIR/err"; then+ bad "$name: stderr contains '$forbid'"+ cat "$WORKDIR/err" >&2 || true+ return+ fi+ if ! grep -q "OPENLIT_VERSION" "$WORKDIR/err"; then+ bad "$name: stderr does not name the OPENLIT_VERSION override"+ return+ fi+ ok "$name"+}++# Newest cli-* on a compact one-line body. A greedy sed returns the oldest.+write_curl << 'EOF'+#!/bin/sh+printf '%s' '[{"tag_name":"cli-0.0.9"},{"tag_name":"sdk-1.0"},{"tag_name":"cli-0.0.1"}]'+EOF+OPENLIT_VERSION=latest OPENLIT_PRINT_TAG=1 PATH="$BIN:$PATH" run_install+expect_tag "compact body keeps the newest cli tag" "cli-0.0.9"++# Pretty-printed, non-CLI release first.+write_curl << 'EOF'+#!/bin/sh+printf '%s\n' '{' ' "tag_name": "otel-gpu-collector-1.0.0"' '}' '{' ' "tag_name": "cli-0.0.1"' '}'+EOF+OPENLIT_VERSION=latest OPENLIT_PRINT_TAG=1 PATH="$BIN:$PATH" run_install+expect_tag "pretty body skips newer non-cli releases" "cli-0.0.1"++# A release note that mentions a cli tag must not win. Inside a JSON+# string the quotes are escaped, so the structural tag_name is the one+# that counts.+write_curl << 'EOF'+#!/bin/sh+printf '%s\n' \+ '{' \+ ' "tag_name": "py-1.2.3",' \+ ' "body": "notes mention \"tag_name\": \"cli-9.9.9\" in prose"' \+ '}' \+ '{' \+ ' "tag_name": "cli-0.0.1"' \+ '}'+EOF+OPENLIT_VERSION=latest OPENLIT_PRINT_TAG=1 PATH="$BIN:$PATH" run_install+expect_tag "escaped tag_name in a release body is ignored" "cli-0.0.1"++# Page 1 is other components; the CLI tag is on page 2.+write_curl << 'EOF'+#!/bin/sh+page=1+for arg in "$@"; do+ case "$arg" in+ *page=*) page=${arg##*page=} ;;+ esac+done+if [ "$page" = "1" ]; then+ printf '%s' '{"tag_name":"otel-gpu-collector-1.0.0"}'+else+ printf '%s' '{"tag_name":"cli-0.0.1"}'+fi+EOF+OPENLIT_VERSION=latest OPENLIT_PRINT_TAG=1 PATH="$BIN:$PATH" run_install+expect_tag "lookup turns the page when page 1 has no cli release" "cli-0.0.1"++# Transport / rate-limit failure is not "no such release".+write_curl << 'EOF'+#!/bin/sh+echo "curl: (22) The requested URL returned error: 403" >&2+exit 22+EOF+OPENLIT_VERSION=latest OPENLIT_PRINT_TAG=1 PATH="$BIN:$PATH" run_install+expect_fail "api failure names reachability" "could not reach" "could not resolve"++# A real empty list is the other error.+write_curl << 'EOF'+#!/bin/sh+printf '%s' '[]'+EOF+OPENLIT_VERSION=latest OPENLIT_PRINT_TAG=1 PATH="$BIN:$PATH" run_install+expect_fail "empty release list names resolution" "could not resolve" "could not reach"++# An explicit version never consults the API.+write_curl << EOF+#!/bin/sh+echo called > "$WORKDIR/curl-called"+exit 99+EOF+rm -f "$WORKDIR/curl-called"+OPENLIT_VERSION=1.2.3 OPENLIT_PRINT_TAG=1 PATH="$BIN:$PATH" run_install+expect_tag "pinned version skips the releases API" "cli-1.2.3"+if [ -f "$WORKDIR/curl-called" ]; then+ bad "pinned version invoked curl"+else+ ok "pinned version did not invoke curl"+fi++# install.ps1: TLS must cover the lookup, and User-Agent must be chosen+# from the parameters this PowerShell actually has. Neither installer+# filters prereleases unless both do.+tls=$(grep -n 'ServicePointManager]::SecurityProtocol' "$PS1" | head -n 1 | cut -d: -f1)+irm=$(grep -n 'Invoke-RestMethod' "$PS1" | head -n 1 | cut -d: -f1)+web=$(grep -n 'Invoke-WebRequest' "$PS1" | head -n 1 | cut -d: -f1)+if [ -z "$tls" ] || [ -z "$irm" ] || [ -z "$web" ]; then+ bad "windows script is missing TLS setup or a web request"+elif [ "$tls" -ge "$irm" ] || [ "$tls" -ge "$web" ]; then+ bad "windows TLS setup must run before Invoke-RestMethod and Invoke-WebRequest (tls=$tls irm=$irm web=$web)"+else+ ok "windows TLS setup covers the release lookup and the download"+fi+if grep -q "Parameters.Keys -contains 'UserAgent'" "$PS1" \+ && grep -q "Parameters.Keys -contains 'UseBasicParsing'" "$PS1" \+ && grep -q 'Invoke-WebRequest -Uri $url -OutFile $zipPath -UseBasicParsing' "$PS1"; then+ ok "windows User-Agent follows the host cmdlet"+else+ bad "windows User-Agent selection or download -UseBasicParsing was dropped"+fi+if grep -q '\$_.prerelease' "$PS1" || grep -q '"prerelease"' "$INSTALL"; then+ bad "prerelease filtering has to change both installers together"+else+ ok "installers agree on prerelease handling"+fi++if [ "$fail" -ne 0 ]; then+ exit 1+fi+say "installer release resolution ok"