From 208a3bd970d495c5691bb9fe866814b6fe47e34b Mon Sep 17 00:00:00 2001 From: mavrick Date: Tue, 24 Nov 2026 13:35:36 -0600 Subject: [PATCH 1/2] ci: run the GDAL and DuckDB tests with both installed, and fail them when either is missing (#2644) Every test that runs GDAL or DuckDB returned early without the program, and no workflow installed either, so they passed without running. A new `GDAL and DuckDB` job installs Ubuntu 24.04's GDAL (3.8, the oldest RustGIS converts with) and a checksum-pinned DuckDB 2.0.1, sets RUSTGIS_REQUIRE_GDAL and RUSTGIS_REQUIRE_DUCKDB, and runs rustgis-data's and rustgis-engine's tests when the run tests either. Tests now skip through `test_runs()` in rustgis-data, which turns a missing program into a failure when the switch is set. Running them found a FileGDB fixture that no GDAL writes: a TIN into a layer typed TINZ is refused (polygon layer). A GEOMETRYCOLLECTIONZ layer is a multipatch, which is what the test reads. The iOS and Android run conditions, written three times, are now `plan` outputs that both jobs and `Tests pass` read. --- .github/workflows/ci.yml | 110 ++++++++++++++---- AGENTS.md | 3 + crates/data/src/filegdb/tests.rs | 4 +- crates/data/src/raster/gdal.rs | 14 ++- crates/data/src/source/duckdb.rs | 10 +- crates/data/src/source/external.rs | 13 +++ crates/data/src/source/gdal.rs | 28 +++-- crates/engine/src/tests.rs | 19 +-- crates/engine/src/tests/sources_own.rs | 4 +- .../integration/portable_projects/reload.rs | 22 ++-- docs/contributing.md | 10 ++ 11 files changed, 177 insertions(+), 60 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b94fbd4e94..e3017ca266 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -94,11 +94,8 @@ jobs: # added, not straight away (ci-label.yml runs test-rust.yml only). ios: name: iOS app - if: >- - github.event_name == 'push' - || (github.event_name == 'workflow_dispatch' && inputs.platforms != 'linux') - || contains(github.event.pull_request.labels.*.name, 'ci:macos') - || contains(github.event.pull_request.labels.*.name, 'ci:full') + needs: plan + if: needs.plan.outputs.ios == 'true' runs-on: macos-latest steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 @@ -121,10 +118,8 @@ jobs: # platform, a pull request labelled `ci:full`), from the next push after the label is added. android: name: Android app - if: >- - github.event_name == 'push' - || (github.event_name == 'workflow_dispatch' && inputs.platforms != 'linux') - || contains(github.event.pull_request.labels.*.name, 'ci:full') + needs: plan + if: needs.plan.outputs.android == 'true' runs-on: ubuntu-latest steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 @@ -375,6 +370,8 @@ jobs: runs-on: ubuntu-latest outputs: os: ${{ steps.os.outputs.os }} + ios: ${{ steps.apps.outputs.ios }} + android: ${{ steps.apps.outputs.android }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: @@ -386,6 +383,22 @@ jobs: LABELS: ${{ toJSON(github.event.pull_request.labels.*.name) }} PLATFORMS: ${{ inputs.platforms }} run: echo "os=$(.github/scripts/platforms.sh)" >> "$GITHUB_OUTPUT" + # Whether the `ios` and `android` jobs run: they read it, and so does `Tests pass`, to tell a + # job meant to skip from one that should have run. + - id: apps + env: + IOS: >- + ${{ github.event_name == 'push' + || (github.event_name == 'workflow_dispatch' && inputs.platforms != 'linux') + || contains(github.event.pull_request.labels.*.name, 'ci:macos') + || contains(github.event.pull_request.labels.*.name, 'ci:full') }} + ANDROID: >- + ${{ github.event_name == 'push' + || (github.event_name == 'workflow_dispatch' && inputs.platforms != 'linux') + || contains(github.event.pull_request.labels.*.name, 'ci:full') }} + run: | + echo "ios=$IOS" >> "$GITHUB_OUTPUT" + echo "android=$ANDROID" >> "$GITHUB_OUTPUT" test: needs: [plan, select] @@ -396,6 +409,70 @@ jobs: # The release build runs nightly; `ci:full` asks for it before merging. release-build: ${{ contains(github.event.pull_request.labels.*.name, 'ci:full') }} + # The tests that run GDAL or DuckDB, with both installed (#2644). Elsewhere they skip without the + # program, so here RUSTGIS_REQUIRE_GDAL and RUSTGIS_REQUIRE_DUCKDB make a missing one fail them + # instead (`test_runs` in rustgis-data). The `test` job installs neither and keeps covering what a + # user without them sees. It runs the whole of rustgis-data and rustgis-engine, which hold those + # tests, when the run tests either; otherwise its steps skip and it passes. + programs: + name: GDAL and DuckDB + needs: select + runs-on: ubuntu-latest + env: + RUSTFLAGS: -D warnings -C linker=clang -C link-arg=-fuse-ld=mold + CARGO_PROFILE_DEV_DEBUG: line-tables-only + RUSTGIS_REQUIRE_GDAL: "1" + RUSTGIS_REQUIRE_DUCKDB: "1" + # GDAL 3.8 is the oldest RustGIS converts with, and Ubuntu 24.04's. DuckDB's command line + # program, pinned by checksum. + DUCKDB_VERSION: 2.0.1 + DUCKDB_SHA256: b676268be4d39e4e41a904442c9796c9914e645cc085c7505f048f2c992b5eca + steps: + - id: scope + env: + PACKAGES: ${{ needs.select.outputs.packages }} + run: | + if [ "$PACKAGES" = --workspace ] || grep -qE '(^| )-p rustgis-(data|engine)( |$)' <<<"$PACKAGES"; then + echo "run=true" >> "$GITHUB_OUTPUT" + else + echo "Neither rustgis-data nor rustgis-engine is tested in this run; skipping." + echo "run=false" >> "$GITHUB_OUTPUT" + fi + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + if: steps.scope.outputs.run == 'true' + with: + persist-credentials: false + - name: Install GDAL and DuckDB + if: steps.scope.outputs.run == 'true' + run: | + set -euo pipefail + sudo apt-get update -qq + sudo apt-get install -y --no-install-recommends mold gdal-bin + curl -fsSLo "$RUNNER_TEMP/duckdb.tar.gz" \ + "https://github.com/duckdb/duckdb/releases/download/v$DUCKDB_VERSION/duckdb-cli-linux-amd64.tar.gz" + echo "$DUCKDB_SHA256 $RUNNER_TEMP/duckdb.tar.gz" | sha256sum -c - + mkdir "$RUNNER_TEMP/duckdb" + tar -xzf "$RUNNER_TEMP/duckdb.tar.gz" -C "$RUNNER_TEMP/duckdb" duckdb + echo "$RUNNER_TEMP/duckdb" >> "$GITHUB_PATH" + # DuckDB Spatial, which every query loads, installed now so a download that fails says so here. + "$RUNNER_TEMP/duckdb/duckdb" -c "INSTALL spatial; LOAD spatial;" + ogrinfo --version + "$RUNNER_TEMP/duckdb/duckdb" --version + - uses: dtolnay/rust-toolchain@b725eda525362e7cf34af9a7243cac1e3f01a7ec # stable + if: steps.scope.outputs.run == 'true' + - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2 + if: steps.scope.outputs.run == 'true' + with: + # Only main saves the cache (see test-rust.yml). + save-if: ${{ github.ref == 'refs/heads/main' }} + - uses: taiki-e/install-action@ab49d3c64680143e184118bed66a46419fc15519 # v2 + if: steps.scope.outputs.run == 'true' + with: + tool: cargo-nextest@0.9.151 + - name: Tests + if: steps.scope.outputs.run == 'true' + run: cargo nextest run -p rustgis-data -p rustgis-engine --locked --profile ci + # A test that failed and then passed on a retry (.config/nextest.toml) on a push to main gets an # issue, or a comment on its open one: a retry hides a flaky test from the run, not from us. A # pull request only lists them in the test jobs' summaries. Like nightly.yml's report, it writes @@ -439,24 +516,17 @@ jobs: # The check to require before merging, so the list of required checks needn't follow the jobs # above (a runner that only a label adds, a job added later). It fails if any of them failed or # was cancelled. A skipped job passes only when it was meant to skip: `ios` and `android` skip - # unless their conditions below hold (the same as on the jobs), and every other job always runs. + # unless `plan` says they run, and every other job always runs. tests_pass: name: Tests pass - needs: [lint, wasm, ios, android, licenses, schema, rows, deferrals, ratchets, plan, select, test] + needs: [lint, wasm, ios, android, licenses, schema, rows, deferrals, ratchets, plan, select, test, programs] if: ${{ always() }} runs-on: ubuntu-latest steps: - env: NEEDS: ${{ toJSON(needs) }} - RUNS_IOS: >- - ${{ github.event_name == 'push' - || (github.event_name == 'workflow_dispatch' && inputs.platforms != 'linux') - || contains(github.event.pull_request.labels.*.name, 'ci:macos') - || contains(github.event.pull_request.labels.*.name, 'ci:full') }} - RUNS_ANDROID: >- - ${{ github.event_name == 'push' - || (github.event_name == 'workflow_dispatch' && inputs.platforms != 'linux') - || contains(github.event.pull_request.labels.*.name, 'ci:full') }} + RUNS_IOS: ${{ needs.plan.outputs.ios }} + RUNS_ANDROID: ${{ needs.plan.outputs.android }} run: | set -euo pipefail meant_to_run() { diff --git a/AGENTS.md b/AGENTS.md index e72c394e04..7395e39314 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -159,6 +159,9 @@ the pull request which of these it reaches and why the rest don't apply: `cargo xtask test-hygiene` (also in CI) requires `// test-wait: reason` on timer waits in tests and `#[ignore = "reason"]` on ignored tests, and refuses an `assert_eq!` or `assert_ne!` (or `debug_assert_*`) whose two sides are the same tokens; prefer completion or progress signals, and a fixed expected value. +A test that needs GDAL or DuckDB skips with `if !gdal::test_runs().unwrap() { return; }` (`duckdb::`, +`raster::gdal::`), never on `available()` or `usable()`: CI's `GDAL and DuckDB` job installs both and +sets `RUSTGIS_REQUIRE_GDAL` and `RUSTGIS_REQUIRE_DUCKDB`, so only then does a missing program fail it. `clippy.toml` refuses the four sphere measures in `rustgis-geom` (`haversine_m`, `geodesic_length_m`, `geodesic_ring_perimeter_m`, `geodesic_ring_area_m2`): the Earth measures on the WGS 84 ellipsoid (`wgs84_distance_m`, `wgs84_length_m`, `wgs84_step_m`, `wgs84_ring_perimeter_area_m2`), and a call kept on diff --git a/crates/data/src/filegdb/tests.rs b/crates/data/src/filegdb/tests.rs index a847ae4f05..c45d707b69 100644 --- a/crates/data/src/filegdb/tests.rs +++ b/crates/data/src/filegdb/tests.rs @@ -626,7 +626,7 @@ fn hostile_bytes_never_panic() { /// fields, and a TIN, which GDAL stores as a multipatch (a triangle fan). #[test] fn reads_what_gdal_writes_when_gdal_is_installed() { - if !crate::source::gdal::available() { + if !crate::source::gdal::test_runs().unwrap() { return; } let dir = std::env::temp_dir().join(format!("rustgis-filegdb-{}", std::process::id())); @@ -647,7 +647,7 @@ fn reads_what_gdal_writes_when_gdal_is_installed() { .unwrap(); let (gdb_s, points_s, tins_s) = (gdb.display().to_string(), points.display().to_string(), tins.display().to_string()); run(&["-f", "OpenFileGDB", "-a_srs", "EPSG:4326", "-nlt", "POINT", "-nln", "places", "-oo", "AUTODETECT_TYPE=YES", &gdb_s, &points_s]); - run(&["-f", "OpenFileGDB", "-update", "-a_srs", "EPSG:2056", "-nlt", "TINZ", "-nln", "blocks", &gdb_s, &tins_s]); + run(&["-f", "OpenFileGDB", "-update", "-a_srs", "EPSG:2056", "-nlt", "GEOMETRYCOLLECTIONZ", "-nln", "blocks", &gdb_s, &tins_s]); assert!(is_geodatabase(&gdb)); assert_eq!(layers(&gdb).unwrap(), ["places", "blocks"]); let read = read_dir(&gdb, None).unwrap().layers; diff --git a/crates/data/src/raster/gdal.rs b/crates/data/src/raster/gdal.rs index 2f52661d67..0a5d0ea43c 100644 --- a/crates/data/src/raster/gdal.rs +++ b/crates/data/src/raster/gdal.rs @@ -71,6 +71,12 @@ pub fn available() -> bool { program("gdal_translate").is_some() && program("gdalinfo").is_some() } +/// Whether a test that needs GDAL's raster programs runs: skipped without them, unless +/// `RUSTGIS_REQUIRE_GDAL` is set, when it fails on the `Err` instead. +pub fn test_runs() -> std::result::Result { + external::test_runs("RUSTGIS_REQUIRE_GDAL", "GDAL's raster programs (gdal_translate and gdalinfo)", available()) +} + /// What converting a file's contents made: the GeoTIFF's bytes, and whether the raster was taken /// as WGS 84 (see [`Converted::assumed_lonlat`]). pub struct ConvertedBytes { @@ -935,10 +941,10 @@ mod tests { /// A VRT renamed `.img` isn't opened as a VRT, so the raster it names isn't read. #[test] fn a_renamed_vrt_isnt_read_when_gdal_is_installed() { - let Some(translate) = program("gdal_translate") else { return }; - if program("gdalinfo").is_none() { + if !test_runs().unwrap() { return; } + let translate = program("gdal_translate").unwrap(); let dir = tempfile::tempdir().unwrap(); let asc = dir.path().join("private.asc"); std::fs::write(&asc, "ncols 1\nnrows 1\nxllcorner 0\nyllcorner 0\ncellsize 1\n7\n").unwrap(); @@ -963,10 +969,10 @@ mod tests { /// Runs only where GDAL is installed: a NetCDF file's variables. #[test] fn raster_conversion_provenance_excludes_cache_files_when_gdal_is_installed() { - let Some(translate) = program("gdal_translate") else { return }; - if program("gdalinfo").is_none() { + if !test_runs().unwrap() { return; } + let translate = program("gdal_translate").unwrap(); let dir = std::env::temp_dir().join(format!("rustgis-gdal-raster-{}", std::process::id())); let _ = std::fs::remove_dir_all(&dir); std::fs::create_dir_all(&dir).unwrap(); diff --git a/crates/data/src/source/duckdb.rs b/crates/data/src/source/duckdb.rs index dc8e3b92c8..31a9d9901a 100644 --- a/crates/data/src/source/duckdb.rs +++ b/crates/data/src/source/duckdb.rs @@ -278,6 +278,12 @@ pub fn available() -> bool { program().is_some() } +/// Whether a test that needs DuckDB runs: skipped without it, unless `RUSTGIS_REQUIRE_DUCKDB` is +/// set, when it fails on the `Err` instead. +pub fn test_runs() -> std::result::Result { + external::test_runs("RUSTGIS_REQUIRE_DUCKDB", "DuckDB (the duckdb program)", available()) +} + /// A live-only database named for a query: add its tables instead. fn live_not_here() -> DataError { DataError::Unsupported( @@ -1605,7 +1611,7 @@ mod tests { #[test] fn previews_rows() { assert!(checked(" ;").is_err() && checked("SELECT 1\0").is_err()); - if !available() { + if !test_runs().unwrap() { return; } let dir = std::env::temp_dir().join(format!("rustgis-duckdb-preview-{}", std::process::id())); @@ -1642,7 +1648,7 @@ mod tests { /// Queries and a database through DuckDB when it is installed (skipped otherwise). #[test] fn runs_queries_when_duckdb_is_installed() { - if !available() { + if !test_runs().unwrap() { return; } let dir = std::env::temp_dir().join(format!("rustgis-duckdb-test-{}", std::process::id())); diff --git a/crates/data/src/source/external.rs b/crates/data/src/source/external.rs index 38ade7b02b..8b4d078840 100644 --- a/crates/data/src/source/external.rs +++ b/crates/data/src/source/external.rs @@ -29,6 +29,19 @@ pub(crate) fn cache_dir(env: &str, sub: &str) -> Option { crate::dirs::cache_dir().map(|b| b.join(sub)) } +/// Whether a test that needs a program runs (`here`: it is installed). Where it isn't, the test is +/// skipped, unless the environment variable `require` is set, as in CI's job that installs the +/// programs: then the `Err` says what is missing, and the test fails instead of passing unrun. +pub(crate) fn test_runs(require: &str, what: &str, here: bool) -> std::result::Result { + if here { + Ok(true) + } else if std::env::var_os(require).is_some_and(|v| !v.is_empty()) { + Err(format!("{require} is set, but {what} isn't installed")) + } else { + Ok(false) + } +} + const RELOAD_PREFIX: &str = "reload-"; const RELOAD_OWNER_MARKER: &[u8] = b"RustGIS reload workspace v1\n"; diff --git a/crates/data/src/source/gdal.rs b/crates/data/src/source/gdal.rs index 333038c47e..ce2ccdb351 100644 --- a/crates/data/src/source/gdal.rs +++ b/crates/data/src/source/gdal.rs @@ -115,6 +115,12 @@ pub fn usable() -> bool { available() && program("ogrinfo").is_some_and(|p| check_version(&p).is_ok()) } +/// Whether a test that needs GDAL runs: skipped without a [`usable`] GDAL, unless +/// `RUSTGIS_REQUIRE_GDAL` is set, when it fails on the `Err` instead. +pub fn test_runs() -> std::result::Result { + external::test_runs("RUSTGIS_REQUIRE_GDAL", "GDAL 3.8 or later (ogr2ogr and ogrinfo)", usable()) +} + fn missing() -> DataError { DataError::Unsupported(missing_text(crate::no_programs_here())) } @@ -984,7 +990,7 @@ mod tests { /// layer was before, and said. A conversion made before is not reused for one in its own. #[test] fn layers_are_converted_in_their_own_system_when_gdal_is_installed() { - if !available() { + if !test_runs().unwrap() { return; } let dir = tempfile::tempdir().unwrap(); @@ -1077,7 +1083,7 @@ mod tests { /// A VRT renamed `.tab` isn't opened as a VRT, so the file it names isn't read. #[test] fn a_renamed_vrt_isnt_read_when_gdal_is_installed() { - if !available() { + if !test_runs().unwrap() { return; } let dir = tempfile::tempdir().unwrap(); @@ -1125,7 +1131,7 @@ mod tests { /// keeps all five: the surfaces, the curves and the collection were left out before. #[test] fn keeps_surfaces_curves_and_collections_when_gdal_is_installed() { - if !usable() { + if !test_runs().unwrap() { return; } let dir = std::env::temp_dir().join(format!("rustgis-gdal-surfaces-{}", std::process::id())); @@ -1166,7 +1172,7 @@ mod tests { #[test] fn converts_a_mixed_kml_with_source_provenance_when_gdal_is_installed() { use crate::source::FeatureSource; - if !usable() { + if !test_runs().unwrap() { return; } let dir = std::env::temp_dir().join(format!("rustgis-gdal-test-{}", std::process::id())); @@ -1231,7 +1237,7 @@ mod tests { /// Both a new conversion and a cache hit must say how many source features were lost. #[test] fn conversion_reports_empty_polygons_left_out_but_not_clean_input() { - if !usable() { + if !test_runs().unwrap() { return; } let dir = tempfile::tempdir().unwrap(); @@ -1281,7 +1287,7 @@ mod tests { /// the conversion cache trusts while making the source unreadable by its allowed driver. #[test] fn reused_conversion_skips_listing_and_keeps_the_source_count() { - if !usable() { + if !test_runs().unwrap() { return; } let dir = tempfile::tempdir().unwrap(); @@ -1332,7 +1338,7 @@ mod tests { #[test] fn fresh_conversion_reports_dropped_dimensions_but_not_for_clean_xy_data() { - if !usable() { + if !test_runs().unwrap() { return; } let dir = std::env::temp_dir().join(format!("rustgis-gdal-fresh-dimensions-{}", std::process::id())); @@ -1389,7 +1395,7 @@ mod tests { #[test] fn fresh_csv_diagnostics_count_repeated_overflows_without_claiming_feature_loss() { - if !usable() { + if !test_runs().unwrap() { return; } let dir = tempfile::tempdir().unwrap(); @@ -1425,7 +1431,7 @@ mod tests { #[test] fn fresh_selected_family_reports_other_geometries_but_not_missing_or_matching_geometries() { - if !usable() { + if !test_runs().unwrap() { return; } let dir = tempfile::tempdir().unwrap(); @@ -1518,7 +1524,7 @@ mod tests { #[test] fn fresh_generic_layer_reports_only_selected_features_with_dropped_dimensions() { - if !usable() { + if !test_runs().unwrap() { return; } let dir = tempfile::tempdir().unwrap(); @@ -1553,7 +1559,7 @@ mod tests { #[test] fn generic_dimension_count_includes_measures_and_quotes_layer_names() { - if !usable() { + if !test_runs().unwrap() { return; } let dir = tempfile::tempdir().unwrap(); diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 6d2ff4c93c..9bee23d89b 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -6392,7 +6392,7 @@ fn a_file_inside_a_geodatabase_adds_the_geodatabase() { let gdb = dir.join("roads.gdb"); let table = gdb.join("a00000001.gdbtable").display().to_string(); let mut s = Session::new(Project::default()); - if rustgis_data::source::gdal::available() { + if rustgis_data::source::gdal::test_runs().unwrap() { let geojson = dir.join("cities.geojson"); std::fs::write( &geojson, @@ -23096,7 +23096,7 @@ fn any_command_editing_a_streamed_layer_is_undone() { #[cfg(not(target_arch = "wasm32"))] #[test] fn gdal_formats_open_when_gdal_is_installed() { - if !rustgis_data::source::gdal::available() { + if !rustgis_data::source::gdal::test_runs().unwrap() { return; } let dir = std::env::temp_dir().join(format!("rustgis-engine-gdal-{}", std::process::id())); @@ -23193,7 +23193,7 @@ fn kml_and_gpx_add_as_layers() { fn duckdb_queries_and_databases() { let mut s = Session::new(Project::default()); let query = "SELECT 'a' AS name, ST_Point(7, 45) AS geom UNION ALL SELECT 'b', ST_GeomFromText('LINESTRING(7 45, 8 46)')"; - if !rustgis_data::source::duckdb::available() { + if !rustgis_data::source::duckdb::test_runs().unwrap() { let e = s.run("layer.addSql", &json!({"sql": query})).unwrap_err(); assert!(e.contains("need DuckDB"), "{e}"); let e = s.run("layer.addData", &json!({"path": "/nowhere/x.duckdb"})).unwrap_err(); @@ -23445,7 +23445,7 @@ fn split_sources_keep_their_points_on_top() { #[test] fn postgres_databases() { let Ok(conn) = std::env::var("RUSTGIS_TEST_POSTGRES") else { return }; - if !rustgis_data::source::duckdb::available() { + if !rustgis_data::source::duckdb::test_runs().unwrap() { return; } let mut s = Session::new(Project::default()); @@ -24477,7 +24477,7 @@ fn jpeg2000_from_a_web_address() { assert_eq!(named("https://x.org/api/tile?f=jp2", jp2_box).unwrap(), "tile.jp2"); assert_eq!(named("https://x.org/", &codestream).unwrap(), "data.j2k"); assert!(named("https://x.org/api/tile", br#""#).unwrap_err().contains("not a data format")); - if !rustgis_data::raster::gdal::available() { + if !rustgis_data::raster::gdal::test_runs().unwrap() { let jp2 = serve(jp2_box, 4); for path in ["TCI.jp2", "api/tile"] { let e = s.run("layer.addUrl", &json!({"url": format!("{jp2}/{path}")})).unwrap_err(); @@ -25056,7 +25056,10 @@ fn spreadsheets_feeds_landxml_and_polylines() { #[test] fn gdal_rasters_reopen_with_their_choices() { // Found as the app finds it (the PATH, or RUSTGIS_GDAL_BIN). - let Some(translate) = rustgis_data::source::gdal::program("gdal_translate") else { return }; + if !rustgis_data::raster::gdal::test_runs().unwrap() { + return; + } + let translate = rustgis_data::source::gdal::program("gdal_translate").unwrap(); let dir = std::env::temp_dir().join(format!("rustgis-gdal-reopen-{}", std::process::id())); let _ = std::fs::remove_dir_all(&dir); std::fs::create_dir_all(&dir).unwrap(); @@ -31002,7 +31005,7 @@ fn geocoding_skips_addresses_too_long_for_the_server() { fn sql_workspace_rows_and_schema() { let mut s = Session::new(Project::default()); assert!(s.run("sql.query", &json!({})).is_err()); - if !rustgis_data::source::duckdb::available() { + if !rustgis_data::source::duckdb::test_runs().unwrap() { assert!(s.run("sql.query", &json!({"sql": "SELECT 1"})).unwrap_err().contains("need DuckDB")); return; } @@ -59358,7 +59361,7 @@ fn a_save_names_a_layer_and_its_table_once_when_they_are_the_same() { #[cfg(not(target_arch = "wasm32"))] #[test] fn a_duckdb_result_names_its_layer_in_its_date_notices() { - if !rustgis_data::source::duckdb::available() { + if !rustgis_data::source::duckdb::test_runs().unwrap() { eprintln!("skipped: DuckDB isn't installed"); return; } diff --git a/crates/engine/src/tests/sources_own.rs b/crates/engine/src/tests/sources_own.rs index b6cde3e7fe..a1d162ecab 100644 --- a/crates/engine/src/tests/sources_own.rs +++ b/crates/engine/src/tests/sources_own.rs @@ -32,7 +32,7 @@ fn first_point(s: &Session, id: u32) -> rustgis_geom::Coord { #[test] fn files_gdal_reads_are_held_in_their_own_system() { use rustgis_data::source::gdal; - if !gdal::available() { + if !gdal::test_runs().unwrap() { return; } let d = dir("gdal"); @@ -72,7 +72,7 @@ fn files_gdal_reads_are_held_in_their_own_system() { /// coordinates as the query gives them. #[test] fn duckdb_results_are_held_in_their_own_system() { - if !rustgis_data::source::duckdb::available() { + if !rustgis_data::source::duckdb::test_runs().unwrap() { return; } let lv95 = Crs::from_epsg(2056).unwrap(); diff --git a/crates/engine/tests/integration/portable_projects/reload.rs b/crates/engine/tests/integration/portable_projects/reload.rs index 92eb7d1f04..894e5b3588 100644 --- a/crates/engine/tests/integration/portable_projects/reload.rs +++ b/crates/engine/tests/integration/portable_projects/reload.rs @@ -569,7 +569,7 @@ fn reload_reconverts_original_gdal_folder_and_accepts_its_declared_empty_table() data::source::gdal, map::source::{GdalOrigin, SourceLayer}, }; - if !gdal::usable() { + if !gdal::test_runs().unwrap() { return; } let f = Fixture::new("reload-gdal-folder"); @@ -721,7 +721,7 @@ fn reload_reconverts_original_gdal_folder_and_accepts_its_declared_empty_table() #[test] fn reload_reconverts_duckdb_table_and_keeps_only_its_original_geometry_branch() { use rustgis_engine::data::source::duckdb; - if !duckdb::available() { + if !duckdb::test_runs().unwrap() { return; } let f = Fixture::new("reload-duckdb"); @@ -833,7 +833,7 @@ fn saved_gdal_conversion_restores_fresh_data_and_loss_notes_despite_an_unchanged data::source::{Family, gdal}, map::source::{GdalOrigin, SourceLayer}, }; - if !gdal::usable() { + if !gdal::test_runs().unwrap() { return; } let f = Fixture::new("restore-gdal-signature"); @@ -920,7 +920,7 @@ fn saved_gdal_conversion_restores_fresh_data_and_loss_notes_despite_an_unchanged #[test] fn saved_duckdb_conversion_restores_fresh_selected_family_despite_an_unchanged_signature() { use rustgis_engine::data::source::duckdb; - if !duckdb::available() { + if !duckdb::test_runs().unwrap() { return; } let f = Fixture::new("restore-duckdb-signature"); @@ -1013,7 +1013,7 @@ fn reload_duckdb_sql(path: &Path, statement: &str) { #[test] fn duckdb_reload_reports_other_family_rows_only_for_mixed_tables() { use rustgis_engine::data::source::duckdb; - if !duckdb::available() { + if !duckdb::test_runs().unwrap() { return; } let f = Fixture::new("reload-duckdb-family-notice"); @@ -1043,7 +1043,7 @@ fn duckdb_reload_reports_other_family_rows_only_for_mixed_tables() { #[test] fn duckdb_repair_refuses_other_family_only_tables_while_reload_installs_an_empty_branch() { use rustgis_engine::data::source::{Family, duckdb}; - if !duckdb::available() { + if !duckdb::test_runs().unwrap() { return; } for (family, geometry, dimension, left_out) in @@ -1332,7 +1332,7 @@ fn saved_conversion_cannot_borrow_another_sessions_reload_workspace_when_origina #[test] fn load_all_after_empty_duckdb_reload_exports_a_point_geopackage() { use rustgis_engine::data::source::duckdb; - if !duckdb::available() { + if !duckdb::test_runs().unwrap() { return; } let f = Fixture::new("reload-duckdb-empty-export"); @@ -1358,7 +1358,7 @@ fn load_all_after_empty_duckdb_reload_exports_a_point_geopackage() { #[test] fn direct_export_after_empty_duckdb_reload_is_a_point_geopackage() { use rustgis_engine::data::source::duckdb; - if !duckdb::available() { + if !duckdb::test_runs().unwrap() { return; } let f = Fixture::new("reload-duckdb-empty-direct-export"); @@ -1383,7 +1383,7 @@ fn project_open_reports_fresh_conversion_losses_once_per_kind_but_not_clean_conv data::source::{Family, gdal}, map::source::{GdalOrigin, SourceLayer}, }; - if !gdal::usable() { + if !gdal::test_runs().unwrap() { return; } for layer_count in [1, 2] { @@ -1461,7 +1461,7 @@ fn project_open_sums_counted_conversion_losses_across_layers_and_keeps_single_la data::source::{Family, gdal}, map::source::{GdalOrigin, SourceLayer}, }; - if !gdal::usable() { + if !gdal::test_runs().unwrap() { return; } for layer_count in [1, 2, 3] { @@ -1528,7 +1528,7 @@ fn reload_generic_gdal_layer_reports_selected_zm_loss_but_not_xy_or_other_famili data::source::{Family, gdal}, map::source::{GdalOrigin, SourceLayer}, }; - if !gdal::usable() { + if !gdal::test_runs().unwrap() { return; } let f = Fixture::new("reload-gdal-generic-dimensions"); diff --git a/docs/contributing.md b/docs/contributing.md index facdaa1c45..e4044fa502 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -337,6 +337,16 @@ it locally, download the files listed there into one folder, check them with `sh the checksums beside them, and run `RUSTGIS_WORKFLOW_DATA= cargo test -p rustgis-engine --test integration workflows:: -- --ignored`. +### Tests that need GDAL or DuckDB + +A test that runs GDAL or DuckDB is skipped where the program isn't installed. It starts with +`if !gdal::test_runs().unwrap() { return; }` (or `duckdb::test_runs()`, or `raster::gdal::test_runs()` +for GDAL's raster programs), not with `available()` or `usable()`. CI's `GDAL and DuckDB` job +installs both and sets `RUSTGIS_REQUIRE_GDAL` and `RUSTGIS_REQUIRE_DUCKDB`, so there a missing +program fails the test instead of skipping it. The usual test jobs install neither, so they keep +covering what a user without them sees. To run them the same way locally: +`RUSTGIS_REQUIRE_GDAL=1 RUSTGIS_REQUIRE_DUCKDB=1 cargo test -p rustgis-data -p rustgis-engine`. + ### Performance regressions When changing a large-data path, add a work budget to an ordinary test. Count what the operation From 705db13a230f92029e4da9df3f602a39ced2a9e1 Mon Sep 17 00:00:00 2001 From: mavrick Date: Tue, 24 Nov 2026 14:14:21 -0600 Subject: [PATCH 2/2] ci: report the GDAL and DuckDB job's flaky tests, and say why it runs both packages whole A fixture GDAL can't make fails the test instead of skipping it, and the switch's message covers a GDAL too old as well as one missing. --- .github/workflows/ci.yml | 41 ++++++++++++++++++++++++++---- crates/data/src/raster/gdal.rs | 4 +-- crates/data/src/source/external.rs | 2 +- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e3017ca266..66843bab2e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -413,7 +413,10 @@ jobs: # program, so here RUSTGIS_REQUIRE_GDAL and RUSTGIS_REQUIRE_DUCKDB make a missing one fail them # instead (`test_runs` in rustgis-data). The `test` job installs neither and keeps covering what a # user without them sees. It runs the whole of rustgis-data and rustgis-engine, which hold those - # tests, when the run tests either; otherwise its steps skip and it passes. + # tests, when the run tests either; otherwise its steps skip and it passes. Whole on purpose: a + # filter on test names would miss a new test named otherwise, and with the programs installed + # other tests take the paths a user with them gets (a geodatabase read through GDAL when the + # built-in reader can't). It runs beside `test`, so it costs runner time, not the run's length. programs: name: GDAL and DuckDB needs: select @@ -423,8 +426,8 @@ jobs: CARGO_PROFILE_DEV_DEBUG: line-tables-only RUSTGIS_REQUIRE_GDAL: "1" RUSTGIS_REQUIRE_DUCKDB: "1" - # GDAL 3.8 is the oldest RustGIS converts with, and Ubuntu 24.04's. DuckDB's command line - # program, pinned by checksum. + # GDAL comes from the runner's packages (RustGIS needs 3.8 or later; the install step prints + # the version). DuckDB's command line program is pinned by checksum. DUCKDB_VERSION: 2.0.1 DUCKDB_SHA256: b676268be4d39e4e41a904442c9796c9914e645cc085c7505f048f2c992b5eca steps: @@ -469,9 +472,37 @@ jobs: if: steps.scope.outputs.run == 'true' with: tool: cargo-nextest@0.9.151 + - name: Clear the previous test report + if: steps.scope.outputs.run == 'true' + run: rm -f target/nextest/ci/junit.xml - name: Tests if: steps.scope.outputs.run == 'true' run: cargo nextest run -p rustgis-data -p rustgis-engine --locked --profile ci + # As in test-rust.yml: a test that passed only on a retry goes in the summary, and on a push to + # main to the `flaky` job. `test` skips these tests, so only this job can see them. + - name: Flaky tests + id: flaky + if: ${{ !cancelled() && steps.scope.outputs.run == 'true' }} + run: | + .github/scripts/flaky-tests.sh target/nextest/ci/junit.xml > flaky-programs.txt + if [ -s flaky-programs.txt ]; then + echo "found=true" >> "$GITHUB_OUTPUT" + echo "::warning::Tests that passed only on a retry with GDAL and DuckDB: see the job summary." + { + echo "### Flaky tests (GDAL and DuckDB)" + echo + echo "These failed and then passed on a retry, so the run did not fail. Each is a bug to fix." + echo + sed 's/^/- `/; s/$/`/' flaky-programs.txt + } >> "$GITHUB_STEP_SUMMARY" + fi + - name: Keep the flaky tests' names + if: ${{ !cancelled() && steps.flaky.outputs.found == 'true' && github.event_name == 'push' }} + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7 + with: + name: flaky-programs + path: flaky-programs.txt + retention-days: 1 # A test that failed and then passed on a retry (.config/nextest.toml) on a push to main gets an # issue, or a comment on its open one: a retry hides a flaky test from the run, not from us. A @@ -479,13 +510,13 @@ jobs: # issues and runs none of the repository's code. flaky: name: Flaky tests - needs: test + needs: [test, programs] if: ${{ !cancelled() && github.event_name == 'push' && github.repository == 'opengeos/RustGIS' }} runs-on: ubuntu-latest permissions: issues: write steps: - # One file a runner, flaky-.txt, each line a test (" "). + # One file a runner (and flaky-programs.txt from `programs`), each line a test (" "). - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8 with: pattern: flaky-* diff --git a/crates/data/src/raster/gdal.rs b/crates/data/src/raster/gdal.rs index 0a5d0ea43c..e3da8bfa0c 100644 --- a/crates/data/src/raster/gdal.rs +++ b/crates/data/src/raster/gdal.rs @@ -990,9 +990,7 @@ mod tests { .arg(&img) .status() .is_ok_and(|s| s.success()); - if !ok { - return; - } + assert!(ok, "gdal_translate couldn't make the ERDAS Imagine fixture"); let cache = dir.join("cache"); let captured = crate::provenance::Capture::start(); let c = convert_in(&cache, &img, None, None, None).unwrap(); diff --git a/crates/data/src/source/external.rs b/crates/data/src/source/external.rs index 8b4d078840..69d892db8c 100644 --- a/crates/data/src/source/external.rs +++ b/crates/data/src/source/external.rs @@ -36,7 +36,7 @@ pub(crate) fn test_runs(require: &str, what: &str, here: bool) -> std::result::R if here { Ok(true) } else if std::env::var_os(require).is_some_and(|v| !v.is_empty()) { - Err(format!("{require} is set, but {what} isn't installed")) + Err(format!("{require} is set, but {what} wasn't found")) } else { Ok(false) }