Commit 320fd9d
authored
fix(upgrade): detect downgrades and skip delta attempt (#358)
## Problem
Two UX issues when running `sentry cli upgrade <older-version>`:
### 1. Wrong messaging for downgrades
```
$ sentry cli upgrade 0.14.0-dev.1772724107
Current version: 0.14.0-dev.1772732047
Upgrading to 0.14.0-dev.1772724107... ← wrong: this is a downgrade
Successfully upgraded to 0.14.0-dev.1772724107. ← wrong
```
### 2. Delta attempt wastes 22+ seconds on downgrades
bsdiff patches are one-directional (old→new only), so a downgrade can
never use deltas. But the code still:
1. Fetches a GHCR token (~100ms)
2. Fetches the target manifest (~100ms-30s due to GHCR cold-start
variance)
3. Builds the ENTIRE patch graph by fetching ALL `patch-*` tag manifests
(~1.5s-22s)
4. Only then discovers no forward path exists and falls back to full
download
From [Sentry
traces](https://sentry.sentry.io/explore/traces/trace/7f6f857d216cd614e2c73257b9eacdef):
a downgrade attempt spent **22.3 seconds** in `build-patch-graph` before
returning `result=unavailable`.
## Fix
### New helpers in `binary.ts`
- `compareVersions(a, b)` — wraps `Bun.semver.order()`, works for both
stable (`X.Y.Z`) and nightly (`X.Y.Z-dev.<unix-seconds>`) formats
- `isDowngrade(current, target)` — returns `true` when the target is
older
### Messaging (`upgrade.ts`)
Now says "Downgrading to" / "Successfully downgraded to" when the target
version is older.
### Delta skip (`delta-upgrade.ts`)
`canAttemptDelta()` returns `false` immediately for downgrades, avoiding
all GHCR calls entirely.
## After
```
$ sentry cli upgrade 0.14.0-dev.1772724107
Current version: 0.14.0-dev.1772732047
Downgrading to 0.14.0-dev.1772724107...
Downloading full binary
Successfully downgraded to 0.14.0-dev.1772724107.
```
## Testing
- `bun run typecheck` ✅
- `bun run lint` ✅
- `bun test test/lib/binary.test.ts` ✅ (40 pass — 12 new tests for
compareVersions/isDowngrade)
- `bun test test/lib/delta-upgrade.test.ts` ✅ (69 pass)1 parent bb04650 commit 320fd9d
File tree
4 files changed
+163
-41
lines changed- src
- commands/cli
- lib
- test/lib
4 files changed
+163
-41
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
21 | 25 | | |
22 | 26 | | |
23 | 27 | | |
| |||
209 | 213 | | |
210 | 214 | | |
211 | 215 | | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
212 | 268 | | |
213 | 269 | | |
214 | 270 | | |
| |||
382 | 438 | | |
383 | 439 | | |
384 | 440 | | |
385 | | - | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
386 | 445 | | |
387 | 446 | | |
388 | 447 | | |
| |||
393 | 452 | | |
394 | 453 | | |
395 | 454 | | |
396 | | - | |
397 | | - | |
398 | | - | |
399 | | - | |
400 | | - | |
401 | | - | |
402 | | - | |
403 | | - | |
404 | | - | |
405 | | - | |
406 | | - | |
407 | | - | |
408 | | - | |
409 | | - | |
410 | | - | |
411 | | - | |
412 | | - | |
413 | | - | |
414 | | - | |
415 | | - | |
416 | | - | |
417 | | - | |
418 | | - | |
419 | | - | |
420 | | - | |
421 | | - | |
422 | | - | |
423 | | - | |
424 | | - | |
425 | | - | |
426 | | - | |
427 | | - | |
428 | | - | |
429 | | - | |
430 | | - | |
431 | | - | |
432 | | - | |
433 | | - | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
434 | 462 | | |
435 | | - | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
436 | 466 | | |
437 | 467 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
70 | 92 | | |
71 | 93 | | |
72 | 94 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
108 | 109 | | |
109 | 110 | | |
110 | 111 | | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
111 | 117 | | |
112 | 118 | | |
113 | 119 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| 26 | + | |
25 | 27 | | |
26 | 28 | | |
27 | 29 | | |
| |||
459 | 461 | | |
460 | 462 | | |
461 | 463 | | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
0 commit comments