Skip to content

フォアグラウンド測位にも精度フィルタを適用し、DevOverlayに生の精度を表示する - #6103

Merged
TinyKitten merged 2 commits into
devfrom
feature/dev-overlay-raw-accuracy
Jun 2, 2026
Merged

TinyKitten merged 2 commits into
devfrom
feature/dev-overlay-raw-accuracy

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Jun 2, 2026 •

Copy link
Copy Markdown
Member

概要

DevOverlay の LOCATION ACCURACY を MAX_PERMIT_ACCURACY フィルタに影響されない生の測位精度で表示し、許容値を超えた場合は赤字で警告するようにしました。あわせて、watchPositionAsync(フォアグラウンド監視)経路に MAX_PERMIT_ACCURACY フィルタが適用されていなかった考慮漏れを修正し、継続測位の2経路で精度フィルタを一貫させました。

変更の種類

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

変更内容

  • watchPositionAsync 経路でも MAX_PERMIT_ACCURACY フィルタが効くよう修正。これまで startLocationUpdatesAsync(background)経路でしかフィルタしておらず、フォアグラウンド監視では許容精度を超える測位もそのまま採用していた。
  • 継続測位の共通入口 handleTrackingLocation を新設し、watch / background 双方の精度フィルタをここへ集約。経路ごとの適用漏れが構造的に起きないようにした(getCurrentPositionAsync のワンショット取得・手動選択は従来どおり setLocation 直呼びでフィルタ対象外)。
  • DevOverlay の精度表示元を、フィルタ前の生の測位値を保持する rawLocationAtom に変更。MAX_PERMIT_ACCURACY で棄却された測位の精度も診断表示できるようにした。
  • 生の精度が MAX_PERMIT_ACCURACY を超える場合、数値・単位を赤字(#f87171)で表示する警告を追加。
  • rawLocationAtom の更新は handleTrackingLocation 内で isDevApp のときだけ行う。DevOverlay は isDevApp 時しか描画されないため、本番ビルドでは余計な atom 更新を発生させない。

テスト

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

関連Issue

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

Summary by CodeRabbit

  • New Features

    • DevOverlayで生の測位精度を基に許容値超過時に警告(赤表示)するよう強化。
    • バックグラウンド/フォアグラウンドの位置更新で共通処理を導入し、生の測位データを保存できるように。
  • Tests

    • 生データ保存と精度フィルタリング挙動、表示の色分岐などに関するテストを拡充。

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

coderabbitai Bot commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bba0b018-0fb9-4ecf-bfbd-fec4202b48d3

📥 Commits

Reviewing files that changed from the base of the PR and between 1065b26 and 4763f0c.

📒 Files selected for processing (1)
  • src/components/DevOverlay.test.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/DevOverlay.test.tsx

📝 Walkthrough

Walkthrough

位置情報の精度チェックと生データ記録ロジックを新規の handleTrackingLocation ユーティリティに統合し、複数の呼び出し元(タスク定義、バックグラウンド更新フック)から参照する。同時に DevOverlay が rawLocationAtom から生の精度を観測して、許容値超過時に赤色警告を表示する。

Changes

位置情報処理統合と精度表示

Layer / File(s) Summary
位置情報状態管理の拡張
src/store/atoms/location.ts, src/store/atoms/location.test.ts
rawLocationAtom を新規追加してフィルタ前の生データを保持可能に。setRawLocation() を公開し、resetLocationState() でも初期化対象に。テストで setRawLocation の独立性と setLocation への非影響を確認。
handleTrackingLocation ユーティリティの実装
src/utils/handleTrackingLocation.ts, src/utils/handleTrackingLocation.test.ts
精度超過判定と生データ記録を統合する共通ユーティリティを新規実装。MAX_PERMIT_ACCURACY 超過時は早期 return、開発時のみ生値を setRawLocation に記録。テストで精度値別・開発フラグ別の呼び出し制御を検証。
タスク定義での統合
index.js
expo-task-manager の位置情報タスク内で、インライン実装の精度チェックと setLocation 直接呼び出しを handleTrackingLocation に統一。import から MAX_PERMIT_ACCURACY と setLocation を削除。
バックグラウンド位置更新フックの統合
src/hooks/useStartBackgroundLocationUpdates.ts, src/hooks/useStartBackgroundLocationUpdates.test.tsx
Location.watchPositionAsync のコールバック引数を setLocation から handleTrackingLocation に変更。複数の位置更新経路で共通ロジックを使用。テストで handleTrackingLocation のモック化を追加。
DevOverlay の精度表示強化
src/components/DevOverlay.tsx, src/components/DevOverlay.test.tsx
rawLocationAtom から生の精度を購読し、MAX_PERMIT_ACCURACY 超過時に「LOCATION ACCURACY」を赤色表示。MetricCard に suffixStyle を追加して値と単位の両方へ危険用スタイルを適用。ランドスケープ/ポートレート両対応。テストで超過・非超過・未提供・バックグラウンド経路の表示分岐を確認。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • TrainLCD/MobileApp#6098: 本PR の handleTrackingLocation で使用される MAX_PERMIT_ACCURACY による精度判定ロジックをこのPRで導入・集約しており、当該PRの精度閾値変更(4000→1500)はこの判定結果に直接的な影響を与えるため関連している。

Suggested labels

react, testing, location-tracking

Poem

🐰 生の位置、そっと貯めておくよ、
赤い兆しは DevOverlay が告げる、
handleTrackingLocation は門番役、
タスクもフックも同じ道を通る、
うさぎはぴょんとテストを祝うよ。

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed PRのタイトルはこの変更セットの主要な目的である「フォアグラウンド測位への精度フィルタ適用」と「DevOverlayへの生の精度表示」を簡潔かつ正確に要約している。
Description check ✅ Passed PRの説明は要件テンプレートの大部分を埋めており、概要・変更種別・変更内容・テスト状況が充実している。テスト実施の確認とスクリーンショット以外は完備されている。
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 feature/dev-overlay-raw-accuracy

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.

🧹 Nitpick comments (2)
src/utils/handleTrackingLocation.test.ts (1)

35-38: 💤 Low value

jest.clearAllMocks() は afterEach で呼び出してください。

機能的には問題ありませんが、本リポジトリの規約ではモッククリアを afterEach で行うことになっています。

♻️ 提案
   beforeEach(() => {
-    jest.clearAllMocks();
     mockIsDevApp = false;
   });
+
+  afterEach(() => {
+    jest.clearAllMocks();
+  });

As per coding guidelines: 「テストの afterEach で jest.clearAllMocks() を呼び出してください」

🤖 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/utils/handleTrackingLocation.test.ts` around lines 35 - 38, Move the
jest.clearAllMocks() call out of the beforeEach block and into an afterEach
block to conform to repo test conventions: remove jest.clearAllMocks() from the
existing beforeEach in src/utils/handleTrackingLocation.test.ts and add an
afterEach(() => { jest.clearAllMocks(); }) so mocks are cleared after each test;
keep other setup (e.g., mockIsDevApp = false) inside the current beforeEach.
src/hooks/useStartBackgroundLocationUpdates.test.tsx (1)

27-29: ⚡ Quick win

handleTrackingLocation がコールバックとして渡されることを直接検証することを推奨します。

現状のテストは watchPositionAsync の第2引数を expect.any(Function)(Line 372, 448)でしか確認しておらず、本 PR の核心であるフォアグラウンド経路への精度フィルタ適用(setLocation 直結から handleTrackingLocation への切替)が回帰しても検知できません。モックを変数に束ね、コールバック実体を断言すると契約が固定されます。

💚 検証アサーション追加の例
+import { handleTrackingLocation } from '~/utils/handleTrackingLocation';
 jest.mock('~/utils/handleTrackingLocation', () => ({
   handleTrackingLocation: jest.fn(),
 }));
+const mockHandleTrackingLocation = handleTrackingLocation as jest.Mock;
       expect(mockWatchPositionAsync).toHaveBeenCalledWith(
         LOCATION_WATCH_OPTIONS,
-        expect.any(Function)
+        mockHandleTrackingLocation
       );
🤖 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/useStartBackgroundLocationUpdates.test.tsx` around lines 27 - 29,
The test should assert that the actual handleTrackingLocation mock is passed as
the callback to watchPositionAsync instead of just expect.any(Function); modify
the jest.mock for '~/utils/handleTrackingLocation' to export a named jest.fn()
variable (e.g., mockedHandleTrackingLocation), use that mock in the test that
mounts useStartBackgroundLocationUpdates, and replace the expect(...,
expect.any(Function)) assertions with an equality assertion that the second
argument to watchPositionAsync is the mockedHandleTrackingLocation (or assert
watchPositionAsync was called with mockedHandleTrackingLocation as the
callback); this guarantees the hook now hands off to handleTrackingLocation
instead of directly calling setLocation.
🤖 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/useStartBackgroundLocationUpdates.test.tsx`:
- Around line 27-29: The test should assert that the actual
handleTrackingLocation mock is passed as the callback to watchPositionAsync
instead of just expect.any(Function); modify the jest.mock for
'~/utils/handleTrackingLocation' to export a named jest.fn() variable (e.g.,
mockedHandleTrackingLocation), use that mock in the test that mounts
useStartBackgroundLocationUpdates, and replace the expect(...,
expect.any(Function)) assertions with an equality assertion that the second
argument to watchPositionAsync is the mockedHandleTrackingLocation (or assert
watchPositionAsync was called with mockedHandleTrackingLocation as the
callback); this guarantees the hook now hands off to handleTrackingLocation
instead of directly calling setLocation.

In `@src/utils/handleTrackingLocation.test.ts`:
- Around line 35-38: Move the jest.clearAllMocks() call out of the beforeEach
block and into an afterEach block to conform to repo test conventions: remove
jest.clearAllMocks() from the existing beforeEach in
src/utils/handleTrackingLocation.test.ts and add an afterEach(() => {
jest.clearAllMocks(); }) so mocks are cleared after each test; keep other setup
(e.g., mockIsDevApp = false) inside the current beforeEach.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 79293cb1-2152-46f8-9441-b6fe39598459

📥 Commits

Reviewing files that changed from the base of the PR and between d952395 and 1065b26.

📒 Files selected for processing (9)
  • index.js
  • src/components/DevOverlay.test.tsx
  • src/components/DevOverlay.tsx
  • src/hooks/useStartBackgroundLocationUpdates.test.tsx
  • src/hooks/useStartBackgroundLocationUpdates.ts
  • src/store/atoms/location.test.ts
  • src/store/atoms/location.ts
  • src/utils/handleTrackingLocation.test.ts
  • src/utils/handleTrackingLocation.ts

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