京王バスGTFSのダウンロード404を修正#1602
Conversation
ODPTのバージョン付きファイルエンドポイント (files/odpt/KeioBus/AllLines.zip) は `date` セレクタが必須で、 省略すると有効なトークンを付けても HTTP 404 を返す。京王バスの フィードURLに `?date=current` を付与し、常に「本日有効なダイヤ」の GTFSを取得するようにする(同一エンドポイント形式の宇野バスで date=current が200・正常なGTFS zipを返すこと、date省略で404に なることを確認済み)。 あわせて以下を修正: - `gtfs_download_url` のクエリ結合バグを修正。URLに既にクエリ 文字列がある場合は `&` で `acl:consumerKey` を連結する (純粋関数 `append_consumer_key` に切り出しユニットテストを追加)。 これが無いと `...?date=current?acl:consumerKey=...` と不正な URLになる - 1フィードのダウンロード失敗を非致命化。従来は京王の404が全 フィード(Toei/Seibu含む)のインポートを巻き添えで中断させて いたが、該当フィードのみスキップして他は継続するようにする (ディレクトリ欠落フィードは後続の取り込みループが元々スキップ) - `test_gtfs_feeds` のURL期待値を更新 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SfBspXi8MZnEjwrAxvbBzz
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughODPT GTFSの取得URLにクエリ処理を追加し、Keio URLを更新した。ダウンロード失敗時は部分データを削除し、対象フィードをスキップして処理を継続する。関連するテストも更新した。 ChangesGTFSインポート改善
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested labels: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 5
🧹 Nitpick comments (1)
stationapi/src/import.rs (1)
3174-3192: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win予約文字を含むトークンの回帰テストを追加してください。
現在のテストは区切り文字だけを検証しており、
TOKEN&x=y、TOKEN#fragment、TOKEN+Aのような値が壊れる問題を検出できません。エンコード処理を追加した後の期待値を固定してください。🤖 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 3174 - 3192, Extend test_append_consumer_key with regression cases for tokens containing reserved characters such as &, #, and +. Assert the expected URL uses the encoded token values after append_consumer_key processes them, while preserving the existing query-separator coverage.
🤖 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.
Inline comments:
In `@stationapi/src/import.rs`:
- Around line 446-451: Update the download_gtfs flow so GTFS archives are
extracted into a temporary directory and renamed to the final feed directory
only after extraction succeeds. On download or extraction failure, remove any
temporary/partial directory so subsequent existence checks do not treat the feed
as valid; preserve the existing warning and continuation behavior in the result
handling.
- Around line 446-451:
ダウンロード失敗時に既存の該当フィードデータを削除・空状態でコミットしないよう、GTFS更新フローの失敗フィード処理を変更してください。フィード単位で成功データだけを置き換えるか、完全なスナップショットを取得できない場合は全テーブル削除とコミットを抑止し、失敗時も最後に成功したデータを保持してください。
- Around line 447-450: Update the download-failure warning in the import flow to
avoid logging the raw reqwest error, which may contain a tokenized URL; log only
feed.name or a sanitized error with its URL removed while preserving the
existing skip-and-continue behavior.
- Around line 443-445: Update the per-feed handling around
spawn_blocking(...).await in import_gtfs so JoinError from panic or cancellation
is logged for that feed and then skipped with continue, rather than propagated
with ?. Preserve normal download result handling and allow subsequent feeds to
proceed.
- Around line 311-318: Update append_consumer_key so token is URL-encoded as a
query value before constructing the URL, while preserving the existing separator
selection and acl:consumerKey parameter name. Use the project’s existing
query-encoding utility if available.
---
Nitpick comments:
In `@stationapi/src/import.rs`:
- Around line 3174-3192: Extend test_append_consumer_key with regression cases
for tokens containing reserved characters such as &, #, and +. Assert the
expected URL uses the encoded token values after append_consumer_key processes
them, while preserving the existing query-separator coverage.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: d0d30625-fe60-48a0-aac4-8591c0b81726
📒 Files selected for processing (1)
stationapi/src/import.rs
CodeRabbitのレビュー指摘のうち、妥当かつ小さいものを対応: - ダウンロードタスクの JoinError(パニック/キャンセル)も非致命化。 従来は spawn_blocking の `?` 伝播で全フィードのインポートが中断 していたが、該当フィードのみログしてスキップし他は継続する - ダウンロード/展開が途中失敗した際に部分生成ディレクトリを削除。 後続の存在確認で不完全なデータを有効フィードとして取り込むのを防ぐ (download_gtfs をラッパ + download_and_extract_gtfs に分割) - reqwest エラーから `without_url()` でリクエストURLを除去し、 `acl:consumerKey` トークンがログや伝播エラーに漏れないようにする Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SfBspXi8MZnEjwrAxvbBzz
|
@coderabbitai approve |
✅ Action performedComments resolved and changes approved. |
概要
京王バス GTFS の起動時ダウンロードが HTTP 404 で失敗していた問題を修正します。
原因は、ODPT のバージョン付きファイルエンドポイント
files/odpt/KeioBus/AllLines.zipがdateセレクタを必須とする点でした。#1601 で登録した URL にはdateが無く、有効なODPT_ACCESS_TOKENを付けても 404 になっていました。フィード URL に?date=current(本日有効なダイヤ)を付与して解消します。同一形式のエンドポイントを無認証で提供する宇野バスで挙動を実証済みです。
.../odpt/UnoBus/AllLines.zip?date=current.../odpt/UnoBus/AllLines.zip(date なし)not found(京王と同症状)変更の種類
変更内容
?date=currentを付与し、常に現行ダイヤの GTFS を取得するよう修正(date省略時は 404)gtfs_download_urlのクエリ結合バグを修正。URL に既存のクエリ文字列がある場合は&でacl:consumerKeyを連結する(純粋関数append_consumer_keyに切り出し、?/&双方のユニットテストを追加)。修正前は...?date=current?acl:consumerKey=...と不正な URL になるtest_gtfs_feedsの URL 期待値を更新テスト
cargo fmt --all -- --checkが通ることcargo clippy -- -D warningsが通ることcargo test(SQLX_OFFLINE=true)が通ること補足: 本環境に有効な
ODPT_ACCESS_TOKENが無いため、京王の認証付き実ダウンロード自体は未検証です。エンドポイント形式・date=currentの挙動・URL 整形は上記の宇野バスでの実証とユニットテストで確認しています。関連Issue
スクリーンショット(任意)
Generated by Claude Code
Summary by CodeRabbit
新機能
不具合修正
テスト