Skip to content

最大許容精度と精度超過時の到着強制をFirebase Remote Config参照に変更し従来値をフォールバックに使用 - #6131

Merged
TinyKitten merged 2 commits into
devfrom
claude/max-precision-firebase-config-lTR30
Jun 5, 2026
Merged

TinyKitten merged 2 commits into
devfrom
claude/max-precision-firebase-config-lTR30

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Jun 5, 2026 •

Copy link
Copy Markdown
Member

概要

最大許容精度(継続測位で受理する測位精度の上限)と、精度超過時に到着判定を強制的に未到着へ倒す挙動を Firebase Remote Config から参照するように変更しました。リモート値が未取得・不正な場合は従来挙動(最大許容精度 1.5km / 強制未到着は有効)にフォールバックします。

変更の種類

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

変更内容

  • src/lib/remoteConfig.ts を新設し、setupRemoteConfig()(起動時に既定値登録+fetchAndActivate)と同期 getter getMaxPermitAccuracy() / isForceNotArrivedOnLowAccuracyEnabled() を実装
  • Remote Config キー max_permit_accuracy(数値, フォールバック 1500m)と force_not_arrived_on_low_accuracy(真偽, フォールバック true)を追加。MAX_PERMIT_ACCURACY 定数はフォールバック既定値として残置
  • 最大許容精度の参照箇所を全て getter 経由に統一(handleTrackingLocation の測位棄却フィルタ、useRefreshStation の到着判定、accuracyChart / DevOverlay の診断表示の色・スケール)
  • useRefreshStation の精度超過時 arrived: false 強制をフィーチャートグルで切り替え可能化(無効時は精度に依らず通常の到着判定を行う)
  • index.js の起動時に setupRemoteConfig() を実行(フォアグラウンド/ヘッドレスのバックグラウンド測位タスク両経路をカバー、失敗時は Sentry 報告のみでアプリ起動はブロックしない)
  • @react-native-firebase/remote-config を依存追加、jest.setup.js に Remote Config のモックを追加、src/lib/remoteConfig.test.ts 新設および関連テストを追加・更新

回帰リスクと緩和

  • 全参照箇所がフォールバックを持つため、Remote Config 未登録・フェッチ失敗時も従来値(1.5km / 強制未到着有効)で従来どおり動作する。
  • boolean トグルは false を正規値と区別できないため、未設定(getSource() === 'static')判定でフォールバックを発火させ、誤って無効化されないようにしている。
  • 新規ネイティブモジュール追加のため、実機ビルド時は pod install(iOS)等のネイティブ依存再取得が必要。

テスト

  • npm run lint が通ること
  • npm test が通ること
  • npm run typecheck が通ること

npm test は 162 suites / 1766 tests 全パス。

関連Issue

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


Generated by Claude Code

Summary by CodeRabbit

  • 新機能

    • Firebase Remote Config を導入し、GPS精度関連の閾値や挙動をサーバー側で動的に制御可能に。
    • 精度表示や到着判定、可視化(精度グラフ)の閾値がリモート値に連動。
  • テスト

    • Remote Config 動作と各種精度処理のユニットテスト・モックを追加。
  • 雑務

    • Remote Config ライブラリを依存に追加。

@github-actions github-actions Bot added the react label Jun 5, 2026
@TinyKitten TinyKitten self-assigned this Jun 5, 2026
@coderabbitai

coderabbitai Bot commented Jun 5, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Firebase Remote Config を導入して、GPS精度関連の許容値と強制未到着フラグをアプリ起動時に取得し、複数のコンポーネント・ユーティリティで固定定数から動的値へ切り替える変更を実施。到着判定・精度警告・グラフ正規化など各機能に反映。

Changes

Remote Config 統合による精度判定の動的化

Layer / File(s) Summary
Remote Config ライブラリ基盤
src/lib/remoteConfig.ts, src/lib/remoteConfig.test.ts, jest.setup.js, package.json, src/constants/location.ts
REMOTE_CONFIG_KEYS/既定値定義、setupRemoteConfig()・getMaxPermitAccuracy()・isForceNotArrivedOnLowAccuracyEnabled() を実装。Jest モックで Remote Config 依存を排除し、正常系・フォールバック・例外のテストを追加。package.json に依存を追加。
アプリ起動フローへの統合
index.js
起動時に setupRemoteConfig() を呼び出し、失敗時は Sentry.captureException へ記録して起動をブロックしない非同期フローを追加。
GPS到着判定ロジック
src/hooks/useRefreshStation.ts, src/hooks/useRefreshStation.test.tsx
isForceNotArrivedOnLowAccuracyEnabled() が有効な場合にのみ低精度で強制未到着扱いを行い、許容精度超過判定を getMaxPermitAccuracy() に切替。無効時の挙動を検証するテストを追加。
位置情報トラッキングの精度フィルタ
src/utils/handleTrackingLocation.ts
位置情報受信時の外れ値判定を getMaxPermitAccuracy() による動的閾値で評価するよう変更。
DevOverlay の精度警告UI
src/components/DevOverlay.tsx
赤/黄の精度警告判定条件を Remote Config の許容精度に基づく比較へ変更。
精度グラフの対数正規化
src/utils/accuracyChart.ts, src/utils/accuracyChart.test.ts
天井値を getAccuracyChartCeiling() に置換、getAccuracyColor と normalizeAccuracy を Remote Config の値に合わせて都度計算するよう更新。退化ケースでの NaN 回避を追加。

Sequence Diagram

sequenceDiagram
  participant App as App
  participant Index as index.js
  participant Setup as setupRemoteConfig
  participant Firebase as FirebaseRemoteConfig
  participant Components as DevOverlay/Track/useRefreshStation
  participant Sentry as Sentry

  App->>Index: 起動
  Index->>Setup: setupRemoteConfig()
  Setup->>Firebase: setConfigSettings / setDefaults / fetchAndActivate
  Firebase-->>Setup: 成功/値
  Setup-->>Index: Promise resolves
  Setup--xIndex: エラー -> Sentry.captureException
  Components->>Firebase: getValue(max_permit_accuracy / force_not_arrived...)
  Firebase-->>Components: 値 or static (フォールバック)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • TrainLCD/MobileApp#6103: handleTrackingLocation / DevOverlay 周辺で MAX_PERMIT_ACCURACY を Remote Config に切替しているため関連。
  • TrainLCD/MobileApp#6128: accuracyChart の天井/対数正規化を同様にリファクタしているため関連。
  • TrainLCD/MobileApp#6098: MAX_PERMIT_ACCURACY 定数変更が本 PR のフォールバック挙動に影響するため関連。

Suggested labels

react, remote-config, gps-tracking

Poem

🐰 Remote Config の草原で、
閾値がそよぐ風に乗る、
固定はもう昔の話、
動的な値で地図が光る、
フェッチして、さぁ走れ!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed タイトルはPRの主要な変更を明確に説明しており、Firebase Remote Config参照への移行とフォールバック機構という核となる内容を簡潔にまとめています。
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.

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

✨ 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/max-precision-firebase-config-lTR30

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

@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: 2

🤖 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 `@jest.setup.js`:
- Around line 58-78: モックの module-scoped "store" がテスト間で保持されリークするので、jest.mock
の返り値に store をクリアするメソッドを追加してテストごとにリセットできるようにしてください:jest.mock(...) 内の store(現在の
store 変数)、setDefaults、getValue に影響を与えるので、例えば resetRemoteConfigMock() をエクスポートして
store を {} に再代入する実装を追加し、各テストの beforeEach でその resetRemoteConfigMock()
を呼ぶようにテスト側で運用してください。

In `@src/utils/accuracyChart.ts`:
- Around line 74-78: normalizeAccuracy can produce NaN when logSpan <= 0; guard
the ceiling/logSpan computed from getAccuracyChartCeiling() so it never falls at
or below the floor: compute const ceiling = Math.max(getAccuracyChartCeiling(),
ACCURACY_CHART_FLOOR_M + Number.EPSILON) or clamp logSpan to a small positive
value (e.g. Math.max(Math.log(ceiling) - LOG_FLOOR, 1e-12)) before using it in
the division; update the code paths in normalizeAccuracy that reference
getAccuracyChartCeiling, LOG_FLOOR and ACCURACY_CHART_FLOOR_M and add a unit
test asserting correct behavior when getAccuracyChartCeiling() returns values at
or below the floor.
🪄 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: 9d10b9fc-73f6-44e2-9b01-e165c8b82eb0

📥 Commits

Reviewing files that changed from the base of the PR and between 0e27596 and 48d3bed.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (12)
  • index.js
  • jest.setup.js
  • package.json
  • src/components/DevOverlay.tsx
  • src/constants/location.ts
  • src/hooks/useRefreshStation.test.tsx
  • src/hooks/useRefreshStation.ts
  • src/lib/remoteConfig.test.ts
  • src/lib/remoteConfig.ts
  • src/utils/accuracyChart.test.ts
  • src/utils/accuracyChart.ts
  • src/utils/handleTrackingLocation.ts

Comment thread jest.setup.js Resolved
Comment thread src/utils/accuracyChart.ts Resolved

@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: 1

🤖 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 `@src/utils/accuracyChart.test.ts`:
- Around line 48-62: Add a global test teardown that calls jest.clearAllMocks()
after each test to prevent mock leakage; specifically, add an afterEach hook
(adjacent to the existing tests that use spy.mockRestore(), e.g. in
src/utils/accuracyChart.test.ts) which invokes jest.clearAllMocks() so all
spies/mocks are cleared between tests.
🪄 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: 076a1b42-3b50-4e6a-88e3-868c0774dfbe

📥 Commits

Reviewing files that changed from the base of the PR and between 48d3bed and 294d977.

📒 Files selected for processing (3)
  • jest.setup.js
  • src/utils/accuracyChart.test.ts
  • src/utils/accuracyChart.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • jest.setup.js
  • src/utils/accuracyChart.ts

Comment thread src/utils/accuracyChart.test.ts Resolved
@TinyKitten
TinyKitten merged commit 5db5dc5 into dev Jun 5, 2026
5 checks passed
@TinyKitten
TinyKitten deleted the claude/max-precision-firebase-config-lTR30 branch June 5, 2026 11:24
@TinyKitten TinyKitten mentioned this pull request Jun 5, 2026
4 of 9 tasks
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.

2 participants