Repository navigation
feat(upgrade): TTY progress bars for delta-patch apply and full download - #1442
Conversation
Adds a reusable makeByteProgress() bar (TTY-only, cosmetic — never aborts the operation, done() guarded) and wires it into the self-upgrade flow: - Apply phase: determinate bar in applyChainAndReturn. Total is the final binary size (last patch's declared newSize), so the number shown is the real output the user gets — not the sum of intermediate hop writes. Progress is byte-driven across all hops via an onBytes callback threaded through transformPatch -> applyReaderToMemory/applyReaderToFile -> applyPatchChainInMemory -> applyPatchChain, so the bar advances smoothly through the whole chain. - Full-binary download: indeterminate byte counter in streamDecompressToFile (used by both nightly and stable). The decompressed size isn't knowable ahead (Content-Length only covers the compressed stream), so it shows a live byte count rather than a fake fraction. The tiny parallel patch downloads get no bar — they're KBs and fast. Adds packages/gateway/test/progress.test.ts (6 tests): determinate/ indeterminate rendering, non-TTY header-only, clamping, byte accumulation, and the never-throws contract (caught an unguarded done() — fixed).
| chain, | ||
| oldBinaryPath, | ||
| destPath, | ||
| progress.onProgress, | ||
| ); | ||
| return { | ||
| sha256, | ||
| patchBytes: chain.totalSize, | ||
| chainLength: chain.patches.length, | ||
| }; | ||
| } finally { |
There was a problem hiding this comment.
Bug: In a multi-patch delta upgrade, the progress bar's reported bytes accumulate across all patches, while the total is only the final patch's size, causing the counter to exceed its maximum.
Severity: MEDIUM
Suggested Fix
To align with the intent of showing progress toward the final file, only pass the onBytes progress callback to the final patch application step (applyReaderToFile). Do not pass it to the intermediate steps that write to memory (applyReaderToMemory). This will ensure the progress bar only tracks bytes written to the final destination file.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: packages/gateway/src/cli/lib/delta-upgrade.ts#L654-L665
Potential issue: The progress bar for delta upgrades is initialized with the size of the
final binary output from the last patch in a chain. However, the progress tracking
function, `onBytes`, is invoked for every byte written during each intermediate patch
application. This causes the displayed number of bytes written to be the sum of the
sizes of all intermediate outputs plus the final output. For any multi-patch upgrade,
the progress bar will show a written amount far exceeding the total (e.g., `9.3 GB / 310
MB`), which is confusing to the user and contradicts the feature's stated intent.
Also affects:
packages/gateway/src/cli/lib/bspatch.ts:737~753
Did we get this right? 👍 / 👎 to inform future reviews.
Codecov Results 📊❌ Patch coverage is 62.71%. Project has 6836 uncovered lines. Files with missing lines (3)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
- Coverage 74.97% 74.95% -0.02%
==========================================
Files 166 167 +1
Lines 27235 27289 +54
Branches 19282 19306 +24
==========================================
+ Hits 20418 20453 +35
- Misses 6817 6836 +19
- Partials 1963 1965 +2Generated by Codecov Action |
|
What
Adds live progress bars to
lore upgradeso the slow phases aren't a silent wait.Applying 3 patches [███████░░░░░░░░░] 152 MB / 310 MB. Total is the final binary size (the last patch's declarednewSize), i.e. the real output the user gets — not the sum of intermediate hop writes. Progress is byte-driven across the whole chain, so it advances smoothly rather than stalling per-hop.Downloading 87.0 MB. The decompressed size isn't knowable ahead (Content-Lengthonly covers the compressed stream), so it shows an honest live byte count, not a fake fraction.The tiny parallel patch downloads (KBs) intentionally get no bar.
How
packages/gateway/src/cli/lib/progress.ts:makeByteProgress(label, totalBytes)— reusable, modeled on the existingmakeSyncProgress. TTY-only; cosmetic (rendering must never abort the operation); clears its line ondone().onBytes) threaded throughtransformPatch→applyReaderToMemory/applyReaderToFile→applyPatchChainInMemory→applyPatchChain, reporting bytes-written per output chunk.applyChainAndReturn; download bar instreamDecompressToFile.Tests
packages/gateway/test/progress.test.ts(6 tests): determinate/indeterminate rendering, non-TTY header-only behavior, full-bar clamping, byte accumulation, and the never-throws contract — which caught an unguardeddone()(a throwing output stream could propagate); fixed.Verification
typecheckclean,lint0 errors,format:checkclean.