比较提交

..
6 次代码提交
作者 SHA1 备注 提交日期
朱四宏 237ea6c09d ci: sync from octopus@1.3.3-post7307
Installer Tests / powershell-discovery (push) Successful in 10s
Installer Tests / bash-discovery (push) Successful in 12s
2026-11-16 18:07:29 +08:00
朱四宏 2a8ecfc660 docs: point desktop downloads at desktop-stable channel (resync fixed source)
Installer Tests / bash-discovery (push) Successful in 1s
Installer Tests / powershell-discovery (push) Successful in 10s
2026-11-16 16:53:53 +08:00
朱四宏 5cc07c4471 ci: sync from octopus@v1.3.3
Installer Tests / bash-discovery (push) Successful in 5s
Installer Tests / powershell-discovery (push) Successful in 11s
2026-11-16 10:27:07 +08:00
fourbroad和Gitea Server 6bbafa9acc Merge pull request 'fix(install): discover stable CLI releases instead of desktop archives' (#16) from workflow/session/cli-release-discovery-public into main
Installer Tests / bash-discovery (push) Successful in 2s
Installer Tests / powershell-discovery (push) Successful in 8s
User-approved CLI discovery repair; Linux and Windows tests passed on exact head.
2026-11-14 22:28:09 +08:00
朱四宏 9b792f5378 [cli-release-discovery][iter-2] test(install): keep host-safety regression offline
Installer Tests / powershell-discovery (pull_request) Successful in 9s
Installer Tests / bash-discovery (pull_request) Successful in 2s
2026-11-14 22:27:26 +08:00
朱四宏 796948d384 [cli-release-discovery][iter-1] fix(install): select stable CLI releases and verify platform assets
Installer Tests / bash-discovery (pull_request) Successful in 1s
Installer Tests / powershell-discovery (pull_request) Successful in 8s
2026-11-14 22:26:21 +08:00
共修改 9 个文件,包含 412 行新增和 44 行删除
+31
查看文件
@@ -0,0 +1,31 @@
name: Installer Tests
on:
pull_request:
branches: [main]
types: [opened, synchronize, reopened]
push:
branches: [main]
permissions:
contents: read
jobs:
bash-discovery:
runs-on: docker-linux-2026-08-29
timeout-minutes: 10
steps:
- uses: Octopus/checkout@039ede8ebea5a92a9b189261f0336f69e59c9ecd
- name: Bash syntax and release-discovery regressions
run: |
bash -n install
python3 -m unittest discover -s tests -p 'test_cli_release_discovery.py' -v
powershell-discovery:
runs-on: windows-amd64
timeout-minutes: 10
steps:
- uses: Octopus/checkout@039ede8ebea5a92a9b189261f0336f69e59c9ecd
- name: PowerShell discovery and existing host-safety regressions
shell: powershell
run: |
& ./tests/release-discovery.ps1
if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
& ./tests/test.ps1
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
+6 -1
查看文件
@@ -1,3 +1,8 @@
<!-- GENERATED FILE — DO NOT EDIT DIRECTLY.
This README is synced to Octopus/octopus-release by script/sync-public-install.sh
on every release (force push). Manual edits here are overwritten.
Source of truth: script/public-readme.md in the Octopus/octopus repo. -->
# Octopus # Octopus
The AI coding agent built for the terminal. The AI coding agent built for the terminal.
@@ -66,7 +71,7 @@ Prefer a GUI? The Octopus desktop app ships Windows, Linux and macOS stable buil
``` ```
The AppImage auto-updates itself from the same channel (`latest-linux.yml`). Prefer a native package? [`octopus-desktop-linux-amd64.deb`](https://eightarms.net/Octopus/octopus-release/releases/download/desktop-stable/octopus-desktop-linux-amd64.deb) and [`octopus-desktop-linux-x86_64.rpm`](https://eightarms.net/Octopus/octopus-release/releases/download/desktop-stable/octopus-desktop-linux-x86_64.rpm) are published on the same channel for first installs only — they do not auto-update (reinstall or switch to the AppImage for updates), and being unsigned they will trip a first-install warning on apt/dnf. The AppImage auto-updates itself from the same channel (`latest-linux.yml`). Prefer a native package? [`octopus-desktop-linux-amd64.deb`](https://eightarms.net/Octopus/octopus-release/releases/download/desktop-stable/octopus-desktop-linux-amd64.deb) and [`octopus-desktop-linux-x86_64.rpm`](https://eightarms.net/Octopus/octopus-release/releases/download/desktop-stable/octopus-desktop-linux-x86_64.rpm) are published on the same channel for first installs only — they do not auto-update (reinstall or switch to the AppImage for updates), and being unsigned they will trip a first-install warning on apt/dnf.
- Stable updates are rolled out gradually: an allowlist of devices receives them first, then the rollout percentage is raised in stages after explicit human approval. If a stable update is not offered to you yet, check back later — your device will pick it up as the rollout expands. - This is the stable channel — the same builds the auto-updater serves to all desktop users.
## Documentation ## Documentation
+7 -2
查看文件
@@ -1,3 +1,8 @@
<!-- 生成文件——请勿直接编辑。
本 README 由主仓库 script/sync-public-install.sh 在每次发布时
强制同步(force push)到 Octopus/octopus-release,此处手工修改会被覆盖。
事实源:Octopus/octopus 仓库 script/public-readme.zh-CN.md。 -->
# Octopus # Octopus
为终端而生的 AI 编程代理。 为终端而生的 AI 编程代理。
@@ -50,7 +55,7 @@ if ($p -notlike "*$dest*") { [Environment]::SetEnvironmentVariable('Path', ($p.T
然后打开一个**新**终端运行 `octopus`。 然后打开一个**新**终端运行 `octopus`。
## 桌面版(正式版) ## 桌面版(stable)
偏好图形界面?Octopus 桌面应用与 CLI 一同发布 Windows / Linux / macOS 正式版构建: 偏好图形界面?Octopus 桌面应用与 CLI 一同发布 Windows / Linux / macOS 正式版构建:
@@ -73,7 +78,7 @@ if ($p -notlike "*$dest*") { [Environment]::SetEnvironmentVariable('Path', ($p.T
[`octopus-desktop-linux-amd64.deb`](https://eightarms.net/Octopus/octopus-release/releases/download/desktop-stable/octopus-desktop-linux-amd64.deb) / [`octopus-desktop-linux-amd64.deb`](https://eightarms.net/Octopus/octopus-release/releases/download/desktop-stable/octopus-desktop-linux-amd64.deb) /
[`octopus-desktop-linux-x86_64.rpm`](https://eightarms.net/Octopus/octopus-release/releases/download/desktop-stable/octopus-desktop-linux-x86_64.rpm)(仅限首装、不自动更新,且未签名会触发首次安装警告)。 [`octopus-desktop-linux-x86_64.rpm`](https://eightarms.net/Octopus/octopus-release/releases/download/desktop-stable/octopus-desktop-linux-x86_64.rpm)(仅限首装、不自动更新,且未签名会触发首次安装警告)。
- 正式版更新采用灰度推送:先向白名单设备推送,经人工批准后再分阶段扩大比例。若尚未收到正式版更新,请稍后再试——灰度扩大后你的设备会自动收到。 - 这是 stable 频道,与自动更新向所有桌面用户下发的构建一致。
## 文档 ## 文档
+120 -3
查看文件
@@ -28,6 +28,125 @@ Examples:
EOF EOF
} }
# Parse release JSON without adding a jq/python/node dependency to curl | bash.
# Return the first public stable CLI release in API order, never a desktop tag.
# Exit 3 means this page contains no eligible release; an empty page ends paging.
select_cli_release() {
LC_ALL=C awk -v asset="$1" '
function fail() { invalid = 1; exit 2 }
function ws() { while (substr(json, pos, 1) ~ /[ \t\r\n]/ && pos <= length(json)) pos++ }
function string( out,c,e,h,n,i,d) {
if (substr(json,pos++,1) != "\"") fail()
out = ""
while (pos <= length(json)) {
c = substr(json,pos++,1)
if (c == "\"") return out
if (c ~ /[[:cntrl:]]/) fail()
if (c == "\\") {
e = substr(json,pos++,1)
if (e == "\"" || e == "\\" || e == "/") c = e
else if (e == "b") c = sprintf("%c",8)
else if (e == "f") c = sprintf("%c",12)
else if (e == "n") c = "\n"
else if (e == "r") c = "\r"
else if (e == "t") c = "\t"
else if (e == "u") {
h = substr(json,pos,4)
if (length(h) != 4 || h ~ /[^0-9a-fA-F]/) fail()
pos += 4; n = 0
for (i=1;i<=4;i++) { d=index("0123456789abcdef",tolower(substr(h,i,1)))-1; n=n*16+d }
# Selection fields are ASCII; non-ASCII never match CLI names.
c = n > 0 && n < 128 ? sprintf("%c",n) : "?"
} else fail()
}
out = out c
}
fail()
}
function parse(path,depth, c,key,child,n,token) {
if (depth > 64) fail()
ws(); c=substr(json,pos,1)
if (c == "{" || c == "[") {
kind[path] = c == "{" ? "object" : "array"
pos++; ws(); n=0
if (substr(json,pos,1) == (c == "{" ? "}" : "]")) { pos++; count[path]=0; return }
while (1) {
if (c == "{") {
ws(); key=string(); ws()
if (substr(json,pos++,1) != ":") fail()
gsub(/%/,"%25",key); gsub(/\//,"%2F",key)
} else key=n
child=path "/" key
if (child in kind) fail()
parse(child,depth+1); n++; ws()
token=substr(json,pos++,1)
if (token == (c == "{" ? "}" : "]")) break
if (token != ",") fail()
}
count[path]=n
} else if (c == "\"") { kind[path]="string"; value[path]=string() }
else {
token=substr(json,pos)
if (match(token,/^(true|false|null)/)) {
value[path]=substr(token,1,RLENGTH); kind[path]="literal"; pos+=RLENGTH
} else if (match(token,/^-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][+-]?[0-9]+)?/)) {
value[path]=substr(token,1,RLENGTH); kind[path]="number"; pos+=RLENGTH
} else fail()
}
}
{ json = json $0 "\n" }
END {
if (invalid) exit 2
pos=1; parse("",0); ws()
if (pos <= length(json) || kind[""] != "array") exit 2
if (count[""] == 0) { print "END"; exit 0 }
for (i=0;i<count[""];i++) {
p="/" i
if (kind[p] != "object") exit 2
if (kind[p "/tag_name"] != "string" || value[p "/tag_name"] !~ /^v[0-9]+\.[0-9]+\.[0-9]+$/) continue
if (kind[p "/draft"] != "literal" || value[p "/draft"] != "false") continue
if (kind[p "/prerelease"] != "literal" || value[p "/prerelease"] != "false") continue
if (kind[p "/assets"] == "array") {
for (j=0;j<count[p "/assets"];j++) {
a=p "/assets/" j "/name"
if (kind[a] == "string" && value[a] == asset) {
print substr(value[p "/tag_name"],2); exit 0
}
}
}
# Do not silently downgrade when the newest CLI release is incomplete.
exit 4
}
exit 3
}'
}
get_latest_cli_version() {
local page releases result status
for ((page=1; page<=100; page++)); do
if ! releases=$(curl -fsSL --connect-timeout 10 --max-time 30 "${GITEA_API_URL:-https://eightarms.net/api/v1}/repos/Octopus/octopus-release/releases?limit=50&page=$page"); then
echo "Error: Failed to fetch CLI releases (page $page)." >&2
return 1
fi
if result=$(printf '%s' "$releases" | select_cli_release "$1"); then
if [ "$result" = "END" ]; then break; fi
printf '%s\n' "$result"
return 0
else
status=$?
if [ "$status" = 3 ]; then continue; fi
if [ "$status" = 4 ]; then
echo "Error: Latest stable CLI release is missing platform asset $1." >&2
else
echo "Error: Invalid CLI release metadata." >&2
fi
return 1
fi
done
echo "Error: No public stable CLI release found within 100 pages." >&2
return 1
}
requested_version=${VERSION:-} requested_version=${VERSION:-}
no_modify_path=false no_modify_path=false
binary_path="" binary_path=""
@@ -183,9 +302,7 @@ else
fi fi
if [ -z "$requested_version" ]; then if [ -z "$requested_version" ]; then
specific_version=$(curl -s "${GITEA_API_URL:-https://eightarms.net/api/v1}/repos/Octopus/octopus-release/releases?limit=1" | sed -n 's/.*"tag_name": *"v\([^"]*\)".*/\1/p') if ! specific_version=$(get_latest_cli_version "$filename"); then
if [[ $? -ne 0 || -z "$specific_version" ]]; then
echo -e "${RED}Failed to fetch version information${NC}" echo -e "${RED}Failed to fetch version information${NC}"
exit 1 exit 1
fi fi
+31 -36
查看文件
@@ -57,37 +57,38 @@ function Test-Avx2Support {
} }
} }
function Get-LatestVersion { function Get-LatestVersion([string]$Filename) {
# Resolve the latest version by following the /releases/latest redirect to # Desktop archives share this repository. /releases/latest and limit=1
# /releases/tag/vX.Y.Z. This avoids the API, which is # are not CLI selectors. Follow API order, paging past non-CLI releases.
# rate-limited to 60 requests/hour per IP. $apiUrl = if ($env:GITEA_API_URL) { $env:GITEA_API_URL.TrimEnd('/') } else { "https://eightarms.net/api/v1" }
$latestUrl = "$baseUrl/$REPO/releases/latest" for ($page = 1; $page -le 100; $page++) {
$location = $null $releases = @(Invoke-RestMethod -Uri "$apiUrl/repos/$REPO/releases?limit=50&page=$page" -UseBasicParsing -TimeoutSec 30 -ErrorAction Stop)
$request = [System.Net.HttpWebRequest]::Create($latestUrl) if ($releases.Count -eq 0) { return "" }
$request.Method = "HEAD" foreach ($release in $releases) {
$request.AllowAutoRedirect = $false if ($release.tag_name -cnotmatch '^v[0-9]+\.[0-9]+\.[0-9]+\z') { continue }
$request.UserAgent = "octopus-installer" if ($release.draft -isnot [bool] -or $release.draft -ne $false) { continue }
try { if ($release.prerelease -isnot [bool] -or $release.prerelease -ne $false) { continue }
$response = $request.GetResponse() $assets = @($release.assets | Where-Object { $_.name -ceq $Filename })
$location = $response.Headers["Location"] if ($assets.Count -eq 0) {
$response.Close() throw "Latest stable CLI release $($release.tag_name) is missing platform asset $Filename."
} catch [System.Net.WebException] { }
$resp = $_.Exception.Response return $release.tag_name.Substring(1)
if ($null -ne $resp) {
$location = $resp.Headers["Location"]
$resp.Close()
} }
} }
if (-not $location) { return "" } throw "No public stable CLI release found within 100 pages."
if ($location -match '/tag/v?([^/]+)/?$') {
return $Matches[1] -replace '^v', ''
}
return ""
} }
function Install-Octopus { function Install-Octopus {
$arch = Get-Arch $arch = Get-Arch
# Resolve the platform asset before discovery, so an incomplete release
# cannot be selected and a missing baseline/ARM64 archive fails clearly.
$target = "$APP-windows-$arch"
if ($arch -eq "x64" -and -not (Test-Avx2Support)) {
$target = "$APP-windows-$arch-baseline"
}
$filename = "$target.zip"
# Resolve version # Resolve version
if ($Version -ne "") { if ($Version -ne "") {
$specificVersion = $Version -replace '^v', '' $specificVersion = $Version -replace '^v', ''
@@ -98,14 +99,14 @@ function Install-Octopus {
} catch { } catch {
Write-Color "Error: Release v$specificVersion not found." "Red" Write-Color "Error: Release v$specificVersion not found." "Red"
Write-Color "Available releases: $baseUrl/$REPO/releases" "DarkGray" Write-Color "Available releases: $baseUrl/$REPO/releases" "DarkGray"
exit 1 throw "Release resolution failed."
} }
} else { } else {
Write-Color "Fetching latest version..." "DarkGray" Write-Color "Fetching latest version..." "DarkGray"
$specificVersion = Get-LatestVersion $specificVersion = Get-LatestVersion -Filename $filename
if (-not $specificVersion) { if (-not $specificVersion) {
Write-Color "Error: Failed to fetch latest version." "Red" Write-Color "Error: Failed to fetch latest version." "Red"
exit 1 throw "Failed to fetch latest CLI version."
} }
} }
@@ -116,19 +117,13 @@ function Install-Octopus {
$installedVersion = & $existing --version 2>$null $installedVersion = & $existing --version 2>$null
if ($installedVersion -eq $specificVersion) { if ($installedVersion -eq $specificVersion) {
Write-Color "Version $specificVersion already installed." "DarkGray" Write-Color "Version $specificVersion already installed." "DarkGray"
exit 0 return
} else { } else {
Write-Color "Installed version: $installedVersion" "DarkGray" Write-Color "Installed version: $installedVersion" "DarkGray"
} }
} catch { } } catch { }
} }
# Build filename
$target = "$APP-windows-$arch"
if ($arch -eq "x64" -and -not (Test-Avx2Support)) {
$target = "$APP-windows-$arch-baseline"
}
$filename = "$target.zip"
$downloadUrl = "$baseUrl/$REPO/releases/download/v$specificVersion/$filename" $downloadUrl = "$baseUrl/$REPO/releases/download/v$specificVersion/$filename"
Write-Color "" Write-Color ""
@@ -147,7 +142,7 @@ function Install-Octopus {
Write-Color "Error: Failed to download $downloadUrl" "Red" Write-Color "Error: Failed to download $downloadUrl" "Red"
Write-Color $_.Exception.Message "Red" Write-Color $_.Exception.Message "Red"
Remove-Item -Recurse -Force $tmpDir -ErrorAction SilentlyContinue Remove-Item -Recurse -Force $tmpDir -ErrorAction SilentlyContinue
exit 1 throw "CLI installation failed."
} }
# Extract # Extract
@@ -159,7 +154,7 @@ function Install-Octopus {
if (-not (Test-Path $exeSrc)) { if (-not (Test-Path $exeSrc)) {
Write-Color "Error: $APP.exe not found in archive." "Red" Write-Color "Error: $APP.exe not found in archive." "Red"
Remove-Item -Recurse -Force $tmpDir -ErrorAction SilentlyContinue Remove-Item -Recurse -Force $tmpDir -ErrorAction SilentlyContinue
exit 1 throw "CLI installation failed."
} }
Copy-Item -Path $exeSrc -Destination (Join-Path $INSTALL_DIR "$APP.exe") -Force Copy-Item -Path $exeSrc -Destination (Join-Path $INSTALL_DIR "$APP.exe") -Force
Remove-Item -Recurse -Force $tmpDir -ErrorAction SilentlyContinue Remove-Item -Recurse -Force $tmpDir -ErrorAction SilentlyContinue
+23
查看文件
@@ -0,0 +1,23 @@
# Installer regression tests
Offline tests; no installation or public API calls are made.
```sh
bash -n install
python3 -m unittest discover -s tests -p 'test_cli_release_discovery.py' -v
pwsh -NoProfile -File tests/release-discovery.ps1
pwsh -NoProfile -File tests/test.ps1
```
On Windows PowerShell 5.1, replace `pwsh` with `powershell`. The Gitea workflow
runs Bash on the existing Linux pool and PowerShell on the Windows pool.
Discovery follows Gitea release order and paginates past desktop archives,
drafts and prereleases. Only exact `vMAJOR.MINOR.PATCH` CLI tags qualify.
The first eligible release must list the detected platform archive; an
incomplete newest CLI release is an error, not a silent downgrade.
The Bash installer uses POSIX awk (no new jq/Python/Node runtime dependency).
Tests execute its actual discovery functions with offline fixture responses.
PowerShell tests load only the discovery function via the language AST, so they
do not execute the installer. Existing host-safety tests also remain enabled.
+69
查看文件
@@ -0,0 +1,69 @@
#Requires -Version 5.1
# Offline tests: pwsh -NoProfile -File tests/release-discovery.ps1
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$repoRoot = Split-Path -Parent $PSScriptRoot
$content = Get-Content (Join-Path $repoRoot 'install.ps1') -Raw
$tokens = $null; $errors = $null
$ast = [System.Management.Automation.Language.Parser]::ParseInput($content, [ref]$tokens, [ref]$errors)
if ($errors.Count) { throw ($errors | Out-String) }
$definition = $ast.Find({ param($node) $node -is [System.Management.Automation.Language.FunctionDefinitionAst] -and $node.Name -eq 'Get-LatestVersion' }, $true)
. ([scriptblock]::Create($definition.Extent.Text))
$REPO = 'Octopus/octopus-release'
$env:GITEA_API_URL = 'https://fixture.invalid/api/v1'
$script:pages = @{}
$script:requests = @()
$script:failHttp = $false
function Invoke-RestMethod {
param($Uri, [switch]$UseBasicParsing, $TimeoutSec, $ErrorAction)
$script:requests += $Uri
if ($script:failHttp) { throw 'HTTP 503' }
$page = [int]([regex]::Match($Uri, 'page=([0-9]+)$').Groups[1].Value)
if ($script:pages.ContainsKey($page)) { return $script:pages[$page] }
return @()
}
function New-Release([string]$Tag = 'v1.3.1', [string]$Asset = 'octopus-windows-x64.zip') {
[pscustomobject]@{ tag_name=$Tag; draft=$false; prerelease=$false; assets=@([pscustomobject]@{name=$Asset}) }
}
$script:passed = 0
function Assert-Equal($Actual, $Expected, [string]$Message) {
if ($Actual -cne $Expected) { throw "$Message : expected [$Expected], got [$Actual]" }
$script:passed++
}
$script:pages = @{1=@((New-Release 'desktop-v1.3.1'), (New-Release))}
Assert-Equal (Get-LatestVersion 'octopus-windows-x64.zip') '1.3.1' 'desktop-first must select CLI'
foreach ($tag in @('desktop-beta-v1.3.1', 'cli-v1.3.1', 'V1.3.1', 'v1.4.0-rc.1', 'v1.4.0+build', 'v1.4', "v1.4.0`n")) {
$script:pages = @{1=@((New-Release $tag), (New-Release))}
Assert-Equal (Get-LatestVersion 'octopus-windows-x64.zip') '1.3.1' "reject $tag"
}
foreach ($field in @('draft', 'prerelease')) {
foreach ($flag in @($true, 'false', $null)) {
$bad = New-Release 'v2.0.0'; $bad.$field = $flag
$script:pages = @{1=@($bad, (New-Release))}
Assert-Equal (Get-LatestVersion 'octopus-windows-x64.zip') '1.3.1' "reject non-false $field"
}
}
foreach ($asset in @('octopus-windows-x64.zip', 'octopus-windows-x64-baseline.zip', 'octopus-windows-arm64.zip')) {
$script:pages = @{1=@((New-Release 'desktop-v1.3.1'), (New-Release 'v1.3.1' $asset))}
Assert-Equal (Get-LatestVersion $asset) '1.3.1' "asset $asset"
}
$script:pages = @{1=@((New-Release 'desktop-v1.3.1')); 2=@((New-Release))}
$script:requests = @()
Assert-Equal (Get-LatestVersion 'octopus-windows-x64.zip') '1.3.1' 'pagination'
Assert-Equal $script:requests.Count 2 'must fetch next page'
$script:pages = @{1=@((New-Release 'desktop-v1.3.1'))}
Assert-Equal (Get-LatestVersion 'octopus-windows-x64.zip') '' 'empty end'
$script:pages = @{1=@((New-Release 'v1.3.1' 'wrong.zip'), (New-Release 'v1.3.0'))}
$caught = $false
try { Get-LatestVersion 'octopus-windows-x64.zip' | Out-Null } catch { $caught = $_.Exception.Message -like '*missing platform asset*' }
Assert-Equal $caught $true 'missing asset fails, no silent downgrade'
$script:pages = @{1=@((New-Release 'v1.3.1' 'OCTOPUS-WINDOWS-X64.ZIP'))}
$caught = $false
try { Get-LatestVersion 'octopus-windows-x64.zip' | Out-Null } catch { $caught = $true }
Assert-Equal $caught $true 'asset name is case-sensitive'
$script:failHttp = $true
$caught = $false
try { Get-LatestVersion 'octopus-windows-x64.zip' | Out-Null } catch { $caught = $_.Exception.Message -eq 'HTTP 503' }
Assert-Equal $caught $true 'HTTP error fails closed'
if ($content -notmatch 'Get-LatestVersion -Filename \$filename') { throw 'detected platform asset must be passed into discovery' }
Write-Host "PASS: $script:passed discovery assertions; full installer parses cleanly."
+5 -2
查看文件
@@ -46,6 +46,9 @@ Assert-True $parseOk "install.ps1 must parse without syntax errors."
$inner = @' $inner = @'
$ErrorActionPreference = "Stop" $ErrorActionPreference = "Stop"
$env:OCTOPUS_DOWNLOAD_BASE = "http://127.0.0.1:1" $env:OCTOPUS_DOWNLOAD_BASE = "http://127.0.0.1:1"
$env:GITEA_API_URL = "http://127.0.0.1:1/api/v1"
$env:PROCESSOR_ARCHITECTURE = "AMD64"
$env:USERPROFILE = [System.IO.Path]::GetTempPath()
$r = "nothing" $r = "nothing"
try { try {
Invoke-Expression (Get-Content -Raw "__INSTALL__") Invoke-Expression (Get-Content -Raw "__INSTALL__")
@@ -56,10 +59,10 @@ try {
Write-Output ("RESULT=$r") Write-Output ("RESULT=$r")
'@.Replace("__INSTALL__", $installScript) '@.Replace("__INSTALL__", $installScript)
$tmp = Join-Path $env:TEMP ("octopus_iex_test_" + $PID + ".ps1") $tmp = Join-Path ([System.IO.Path]::GetTempPath()) ("octopus_iex_test_" + $PID + ".ps1")
Set-Content -Path $tmp -Value $inner -Encoding UTF8 Set-Content -Path $tmp -Value $inner -Encoding UTF8
try { try {
$childOut = (& powershell -NoProfile -File $tmp 2>&1 | Out-String) $childOut = (& (Get-Process -Id $PID).Path -NoProfile -File $tmp 2>&1 | Out-String)
} finally { } finally {
Remove-Item $tmp -ErrorAction SilentlyContinue Remove-Item $tmp -ErrorAction SilentlyContinue
} }
+120
查看文件
@@ -0,0 +1,120 @@
#!/usr/bin/env python3
# Offline behavioral tests of the actual Bash installer discovery functions.
# python3 -m unittest discover -s tests -p 'test_cli_release_discovery.py' -v
import json
import os
from pathlib import Path
import subprocess
import tempfile
import unittest
ROOT = Path(__file__).resolve().parents[1]
SOURCE = (ROOT / "install").read_text()
FUNCTIONS = SOURCE[SOURCE.index("select_cli_release() {"):SOURCE.index("requested_version=${VERSION:-}")]
ASSET = "octopus-linux-x64.tar.gz"
def release(tag="v1.3.1"):
return dict(tag_name=tag, draft=False, prerelease=False, assets=[dict(name=ASSET)])
class DiscoveryTests(unittest.TestCase):
def select(self, releases, asset=ASSET, raw=False):
data = releases if raw else json.dumps(releases, ensure_ascii=True, indent=2)
return subprocess.run(["bash", "-c", FUNCTIONS + '\nselect_cli_release "$1"', "test", asset],
input=data, text=True, capture_output=True)
def test_desktop_archive_first(self):
desktop = release("desktop-v1.3.1")
desktop["body"] = 'Notes with braces { [ ], escaped "tag_name": "v99.0.0" and unicode 中文'
result = self.select([desktop, release()])
self.assertEqual((result.returncode, result.stdout.strip()), (0, "1.3.1"))
def test_raw_utf8_release_notes(self):
item = release("desktop-v1.3.1")
item["body"] = "中文 notes with emoji 🚀 and punctuation —"
data = json.dumps([item, release()], ensure_ascii=False)
result = self.select(data, raw=True)
self.assertEqual((result.returncode, result.stdout.strip()), (0, "1.3.1"))
def test_only_exact_stable_cli_tags(self):
bad = [release(tag) for tag in ["desktop-beta-v1.3.1", "cli-v1.3.1", "V1.3.1", "v1.4.0-rc.1", "v1.4.0+build", "v1.4", "v1.4.0\n"]]
for field, value in [("draft", True), ("prerelease", True), ("draft", "false"), ("prerelease", None)]:
item = release("v2.0.0"); item[field] = value; bad.append(item)
result = self.select(bad + [release()])
self.assertEqual((result.returncode, result.stdout.strip()), (0, "1.3.1"))
def test_missing_platform_asset_is_not_silent_downgrade(self):
latest = release(); latest["assets"] = [dict(name="octopus-desktop-linux-x86_64.AppImage")]
self.assertEqual(self.select([latest, release("v1.3.0")]).returncode, 4)
def test_each_supported_archive_name(self):
for asset in ["octopus-darwin-arm64.zip", "octopus-darwin-x64-baseline.zip", "octopus-linux-x64-musl.tar.gz", "octopus-windows-arm64.zip", "octopus-windows-x64-baseline.zip"]:
with self.subTest(asset=asset):
item = release(); item["assets"] = [dict(name=asset)]
result = self.select([release("desktop-v1.3.1"), item], asset)
self.assertEqual(result.stdout.strip(), "1.3.1")
self.assertEqual(result.returncode, 0)
def test_asset_match_is_exact(self):
self.assertEqual(self.select([release()], ASSET.upper()).returncode, 4)
def test_no_candidate_and_empty_page_have_distinct_results(self):
self.assertEqual(self.select([release("desktop-v1.3.1")]).returncode, 3)
result = self.select([])
self.assertEqual((result.returncode, result.stdout.strip()), (0, "END"))
def test_reject_malformed_or_non_array_json(self):
for raw in ['{"message":"rate limited"}', '[', '[{}] garbage', '[{"tag_name":"v1.3.1",}]', 'null', '[1]', '[{"a":1,"a":2}]']:
with self.subTest(raw=raw):
self.assertEqual(self.select(raw, raw=True).returncode, 2)
def test_unicode_escaped_ascii_fields(self):
data = json.dumps([release()]).replace('v1.3.1', r'v1\u002e3.1')
self.assertEqual(self.select(data, raw=True).stdout.strip(), "1.3.1")
def fetch(self, pages, fail=False):
with tempfile.TemporaryDirectory() as directory:
for i, page in enumerate(pages, 1):
Path(directory, f"{i}.json").write_text(json.dumps(page))
script = FUNCTIONS + r'''
curl() {
local url="${@: -1}" page
printf '%s\n' "$url" >> "$FIXTURES/requests"
if [ "$CURL_FAIL" = 1 ]; then return 22; fi
page="${url##*page=}"
if [ -f "$FIXTURES/$page.json" ]; then
while IFS= read -r line || [ -n "$line" ]; do printf '%s\n' "$line"; done < "$FIXTURES/$page.json"
else printf '[]'; fi
}
get_latest_cli_version "$1"
'''
env = dict(os.environ, FIXTURES=directory, CURL_FAIL="1" if fail else "0", GITEA_API_URL="https://fixture.invalid/api/v1")
result = subprocess.run(["bash", "-c", script, "test", ASSET], text=True, capture_output=True, env=env)
requests = Path(directory, "requests").read_text().splitlines()
return result, requests
def test_paginates_past_desktop_only_page(self):
result, requests = self.fetch([[release("desktop-v1.3.1")], [release()]])
self.assertEqual((result.returncode, result.stdout.strip()), (0, "1.3.1"))
self.assertEqual(len(requests), 2)
self.assertTrue(requests[1].endswith("limit=50&page=2"))
def test_empty_end_fails_without_downloading(self):
result, requests = self.fetch([[release("desktop-v1.3.1")], []])
self.assertNotEqual(result.returncode, 0)
self.assertIn("No public stable CLI release", result.stderr)
self.assertEqual(len(requests), 2)
def test_http_error_fails_closed(self):
result, requests = self.fetch([[release()]], fail=True)
self.assertNotEqual(result.returncode, 0)
self.assertEqual(len(requests), 1)
def test_installer_passes_detected_asset_to_discovery(self):
self.assertIn('specific_version=$(get_latest_cli_version "$filename")', SOURCE)
self.assertNotIn('releases?limit=1"', SOURCE)
if __name__ == "__main__":
unittest.main()