Modern Apps git

← Modern-Apps.git

maps: pin the TRX2 reader to a real ingester fixture

Commit
c3862a319a8cd892b83944f8ccbe19f9f5c03e88
Author
vayun-mathur <[email protected]>
When
2026-08-20 22:02 UTC (3 months ago)
Parents
5bdcba2

Diff

maps/src/main/rust/src/transit.rs
diff --git a/maps/src/main/rust/src/transit.rs b/maps/src/main/rust/src/transit.rsindex 87c3de6609..08bbb5f6da 100644--- a/maps/src/main/rust/src/transit.rs+++ b/maps/src/main/rust/src/transit.rs@@ -2554,4 +2554,60 @@ mod tests {         };         assert!(plan(&idx, 37.700, -122.400, 37.720, -122.400, 25_000, sched(sunday)).is_none());     }++    /// The hand-built harness above is an independent *reimplementation* of the+    /// writer, which is what makes it a useful cross-check — but it also means both+    /// sides could drift from the real producer together. This reads a pack+    /// actually emitted by `scripts/maps/gtfs_ingest`, so the two crates are pinned+    /// to each other rather than to a shared assumption.+    ///+    /// Regenerate after any format change (from the repo root):+    ///+    /// ```text+    /// cargo run --release --manifest-path scripts/maps/gtfs_ingest/Cargo.toml -- \+    ///     maps/src/main/rust/test_fixtures mini \+    ///     mini=scripts/maps/gtfs_ingest/test_fixtures/mini_feed+    /// ```+    ///+    /// then delete the `mini.transit.json` manifest it writes alongside. The bytes+    /// are a captured artefact, not a reproducible one: the ingester groups trips+    /// out of a `HashMap`, so route order varies between runs. The assertions are+    /// therefore semantic, which is what catches drift anyway.+    #[test]+    fn reads_a_pack_written_by_the_real_ingester() {+        let bytes = include_bytes!("../test_fixtures/mini.transit").to_vec();+        let idx = TransitIndex::from_bytes(bytes).expect("the committed fixture parses");++        // The fixture feed: 3 stops on one route, two trips, a shape detouring east+        // between each pair of stops.+        assert_eq!(idx.stop_count, 3);+        assert_eq!(idx.route_count, 1);+        assert_eq!(idx.timezone_at(37.700, -122.400), "America/Los_Angeles");++        let legs = plan(&idx, 37.700, -122.400, 37.720, -122.400, 25_000, sched(wednesday()))+            .expect("a journey exists");+        let ride = legs.iter().find(|l| l.kind == LegKind::Ride).expect("a ride leg");+        assert_eq!(ride.name, "N");+        assert_eq!(ride.feed, "mini");+        assert_eq!(ride.from_stop, "Alpha");+        assert_eq!(ride.to_stop, "Gamma");+        assert_eq!(ride.dep_secs, 28_800);+        assert_eq!(ride.arr_secs, 29_400);+        assert_eq!(ride.stop_count, 2);++        // The v4 sections the ingester wrote must decode into real geometry: more+        // vertices than the three stops, and a longer path than the straight line.+        assert!(+            ride.coords.len() > 6,+            "expected shape geometry, got {} coords",+            ride.coords.len()+        );+        let lons: Vec<f64> = ride.coords.chunks(2).map(|c| c[0]).collect();+        assert!(+            lons.iter().any(|&lon| lon > -122.395),+            "the eastward detour is missing: {lons:?}"+        );+        let crow = dist_m(37.700, -122.400, 37.720, -122.400);+        assert!(ride.dist_m > crow, "shape distance {} must exceed {crow}", ride.dist_m);+    } }
maps/src/main/rust/test_fixtures/mini.transit
diff --git a/maps/src/main/rust/test_fixtures/mini.transit b/maps/src/main/rust/test_fixtures/mini.transitnew file mode 100644index 0000000000..9ae7ba0b3bBinary files /dev/null and b/maps/src/main/rust/test_fixtures/mini.transit differ
scripts/maps/gtfs_ingest/README.md
diff --git a/scripts/maps/gtfs_ingest/README.md b/scripts/maps/gtfs_ingest/README.mdindex c4c32e7fa3..941fc2f169 100644--- a/scripts/maps/gtfs_ingest/README.md+++ b/scripts/maps/gtfs_ingest/README.md@@ -147,6 +147,24 @@ blobs and plans over them. The two crates cannot link to each other, so each codec is exercised by an independent counterpart — which is what catches drift in a format whose spec lives in a doc comment. +Because both halves are *reimplementations*, they could also drift together. So+`test_fixtures/mini_feed/` (a three-stop feed with a shape) is ingested into+`maps/src/main/rust/test_fixtures/mini.transit`, committed, and read back by+`transit.rs::reads_a_pack_written_by_the_real_ingester`. That pins the two crates+to each other rather than to a shared assumption. Regenerate it after any format+change, from the repo root:++```sh+cargo run --release --manifest-path scripts/maps/gtfs_ingest/Cargo.toml -- \+    maps/src/main/rust/test_fixtures mini \+    mini=scripts/maps/gtfs_ingest/test_fixtures/mini_feed+rm maps/src/main/rust/test_fixtures/mini.transit.json+```++The bytes are a captured artefact, not a reproducible one — trips are grouped out+of a `HashMap`, so route order varies between runs. The device-side assertions are+semantic for that reason.+ ## Known limitations  - Transfers use a straight-line ≤400 m footpath heuristic (not the road graph);
scripts/maps/gtfs_ingest/test_fixtures/mini_feed/agency.txt
diff --git a/scripts/maps/gtfs_ingest/test_fixtures/mini_feed/agency.txt b/scripts/maps/gtfs_ingest/test_fixtures/mini_feed/agency.txtnew file mode 100644index 0000000000..51e5517aae--- /dev/null+++ b/scripts/maps/gtfs_ingest/test_fixtures/mini_feed/agency.txt@@ -0,0 +1,2 @@+agency_id,agency_name,agency_url,agency_timezone+MINI,Mini Transit,https://example.invalid,America/Los_Angeles
scripts/maps/gtfs_ingest/test_fixtures/mini_feed/calendar.txt
diff --git a/scripts/maps/gtfs_ingest/test_fixtures/mini_feed/calendar.txt b/scripts/maps/gtfs_ingest/test_fixtures/mini_feed/calendar.txtnew file mode 100644index 0000000000..7840653783--- /dev/null+++ b/scripts/maps/gtfs_ingest/test_fixtures/mini_feed/calendar.txt@@ -0,0 +1,2 @@+service_id,monday,tuesday,wednesday,thursday,friday,saturday,sunday,start_date,end_date+WK,1,1,1,1,1,0,0,20240101,20241231
scripts/maps/gtfs_ingest/test_fixtures/mini_feed/routes.txt
diff --git a/scripts/maps/gtfs_ingest/test_fixtures/mini_feed/routes.txt b/scripts/maps/gtfs_ingest/test_fixtures/mini_feed/routes.txtnew file mode 100644index 0000000000..e9d9ae1426--- /dev/null+++ b/scripts/maps/gtfs_ingest/test_fixtures/mini_feed/routes.txt@@ -0,0 +1,2 @@+route_id,route_short_name,route_long_name,route_type,route_color+R1,N,North Line,0,0000FF
scripts/maps/gtfs_ingest/test_fixtures/mini_feed/shapes.txt
diff --git a/scripts/maps/gtfs_ingest/test_fixtures/mini_feed/shapes.txt b/scripts/maps/gtfs_ingest/test_fixtures/mini_feed/shapes.txtnew file mode 100644index 0000000000..3079d17c9f--- /dev/null+++ b/scripts/maps/gtfs_ingest/test_fixtures/mini_feed/shapes.txt@@ -0,0 +1,6 @@+shape_id,shape_pt_lat,shape_pt_lon,shape_pt_sequence,shape_dist_traveled+SH1,37.700,-122.400,1,0.0+SH1,37.705,-122.390,2,0.65+SH1,37.710,-122.400,3,1.3+SH1,37.715,-122.390,4,1.95+SH1,37.720,-122.400,5,2.6
scripts/maps/gtfs_ingest/test_fixtures/mini_feed/stop_times.txt
diff --git a/scripts/maps/gtfs_ingest/test_fixtures/mini_feed/stop_times.txt b/scripts/maps/gtfs_ingest/test_fixtures/mini_feed/stop_times.txtnew file mode 100644index 0000000000..271c5e2cac--- /dev/null+++ b/scripts/maps/gtfs_ingest/test_fixtures/mini_feed/stop_times.txt@@ -0,0 +1,7 @@+trip_id,stop_id,stop_sequence,arrival_time,departure_time,shape_dist_traveled+T1,S1,1,08:00:00,08:00:00,0.0+T1,S2,2,08:05:00,08:06:00,1.3+T1,S3,3,08:10:00,08:10:00,2.6+T2,S1,1,09:00:00,09:00:00,0.0+T2,S2,2,09:05:00,09:06:00,1.3+T2,S3,3,09:10:00,09:10:00,2.6
scripts/maps/gtfs_ingest/test_fixtures/mini_feed/stops.txt
diff --git a/scripts/maps/gtfs_ingest/test_fixtures/mini_feed/stops.txt b/scripts/maps/gtfs_ingest/test_fixtures/mini_feed/stops.txtnew file mode 100644index 0000000000..8bc4169839--- /dev/null+++ b/scripts/maps/gtfs_ingest/test_fixtures/mini_feed/stops.txt@@ -0,0 +1,4 @@+stop_id,stop_name,stop_lat,stop_lon,stop_code+S1,Alpha,37.700,-122.400,A1+S2,Beta,37.710,-122.400,B2+S3,Gamma,37.720,-122.400,C3
scripts/maps/gtfs_ingest/test_fixtures/mini_feed/trips.txt
diff --git a/scripts/maps/gtfs_ingest/test_fixtures/mini_feed/trips.txt b/scripts/maps/gtfs_ingest/test_fixtures/mini_feed/trips.txtnew file mode 100644index 0000000000..fa50a04cbf--- /dev/null+++ b/scripts/maps/gtfs_ingest/test_fixtures/mini_feed/trips.txt@@ -0,0 +1,3 @@+route_id,service_id,trip_id,trip_headsign,shape_id+R1,WK,T1,Downtown,SH1+R1,WK,T2,Downtown,SH1