Skip to content

Commit 29f04fa

Browse files
mldangeloclaude
andauthored
fix(update): bypass GitHub raw CDN cache for self-update (#22)
## Summary - `crab update` was always reporting "Already up to date" after a new version was merged because `raw.githubusercontent.com` serves cached content (`max-age=300`) - Added cache-busting via `Cache-Control: no-cache` header and a timestamp query parameter to force fresh downloads - Added validation that the downloaded file actually contains a version string before replacing the installed binary ## Test plan - [ ] Run `crab update` immediately after merging a version bump — should detect the new version instead of reporting "Already up to date" - [ ] Run `crab update` when already on latest — should correctly report "Already up to date" - [ ] Simulate a corrupted download (e.g. empty file) — should error with "Downloaded file is invalid" instead of replacing the binary 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 09f4bf8 commit 29f04fa

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/crabcode

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9713,10 +9713,17 @@ main() {
97139713
local install_dir=$(dirname "$(realpath "$0")")
97149714
local tmp_file="/tmp/crabcode-update-$$"
97159715

9716-
if curl -fsSL "https://raw.githubusercontent.com/promptfoo/crabcode/main/src/crabcode" -o "$tmp_file" 2>/dev/null; then
9717-
local new_version=$(grep '^VERSION=' "$tmp_file" | cut -d'"' -f2)
9716+
# Cache-bust to bypass GitHub raw CDN cache (max-age=300)
9717+
if curl -fsSL -H 'Cache-Control: no-cache' "https://raw.githubusercontent.com/promptfoo/crabcode/main/src/crabcode?t=$(date +%s)" -o "$tmp_file" 2>/dev/null; then
9718+
local new_version=$(grep '^VERSION=' "$tmp_file" | head -1 | cut -d'"' -f2)
97189719
local current_version="$VERSION"
97199720

9721+
if [ -z "$new_version" ]; then
9722+
error "Downloaded file is invalid (no version found)"
9723+
rm -f "$tmp_file"
9724+
exit 1
9725+
fi
9726+
97209727
if [ "$new_version" = "$current_version" ]; then
97219728
echo -e "${GREEN}Already up to date (v$VERSION)${NC}"
97229729
else

0 commit comments

Comments
 (0)