Skip to content

京王バスGTFSのダウンロード404を修正#1602

Merged
TinyKitten merged 2 commits into
devfrom
claude/keio-bus-support-mqlc0f
Jul 12, 2026
Merged

京王バスGTFSのダウンロード404を修正#1602
TinyKitten merged 2 commits into
devfrom
claude/keio-bus-support-mqlc0f

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Jul 12, 2026

Copy link
Copy Markdown
Member

概要

京王バス GTFS の起動時ダウンロードが HTTP 404 で失敗していた問題を修正します。

原因は、ODPT のバージョン付きファイルエンドポイント files/odpt/KeioBus/AllLines.zipdate セレクタを必須とする点でした。#1601 で登録した URL には date が無く、有効な ODPT_ACCESS_TOKEN を付けても 404 になっていました。フィード URL に ?date=current(本日有効なダイヤ)を付与して解消します。

同一形式のエンドポイントを無認証で提供する宇野バスで挙動を実証済みです。

URL 結果
.../odpt/UnoBus/AllLines.zip?date=current HTTP 200・約 533KB の正常な GTFS zip
.../odpt/UnoBus/AllLines.zip(date なし) HTTP 404 not found(京王と同症状)

変更の種類

  • バグ修正
  • 新機能
  • データの修正・追加
  • リファクタリング
  • ドキュメント
  • CI/CD
  • その他

変更内容

  • 京王バスのフィード URL に ?date=current を付与し、常に現行ダイヤの GTFS を取得するよう修正(date 省略時は 404)
  • gtfs_download_url のクエリ結合バグを修正。URL に既存のクエリ文字列がある場合は &acl:consumerKey を連結する(純粋関数 append_consumer_key に切り出し、? / & 双方のユニットテストを追加)。修正前は ...?date=current?acl:consumerKey=... と不正な URL になる
  • 1 フィードのダウンロード失敗を非致命化。従来は京王の 404 が Toei / 西武を含む全フィードのインポートを巻き添えで中断させていたが、該当フィードのみスキップして他フィードは継続するよう変更(ディレクトリ欠落フィードは後続の取り込みループが元々スキップする)
  • test_gtfs_feeds の URL 期待値を更新

テスト

  • cargo fmt --all -- --check が通ること
  • cargo clippy -- -D warnings が通ること
  • cargo testSQLX_OFFLINE=true)が通ること

補足: 本環境に有効な ODPT_ACCESS_TOKEN が無いため、京王の認証付き実ダウンロード自体は未検証です。エンドポイント形式・date=current の挙動・URL 整形は上記の宇野バスでの実証とユニットテストで確認しています。

関連Issue

スクリーンショット(任意)


Generated by Claude Code

Summary by CodeRabbit

  • 新機能

    • GTFS取得URLのクエリ生成を見直し、日付指定やトークン付きクエリをURL形式に応じて適切に付与できるよう改善しました。
  • 不具合修正

    • 取得・展開に失敗した場合でも、対象フィードのみスキップして他のフィードの取り込みを継続します。
    • 失敗時に部分的に作成されたデータを後片付けし、エラー情報へのトークン混入を防ぎます。
  • テスト

    • 期待値とクエリ有無の動作確認を追加・更新しました。

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
@TinyKitten TinyKitten self-assigned this Jul 12, 2026
@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 312d8be4-5112-42d0-ac68-edfb6790ae3c

📥 Commits

Reviewing files that changed from the base of the PR and between bc0976c and 6137327.

📒 Files selected for processing (1)
  • stationapi/src/import.rs

📝 Walkthrough

Walkthrough

ODPT GTFSの取得URLにクエリ処理を追加し、Keio URLを更新した。ダウンロード失敗時は部分データを削除し、対象フィードをスキップして処理を継続する。関連するテストも更新した。

Changes

GTFSインポート改善

Layer / File(s) Summary
GTFS URL生成と検証
stationapi/src/import.rs
Keio URLに date=current を追加し、クエリの有無に応じて acl:consumerKey を付与する処理とテストを更新した。
フィード単位のダウンロード継続
stationapi/src/import.rs
ダウンロード失敗時に部分展開ディレクトリを削除し、エラーからURLを除外する。失敗したフィードを警告してスキップし、処理を継続する。

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested labels: deploy-dev, fix

Poem

URLに鍵をそっと添え
けいおう列車も出発だ
ひとつの便が転んでも
仲間の便は走りゆく
ぴょんと進むよ、GTFS!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed 主な変更点である京王バスGTFSの404修正を簡潔に表しており、内容と一致しています。
Description check ✅ Passed 概要・変更の種類・変更内容・テストが揃っており、テンプレート要件をほぼ満たしています。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/keio-bus-support-mqlc0f

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Nitpick comments (1)
stationapi/src/import.rs (1)

3174-3192: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

予約文字を含むトークンの回帰テストを追加してください。

現在のテストは区切り文字だけを検証しており、TOKEN&x=yTOKEN#fragmentTOKEN+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

📥 Commits

Reviewing files that changed from the base of the PR and between 2ea8022 and bc0976c.

📒 Files selected for processing (1)
  • stationapi/src/import.rs

Comment thread stationapi/src/import.rs
Comment thread stationapi/src/import.rs Outdated
Comment thread stationapi/src/import.rs Outdated
Comment thread stationapi/src/import.rs Outdated
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
@TinyKitten

Copy link
Copy Markdown
Member Author

@coderabbitai approve

@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Comments resolved and changes approved.

@TinyKitten TinyKitten merged commit a13b50a into dev Jul 12, 2026
12 checks passed
@TinyKitten TinyKitten deleted the claude/keio-bus-support-mqlc0f branch July 12, 2026 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants