Repository navigation
環状路線のETA取得時にdirectionIdを明示的に指定して進行方向の弧を確定させる - #6334
Conversation
Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WpLyvxXSyp54snZ63h5HwS
📝 WalkthroughWalkthroughEstimateArrivalTimes の GraphQL クエリと型定義に directionId 変数を追加し、useEstimateArrivalTimes フックで環状路線判定と選択方向から directionId を算出してクエリに渡すよう変更。対応するテストケースも追加された。 ChangesdirectionId 送信対応
Estimated code review effort: 2 (Simple) | ~12 minutes Sequence Diagram(s)sequenceDiagram
participant Component
participant useEstimateArrivalTimes
participant useLoopLine
participant GraphQLAPI
Component->>useEstimateArrivalTimes: selectedDirection を渡す
useEstimateArrivalTimes->>useLoopLine: isLoopLine 判定
useLoopLine-->>useEstimateArrivalTimes: isLoopLine
useEstimateArrivalTimes->>useEstimateArrivalTimes: directionId 算出(LOOP_LINE_DIRECTION_ID)
useEstimateArrivalTimes->>GraphQLAPI: ESTIMATE_ARRIVAL_TIMES(variables含むdirectionId)
GraphQLAPI-->>useEstimateArrivalTimes: 推定到着時刻レスポンス
Possibly related PRs
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.
🧹 Nitpick comments (1)
src/hooks/useEstimateArrivalTimes.test.tsx (1)
199-251: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value環状路線かつ方面未選択のケースのテストが未追加。
directionIdの算出条件はisLoopLine && selectedDirection != nullですが、現在のテストは「非環状」「環状+INBOUND」「環状+OUTBOUND」の3パターンのみで、「環状路線だがselectedDirectionがnull(方面未選択)」のケースが未検証です。この分岐が正しくdirectionId: undefinedになることを確認するテストを追加すると、条件式の両方の要素(isLoopLineとselectedDirection != null)がそれぞれ独立してテストされ、より安心です。As per path instructions: "When modifying behavior, update or add tests in the same change set; document skipped tests with TODOs and owner rationale."
♻️ 追加テスト案
+ it('環状路線でも方面未選択のとき directionId を送信しない', async () => { + mockUseLoopLine.mockReturnValue({ + isLoopLine: true, + } as ReturnType<typeof useLoopLine>); + setupAtoms({ selectedDirection: null }); + mockGqlRequest.mockResolvedValue({ + estimateArrivalTimes: { routes: [] }, + }); + + renderHook(); + + await waitFor(() => { + expect(mockGqlRequest).toHaveBeenCalled(); + }); + + const variables = mockGqlRequest.mock.calls[0][1]; + expect(variables.directionId).toBeUndefined(); + });🤖 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 `@src/hooks/useEstimateArrivalTimes.test.tsx` around lines 199 - 251, The current tests cover non-loop, loop+INBOUND, and loop+OUTBOUND cases, but miss the branch where useLoopLine().isLoopLine is true and selectedDirection is null. Add a test in useEstimateArrivalTimes.test.tsx that sets mockUseLoopLine to loop mode without setting selectedDirection, then assert the gql request variables from mockGqlRequest include directionId as undefined. This should verify the isLoopLine && selectedDirection != null logic in the hook’s directionId calculation alongside the existing direction cases.Source: Path instructions
🤖 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 `@src/hooks/useEstimateArrivalTimes.test.tsx`:
- Around line 199-251: The current tests cover non-loop, loop+INBOUND, and
loop+OUTBOUND cases, but miss the branch where useLoopLine().isLoopLine is true
and selectedDirection is null. Add a test in useEstimateArrivalTimes.test.tsx
that sets mockUseLoopLine to loop mode without setting selectedDirection, then
assert the gql request variables from mockGqlRequest include directionId as
undefined. This should verify the isLoopLine && selectedDirection != null logic
in the hook’s directionId calculation alongside the existing direction cases.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 7b232493-a0fa-4374-849f-afadeb77e61f
📒 Files selected for processing (4)
src/@types/graphql.d.tssrc/hooks/useEstimateArrivalTimes.test.tsxsrc/hooks/useEstimateArrivalTimes.tssrc/lib/graphql/queries.ts
Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WpLyvxXSyp54snZ63h5HwS
概要
環状路線(山手線・大阪環状線・名城線など)でETAを取得する際、
EstimateArrivalTimesクエリにdirectionIdを明示的に指定するようにする。StationAPI 側の TrainLCD/StationAPI#1581 で環状路線の弧選択が実装され、
direction_id未指定時は「直線距離が短い方の弧」を選ぶヒューリスティックにフォールバックするため、遠回り方向に乗車中は逆回りのETAが返ることがある。同PRで推奨されているとおり、クライアントから進行方向を明示して送ることでこれを防ぐ。変更の種類
変更内容
ESTIMATE_ARRIVAL_TIMESクエリに$directionId: Int変数を追加(src/lib/graphql/queries.ts)useEstimateArrivalTimesでuseLoopLine()のisLoopLineが true かつ方面選択済みのときだけdirectionIdを送信するように変更。非環状路線ではundefinedのためシリアライズ時に落ち、従来どおり未指定で送信される(src/hooks/useEstimateArrivalTimes.ts)EstimateArrivalTimesRequest.direction_id:0 = default order, 1 = reverse order)に基づき、stations 配列の格納順に進むINBOUND → 0、逆順に進むOUTBOUND → 1。INBOUND でも0を明示的に送らないとバックエンドが短い弧ヒューリスティックに落ちるため、環状路線では両方向とも必ず送信するEstimateArrivalTimesQueryVariablesにdirectionIdを追加(src/@types/graphql.d.ts。環境にGQL_API_URLが無くnpm run gql:codegenを実行できないため、codegen の出力形式に合わせて手動反映。次回 codegen 実行で同一内容が再生成される想定)directionIdを送信しない / 環状路線かつ INBOUND で0/ OUTBOUND で1/ 環状路線でも方面未選択なら送信しない(src/hooks/useEstimateArrivalTimes.test.tsx)テスト
ローカルで
npm run lint && npm test && npm run typecheckを実行し、すべて通過。npm run lintが通ることnpm testが通ることnpm run typecheckが通ること関連Issue
参考: TrainLCD/StationAPI#1581
スクリーンショット(任意)
Summary by CodeRabbit