Repository navigation
路線推定を利用した列車種別の誤指定検出機能を追加 - #5754
Conversation
📝 WalkthroughWalkthrough新しいフック Changes
sequenceDiagram
participant UI as "UI / useWarningInfo"
participant Hook as "useTrainTypeMismatchDetector"
participant AtomNav as "Jotai:navigationState"
participant AtomStation as "Jotai:stationState"
participant Est as "useRouteEstimation"
participant Control as "useRouteEstimationControl"
UI->>Hook: フック呼び出し
Hook->>AtomNav: trainType 読取
Hook->>AtomStation: selectedBound 読取
alt selectedBound.id && trainType
Hook->>Control: startEstimation()
Hook->>Est: candidates / status 取得
Est-->>Hook: candidates, status
alt status == "ready" && candidates[0].confidence >= 0.7 && trainType.groupId && candidate.groupId
Hook-->>UI: isMismatch = (trainType.groupId != candidate.groupId)
else
Hook-->>UI: isMismatch = false
end
else selectedBound cleared
Hook->>Control: stopEstimation()
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the Comment |
|
APIアクセスが定期的に発生するのが痛い |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/hooks/useWarningInfo.ts (1)
145-156:⚠️ Potential issue | 🟠 Major警告の優先順位を確認してください。
isTrainTypeMismatch(WARNING レベル)がbadAccuracy(URGENT レベル)よりも先に評価されています。両方の条件が同時に true の場合、より緊急度の高い GPS 精度の警告が表示されず、列車種別の不一致警告が優先されます。GPS 精度の問題はナビゲーション全体の信頼性に影響するため、
badAccuracyのチェックを先に配置することを検討してください。🔧 優先順位の修正案
if (isLoopLineWrongDirection) { return { level: WARNING_PANEL_LEVEL.WARNING, text: translate('wrongDirectionLoopLineWarning'), }; } + if (badAccuracy) { + return { + level: WARNING_PANEL_LEVEL.URGENT, + text: translate('badAccuracy'), + }; + } if (isTrainTypeMismatch) { return { level: WARNING_PANEL_LEVEL.WARNING, text: translate('trainTypeMismatchWarning'), }; } - if (badAccuracy) { - return { - level: WARNING_PANEL_LEVEL.URGENT, - text: translate('badAccuracy'), - }; - }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/hooks/useWarningInfo.ts` around lines 145 - 156, The current ordering in useWarningInfo.ts evaluates isTrainTypeMismatch before badAccuracy, causing WARNING-level train type alerts to suppress URGENT GPS accuracy alerts when both are true; swap the checks so badAccuracy is evaluated first (returning level: WARNING_PANEL_LEVEL.URGENT, text: translate('badAccuracy')) before the isTrainTypeMismatch block, ensuring URGENT accuracy warnings take precedence over WARNING train-type mismatch messages.
🧹 Nitpick comments (1)
src/hooks/useTrainTypeMismatchDetector.test.tsx (1)
285-303: 境界値テストの追加を検討してください。信頼度 0.5 で「低すぎる」ケースをテストしていますが、実際の閾値は
MIN_MISMATCH_CONFIDENCE = 0.7です。境界値として0.69(false を期待)と0.7(true を期待)のテストケースを追加すると、閾値ロジックがより厳密に検証されます。🧪 境界値テストの追加案
it('returns false when confidence is just below threshold (0.69)', async () => { mockUseAtomValue.mockImplementation((atom: unknown) => { if (atom === require('../store/atoms/navigation').default) { return { trainType: createTrainType(100) }; } if (atom === require('../store/atoms/station').default) { return { selectedBound: { id: 1 } }; } return {}; }); mockCandidates = [createCandidate(200, 0.69)]; mockStatus = 'ready'; const { getByTestId } = render(<TestComponent />); await waitFor(() => { expect(getByTestId('result').props.children).toBe('ok'); }); }); it('detects mismatch when confidence is at threshold (0.7)', async () => { mockUseAtomValue.mockImplementation((atom: unknown) => { if (atom === require('../store/atoms/navigation').default) { return { trainType: createTrainType(100) }; } if (atom === require('../store/atoms/station').default) { return { selectedBound: { id: 1 } }; } return {}; }); mockCandidates = [createCandidate(200, 0.7)]; mockStatus = 'ready'; const { getByTestId } = render(<TestComponent />); await waitFor(() => { expect(getByTestId('result').props.children).toBe('mismatch'); }); });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/hooks/useTrainTypeMismatchDetector.test.tsx` around lines 285 - 303, Add two boundary tests around MIN_MISMATCH_CONFIDENCE to ensure threshold behavior: update the test file to include one case where mockCandidates = [createCandidate(200, 0.69)] and mockStatus = 'ready' and assert TestComponent returns 'ok' (no mismatch), and another where mockCandidates = [createCandidate(200, 0.7)] with mockStatus = 'ready' and assert TestComponent returns 'mismatch'; reuse the same mockUseAtomValue setup (checking navigation and station atoms) and the existing render/waitFor pattern so the tests exercise the MIN_MISMATCH_CONFIDENCE logic used by the detector.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/hooks/useTrainTypeMismatchDetector.ts`:
- Around line 41-49: The current logic in useTrainTypeMismatchDetector calls
stopEstimation() and startEstimation() but those only flip state and do not
clear bufferRef, so old location data remains; update the code to call the
reset() routine (which clears bufferRef.current) when the bound/direction
changes instead of—or in addition to—calling stopEstimation()/startEstimation();
to do this either export reset() from useRouteEstimation or expose it via
useRouteEstimationControl and invoke reset() (or explicitly clear
bufferRef.current) in the bound-change branch in useTrainTypeMismatchDetector to
ensure the buffer is cleared before restarting estimation.
---
Outside diff comments:
In `@src/hooks/useWarningInfo.ts`:
- Around line 145-156: The current ordering in useWarningInfo.ts evaluates
isTrainTypeMismatch before badAccuracy, causing WARNING-level train type alerts
to suppress URGENT GPS accuracy alerts when both are true; swap the checks so
badAccuracy is evaluated first (returning level: WARNING_PANEL_LEVEL.URGENT,
text: translate('badAccuracy')) before the isTrainTypeMismatch block, ensuring
URGENT accuracy warnings take precedence over WARNING train-type mismatch
messages.
---
Nitpick comments:
In `@src/hooks/useTrainTypeMismatchDetector.test.tsx`:
- Around line 285-303: Add two boundary tests around MIN_MISMATCH_CONFIDENCE to
ensure threshold behavior: update the test file to include one case where
mockCandidates = [createCandidate(200, 0.69)] and mockStatus = 'ready' and
assert TestComponent returns 'ok' (no mismatch), and another where
mockCandidates = [createCandidate(200, 0.7)] with mockStatus = 'ready' and
assert TestComponent returns 'mismatch'; reuse the same mockUseAtomValue setup
(checking navigation and station atoms) and the existing render/waitFor pattern
so the tests exercise the MIN_MISMATCH_CONFIDENCE logic used by the detector.
🪄 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: c8089d53-8b25-4642-b2ba-482bc5f33e50
📒 Files selected for processing (6)
assets/translations/en.jsonassets/translations/ja.jsonsrc/hooks/index.tssrc/hooks/useTrainTypeMismatchDetector.test.tsxsrc/hooks/useTrainTypeMismatchDetector.tssrc/hooks/useWarningInfo.ts
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/hooks/useTrainTypeMismatchDetector.test.tsx (1)
201-206:jest.clearAllMocks()はafterEachブロックで呼び出すべきコーディングガイドラインでは、
jest.clearAllMocks()はafterEachブロックで呼び出すことが推奨されています。beforeEachでも動作しますが、テスト後のクリーンアップというセマンティクスに合わせるためafterEachを使用してください。♻️ 修正案
beforeEach(() => { - jest.clearAllMocks(); mockCandidates = []; mockStatus = 'idle'; mockIsEstimating = false; }); + + afterEach(() => { + jest.clearAllMocks(); + });As per coding guidelines: "Call
jest.clearAllMocks()inafterEachblocks"🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/hooks/useTrainTypeMismatchDetector.test.tsx` around lines 201 - 206, Move the jest.clearAllMocks() call out of the beforeEach block and into an afterEach block: remove jest.clearAllMocks() from the existing beforeEach (which should continue to initialize mockCandidates, mockStatus, mockIsEstimating) and add a new afterEach that calls jest.clearAllMocks(); this aligns with the testing guideline to perform mock cleanup in afterEach and keeps the initialization logic inside beforeEach.
🤖 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/useTrainTypeMismatchDetector.test.tsx`:
- Around line 201-206: Move the jest.clearAllMocks() call out of the beforeEach
block and into an afterEach block: remove jest.clearAllMocks() from the existing
beforeEach (which should continue to initialize mockCandidates, mockStatus,
mockIsEstimating) and add a new afterEach that calls jest.clearAllMocks(); this
aligns with the testing guideline to perform mock cleanup in afterEach and keeps
the initialization logic inside beforeEach.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 8643c217-3efe-42a1-979c-26e04d394380
📒 Files selected for processing (3)
src/hooks/useTrainTypeMismatchDetector.test.tsxsrc/hooks/useTrainTypeMismatchDetector.tssrc/hooks/useWarningInfo.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- src/hooks/useWarningInfo.ts
- src/hooks/useTrainTypeMismatchDetector.ts
This reverts commit 775ade1.
closes #5753
https://claude.ai/code/session_01RZhe3b5iSb3gpaLzht8wAv
Summary by CodeRabbit