build_stop_route_mapping のSQL回帰テスト基盤を整備#1519
Conversation
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthrough
Changesbuild_stop_route_mapping 回帰テストスイート
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
stationapi/src/import.rs (1)
3219-3221: ⚡ Quick win失敗時でも
drop_schemaが必ず走る順序にしてください。
build_stop_route_mapping(...).await.unwrap()が先に失敗するとクリーンアップがスキップされ、失敗テスト時のスキーマ残骸が増えます。Resultを保持して先にdrop_schemaを実行してからexpectする形にすると防げます。差分例(1テスト分、同パターンを他5テストにも適用)
- let mapping = build_stop_route_mapping(&mut conn).await.unwrap(); - let actual = collect_route(&mapping, "IKE86"); - stop_route_mapping_fixtures::drop_schema(&mut conn, &schema).await; + let mapping_result = build_stop_route_mapping(&mut conn).await; + stop_route_mapping_fixtures::drop_schema(&mut conn, &schema).await; + let mapping = mapping_result.expect("build_stop_route_mapping should succeed"); + let actual = collect_route(&mapping, "IKE86");Also applies to: 3276-3278, 3331-3333, 3402-3404, 3452-3454, 3504-3506
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@stationapi/src/import.rs` around lines 3219 - 3221, The cleanup call drop_schema must run even if build_stop_route_mapping fails: change the code to capture the Result from build_stop_route_mapping into a variable (e.g., let mapping_res = build_stop_route_mapping(&mut conn).await;), then call stop_route_mapping_fixtures::drop_schema(&mut conn, &schema).await before unwrapping or expect-ing the result, and finally unwrap/expect mapping_res to get mapping (used by collect_route). Apply the same pattern for the other occurrences around lines using build_stop_route_mapping, drop_schema, and collect_route.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@stationapi/src/import.rs`:
- Around line 3219-3221: The cleanup call drop_schema must run even if
build_stop_route_mapping fails: change the code to capture the Result from
build_stop_route_mapping into a variable (e.g., let mapping_res =
build_stop_route_mapping(&mut conn).await;), then call
stop_route_mapping_fixtures::drop_schema(&mut conn, &schema).await before
unwrapping or expect-ing the result, and finally unwrap/expect mapping_res to
get mapping (used by collect_route). Apply the same pattern for the other
occurrences around lines using build_stop_route_mapping, drop_schema, and
collect_route.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 6f7a3038-1d1a-4fd1-a24f-59a5f9764b26
📒 Files selected for processing (1)
stationapi/src/import.rs
概要
stationapi/src/import.rsのbuild_stop_route_mapping()(バス経路順序を決定する SQL パイプライン) に対する回帰テスト基盤を整備した。PR #1511 / #1512 / #1515 で繰り返し調整が入っている関数だが、これまで実 GTFS に近い形で検証する単体テストが存在しなかった。変更の種類
変更内容
stationapi/src/import.rsの#[cfg(test)] mod testsにbuild_stop_route_mapping用の回帰テストを追加 (516 行)mod stop_route_mapping_fixturesとして、隔離スキーマ生成・最小 GTFS テーブル構築 (gtfs_stops/gtfs_trips/gtfs_stop_times)・fixture 投入ヘルパを実装SET search_pathで切り替えるため複数テストを並列実行可能test_build_stop_route_mapping_ike86_canonical_shape: 池86 風多バリアント系統で stop 数が最多の shape が canonical に選ばれるtest_build_stop_route_mapping_canonical_shape_direction_tiebreak: stops/dist が並ぶ場合direction_id=0がタイブレーク勝利test_build_stop_route_mapping_main_trip_prefers_direction_zero: canonical shape を共有する trip 群からdirection_id=0を main trip に選ぶtest_build_stop_route_mapping_variant_chain_recursive_interpolation: variant-only 連鎖を LAG/LEAD + 再帰 CTE で補間test_build_stop_route_mapping_null_shape_dist_traveled:shape_dist_traveled全 NULL でも stops 数フォールバックで動作test_build_stop_route_mapping_parent_station_grouping: 同一物理停留所の複数ポールをCOALESCE(parent_station, stop_id)で正しく集約#[cfg_attr(not(feature = "integration-tests"), ignore)]でゲート。既存 CI (cargo testのみ) には影響を与えないTEST_DATABASE_URL=... cargo test -p stationapi --features integration-tests build_stop_route_mapping)テスト
cargo fmt --all -- --checkが通ることcargo clippy -- -D warningsが通ることcargo test(SQLX_OFFLINE=true)が通ること追加で、
integration-testsfeature 有効時に新規 6 テストすべてが pass することをローカル Postgres (Dockerstationapi-psql-1) で確認済み:関連Issue
Closes #1514
スクリーンショット(任意)
Summary by CodeRabbit