Repository navigation
fix(aqua): fetch the checksum manifest with get_text again - #11558
Conversation
📝 WalkthroughWalkthroughThe aqua backend now retrieves checksum files with ChangesChecksum text retrieval
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/backend/aqua.rs (2)
2177-2180: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winRemove the stale byte-only wording.
The neighboring comment still says that only bytes are read. This path now reads decoded text with
HTTP.get_text. Keep the transport-URL rationale, but remove the byte-specific statement.Proposed comment update
- // Only the bytes are read here (no filename derivation), so the transport - // URL is all that is needed. + // No filename derivation is needed here, so the transport URL is all that + // is needed.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/backend/aqua.rs` around lines 2177 - 2180, Update the comment above the checksum download to remove the stale byte-only wording, accurately describe that HTTP.get_text reads decoded text, and retain the rationale about transport URLs and HTML-body HTTPS retries.
2177-2187: 🗄️ Data Integrity & Integration | 🔵 Trivial | 🏗️ Heavy liftAdd regression coverage for the HTTP checksum path.
Test UTF-16 checksum responses with a BOM and a plain-HTTP response that returns HTML before the HTTPS retry returns checksum text. Assert the parsed
algorithm:digestresult. The PR verification notes state that no HTTP-path exercise was performed.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/backend/aqua.rs` around lines 2177 - 2187, Add regression tests for the HTTP checksum flow using the checksum-fetching function around HTTP.get_text: cover a UTF-16 response with a BOM and a plain-HTTP response containing HTML followed by a successful HTTPS checksum response, asserting both produce the parsed algorithm:digest result.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/backend/aqua.rs`:
- Around line 2177-2180: Update the comment above the checksum download to
remove the stale byte-only wording, accurately describe that HTTP.get_text reads
decoded text, and retain the rationale about transport URLs and HTML-body HTTPS
retries.
- Around line 2177-2187: Add regression tests for the HTTP checksum flow using
the checksum-fetching function around HTTP.get_text: cover a UTF-16 response
with a BOM and a plain-HTTP response containing HTML followed by a successful
HTTPS checksum response, asserting both produce the parsed algorithm:digest
result.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Central YAML (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro Plus
Run ID: 2ddb57a3-b048-4a20-b67f-520924b67a89
📒 Files selected for processing (2)
src/backend/aqua.rssrc/file.rs
jdx#11552 converted `fetch_checksum_from_file` from `get_text` to `get_bytes` + `file::decode_text`, on the reasoning that `get_text` "decodes with the response charset and silently replaces anything it cannot map — a UTF-16 checksum file would be recorded as mojibake instead of failing". That reasoning is wrong. reqwest's `text()` delegates to `text_with_charset("utf-8")` when the `charset` feature is enabled, which mise enables, and that calls `encoding_rs::Encoding::decode`: let (encoding, without_bom) = match Encoding::for_bom(bytes) { Some((encoding, bom_length)) => (encoding, &bytes[bom_length..]), None => (self, bytes), }; A BOM overrides the declared encoding and is stripped, so this path already handled UTF-16 correctly and the conversion fixed nothing. It also cost something. `get_text` goes through `TextRequest::send`, which detects a `<!DOCTYPE html>` body and re-sends over https when the URL was plain http; `get_bytes` has no such branch, so an http checksum URL answered with an HTML error page would be parsed as a checksum instead of retried. Registry checksum URLs are https, so the exposure was small, but it was behaviour given up for no gain. (Retries were never lost — both paths run through `send_with_https_fallback_with_retries` with `http_retries()`.) The two file-reading sites from jdx#11552 are unaffected and stay: `std::fs` really does reject non-UTF-8, which is the failure in jdx#5399's stack trace. `file::read_to_string_bom` now documents that asymmetry so the HTTP path does not get "fixed" again.
f5625f5 to
50d2a1d
Compare
Greptile SummaryRestores the BOM-aware text transport for Aqua checksum manifests.
Confidence Score: 5/5The PR appears safe to merge with no actionable defects identified. The restored text-fetch path retains BOM-aware decoding while recovering HTML detection and HTTP-to-HTTPS fallback, and the added regression test covers the intended UTF-16 response behavior. Important Files Changed
Reviews (1): Last reviewed commit: "fix(aqua): fetch the checksum manifest w..." | Re-trigger Greptile |
Corrects one third of my own #11552. The reasoning I gave for the HTTP-side change there was wrong, and the comment stating it is now in
main.The claim, and why it's false
#11552 converted
fetch_checksum_from_filefromget_texttoget_bytes+file::decode_text, with this comment:reqwest's
text()(reqwest-0.13.4/src/async_impl/response.rs:163) delegates totext_with_charset("utf-8")when thecharsetfeature is on — which mise enables inCargo.toml. Its own docs say it "decodes the response body with BOM sniffing" and that "the BOM is stripped from the returned String". The body isencoding.decode(&full), which isencoding_rs-0.8.35/src/lib.rs:3009:A BOM overrides the declared encoding and is stripped. The HTTP path already handled UTF-16 correctly, so that conversion fixed nothing.
What it cost
get_textgoes throughTextRequest::send(http.rs:845), which detects a<!DOCTYPE html>body and re-sends over https when the URL was plainhttp.get_bytes→get_async→send_with_https_fallbackhas no such branch. So anhttp://checksum URL answered with an HTML error page would decode cleanly and get parsed as a checksum, where it used to be retried over https.Registry checksum URLs are https, so the exposure is small — but it was behaviour given up for no gain.
To be precise about what was not lost: retries were fine either way.
send_with_https_fallback(http.rs:484) delegates tosend_with_https_fallback_with_retrieswithSettings::get().http_retries(), the same defaultTextRequestuses. I checked before writing this.What stays
The two file-reading sites from #11552 are correct and untouched:
aqua.rs:1785and:2515go throughstd::fs::read_to_string, which really does reject non-UTF-8 — that is the exact frame in #5399's stack trace, andfile::read_to_string_bomis the right fix for it.read_to_string_bomnow documents the asymmetry, so the HTTP path doesn't get "fixed" again:The same finding also applies to
static_helpers.rs,backend/http.rs,node.rsandpkgx.rs, which all read checksums viaget_text/get_text_cached. I had listed those in #11552 as adjacent work left for later; they need nothing, and this PR is the record of why.Verification
Read from reqwest's and encoding_rs's source, cited above — I have not exercised the HTTP path locally. No local
cargorun;rustfmt --edition 2024only. Thesrc/file.rsdecoder tests and #11552's aqua UTF-16 fixture test both cover file paths and are unaffected.Summary by CodeRabbit
Bug Fixes
Documentation