diff --git a/crates/analysis/src/network.rs b/crates/analysis/src/network.rs index cfa8a6d798..379f2e30a8 100644 --- a/crates/analysis/src/network.rs +++ b/crates/analysis/src/network.rs @@ -1974,6 +1974,62 @@ mod tests { assert!(within(&ds, &[0], center, 100_000.0).is_empty()); } + /// Bounding-box culling in `route_on` matches unculled snapping bit for bit and preserves the + /// distinct error messages for an empty network versus an endpoint beyond `snap_m`. + #[test] + fn route_on_culls_by_snap_window_with_identical_results_and_errors() { + let n = 25usize; + let step = 0.001; + let (x0, y0) = (-84.0, 35.9); + let mut ds = Dataset::new("roads", GeometryType::Polyline, vec![]); + for r in 0..n { + for c in 0..(n - 1) { + let a = Coord::new(x0 + c as f64 * step, y0 + r as f64 * step); + let b = Coord::new(x0 + (c + 1) as f64 * step, y0 + r as f64 * step); + ds.push(Some(Geometry::Line(vec![vec![a, b]])), vec![]); + } + } + for r in 0..(n - 1) { + for c in 0..n { + let a = Coord::new(x0 + c as f64 * step, y0 + r as f64 * step); + let b = Coord::new(x0 + c as f64 * step, y0 + (r + 1) as f64 * step); + ds.push(Some(Geometry::Line(vec![vec![a, b]])), vec![]); + } + } + let rows: Vec = (0..ds.features.len()).collect(); + let graph = Network::build(&ds, &rows, None).unwrap(); + let stops: Vec = (0..10) + .map(|i| { + let c = (i * 5 + 2) % (n - 1); + let r = (i * 7 + 1) % (n - 1); + Coord::new(x0 + (c as f64 + 0.5) * step, y0 + r as f64 * step + 0.0001) + }) + .collect(); + for &p in &stops { + let unculled = nearest_segment(&graph.segs, &graph.nodes, p, None).unwrap().unwrap(); + let culled = nearest_segment(&graph.segs, &graph.nodes, p, Some(50.0)).unwrap().unwrap(); + assert_eq!(unculled.0, culled.0); + assert_eq!(unculled.1.to_bits(), culled.1.to_bits()); + assert_eq!(unculled.2.x.to_bits(), culled.2.x.to_bits()); + assert_eq!(unculled.2.y.to_bits(), culled.2.y.to_bits()); + assert_eq!(unculled.3.to_bits(), culled.3.to_bits()); + } + for w in stops.windows(2) { + let r = route_on(&graph, &ds, w[0], w[1], 50.0).unwrap(); + assert!(!r.rows.is_empty() && r.length_m > 0.0); + } + // Culled to None on a non-empty network still reports a distance error, not an empty layer. + let far = route_on(&graph, &ds, Coord::new(x0 - 1.0, y0), stops[0], 50.0).unwrap_err(); + assert!(far.contains("from the network"), "{far}"); + let neg = route_on(&graph, &ds, stops[0], stops[1], -1.0).unwrap_err(); + assert!(neg.contains("from the network"), "{neg}"); + // An actually empty network still reports having no lines. + let empty_ds = Dataset::new("empty", GeometryType::Polyline, vec![]); + let empty_graph = Network::build(&empty_ds, &[], None).unwrap(); + let empty_err = route_on(&empty_graph, &empty_ds, stops[0], stops[1], 50.0).unwrap_err(); + assert!(empty_err.contains("the layer has no lines"), "{empty_err}"); + } + #[test] fn route_overlay_handles_empty_far_same_segment_and_endpoint_snaps() { let cache = Mutex::new(None); diff --git a/crates/ui-egui/src/readjob.rs b/crates/ui-egui/src/readjob.rs index bed6c31085..2e6a613430 100644 --- a/crates/ui-egui/src/readjob.rs +++ b/crates/ui-egui/src/readjob.rs @@ -184,6 +184,8 @@ fn run_presented( preview: Option, ) -> Result { if !app.reads_off_frame { + // Release any preview snapshot before running inline so it does not pin the rows' `Arc`. + drop(preview); // Read here and now: what its file holds now is what it reads. if matches!(command, "layer.reloadData" | "map.reloadTiles") { crate::diskwatch::reading(app, command, &p); diff --git a/crates/ui-egui/src/table.rs b/crates/ui-egui/src/table.rs index 71b9c95142..5da8f29c13 100644 --- a/crates/ui-egui/src/table.rs +++ b/crates/ui-egui/src/table.rs @@ -396,28 +396,33 @@ pub fn show(app: &mut RustGisApp, ui: &mut Ui) { .size_range(120.0..=600.0) .frame(egui::Frame::NONE.fill(t.pane)) .show(ui, |ui| { - // Data source: a layer or a standalone table. - let (ds, selection, title, key, table_instance): (Dataset, Vec, String, ViewKey, Option) = - match layer_id.and_then(|id| app.session.map().layer(id)) { - Some(l) => (l.dataset.clone(), l.selection.clone(), l.name.clone(), ViewKey::Layer(l.instance_id()), None), + prune_views(app); + // Data source: a layer or a standalone table. The header reads it through a short + // borrow, never a clone, so the toolbar's commands run with no extra reference + // pinning the rows (an edit would otherwise copy them). + let (title, key, table_instance, selected_n, total_n, shown, hidden_n) = { + let (ds, selected_n, title, key, table_instance) = match layer_id.and_then(|id| app.session.map().layer(id)) { + Some(l) => (&l.dataset, l.selection.len(), l.name.clone(), ViewKey::Layer(l.instance_id()), None), None => match app.session.table_standalone.and_then(|id| app.session.project.table(id)) { - Some(tb) => (tb.dataset.clone(), Vec::new(), tb.name.clone(), ViewKey::Table(tb.id), Some(tb.instance_id())), + Some(tb) => (&tb.dataset, 0, tb.name.clone(), ViewKey::Table(tb.id), Some(tb.instance_id())), None => { app.session.table_standalone = None; return; } }, }; - let is_layer = layer_id.is_some(); - prune_views(app); - if app.table.sort_schema.as_ref().is_none_or(|(view, fields)| *view != key || *fields != ds.fields) { - app.table.sort = None; - app.table.sort_schema = Some((key, ds.fields.clone())); - } - let view = app.table.views.entry(key).or_default(); - view.repair(&ds.fields); - let shown = view.shown(&ds.fields); - let hidden_n = view.hidden_count(&ds.fields); + if app.table.sort_schema.as_ref().is_none_or(|(view, fields)| *view != key || *fields != ds.fields) { + app.table.sort = None; + app.table.sort_schema = Some((key, ds.fields.clone())); + } + let view = app.table.views.entry(key).or_default(); + view.repair(&ds.fields); + let shown = view.shown(&ds.fields); + let hidden_n = view.hidden_count(&ds.fields); + (title, key, table_instance, selected_n, ds.features.len(), shown, hidden_n) + }; + // By what is shown: a stale layer id with a table shown aims nothing at the layer. + let is_layer = matches!(key, ViewKey::Layer(_)); let mut show_all = false; // Header. let (hr, _) = ui.allocate_exact_size(vec2(ui.available_width(), 34.0), Sense::hover()); @@ -434,7 +439,7 @@ pub fn show(app: &mut RustGisApp, ui: &mut Ui) { ui.label( egui::RichText::new(crate::i18n::fmt( "{n} of {total} selected", - &[("n", &selection.len().to_string()), ("total", &ds.features.len().to_string())], + &[("n", &selected_n.to_string()), ("total", &total_n.to_string())], )) .size(11.5) .color(t.text_dim), @@ -500,22 +505,29 @@ pub fn show(app: &mut RustGisApp, ui: &mut Ui) { } }); } + // The grid borrows the data source (the toolbar's commands may have changed it) until + // the frame's commands are resolved to what they need, below. + let source = match key { + ViewKey::Layer(_) => layer_id.and_then(|id| app.session.map().layer(id)).map(|l| (&l.dataset, l.selection.as_slice())), + ViewKey::Table(id) => app.session.project.table(id).map(|tb| (&tb.dataset, &[] as &[usize])), + }; + let Some((ds, selection)) = source else { return }; let rows = RowOrder::displayed( &mut app.table.row_order, - &ds, + ds, app.table.sort, &app.table.filter, - (app.table.selected_only && is_layer).then_some(selection.as_slice()), + (app.table.selected_only && is_layer).then_some(selection), ); let row_count = rows.map_or(ds.features.len(), <[usize]>::len); - let table = cursor::Shown { view: key, table_instance, ds: &ds, rows, columns: &shown }; + let table = cursor::Shown { view: key, table_instance, ds, rows, columns: &shown }; if app.table.current.as_mut().is_some_and(|c| !c.follow(&table)) { app.table.current = None; } - let mark = app.table.current.as_ref().and_then(|c| c.mark(&ds)); + let mark = app.table.current.as_ref().and_then(|c| c.mark(ds)); // The place and field of the current cell, when this frame is to scroll to it. let reveal = std::mem::take(&mut app.table.reveal) - .then(|| app.table.current.as_mut().and_then(|c| c.place(&table).zip(c.mark(&ds)).map(|(at, (_, field))| (at, field)))) + .then(|| app.table.current.as_mut().and_then(|c| c.place(&table).zip(c.mark(ds)).map(|(at, (_, field))| (at, field)))) .flatten(); // Sideways, the column's header is scrolled to: it is drawn wherever the rows are, and // the rows' own scroll area keeps what is asked inside it. @@ -802,12 +814,32 @@ pub fn show(app: &mut RustGisApp, ui: &mut Ui) { view.show_all(); } } - if let Some(i) = statistics - && let Some(fd) = ds.fields.get(i) + // A cell scrolled out of view loses the focus unseen: kept, as a click elsewhere (left + // as it was on Escape). + if !drawn + && let Some(e) = app.table.editing.take_if(|e| !e.focus) + && !(had_focus(&app.table, pass) && ui.input(|i| i.key_pressed(egui::Key::Escape))) + { + commits.push((e.fid, e.col, e.text, e.was)); + } + // What the frame's commands need from the data source, read now so that none of them + // runs while the grid's borrow (or a copy) holds the rows. + let field_name = |i: usize| ds.fields.get(i).map(|fd| fd.name.clone()); + let statistics = statistics.and_then(|i| field_name(i).map(|name| (i, name))); + let streamed = is_layer && layer_id.and_then(|id| app.session.map().layer(id)).is_some_and(|l| l.is_streamed()); + // Only the dialog's background scan takes a copy, and only when it opens. + let convert = convert.and_then(|(i, ty)| field_name(i).map(|name| (i, ty, name, (!streamed).then(|| ds.clone())))); + let delete_field = delete_field.and_then(field_name); + let clicked = clicked.filter(|_| is_layer).map(|(r, add)| { + let mode = if add { if selection.contains(&r) { "remove" } else { "add" } } else { "new" }; + (r, mode) + }); + let commits: Vec<_> = commits.into_iter().map(|(fid, c, text, was)| (fid, c, text, was, ds.fields.get(c).cloned())).collect(); + if let Some((i, name)) = statistics && let Some(layer) = layer_id { // By the column's place, so a second column of the same name is its own. - let asked = json!({"layer": layer, "field": fd.name, "index": i, "selected": app.table.selected_only}); + let asked = json!({"layer": layer, "field": name, "index": i, "selected": app.table.selected_only}); ask_statistics(app, asked); } // The layer or table the view shows, as the edit commands name it. @@ -818,50 +850,38 @@ pub fn show(app: &mut RustGisApp, ui: &mut Ui) { } p }; - if let Some((i, ty)) = convert - && let Some(fd) = ds.fields.get(i) - { - let params = target(json!({"field": fd.name, "type": ty})); - if is_layer && layer_id.and_then(|id| app.session.map().layer(id)).is_some_and(|l| l.is_streamed()) { + if let Some((i, ty, name, copy)) = convert { + let params = target(json!({"field": name, "type": ty})); + match copy { + Some(copy) => app.table.dates = Some(dates::Dialog::new(key, table_instance, copy, i, ty, params)), // Use the ordinary command admission refusal before scanning a view sample. - let _ = app.run("edit.convertField", params); - } else { - app.table.dates = Some(dates::Dialog::new(key, table_instance, ds.clone(), i, ty, params)); + None => { + let _ = app.run("edit.convertField", params); + } } } if by_other_name { app.session.notify(shadowed().to_string(), true); } - if let Some(fd) = delete_field.and_then(|i| ds.fields.get(i)) { + if let Some(name) = delete_field { // Refused (a definition query reading it): said, unless the command said so. let mark = app.session.notice_mark(); - if let Err(e) = app.run("edit.deleteField", target(json!({"field": fd.name}))) + if let Err(e) = app.run("edit.deleteField", target(json!({"field": name}))) && app.session.notices_since(mark).is_empty() { app.session.notify(e, true); } } - if let Some((r, add)) = clicked - && is_layer - { - let mode = if add { if selection.contains(&r) { "remove" } else { "add" } } else { "new" }; + if let Some((r, mode)) = clicked { let _ = app.run("select.rows", json!({"layer": layer_id, "rows": [r], "mode": mode})); } - // A cell scrolled out of view loses the focus unseen: kept, as a click elsewhere (left - // as it was on Escape). - if !drawn - && let Some(e) = app.table.editing.take_if(|e| !e.focus) - && !(had_focus(&app.table, pass) && ui.input(|i| i.key_pressed(egui::Key::Escape))) - { - commits.push((e.fid, e.col, e.text, e.was)); - } let ends = |editing: &Option, fid: u64, c: usize| editing.as_ref().is_some_and(|e| e.fid == fid && e.col == c); if let Some((fid, c)) = cancel && ends(&app.table.editing, fid, c) { app.table.editing = None; } - for (fid, c, text, was) in commits { + for (fid, c, text, was, field) in commits { if ends(&app.table.editing, fid, c) { app.table.editing = None; } @@ -872,7 +892,7 @@ pub fn show(app: &mut RustGisApp, ui: &mut Ui) { ViewKey::Table(id) => app.session.project.table(id).map(|t| &t.dataset.features), }; let live = rows.and_then(|rows| rows.iter().position(|f| f.id == fid)); - let (Some(fd), Some(r)) = (ds.fields.get(c), live) else { continue }; + let (Some(fd), Some(r)) = (field, live) else { continue }; if text == was { continue; } @@ -2430,4 +2450,159 @@ mod tests { assert_eq!(app.table.stats.is_some(), !selected, "only the selected-row window closes"); } } + + /// Attribute table mutations (`edit.setValue`, `edit.delete`, `edit.addFeature`, + /// `edit.deleteField`) must not run while the table pane holds an extra `Dataset` clone. + #[test] + fn attribute_table_drops_dataset_borrow_before_mutating_commands() { + use rustgis_engine::data::{FieldType, GeometryType}; + use std::sync::{ + Arc, + atomic::{AtomicUsize, Ordering}, + }; + + let sample_ds = || { + let mut ds = Dataset::new( + "Parcels", + GeometryType::Point, + vec![Field::new("name", FieldType::Text), Field::new("code", FieldType::Integer)], + ); + for i in 0..8 { + ds.push(None, vec![V::Text(format!("Parcel {i}")), V::Int(i)]); + } + ds + }; + + // 1. Cell edit (`edit.setValue`): only live + Undo snapshot (2), no extra table clone. + let mut app = RustGisApp::new(rustgis_engine::Session::new(rustgis_engine::Project::default())); + let id = app.session.map_mut().add_dataset(sample_ds()); + app.session.table_layer = Some(id); + app.session.map_mut().editing.settings.enabled = true; + let ds_ref = &app.session.map().layer(id).unwrap().dataset; + let fid0 = ds_ref.features[0].id; + let schema = ds_ref.fields.clone(); + let key = ViewKey::Layer(app.session.map().layer(id).unwrap().instance_id()); + let mut h = egui_kittest::Harness::builder().with_size(vec2(1400.0, 1000.0)).build_ui_state( + |ui, app: &mut RustGisApp| { + app.logic(&ui.ctx().clone()); + show(app, ui); + }, + app, + ); + h.run_steps(2); + h.state_mut().table.editing = Some(CellEdit::new(key, fid0, 0, "Parcel 0".into(), &schema, None)); + h.run_steps(2); + h.event(egui::Event::Text("X".into())); + h.run_steps(2); + let weak = h.state().session.map().layer(id).unwrap().dataset.features.allocation_key(); + assert_eq!(weak.strong_count(), 1); + let seen = Arc::new(AtomicUsize::new(0)); + let seen_c = Arc::clone(&seen); + let weak_c = weak.clone(); + h.key_press(egui::Key::Enter); + let ((), fired) = rustgis_engine::data::before_rows_copy( + Box::new(move || { + seen_c.store(weak_c.strong_count(), Ordering::SeqCst); + }), + || h.step(), + ); + assert!(fired); + assert_eq!(seen.load(Ordering::SeqCst), 2, "table::show must not hold an extra Dataset Arc across edit.setValue"); + h.run_steps(1); + assert_eq!(h.state().session.map().layer(id).unwrap().dataset.value(0, 0).to_string(), "Parcel 0X"); + + // 2. Toolbar Delete (`edit.delete`): only live + Undo snapshot (2), no extra table clone. + let mut app = RustGisApp::new(rustgis_engine::Session::new(rustgis_engine::Project::default())); + let id = app.session.map_mut().add_dataset(sample_ds()); + app.session.table_layer = Some(id); + app.session.active_layer = Some(id); + app.session.map_mut().editing.settings.enabled = true; + app.session.map_mut().layer_mut(id).unwrap().selection = vec![0]; + let mut h = egui_kittest::Harness::builder().with_size(vec2(1400.0, 1000.0)).build_ui_state( + |ui, app: &mut RustGisApp| { + app.logic(&ui.ctx().clone()); + show(app, ui); + }, + app, + ); + h.run_steps(2); + let weak = h.state().session.map().layer(id).unwrap().dataset.features.allocation_key(); + assert_eq!(weak.strong_count(), 1); + let seen = Arc::new(AtomicUsize::new(0)); + let seen_c = Arc::clone(&seen); + let weak_c = weak.clone(); + h.get_by_label("Delete selected rows").click(); + let ((), fired) = rustgis_engine::data::before_rows_copy( + Box::new(move || { + seen_c.store(weak_c.strong_count(), Ordering::SeqCst); + }), + || h.step(), + ); + assert!(fired); + assert_eq!(seen.load(Ordering::SeqCst), 2, "table::show must not hold an extra Dataset Arc across edit.delete"); + + // 3. Standalone table Add row (`edit.addFeature`) and Delete Field (`edit.deleteField`). + let mut app = RustGisApp::new(rustgis_engine::Session::new(rustgis_engine::Project::default())); + let mut tb_ds = + Dataset::new("Notes", GeometryType::None, vec![Field::new("alpha", FieldType::Text), Field::new("beta", FieldType::Text)]); + tb_ds.push(None, vec![V::Text("a".into()), V::Text("b".into())]); + let tid = app.session.project.add_table(tb_ds); + app.session.table_standalone = Some(tid); + app.session.map_mut().editing.settings.enabled = true; + let mut h = egui_kittest::Harness::builder().with_size(vec2(1400.0, 1000.0)).build_ui_state( + |ui, app: &mut RustGisApp| { + app.logic(&ui.ctx().clone()); + show(app, ui); + }, + app, + ); + h.run_steps(2); + let weak = h.state().session.project.table(tid).unwrap().dataset.features.allocation_key(); + assert_eq!(weak.strong_count(), 1); + let seen = Arc::new(AtomicUsize::new(0)); + let seen_c = Arc::clone(&seen); + let weak_c = weak.clone(); + h.get_by_label("Add row").click(); + let ((), fired) = rustgis_engine::data::before_rows_copy( + Box::new(move || { + seen_c.store(weak_c.strong_count(), Ordering::SeqCst); + }), + || h.step(), + ); + assert!(fired); + assert_eq!(seen.load(Ordering::SeqCst), 2, "table::show must not hold an extra Dataset Arc across edit.addFeature"); + + // Fresh table for Delete Field so Undo starts empty. + let mut app = RustGisApp::new(rustgis_engine::Session::new(rustgis_engine::Project::default())); + let mut tb_ds = + Dataset::new("Notes", GeometryType::None, vec![Field::new("alpha", FieldType::Text), Field::new("beta", FieldType::Text)]); + tb_ds.push(None, vec![V::Text("a".into()), V::Text("b".into())]); + let tid = app.session.project.add_table(tb_ds); + app.session.table_standalone = Some(tid); + app.session.map_mut().editing.settings.enabled = true; + let mut h = egui_kittest::Harness::builder().with_size(vec2(1400.0, 1000.0)).build_ui_state( + |ui, app: &mut RustGisApp| { + app.logic(&ui.ctx().clone()); + show(app, ui); + }, + app, + ); + h.run_steps(4); + h.get_by_label("alpha").click_secondary(); + h.run_steps(2); + let weak = h.state().session.project.table(tid).unwrap().dataset.features.allocation_key(); + assert_eq!(weak.strong_count(), 1); + let seen = Arc::new(AtomicUsize::new(0)); + let seen_c = Arc::clone(&seen); + let weak_c = weak.clone(); + h.get_by_label("Delete Field").click(); + let ((), fired) = rustgis_engine::data::before_rows_copy( + Box::new(move || { + seen_c.store(weak_c.strong_count(), Ordering::SeqCst); + }), + || h.step(), + ); + assert!(fired); + assert_eq!(seen.load(Ordering::SeqCst), 2, "table::show must not hold an extra Dataset Arc across edit.deleteField"); + } } diff --git a/crates/ui-egui/src/table/dates.rs b/crates/ui-egui/src/table/dates.rs index aabdfcb57a..49ae3aa969 100644 --- a/crates/ui-egui/src/table/dates.rs +++ b/crates/ui-egui/src/table/dates.rs @@ -207,11 +207,21 @@ pub(super) fn show(app: &mut RustGisApp, ctx: &egui::Context) { if pattern.contains("%y") { dialog.params["pivotYear"] = json!(dialog.pivot); } + let params = std::mem::take(&mut dialog.params); + #[cfg(not(target_arch = "wasm32"))] + let preview = app + .reads_off_frame + .then(|| std::mem::replace(&mut dialog.dataset, Dataset::new("", rustgis_engine::data::GeometryType::None, Vec::new()))); + // Drop the dialog and its dataset snapshot before running the conversion inline. + drop(dialog); let mark = app.session.notice_mark(); #[cfg(not(target_arch = "wasm32"))] - let result = crate::readjob::run_date_preview(app, dialog.params.clone(), dialog.dataset.clone()); + let result = match preview { + Some(dataset) => crate::readjob::run_date_preview(app, params, dataset), + None => app.run("edit.convertField", params), + }; #[cfg(target_arch = "wasm32")] - let result = app.run("edit.convertField", dialog.params.clone()); + let result = app.run("edit.convertField", params); if let Err(e) = result && app.session.notices_since(mark).is_empty() { @@ -330,4 +340,55 @@ mod tests { assert_eq!(choices.iter().map(|c| PRESETS[c.index].0).collect::>(), ["MM/DD/YY HH:MM", "DD/MM/YY HH:MM"]); assert_eq!(choices[0].examples[0].1, "1926-03-05T14:30:00"); } + + /// Inline date conversion drops the dialog's dataset snapshot before running + /// `edit.convertField`, so no extra `Arc` reference pins the rows during mutation. + #[test] + fn date_dialog_drops_dataset_before_inline_convert() { + let mut app = RustGisApp::new(rustgis_engine::Session::new(rustgis_engine::Project::default())); + let mut ds = Dataset::new("Dates", rustgis_engine::data::GeometryType::None, vec![Field::new("d", FieldType::Text)]); + for _ in 0..8 { + ds.push(None, vec![V::Text("03/05/2026".into())]); + } + let tid = app.session.project.add_table(ds); + app.session.table_standalone = Some(tid); + app.session.map_mut().editing.settings.enabled = true; + let mut h = egui_kittest::Harness::builder().with_size(vec2(1400.0, 1000.0)).with_max_steps(64).build_ui_state( + |ui, app: &mut RustGisApp| { + let ctx = ui.ctx().clone(); + app.logic(&ctx); + app.ui(ui); + }, + app, + ); + h.run_steps(4); + h.get_by_label("d").click_secondary(); + h.run_steps(2); + h.get_by_label("Convert to Date").click(); + h.run_steps(2); + let d = h.state_mut().table.dates.as_mut().unwrap(); + if d.choices.is_none() { + d.choices = Some(d.result.recv_timeout(std::time::Duration::from_secs(5)).unwrap()); + } + h.run_steps(2); + h.get_by_label("DD/MM/YYYY").click(); + h.run_steps(2); + let weak = h.state().session.project.table(tid).unwrap().dataset.features.allocation_key(); + // While the dialog is open, it owns one preview clone beside the live table. + assert_eq!(weak.strong_count(), 2); + let seen = Arc::new(AtomicUsize::new(0)); + let seen_c = Arc::clone(&seen); + let weak_c = weak.clone(); + h.get_by_label("Convert").click(); + let ((), fired) = rustgis_engine::data::before_rows_copy( + Box::new(move || { + seen_c.store(weak_c.strong_count(), Ordering::SeqCst); + }), + || h.step(), + ); + assert!(fired); + assert_eq!(seen.load(Ordering::SeqCst), 2, "dates::show must drop dialog.dataset before running edit.convertField"); + h.run_steps(2); + assert_eq!(h.state().session.project.table(tid).unwrap().dataset.value(0, 0).to_string(), "2026-05-03"); + } }