Skip to content

Commit 314aeb8

Browse files
committed
fix: reuse installed agent when update check fails
1 parent 1e14687 commit 314aeb8

7 files changed

Lines changed: 171 additions & 24 deletions

File tree

.antigravity-plugin/scripts/ensure-monk-agent.ps1

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,28 @@ $ChecksumTmp = Join-Path $InstallDir ".monk-agent.tmp.sha256"
102102
$ExtractDir = Join-Path $InstallDir ".monk-agent.extract"
103103
New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null
104104

105-
Invoke-WebRequest -Uri $ChecksumUrl -OutFile $ChecksumTmp
105+
try {
106+
Invoke-WebRequest -Uri $ChecksumUrl -OutFile $ChecksumTmp
107+
} catch {
108+
$Installed = ""
109+
if ((Test-Path $Target) -and (Test-Path $ChecksumInstalled)) {
110+
try {
111+
$Installed = ((Get-Content -Raw $ChecksumInstalled).Trim() -split "\s+")[0].ToLowerInvariant()
112+
} catch {
113+
$Installed = ""
114+
}
115+
}
116+
117+
$TargetSize = if (Test-Path $Target) { (Get-Item $Target).Length } else { 0 }
118+
if ($TargetSize -gt 0 -and $Installed -match "^[0-9a-f]{64}$") {
119+
Remove-Item -Force $ChecksumTmp -ErrorAction SilentlyContinue
120+
Write-Warning "Unable to check for monk-agent updates; using the previously checksummed installation at $Target."
121+
Write-Output $Target
122+
exit 0
123+
}
124+
125+
throw
126+
}
106127

107128
$Expected = ((Get-Content -Raw $ChecksumTmp).Trim() -split "\s+")[0].ToLowerInvariant()
108129

.antigravity-plugin/scripts/ensure-monk-agent.sh

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,34 @@ if [ "$auto_update" = "0" ] || [ "$auto_update" = "false" ]; then
5151
fi
5252
fi
5353

54-
if command -v curl >/dev/null 2>&1; then
55-
curl -fL "$checksum_url" -o "$checksum_tmp"
56-
elif command -v wget >/dev/null 2>&1; then
57-
wget -O "$checksum_tmp" "$checksum_url"
58-
else
59-
echo "curl or wget is required to install monk-agent." >&2
60-
exit 2
54+
download_checksum() {
55+
if command -v curl >/dev/null 2>&1; then
56+
curl -fL "$checksum_url" -o "$checksum_tmp"
57+
elif command -v wget >/dev/null 2>&1; then
58+
wget -O "$checksum_tmp" "$checksum_url"
59+
else
60+
echo "curl or wget is required to check for monk-agent updates." >&2
61+
return 2
62+
fi
63+
}
64+
65+
if ! download_checksum; then
66+
if [ -x "$target" ] && [ -s "$target" ] && [ -f "$checksum_installed" ]; then
67+
installed="$(awk '{print $1}' "$checksum_installed")"
68+
case "$installed" in
69+
*[!0-9a-fA-F]*|'') ;;
70+
*)
71+
if [ "${#installed}" -eq 64 ]; then
72+
rm -f "$checksum_tmp"
73+
echo "Warning: unable to check for monk-agent updates; using the previously checksummed installation at $target." >&2
74+
printf '%s\n' "$target"
75+
exit 0
76+
fi
77+
;;
78+
esac
79+
fi
80+
echo "Unable to check for monk-agent updates and no verified local installation is available." >&2
81+
exit 1
6182
fi
6283

6384
expected="$(awk '{print $1}' "$checksum_tmp")"

.github/workflows/install-e2e.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ jobs:
3838
test "$installed" = "$MONK_AGENT_INSTALL_DIR/monk-agent"
3939
test -x "$installed"
4040
41+
- name: Reuse installed agent when update endpoint is unavailable
42+
shell: bash
43+
env:
44+
MONK_AGENT_INSTALL_DIR: ${{ runner.temp }}/monk-bin
45+
MONK_AGENT_DOWNLOAD_BASE: http://127.0.0.1:1
46+
run: |
47+
set -euo pipefail
48+
installed="$(./scripts/ensure-monk-agent.sh)"
49+
test "$installed" = "$MONK_AGENT_INSTALL_DIR/monk-agent"
50+
4151
- name: Run monk-agent status
4252
shell: bash
4353
env:
@@ -76,6 +86,17 @@ jobs:
7686
throw "monk-agent.exe was not installed"
7787
}
7888
89+
- name: Reuse installed agent when update endpoint is unavailable
90+
shell: pwsh
91+
env:
92+
MONK_AGENT_INSTALL_DIR: ${{ runner.temp }}\monk-bin
93+
MONK_AGENT_DOWNLOAD_BASE: http://127.0.0.1:1
94+
run: |
95+
$installed = .\scripts\ensure-monk-agent.ps1
96+
if ($installed -ne "$env:MONK_AGENT_INSTALL_DIR\monk-agent.exe") {
97+
throw "unexpected offline fallback path: $installed"
98+
}
99+
79100
- name: Run monk-agent status
80101
shell: pwsh
81102
env:

plugins/monk/scripts/ensure-monk-agent.ps1

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,28 @@ $ChecksumTmp = Join-Path $InstallDir ".monk-agent.tmp.sha256"
102102
$ExtractDir = Join-Path $InstallDir ".monk-agent.extract"
103103
New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null
104104

105-
Invoke-WebRequest -Uri $ChecksumUrl -OutFile $ChecksumTmp
105+
try {
106+
Invoke-WebRequest -Uri $ChecksumUrl -OutFile $ChecksumTmp
107+
} catch {
108+
$Installed = ""
109+
if ((Test-Path $Target) -and (Test-Path $ChecksumInstalled)) {
110+
try {
111+
$Installed = ((Get-Content -Raw $ChecksumInstalled).Trim() -split "\s+")[0].ToLowerInvariant()
112+
} catch {
113+
$Installed = ""
114+
}
115+
}
116+
117+
$TargetSize = if (Test-Path $Target) { (Get-Item $Target).Length } else { 0 }
118+
if ($TargetSize -gt 0 -and $Installed -match "^[0-9a-f]{64}$") {
119+
Remove-Item -Force $ChecksumTmp -ErrorAction SilentlyContinue
120+
Write-Warning "Unable to check for monk-agent updates; using the previously checksummed installation at $Target."
121+
Write-Output $Target
122+
exit 0
123+
}
124+
125+
throw
126+
}
106127

107128
$Expected = ((Get-Content -Raw $ChecksumTmp).Trim() -split "\s+")[0].ToLowerInvariant()
108129

plugins/monk/scripts/ensure-monk-agent.sh

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,34 @@ if [ "$auto_update" = "0" ] || [ "$auto_update" = "false" ]; then
5151
fi
5252
fi
5353

54-
if command -v curl >/dev/null 2>&1; then
55-
curl -fL "$checksum_url" -o "$checksum_tmp"
56-
elif command -v wget >/dev/null 2>&1; then
57-
wget -O "$checksum_tmp" "$checksum_url"
58-
else
59-
echo "curl or wget is required to install monk-agent." >&2
60-
exit 2
54+
download_checksum() {
55+
if command -v curl >/dev/null 2>&1; then
56+
curl -fL "$checksum_url" -o "$checksum_tmp"
57+
elif command -v wget >/dev/null 2>&1; then
58+
wget -O "$checksum_tmp" "$checksum_url"
59+
else
60+
echo "curl or wget is required to check for monk-agent updates." >&2
61+
return 2
62+
fi
63+
}
64+
65+
if ! download_checksum; then
66+
if [ -x "$target" ] && [ -s "$target" ] && [ -f "$checksum_installed" ]; then
67+
installed="$(awk '{print $1}' "$checksum_installed")"
68+
case "$installed" in
69+
*[!0-9a-fA-F]*|'') ;;
70+
*)
71+
if [ "${#installed}" -eq 64 ]; then
72+
rm -f "$checksum_tmp"
73+
echo "Warning: unable to check for monk-agent updates; using the previously checksummed installation at $target." >&2
74+
printf '%s\n' "$target"
75+
exit 0
76+
fi
77+
;;
78+
esac
79+
fi
80+
echo "Unable to check for monk-agent updates and no verified local installation is available." >&2
81+
exit 1
6182
fi
6283

6384
expected="$(awk '{print $1}' "$checksum_tmp")"

scripts/ensure-monk-agent.ps1

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,28 @@ $ChecksumTmp = Join-Path $InstallDir ".monk-agent.tmp.sha256"
102102
$ExtractDir = Join-Path $InstallDir ".monk-agent.extract"
103103
New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null
104104

105-
Invoke-WebRequest -Uri $ChecksumUrl -OutFile $ChecksumTmp
105+
try {
106+
Invoke-WebRequest -Uri $ChecksumUrl -OutFile $ChecksumTmp
107+
} catch {
108+
$Installed = ""
109+
if ((Test-Path $Target) -and (Test-Path $ChecksumInstalled)) {
110+
try {
111+
$Installed = ((Get-Content -Raw $ChecksumInstalled).Trim() -split "\s+")[0].ToLowerInvariant()
112+
} catch {
113+
$Installed = ""
114+
}
115+
}
116+
117+
$TargetSize = if (Test-Path $Target) { (Get-Item $Target).Length } else { 0 }
118+
if ($TargetSize -gt 0 -and $Installed -match "^[0-9a-f]{64}$") {
119+
Remove-Item -Force $ChecksumTmp -ErrorAction SilentlyContinue
120+
Write-Warning "Unable to check for monk-agent updates; using the previously checksummed installation at $Target."
121+
Write-Output $Target
122+
exit 0
123+
}
124+
125+
throw
126+
}
106127

107128
$Expected = ((Get-Content -Raw $ChecksumTmp).Trim() -split "\s+")[0].ToLowerInvariant()
108129

scripts/ensure-monk-agent.sh

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,34 @@ if [ "$auto_update" = "0" ] || [ "$auto_update" = "false" ]; then
5151
fi
5252
fi
5353

54-
if command -v curl >/dev/null 2>&1; then
55-
curl -fL "$checksum_url" -o "$checksum_tmp"
56-
elif command -v wget >/dev/null 2>&1; then
57-
wget -O "$checksum_tmp" "$checksum_url"
58-
else
59-
echo "curl or wget is required to install monk-agent." >&2
60-
exit 2
54+
download_checksum() {
55+
if command -v curl >/dev/null 2>&1; then
56+
curl -fL "$checksum_url" -o "$checksum_tmp"
57+
elif command -v wget >/dev/null 2>&1; then
58+
wget -O "$checksum_tmp" "$checksum_url"
59+
else
60+
echo "curl or wget is required to check for monk-agent updates." >&2
61+
return 2
62+
fi
63+
}
64+
65+
if ! download_checksum; then
66+
if [ -x "$target" ] && [ -s "$target" ] && [ -f "$checksum_installed" ]; then
67+
installed="$(awk '{print $1}' "$checksum_installed")"
68+
case "$installed" in
69+
*[!0-9a-fA-F]*|'') ;;
70+
*)
71+
if [ "${#installed}" -eq 64 ]; then
72+
rm -f "$checksum_tmp"
73+
echo "Warning: unable to check for monk-agent updates; using the previously checksummed installation at $target." >&2
74+
printf '%s\n' "$target"
75+
exit 0
76+
fi
77+
;;
78+
esac
79+
fi
80+
echo "Unable to check for monk-agent updates and no verified local installation is available." >&2
81+
exit 1
6182
fi
6283

6384
expected="$(awk '{print $1}' "$checksum_tmp")"

0 commit comments

Comments
 (0)