Skip to content

test: mock prefs so the Health export churn test passes on macOS - #712

Open
kurexw wants to merge 1 commit into
OpenStrap:mainfrom
kurexw:test/health-churn-apple-host
Open

kurexw wants to merge 1 commit into
OpenStrap:mainfrom
kurexw:test/health-churn-apple-host

Conversation

@kurexw

@kurexw kurexw commented Nov 13, 2026 •

Copy link
Copy Markdown

Summary

test/health_export_finalized_churn_test.dart fails on every local macOS run (Expected: <2> Actual: <0>) and passes in CI.

Cause. HealthExporter.isApple is Platform.isIOS || Platform.isMacOS, so on a Mac host the exporter takes the Apple path. Apple nap export reads SharedPreferences, which this test never mocked. Each day therefore logged MissingPluginException, then write Apple naps returned false and export incomplete, and the first pass exported 0 days. CI runs on Linux (Health Connect path, no nap prefs read), so only local runs failed.

Fix. SharedPreferences.setMockInitialValues({}) in setUpAll. I chose this over pinning isApple: false (the #685 approach) because it keeps the host's own path under test.

Test-only change; no product code touched.

Testing

  • flutter test test/health_export_finalized_churn_test.dart on macOS: was 1 failure, now passes.
  • Same test with the exporter forced to isApple: true and to isApple: false (throwaway copies, not committed): both pass.
  • flutter analyze on the file: no issues.

Risks and rollback

None for the app. Revert the commit to roll back.

Not in this PR

TZ=UTC flutter test test/whoop_freeze_golden_test.dart also fails locally on this Mac (macOS 27): dyn_p90 differs in the last digit (0.016617360477042792 vs golden 0.0166173604770428). The goldens compare exactly only on macOS, so this looks like libm last-bit drift on the newer OS. The golden README says not to regenerate without owner approval, so I left it alone. Does it reproduce on another Mac?

  • Tests pass
  • Analyze passes
  • Self-review completed
  • Human approval required before merge

🤖 Generated with Claude Code

Summary by Sourcery

Make the Health export finalized-churn test reliable across host platforms by providing mocked preferences for Apple-specific settings.

Bug Fixes:

  • Fix the Health export finalized-churn test on macOS by mocking SharedPreferences used by the Apple nap export path.

Tests:

  • Ensure the churn test runs against the host platform's export path without plugin exceptions.

On a macOS host the exporter takes the Apple path, whose nap writer reads
SharedPreferences. The test never mocked it, so every day hit
MissingPluginException, reported "export incomplete", and the first pass
exported 0 days instead of 2. CI runs on Linux (Health Connect path), so
only local macOS runs failed. Mocking prefs keeps the host's own path
under test instead of pinning one platform.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters: 1

  • test/health_export_finalized_churn_test.dart is excluded by !test/**

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

Run configuration

  • Source mode: Auto
  • Repository: OpenStrap/edge
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: 825486c
  • Layers: Repository YAML
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 6cce3696-528d-43c4-a4bf-0b013ce58940

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@sourcery-ai

sourcery-ai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Tests

Mock SharedPreferences in the churn test so the macOS Apple export path can read its nap settings.

  • test/health_export_finalized_churn_test.dart L4, L28-32

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="test/health_export_finalized_churn_test.dart" line_range="32" />
<code_context>
+    // MissingPluginException on a macOS host (where the exporter takes the
+    // Apple path), every day reported "export incomplete", and the first
+    // pass exported 0 instead of 2.
+    SharedPreferences.setMockInitialValues({});
     sqfliteFfiInit();
     databaseFactory = databaseFactoryFfi;
</code_context>
<issue_to_address>
**Apple nap regressions go undetected**

When the test runs with the newly mocked empty preference store, `HealthNapExporter._defaultHealthSyncEnabled` reads the unset sync preference as false, so `exportDayNaps` returns successfully before scanning nap rows or reaching the Apple nap writer; this test passes without exercising enabled nap export.

If this test is intended to cover enabled Apple nap export, set `kHealthSyncPref` to true and add a confirmed nap fixture with the writer mocked.
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: test/health_export_finalized_churn_test.dart:32


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@abdulsaheel

Copy link
Copy Markdown
Collaborator

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor
Action not completed

Path filters excluded 1 file from this review.

@abdulsaheel

Copy link
Copy Markdown
Collaborator

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor
Action not completed

Path filters excluded 1 file from this review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants