From 43f9dad522df307eb3b367ef8e3d8a0022c473a2 Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Wed, 25 Nov 2026 23:54:51 -0300 Subject: [PATCH 1/2] fix(plugins): a GRIB byte range a plugin command asked for lands for it (#2428) The desktop app downloads a range under its marked address (`ranged_address`), so `asked_by` never matched it: the command waited out its 10 minutes before running again. A range asked for now matches the address with that range marked, and only that one. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/plugin_fetch.rs | 30 +++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/plugin_fetch.rs b/crates/engine/src/cmd/plugin_fetch.rs index 261aec087f..e00cdccac8 100644 --- a/crates/engine/src/cmd/plugin_fetch.rs +++ b/crates/engine/src/cmd/plugin_fetch.rs @@ -547,9 +547,15 @@ const MAX_EXPIRED: usize = 1024; /// asked for: the same address (spaces around it set aside), and every other key it gave that /// the front end passes on, with the same value. What the front end leaves out or sets itself, /// and what the app adds of its own (`id`), don't count. Another import of the same address -/// (other columns, another name) isn't it. +/// (other columns, another name) isn't it. A byte range of a GRIB file (`"bytes"`) comes back as +/// the address the front end downloads, with the range marked in it +/// ([`crate::cmd::layer::ranged_address`]). fn asked_by(asked: &Value, params: &Value) -> bool { let Some(o) = asked.as_object() else { return false }; + let range = match asked.get("bytes").and_then(Value::as_array).map(Vec::as_slice) { + Some([a, b]) => a.as_u64().zip(b.as_u64()), + _ => None, + }; // What the front end passes on to a download's own `layer.addUrl` (the desktop app's // `ui.addUrl`): only these come back, and must come back the same. Any other key (`whole`, // `cog`, `dates`, a `name` that isn't text…) it leaves out. `zoom` it passes on, but may change @@ -562,7 +568,10 @@ fn asked_by(asked: &Value, params: &Value) -> bool { _ => false, }; let given = o.iter().all(|(k, v)| match k.as_str() { - "url" => v.as_str().map(str::trim) == params["url"].as_str().map(str::trim), + "url" => { + let (u, given) = (v.as_str().map(str::trim), params["url"].as_str().map(str::trim)); + u == given || u.zip(range).is_some_and(|(u, r)| given == Some(crate::cmd::layer::ranged_address(u, r).as_str())) + } _ if passed_on(k, v) => params.get(k) == Some(v), _ => true, }); @@ -1331,6 +1340,23 @@ mod tests { assert!(!asked_by(&json!({"url": u}), &json!({"url": u, "connection": "c1"}))); } + /// A byte range of a GRIB file lands under the address the front end downloads, the range + /// marked in it: that is what was asked, and another range of the same file isn't (#2428). + #[test] + fn a_byte_range_lands_under_its_marked_address() { + let u = "https://x.org/model.grb"; + let asked = json!({"url": u, "bytes": [100, 199], "format": "grib", "name": "rain", "anonymous": true}); + let ranged = crate::cmd::layer::ranged_address(u, (100, 199)); + assert!(asked_by(&asked, &json!({"url": ranged, "name": "rain", "anonymous": true, "id": 3}))); + let other = crate::cmd::layer::ranged_address(u, (200, 299)); + assert!(!asked_by(&asked, &json!({"url": other, "name": "rain", "anonymous": true, "id": 3}))); + // Without a range asked, the marked address is another download. + assert!(!asked_by( + &json!({"url": u, "name": "rain", "anonymous": true}), + &json!({"url": ranged, "name": "rain", "anonymous": true}) + )); + } + fn load_test_plugin(id: &str) -> String { let package = rustgis_plugins::Package::from_zip(&rustgis_plugins::testing::package(id, &["edit", "network"])).unwrap(); rustgis_plugins::load(package, "test").unwrap(); From b5c71f0b0acadbff5ae34caac44cc356fa0edb76 Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Thu, 26 Nov 2026 22:18:54 -0300 Subject: [PATCH 2/2] fix(plugins): a ranged address asked with spaces around it is the one the app marks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The desktop app marks a GRIB range on the address as the plugin gave it, spaces and all, so a request for "…/model.grb " landed under "…/model.grb #rustgis-range=…" and wasn't matched: its command still waited the ten minutes. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/plugin_fetch.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/plugin_fetch.rs b/crates/engine/src/cmd/plugin_fetch.rs index e00cdccac8..ee6158fcdb 100644 --- a/crates/engine/src/cmd/plugin_fetch.rs +++ b/crates/engine/src/cmd/plugin_fetch.rs @@ -569,8 +569,12 @@ fn asked_by(asked: &Value, params: &Value) -> bool { }; let given = o.iter().all(|(k, v)| match k.as_str() { "url" => { - let (u, given) = (v.as_str().map(str::trim), params["url"].as_str().map(str::trim)); - u == given || u.zip(range).is_some_and(|(u, r)| given == Some(crate::cmd::layer::ranged_address(u, r).as_str())) + let (u, given) = (v.as_str(), params["url"].as_str().map(str::trim)); + // The desktop app marks a range on the address as asked, spaces and all; it may come + // marked on it trimmed too. + u.map(str::trim) == given + || u.zip(range) + .is_some_and(|(u, r)| [u, u.trim()].iter().any(|u| given == Some(crate::cmd::layer::ranged_address(u, r).trim()))) } _ if passed_on(k, v) => params.get(k) == Some(v), _ => true, @@ -1350,6 +1354,11 @@ mod tests { assert!(asked_by(&asked, &json!({"url": ranged, "name": "rain", "anonymous": true, "id": 3}))); let other = crate::cmd::layer::ranged_address(u, (200, 299)); assert!(!asked_by(&asked, &json!({"url": other, "name": "rain", "anonymous": true, "id": 3}))); + // An address asked with spaces around it: the app marks the range on it as given. + let spaced = json!({"url": format!("{u} "), "bytes": [100, 199], "name": "rain", "anonymous": true}); + let marked = crate::cmd::layer::ranged_address(&format!("{u} "), (100, 199)); + assert!(asked_by(&spaced, &json!({"url": marked, "name": "rain", "anonymous": true, "id": 3}))); + assert!(asked_by(&spaced, &json!({"url": ranged, "name": "rain", "anonymous": true, "id": 3}))); // Without a range asked, the marked address is another download. assert!(!asked_by( &json!({"url": u, "name": "rain", "anonymous": true}),