Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion crates/engine/src/cmd/gp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nits, grouped: the comment reads "A look at Cancel as the work's own are", which is hard to parse. "As the work's own checks are" would say it. The new not_in_background message (reads.rs:252) is also much less helpful than the old one, which listed the commands that do prepare background work. The behaviour change is fine: in production looked_at counts only for a test control, so the pre-start check behaves as before.

Category: quality

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left for the release quality pass: the comment's wording, and naming the commands in the refusal.

// 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);
}
Expand Down
87 changes: 63 additions & 24 deletions crates/engine/src/cmd/reads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,50 +212,89 @@ pub fn read_ahead(s: &mut Session, command: &str, p: &Value) -> Result<ReadAhead
s.start_read(command, p)
}

/// The commands whose read the desktop app makes on a thread of its own before they land
/// ([`read_ahead`]), each with what its read is called, besides the table edits
/// (`edit::TABLE_EDITS`). The cancel tests (`tests/cancellation.rs`) exercise every one, or name
/// why not.
pub(crate) const IN_BACKGROUND: &[(&str, &str)] = &[
("service.layers", "List Service Layers"),
("service.add", "Add Service Layer"),
("layer.addData", "Add Data"),
("layer.loadAll", "Load All Features"),
("labels.convert", "Convert To Annotation"),
("layer.repairSource", "Repair Data Source"),
("layer.reloadData", "Reload Data"),
("model.run", "Run Model"),
("script.run", "Run Script"),
("map.reloadTiles", "Reload Data"),
("map.repairTiles", "Repair Data Source"),
("topology.validate", "Error Inspector"),
("source.syncState", "Source File State"),
("raster.imageGrid", "Read Original Image Grid"),
("edit.previewShapeConversion", "Preview Shape Conversion"),
("table.statistics", "Column Statistics"),
("data.similar", "Find Similar"),
("layer.sizeBy", "Size by Field"),
];

/// What `command`'s read is called, when it is one the app makes before the command lands
/// ([`IN_BACKGROUND`] or a table edit).
pub(crate) fn in_background(command: &str) -> 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<CommandOp>, owner: Continuation) -> Result<ReadAhead, String> {
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
Expand All @@ -264,32 +303,32 @@ pub(crate) fn prepare(s: &mut Session, op: Authorized<CommandOp>, 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)
Expand Down
59 changes: 0 additions & 59 deletions crates/engine/src/cmd/tiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description says every id on the removed NETWORK list already declares Effect::Network, and that doesn't hold for map.body. It was on the list, but it is declared with .effects(crate::policy::Effects::NONE) (crates/engine/src/cmd/tiles.rs:42). map.body switches the basemap to remote planetary tiles, so the map fetches from the network when drawn. A plugin without the network permission could therefore run it. The fixed host list limits the exposure, and I haven't traced every path, so my confidence is medium. Either declare Effect::Network on map.body, or say in the PR why it is not a network command.

Category: security

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No permission changes. On main the removed list is read only by three tests; a plugin call's effects come from policy::command_effects, which gives map.body Effect::Network per call unless basemap is false (policy/effects.rs:57). The description overstated it and is corrected: every id but map.body declares the effect on its spec.

pub fn commands() -> Vec<C> {
vec![
Expand Down
25 changes: 2 additions & 23 deletions crates/engine/src/policy/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<crate::cmd::reads::ReadAhead, String> {
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() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The registry isn't the only copy of these ids. start_scoped_archive_read still has its own hardcoded list of eight ids and its own error text (dispatch.rs:129-143). Its error text also still lists different commands from the new message. The names are duplicated as well: reads::IN_BACKGROUND and about a dozen reads::ahead("…") constructors (for example repair.rs:208, publish.rs:198, layer.rs:4452) each hardcode a progress name. The work's own name wins whenever work exists, so a drift between them would go unnoticed. Consider having the scoped path check in_background as well, and taking the name from the registry, or a test that the two names match. Confidence high.

Category: quality

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The scoped list names a different property (which reads may start scoped), and the description lists it among the lists left alone. Checking it against the registry and taking the progress names from one place are left for the release quality pass.

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
Expand Down
12 changes: 9 additions & 3 deletions crates/engine/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -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}");
}
}

Expand Down
Loading
Loading