fix(scrape): normalize Japan's relative/unencoded hrefs to the legacy URL - #193
Merged
Conversation
… URL prod確認の結果判明: japanese.simutrans.com の一覧ページ(?cmd=list)が 返す<a href>が、絶対URL+完全パーセントエンコード (https://.../index.php?Addon128%2FXxx)から、相対URL+非エンコードの スラッシュ(./?Addon128/Xxx)に変わっていた。FindUrls::filter()は絶対 URLの前方一致でしか判定しないため、全URLが例外なく弾かれ、例外も 出さずに毎回0件になっていた(raw_pages.updated_at は2024-11-26で 停止、以降ずっと無音で放置されていた)。 href を一度 urldecode() で生バイトに戻し、rawurlencode() で旧来と 同じ絶対URL形式に再構築してから既存の filter() に通すことで、相対/ 絶対・新旧いずれのエンコーディングでも同じ結果になるようにした。 これにより既存 raw_pages の url と一致し、重複行を作らず正しく upsert される。 あわせて filter() 内の「アドオン/」判定だけ :443 ポート指定が 抜けていた(他の3判定は :443 付き)コピペミスも修正。実データで 確認したところ、この判定漏れにより「アドオン/」単独名前空間の ページ(例: アドオン/例車20 等)が本来マッチすべきなのに常に除外 されていた。 実際の prod の一覧ページHTMLをローカルに取得し、修正後の FindUrls に通して動作確認済み(141件マッチ、既存 raw_pages 140件とほぼ一致)。 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
コードレビュー指摘への対応。 - 0件マッチ時に例外を投げ、ScrapeAction/ScrapeCommand の既存の失敗 検知・通知経路(report()→Discord、last_crawl据え置き)に乗せる。 一覧ページ構造が再び変わっても、今回のように21ヶ月気づかれない ことがないようにする。 - 「アドオン/」の :443 抜けコピペミス修正の回帰テストを追加。 - toFullUrl() に同一オリジン検証を追加。href のホストが japanese.simutrans.com 以外なら再構築せずそのまま返す(既存の filter() 側の絞り込みだけに依存しない)。 - Japan/Twitrans 双方の toFullUrl() に、実装が異なる理由を示す 相互参照コメントを追加。 上記の変更に伴い、ScrapeActionTest の Japan 向け Http::fake が空HTML のままだと新しい0件例外に引っかかるため、実在のアドオンリンクを含む レスポンスに差し替え。 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
japanese.simutrans.comの一覧ページ(?cmd=list)が返す<a href>が、絶対URL+完全パーセントエンコード形式から相対URL+非エンコードのスラッシュ形式に変わっていたFindUrls::filter()は絶対URLの前方一致でしか判定しないため、例外を投げることなく毎回0件になっていた(raw_pagesのupdated_atは2024-11-26で停止、以降ずっと無音で放置)urldecode()→rawurlencode()で正規化し、旧来と同じ絶対URL形式(https://japanese.simutrans.com:443/index.php?Addon128%2FXxx)に再構築してから既存filter()ロジックに通すようにした。相対/絶対・新旧いずれのエンコーディングでも同じ結果になり、既存raw_pagesのurlと一致するため重複行を作らないfilter()内の「アドオン/」判定だけ:443が抜けていたコピペミスも修正(実データで、この判定漏れにより「アドオン/」単独名前空間のページが常に除外されていたことを確認)Test plan
FindUrlsTestで相対URL正規化・旧絶対URLとの後方互換・除外ロジックを検証FindUrlsに通して動作確認(141件マッチ、既存raw_pages140件とほぼ一致)php artisan test --filter=Scrape全17件パスphpstan analyseエラーなしpint --testパス🤖 Generated with Claude Code