Skip to content

オートモードの終着前巻き戻りを防ぐ#5558

Merged
TinyKitten merged 1 commit intodevfrom
codex/fix-auto-mode-terminal-regression
Mar 10, 2026
Merged

オートモードの終着前巻き戻りを防ぐ#5558
TinyKitten merged 1 commit intodevfrom
codex/fix-auto-mode-terminal-regression

Conversation

@TinyKitten
Copy link
Copy Markdown
Member

@TinyKitten TinyKitten commented Mar 10, 2026

概要

  • オートモードで次停車駅を前方インデックス走査で解決するよう修正
  • 同一駅IDや同一駅オブジェクトが再登場する長い駅リストでも終着側へ進行を継続
  • 同一駅オブジェクト再登場ケースの回帰テストを追加

リスク

  • オートモードの停車駅遷移ロジックに影響するため、長距離路線と重複駅を含む路線で重点確認が必要
  • 通過駅を含む区間の速度プロファイル生成に影響するため、既存ケースの回帰確認が必要

実行コマンド

  • npm test -- src/hooks/useSimulationMode.test.tsx --runInBand
  • npm run typecheck
  • npm run lint

チケット

  • なし

Summary by CodeRabbit

リリースノート

  • バグ修正

    • 複数回登場する駅を含むルートでのシミュレーション動作が改善されました。
    • 特殊な駅配置での速度プロファイル生成がより正確になりました。
    • 終着駅到着判定の精度が向上しました。
  • パフォーマンス改善

    • シミュレーション実行時の計算処理を最適化しました。

@github-actions github-actions Bot added the react label Mar 10, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 10, 2026

📝 Walkthrough

ウォークスルー

駅オブジェクトの次の非通過駅選択ロジックを、フィルタリング方式から直接インデックス検索方式に変更しました。さらに、同一駅が駅リストで再び登場した場合のテストケースを追加し、速度プロファイル生成とシミュレーション進行の正確性を検証しました。

変更内容

コホート / ファイル(s) 要約
次駅選択ロジックの改善
src/hooks/useSimulationMode.ts
次の非通過駅の選択方法を、フィルタリングされたリストからの間接的なインデックス参照から、findIndexによる直接的なインデックス検索に変更しました。セグメント内の駅間スライスを計算する際のインデックス管理を簡素化し、ガード条件を追加して駅座標の存在確認を強化しました。
重複駅シナリオのテスト
src/hooks/useSimulationMode.test.tsx
同一駅オブジェクトが駅リスト内で複数回登場する場合のテストケースを新規追加しました。初期状態の設定、速度設定の注入、時間進行をシミュレートし、複数の位置更新で速度が正の値を保ち、終点に到達することを検証します。

推定コード審査工数

🎯 3 (中程度) | ⏱️ ~20分

関連する可能性のあるPR

ウサギの詩

🐰✨ 駅がまた顔を出すとき、
インデックスが真っすぐ指し示し、
フィルタのもつれも解けていく、
シミュレーションは正確に走る、
さあ次の駅へ、ぴょん!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed プルリクエストのタイトル「オートモードの終着前巻き戻りを防ぐ」は、変更セットの主な目的と完全に合致しており、オートモードで同一駅の再登場時に終着方向への進行を継続する修正という核心をよく表現している。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/fix-auto-mode-terminal-regression

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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

@TinyKitten TinyKitten self-assigned this Mar 10, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/hooks/useSimulationMode.ts (1)

305-313: 到達不能なガード条件の簡略化を検討

Line 264でnextStopStationIndex === -1の場合は早期リターンしており、findIndexidx > normalizedSegmentIndexで探索するため、見つかった場合は必ずnextStopStationIndex > currentSegmentStationIndexとなります。このため、Line 306のnextStopStationIndex < currentSegmentStationIndexチェックは到達不能です。

防御的コーディングとして残すか、簡略化するかは任意ですが、削除すればコードがより明確になります。

♻️ 簡略化案
-      if (
-        nextStopStationIndex < 0 ||
-        nextStopStationIndex < currentSegmentStationIndex
-      ) {
-        segmentIndexRef.current = 0;
-        childIndexRef.current = 0;
-        segmentProgressDistanceRef.current = 0;
-        return;
-      }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/hooks/useSimulationMode.ts` around lines 305 - 313, The if-block that
checks "nextStopStationIndex < 0 || nextStopStationIndex <
currentSegmentStationIndex" contains a redundant unreachable condition: earlier
you already early-return when nextStopStationIndex === -1 and the findIndex uses
"idx > normalizedSegmentIndex", so any found nextStopStationIndex will always be
> currentSegmentStationIndex; remove the "nextStopStationIndex <
currentSegmentStationIndex" clause and keep the simple guard
"nextStopStationIndex < 0" while preserving the reset behavior that sets
segmentIndexRef.current, childIndexRef.current, and
segmentProgressDistanceRef.current to 0.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/hooks/useSimulationMode.ts`:
- Around line 305-313: The if-block that checks "nextStopStationIndex < 0 ||
nextStopStationIndex < currentSegmentStationIndex" contains a redundant
unreachable condition: earlier you already early-return when
nextStopStationIndex === -1 and the findIndex uses "idx >
normalizedSegmentIndex", so any found nextStopStationIndex will always be >
currentSegmentStationIndex; remove the "nextStopStationIndex <
currentSegmentStationIndex" clause and keep the simple guard
"nextStopStationIndex < 0" while preserving the reset behavior that sets
segmentIndexRef.current, childIndexRef.current, and
segmentProgressDistanceRef.current to 0.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d4d8abc1-ede4-4d13-9a21-6d9b4c2d15ac

📥 Commits

Reviewing files that changed from the base of the PR and between a0726f1 and 81c959f.

📒 Files selected for processing (2)
  • src/hooks/useSimulationMode.test.tsx
  • src/hooks/useSimulationMode.ts

@TinyKitten TinyKitten merged commit 196d618 into dev Mar 10, 2026
7 checks passed
@TinyKitten TinyKitten deleted the codex/fix-auto-mode-terminal-regression branch March 10, 2026 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant