From a256cdfedc6dc52f3da96d684a36316a37eb8ff7 Mon Sep 17 00:00:00 2001 From: mavrick Date: Sun, 22 Nov 2026 00:28:50 -0600 Subject: [PATCH 1/2] test(engine): the cancel tests run every read made ahead, from one registry The commands the desktop app reads ahead on a thread of its own were named in three hand-kept places (the reads::prepare match, the admission check in dispatch.rs and long_commands), and long_commands had fallen behind: Load All, Convert To Annotation, Reload Data, Run Model, the tile archive reload and repair, the Error Inspector and Source File State were never run under Cancel. They are now listed once, in reads::IN_BACKGROUND, which prepare and admission both read; long_commands fails unless it runs every one there (and every table edit) or names why it doesn't in its exemptions. All eight now run in both cancel tests. A model's tool looked at Cancel between steps without counting the look, so the first-check test saw a cancelled run that never looked; that check now counts, like the work's own checks. cmd::tiles::NETWORK, a list of network commands nothing but three tests read, is removed: each command's declared effects (Effect::Network) are what the policy uses, and those tests now check them. --- AGENTS.md | 4 +- crates/engine/src/cmd/gp.rs | 4 +- crates/engine/src/cmd/reads.rs | 87 ++++++++++++++++++------- crates/engine/src/cmd/tiles.rs | 59 ----------------- crates/engine/src/policy/dispatch.rs | 25 +------ crates/engine/src/tests.rs | 12 +++- crates/engine/src/tests/cancellation.rs | 84 ++++++++++++++++++++---- 7 files changed, 150 insertions(+), 125 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 4be35105d2..2dce159a12 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -43,8 +43,8 @@ is out of scope. - A new background raster command or export, or a tool whose work grows with its input, goes in the lists in `long_commands` (`crates/engine/src/tests/cancellation.rs`), which both cancel tests run; the raster and export lists must match the background registries. A read-ahead command - (`reads::prepare`, such as `service.layers`, `edit.previewShapeConversion` or `data.similar`) - has no registry: add its call to `long_commands` by hand. + goes in `reads::IN_BACKGROUND` (a table edit in `edit::TABLE_EDITS`), and `long_commands` + fails until it runs every one there or names why not in its exemptions. `long_commands_stop_when_cancelled_while_they_run` fails one that never looks at Cancel; `cancelling_at_each_check_leaves_nothing_behind` cancels at every check in turn until the command finishes before reaching it, on small fixtures, failing if one needs 256 or more checks. It diff --git a/crates/engine/src/cmd/gp.rs b/crates/engine/src/cmd/gp.rs index e33a50e6c1..ecbb910ad9 100644 --- a/crates/engine/src/cmd/gp.rs +++ b/crates/engine/src/cmd/gp.rs @@ -2892,7 +2892,9 @@ pub(crate) fn execute( #[cfg(not(target_arch = "wasm32"))] let control = current.as_ref().unwrap_or(control); let t0 = now_ms(); - if control.is_cancelled() { + // A look at Cancel as the work's own are (counted for a test's control): a model's or script's + // tool on the copy stops here when cancelled between steps. + if rustgis_data::progress::Probe::cancelled(control.as_ref()) { let e = format!("{} was cancelled before it started", spec.name); return apply_with(s, run_of(t0), kept(), Err(e), 0, opts); } diff --git a/crates/engine/src/cmd/reads.rs b/crates/engine/src/cmd/reads.rs index 098dc3c894..e73822cf2b 100644 --- a/crates/engine/src/cmd/reads.rs +++ b/crates/engine/src/cmd/reads.rs @@ -212,50 +212,89 @@ pub fn read_ahead(s: &mut Session, command: &str, p: &Value) -> Result Option<&'static str> { + IN_BACKGROUND + .iter() + .find(|(c, _)| *c == command) + .map(|(_, name)| *name) + .or_else(|| super::edit::table_edit_in_background(command).map(|_| "Edit Table")) +} + +/// Why `command` can't be read ahead. +pub(crate) fn not_in_background(command: &str) -> String { + format!("{command} doesn't prepare background work") +} + /// Picks work only for an already admitted command, retaining its exact streamed-source opening. pub(crate) fn prepare(s: &mut Session, op: Authorized, owner: Continuation) -> Result { let CommandOp::Registered { spec, params } = op.op() else { return Err("not a registered read command".into()) }; - let (name, work, source) = match spec.id { + let name = in_background(spec.id).ok_or_else(|| not_in_background(spec.id))?; + let (work, source) = match spec.id { "service.layers" => { #[cfg(not(target_arch = "wasm32"))] let work = super::service::listing_ahead(s, params)?; #[cfg(target_arch = "wasm32")] let work = None; - ("List Service Layers", work, None) + (work, None) } "service.add" => { #[cfg(not(target_arch = "wasm32"))] let work = super::service::adding_ahead(s, params)?; #[cfg(target_arch = "wasm32")] let work = None; - ("Add Service Layer", work, None) + (work, None) } - "layer.addData" => ("Add Data", super::layer::add_data_ahead(params), None), + "layer.addData" => (super::layer::add_data_ahead(params), None), "layer.loadAll" => { let layer = s.map().layer(s.layer_id(params)?).ok_or("no such layer")?; - ("Load All Features", super::layer::load_all_ahead(s, params), layer.source.clone()) + (super::layer::load_all_ahead(s, params), layer.source.clone()) } "labels.convert" => { let layer = s.map().layer(s.layer_id(params)?).ok_or("no such layer")?; // Nothing to convert: the command says so at once, with no read. - let work = super::labels::has_label_text(layer, s.map().scale()) - .then(|| super::whole::ahead(s, params, "Convert To Annotation")) - .flatten(); - ("Convert To Annotation", work, layer.source.clone()) + let work = super::labels::has_label_text(layer, s.map().scale()).then(|| super::whole::ahead(s, params, name)).flatten(); + (work, layer.source.clone()) } "layer.repairSource" => { #[cfg(not(target_arch = "wasm32"))] let work = super::repair::repair_ahead(s, params); #[cfg(target_arch = "wasm32")] let work = None; - ("Repair Data Source", work, None) + (work, None) } "layer.reloadData" => { #[cfg(not(target_arch = "wasm32"))] let work = super::repair::reload_ahead(s, params); #[cfg(target_arch = "wasm32")] let work = None; - ("Reload Data", work, None) + (work, None) } "model.run" => { // A copied session has native authority. Scoped callers keep their admitted @@ -264,32 +303,32 @@ pub(crate) fn prepare(s: &mut Session, op: Authorized, owner: Continu let work = owner.native_tool_owner().then(|| super::workflows::ahead_on_copy(s, "model.run", params)); #[cfg(target_arch = "wasm32")] let work = None; - ("Run Model", work, None) + (work, None) } "script.run" => { #[cfg(not(target_arch = "wasm32"))] let work = super::workflows::script_ahead(s, params, owner.native_tool_owner())?; #[cfg(target_arch = "wasm32")] let work = None; - ("Run Script", work, None) + (work, None) } "map.reloadTiles" | "map.repairTiles" => { #[cfg(not(target_arch = "wasm32"))] let work = Some(super::repair::archive_ahead(s, spec.id, params)); #[cfg(target_arch = "wasm32")] let work = None; - let name = if spec.id == "map.repairTiles" { "Repair Data Source" } else { "Reload Data" }; - (name, work, None) + (work, None) } - id if super::edit::table_edit_in_background(id).is_some() => ("Edit Table", super::edit::table_ahead(s, spec.id, params)?, None), - "topology.validate" => ("Error Inspector", super::design::topology_ahead(s, params), None), - "source.syncState" => ("Source File State", super::publish::sync_ahead(s, params), None), - "raster.imageGrid" => ("Read Original Image Grid", crate::image_grid::ahead(s, params), None), - "edit.previewShapeConversion" => ("Preview Shape Conversion", crate::shape_conversion::ahead(s, params), None), - "table.statistics" => ("Column Statistics", super::table_stats::stats_ahead(s, params), None), - "data.similar" => ("Find Similar", super::similar::ahead(s, params), None), - "layer.sizeBy" => ("Size by Field", super::layer::size_by_ahead(s, params), None), - _ => return Err("only Add Data, Load All, Repair/Reload Data, Convert To Annotation, models, scripts, tile archives, service listings, topology, Source File State, Read Original Image Grid, Preview Shape Conversion, Column Statistics, Similar and Size by Field prepare background work".into()), + id if super::edit::table_edit_in_background(id).is_some() => (super::edit::table_ahead(s, spec.id, params)?, None), + "topology.validate" => (super::design::topology_ahead(s, params), None), + "source.syncState" => (super::publish::sync_ahead(s, params), None), + "raster.imageGrid" => (crate::image_grid::ahead(s, params), None), + "edit.previewShapeConversion" => (crate::shape_conversion::ahead(s, params), None), + "table.statistics" => (super::table_stats::stats_ahead(s, params), None), + "data.similar" => (super::similar::ahead(s, params), None), + "layer.sizeBy" => (super::layer::size_by_ahead(s, params), None), + // Listed in IN_BACKGROUND without a read here. + id => return Err(not_in_background(id)), }; let name = work.as_ref().map_or(name, |work| work.name); let table = super::edit::table_edit_in_background(spec.id) diff --git a/crates/engine/src/cmd/tiles.rs b/crates/engine/src/cmd/tiles.rs index 52c9296dd9..1689e8ad16 100644 --- a/crates/engine/src/cmd/tiles.rs +++ b/crates/engine/src/cmd/tiles.rs @@ -10,65 +10,6 @@ use serde_json::{Value, json}; use super::{b, f, ps}; use crate::{CmdResult, CommandSpec as C, Session}; -/// Commands that make the map fetch from an address they're given (a plugin needs the -/// `network` permission to run them). -pub const NETWORK: &[&str] = &[ - "map.route", - "map.addTiles", - "map.body", - "map.terrain", - "layer.addUrl", - "service.layers", - "service.add", - "identify.featureInfo", - "service.import", - "service.refresh", - "service.groupPlan", - "service.coverage", - "catalog.search", - "stac.collections", - "stac.search", - "stac.addAsset", - "stac.addBands", - "stac.addIndex", - "stac.addCube", - // From the catalog entry's address (a Zarr entry also as `layer.addZarr`: plugins.rs). - "cube.open", - "map.findPlace", - "layer.geocode", - "osm.download", - "boundaries.add", - "boundaries.countries", - "s3.list", - "overture.add", - "sourcecoop.products", - "sourcecoop.list", - "portal.search", - "portal.add", - "nationalMap.add", - "fieldsOfTheWorld.add", - "portal.files", - "embeddings.search", - "embeddings.add", - "embeddings.addCube", - "embeddings.similarity", - "embeddings.change", - "earthdata.collections", - "earthdata.granules", - "nldi.flowline", - "nldi.comid", - "nldi.basin", - "nldi.sources", - "nldi.navigate", - // A sign-in reaches the portal, and a sign-out revokes its token there; a token is sent to - // the server it is given for. - "arcgis.signIn", - "arcgis.signOut", - "arcgis.token", - // A sign-in reaches Copernicus Data Space's sign-in host. - "copernicus.login", -]; - /// Registers commands for tile-layer sources, drawing properties, coverage and celestial bodies. pub fn commands() -> Vec { vec![ diff --git a/crates/engine/src/policy/dispatch.rs b/crates/engine/src/policy/dispatch.rs index eb21357ca8..7e3e16a682 100644 --- a/crates/engine/src/policy/dispatch.rs +++ b/crates/engine/src/policy/dispatch.rs @@ -154,29 +154,8 @@ impl Session { } /// Private pre-handler capture shared by native reads and the exact scoped archive entry. fn capture_read(&mut self, command: &str, params: &Value) -> Result { - if !matches!( - command, - "layer.addData" - | "layer.loadAll" - | "layer.reloadData" - | "layer.repairSource" - | "labels.convert" - | "model.run" - | "script.run" - | "map.reloadTiles" - | "map.repairTiles" - | "topology.validate" - | "service.layers" - | "service.add" - | "source.syncState" - | "table.statistics" - | "data.similar" - | "raster.imageGrid" - | "edit.previewShapeConversion" - | "layer.sizeBy" - ) && crate::cmd::edit::table_edit_in_background(command).is_none() - { - return Err("only Add Data, Load All, Repair/Reload Data, Convert To Annotation, models, scripts, tile archives, service reads, topology, Source File State, Read Original Image Grid, Preview Shape Conversion, Column Statistics, Similar and Size by Field prepare background work".into()); + if crate::cmd::reads::in_background(command).is_none() { + return Err(crate::cmd::reads::not_in_background(command)); } let mut params = params.as_object().cloned().ok_or("read parameters must be an object")?; // Scoped previews retain the raw invocation that was approved. Their admitted owner diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index c68147e2bc..d453ebb67d 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -28951,7 +28951,10 @@ fn a_stac_data_cube_on_the_time_slider() { ); assert_eq!(r["duplicates"], 1, "the second item of T2 on 2024-01-01 is left out and counted"); assert!(!s.notices.iter().any(|n| n.text.contains("failed retrievals")), "no codes, no notice of them"); - assert!(crate::cmd::tiles::NETWORK.contains(&"stac.addCube"), "a network command: a plugin needs the network permission to run it"); + assert!( + s.registry.get("stac.addCube").is_some_and(|c| c.effects.contains(crate::policy::Effect::Network)), + "a network command: a plugin needs the network permission to run it" + ); // An end given as a year or a month takes all of it: "end": "2024-01" reaches 31 January. // Read as 1 January, it would be before this start and refused. let mut by_month = Session::new(Project::default()); @@ -29376,7 +29379,10 @@ fn a_catalog_entry_opens_as_its_command_would() { { assert!(s.run("cube.catalog", &bad).is_err(), "{bad}"); } - assert!(crate::cmd::tiles::NETWORK.contains(&"cube.open"), "a plugin needs the network permission to open a cube"); + assert!( + s.registry.get("cube.open").is_some_and(|c| c.effects.contains(crate::policy::Effect::Network)), + "a plugin needs the network permission to open a cube" + ); // A Zarr entry reaches as layer.addZarr does (a plugin needs files and network); the catalog // itself is built in. use crate::cmd::plugins::{Reach, reaches}; @@ -38340,7 +38346,7 @@ fn ogc_group_supplied_responses_never_fetch_and_need_every_child() { assert_eq!(s.map().layers.len(), 2); assert_eq!(s.map().service_groups[0].children.len(), 2); for id in ["service.import", "service.refresh", "service.groupPlan"] { - assert!(crate::cmd::tiles::NETWORK.contains(&id)); + assert!(s.registry.get(id).is_some_and(|c| c.effects.contains(crate::policy::Effect::Network)), "{id}"); } } diff --git a/crates/engine/src/tests/cancellation.rs b/crates/engine/src/tests/cancellation.rs index 8f804c39b1..1193f399bf 100644 --- a/crates/engine/src/tests/cancellation.rs +++ b/crates/engine/src/tests/cancellation.rs @@ -15,6 +15,13 @@ pub(super) fn long_commands(boundaries: bool) { let _ = std::fs::remove_dir_all(&dir.0); std::fs::create_dir_all(&dir.0).unwrap(); let out = |f: &str| dir.0.join(f).display().to_string(); + // The reads made ahead that run here, checked at the end against every one there is + // (`reads::IN_BACKGROUND` and the table edits). + let covered = std::cell::RefCell::new(std::collections::BTreeSet::new()); + let read = |fixture: &Session, command: &'static str, p: &Value| { + covered.borrow_mut().insert(command); + exercise(fixture, command, p, Kind::Read, &dir.0, boundaries); + }; let mut s = world(); if boundaries { // A few sample rows and simple shapes exercise the same commands without a world-sized @@ -164,15 +171,17 @@ pub(super) fn long_commands(boundaries: bool) { // The Add Service dialog replays supplied metadata off the desktop frame too. let params = json!({"url":"https://maps.example.org/dataset","type":"ogcapi","text":"{\"collections\":[]}"}); for command in ["service.layers", "service.add"] { + covered.borrow_mut().insert(command); // Adding a service needs a real collection and remote features to succeed. An empty // listing is useful only for the original first-check cancellation test. if !boundaries || command == "service.layers" { - exercise(&s, command, ¶ms, Kind::Read, &dir.0, boundaries); + read(&s, command, ¶ms); } } // Shape fitting uses the same cancellable read queue, without modifying its source. Its // fixture is an editing session of its own, which the boundary sweep's sessions don't carry, // so it keeps first-check coverage. + covered.borrow_mut().insert("edit.previewShapeConversion"); if !boundaries { let mut shapes = Session::new(Project::default()); let id = shapes.map_mut().add_dataset(rustgis_data::Dataset::new("Conversion", rustgis_data::GeometryType::Polygon, vec![])); @@ -190,30 +199,30 @@ pub(super) fn long_commands(boundaries: bool) { // records indexed, the GeoJSON file's features found, Cancel looked at as they go (#2446). for file in ["in-place.shp", "in-place.geojson"] { s.run("share.exportLayer", &json!({"layer": "Cities", "path": out(file)})).unwrap(); - exercise(&s, "layer.addData", &json!({"path": out(file), "stream": true}), Kind::Read, &dir.0, boundaries); + read(&s, "layer.addData", &json!({"path": out(file), "stream": true})); } // Past the first few thousand features, the GeoJSON scan looks at Cancel again. let many: Vec = (0..4097) .map(|i| json!({"type": "Feature", "properties": {}, "geometry": {"type": "Point", "coordinates": [10.0 + f64::from(i) * 1e-4, 45.0]}})) .collect(); std::fs::write(out("many.geojson"), json!({"type": "FeatureCollection", "features": many}).to_string()).unwrap(); - exercise(&s, "layer.addData", &json!({"path": out("many.geojson"), "stream": true}), Kind::Read, &dir.0, boundaries); + read(&s, "layer.addData", &json!({"path": out("many.geojson"), "stream": true})); // Original TIFF headers share the read queue and both cancellation sweeps. - exercise(&s, "raster.imageGrid", &json!({"layer": dem}), Kind::Read, &dir.0, boundaries); + read(&s, "raster.imageGrid", &json!({"layer": dem})); // A PDF's page is read on the same queue: the file, then its drawing, Cancel looked at between // (#2336). s.run("layout.new", &json!({"page": "a4", "template": "map"})).unwrap(); s.run("layout.export", &json!({"path": out("page.pdf"), "dpi": 36, "allPages": false})).unwrap(); - exercise(&s, "layer.addData", &json!({"path": out("page.pdf")}), Kind::Read, &dir.0, boundaries); - exercise(&s, "table.statistics", &json!({"layer": "Cities", "field": "pop_max"}), Kind::Read, &dir.0, boundaries); - exercise(&s, "data.similar", &json!({"layer": "Cities", "row": 0, "fields": ["pop_max"], "count": 2}), Kind::Read, &dir.0, boundaries); + read(&s, "layer.addData", &json!({"path": out("page.pdf")})); + read(&s, "table.statistics", &json!({"layer": "Cities", "field": "pop_max"})); + read(&s, "data.similar", &json!({"layer": "Cities", "row": 0, "fields": ["pop_max"], "count": 2})); // The topology worker evaluates the primary query before its geometric check. { let id = s.map().layer_by_name("Cities").unwrap().id; let query = s.map_mut().layer_mut(id).unwrap().definition_query.replace("pop_max >= 0".into()); let rules = s.map().editing.topology.clone(); s.run("topology.rules", &json!({"add":{"rule":"mustNotSelfIntersect","layer":"Cities"}})).unwrap(); - exercise(&s, "topology.validate", &json!({}), Kind::Read, &dir.0, boundaries); + read(&s, "topology.validate", &json!({})); s.map_mut().layer_mut(id).unwrap().definition_query = query; s.map_mut().editing.topology = rules; } @@ -252,7 +261,7 @@ pub(super) fn long_commands(boundaries: bool) { } // Automatic size bounds scan the numeric field on that queue too. s.run("layer.symbology", &json!({"layer": "Cities", "type": "unique", "field": "name"})).unwrap(); - exercise(&s, "layer.sizeBy", &json!({"layer": "Cities", "field": "pop_max"}), Kind::Read, &dir.0, boundaries); + read(&s, "layer.sizeBy", &json!({"layer": "Cities", "field": "pop_max"})); s.run("layer.addDataText", &json!({"fileName": "calc.csv", "text": "n,day\n1,01/02/2024\n2,02/03/2024\n"})).unwrap(); s.run("edit.enable", &json!({"on": true})).unwrap(); @@ -266,9 +275,9 @@ pub(super) fn long_commands(boundaries: bool) { ]; assert_eq!(listed(&edits), crate::cmd::edit::TABLE_EDITS.iter().map(|(id, ..)| *id).collect(), "add a new table worker here"); for (command, p) in edits { - exercise(&s, command, &p, Kind::Read, &dir.0, boundaries); + read(&s, command, &p); let script = json!({"script": format!("{command} {p}")}); - exercise(&s, "script.run", &script, Kind::Read, &dir.0, boundaries); + read(&s, "script.run", &script); } s.run( "layer.addDataText", @@ -278,7 +287,7 @@ pub(super) fn long_commands(boundaries: bool) { ) .unwrap(); let params = json!({"layer":"dated", "field":"day", "type":"date", "format":"%m/%d/%Y"}); - exercise(&s, "edit.convertField", ¶ms, Kind::Read, &dir.0, boundaries); + read(&s, "edit.convertField", ¶ms); // Replacement validation can now scan temporal fields as well as probing geometry. let mut dates = rustgis_data::Dataset::new( @@ -293,7 +302,7 @@ pub(super) fn long_commands(boundaries: bool) { let replacement = out("cancel-repair-source.fgb"); std::fs::write(&replacement, rustgis_data::source::fgb::write(&dates).unwrap()).unwrap(); let id = s.run("layer.addData", &json!({"path": replacement, "stream": true})).unwrap()["layer"].as_u64().unwrap(); - exercise(&s, "layer.repairSource", &json!({"layer": id, "path": replacement}), Kind::Read, &dir.0, boundaries); + read(&s, "layer.repairSource", &json!({"layer": id, "path": replacement})); std::fs::remove_file(replacement).unwrap(); // The tools whose work grows past a second or two on real data: buffers, overlays, joins, @@ -327,6 +336,55 @@ pub(super) fn long_commands(boundaries: bool) { for (tool, params) in &tools { exercise(&s, tool, params, Kind::Tool, &dir.0, boundaries); } + + // A layer read in place, loaded whole, converted to annotation and reloaded; one read whole + // from its file, compared with it. + s.run("layer.addData", &json!({"path": out("towns.shp"), "name": "towns in place", "stream": true})).unwrap(); + read(&s, "layer.loadAll", &json!({"layer": "towns in place"})); + read(&s, "labels.convert", &json!({"layer": "towns in place"})); + read(&s, "layer.reloadData", &json!({"layer": "towns in place"})); + read(&s, "source.syncState", &json!({"layer": "towns"})); + let graph = json!({"nodes": [ + {"id": "squares", "kind": "input", "layer": "Squares"}, + {"id": "ring", "kind": "tool", "tool": "buffer", "params": {"distance": 100}}, + {"id": "output", "kind": "output", "name": "Rings"} + ], "edges": [ + {"from": "squares", "fromPort": "out", "to": "ring", "toPort": "input"}, + {"from": "ring", "fromPort": "out", "to": "output", "toPort": "in"} + ]}); + read(&s, "model.run", &json!({"graph": graph})); + // A tile archive reloaded from its file, and repaired to a copy of it. + { + use crate::render::rustgis_tiles::pmtiles; + let archive = pmtiles::NewArchive { + tile_type: pmtiles::TileType::Png, + gzipped_tiles: false, + bounds: [-180.0, -85.0, 180.0, 85.0], + metadata: json!({}), + }; + let mut tile = tiny_skia::Pixmap::new(1, 1).unwrap(); + tile.fill(tiny_skia::Color::from_rgba8(10, 20, 30, 255)); + let bytes = pmtiles::write(vec![(0, 0, 0, tile.encode_png().unwrap())], &archive).unwrap(); + std::fs::write(out("archive.pmtiles"), &bytes).unwrap(); + std::fs::write(out("moved.pmtiles"), &bytes).unwrap(); + } + s.run("map.addTiles", &json!({"url": out("archive.pmtiles"), "overlay": true})).unwrap(); + read(&s, "map.reloadTiles", &json!({"index": 0})); + read(&s, "map.repairTiles", &json!({"index": 0, "path": out("moved.pmtiles")})); + + // Reads made ahead that aren't run here, and why. + let exempt: [(&str, &str); 0] = []; + let covered = covered.into_inner(); + for (command, why) in exempt { + assert!(!covered.contains(command), "{command} is run here: take it out of the exemptions ({why})"); + } + let registered = crate::cmd::reads::IN_BACKGROUND + .iter() + .map(|(c, _)| *c) + .chain(crate::cmd::edit::TABLE_EDITS.iter().map(|(c, ..)| *c)) + .collect::>(); + let known = covered.iter().copied().chain(exempt.iter().map(|(c, _)| *c)).collect::>(); + assert_eq!(known, registered, "a command read ahead (reads::IN_BACKGROUND) is run here, or exempted with the reason it isn't"); } #[derive(Clone, Copy)] From 89008c73b8dad112f78813a867aa6f6a191f865e Mon Sep 17 00:00:00 2001 From: mavrick Date: Sun, 22 Nov 2026 01:34:07 -0600 Subject: [PATCH 2/2] test(engine): a read counts as run in the cancel tests only where it runs The boundary sweep marked service.add and edit.previewShapeConversion as run though it leaves them out, so the registry check passed there without them. The check now belongs to the first-check pass, which reaches every read. --- crates/engine/src/tests/cancellation.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/tests/cancellation.rs b/crates/engine/src/tests/cancellation.rs index 1193f399bf..1b677a19fa 100644 --- a/crates/engine/src/tests/cancellation.rs +++ b/crates/engine/src/tests/cancellation.rs @@ -171,7 +171,6 @@ pub(super) fn long_commands(boundaries: bool) { // The Add Service dialog replays supplied metadata off the desktop frame too. let params = json!({"url":"https://maps.example.org/dataset","type":"ogcapi","text":"{\"collections\":[]}"}); for command in ["service.layers", "service.add"] { - covered.borrow_mut().insert(command); // Adding a service needs a real collection and remote features to succeed. An empty // listing is useful only for the original first-check cancellation test. if !boundaries || command == "service.layers" { @@ -181,8 +180,8 @@ pub(super) fn long_commands(boundaries: bool) { // Shape fitting uses the same cancellable read queue, without modifying its source. Its // fixture is an editing session of its own, which the boundary sweep's sessions don't carry, // so it keeps first-check coverage. - covered.borrow_mut().insert("edit.previewShapeConversion"); if !boundaries { + covered.borrow_mut().insert("edit.previewShapeConversion"); let mut shapes = Session::new(Project::default()); let id = shapes.map_mut().add_dataset(rustgis_data::Dataset::new("Conversion", rustgis_data::GeometryType::Polygon, vec![])); shapes.active_layer = Some(id); @@ -384,7 +383,11 @@ pub(super) fn long_commands(boundaries: bool) { .chain(crate::cmd::edit::TABLE_EDITS.iter().map(|(c, ..)| *c)) .collect::>(); let known = covered.iter().copied().chain(exempt.iter().map(|(c, _)| *c)).collect::>(); - assert_eq!(known, registered, "a command read ahead (reads::IN_BACKGROUND) is run here, or exempted with the reason it isn't"); + // The boundary sweep leaves out the reads that keep first-check coverage only, so the first-check + // run is the one that must reach every read. + if !boundaries { + assert_eq!(known, registered, "a command read ahead (reads::IN_BACKGROUND) is run here, or exempted with the reason it isn't"); + } } #[derive(Clone, Copy)]