digidem / digidem/comapeo-core-react-native

Test: cover ComapeoPrefs.open() factory path on Android (Robolectric)

Open
#65 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area: android priority: P3 testing
Dominant language
Kotlin
Stars
1
Forks
0
Avg merge
8h 24m
Merged PRs (30d)
9

Description

Background

The Android ComapeoPrefs JVM unit tests in android/src/test/java/com/comapeo/core/ComapeoPrefsTest.kt exercise the lambda-seam constructor only — the open(context) factory that actually wires SharedPreferences("com.comapeo.core.prefs", MODE_PRIVATE) and reads the plugin defaults via SentryConfig.loadFromManifest is untested.

This came up in the review of the diagnostics-toggle PR (#TBD). A regression in the production factory (wrong MODE_* constant, key-namespace typo in the production getSharedPreferences lambda, wrong default precedence between manifest/baked-in) wouldn't be caught by the existing tests.

What's needed

A Robolectric-based test (or instrumented test if Robolectric is too heavy to add) that:

  1. Verifies open(context) returns a ComapeoPrefs reading from getSharedPreferences("com.comapeo.core.prefs", MODE_PRIVATE) — write through it via a separate SharedPreferences handle to the same file, observe via readDiagnosticsEnabled().
  2. Verifies the default-fallback precedence: user write > plugin default > baked-in DEFAULT_DIAGNOSTICS_ENABLED. Plugin defaults come via SentryConfig.loadFromManifest, which reads <meta-data> from AndroidManifest.xml — easiest via Robolectric's RuntimeEnvironment.application.
  3. Verifies the storage key names by reading the on-disk prefs file directly after a write.

Why deferred

Adding Robolectric is a non-trivial dependency bump on the test classpath — out of scope for the toggle-persistence PR. The lambda-seam tests cover the read/write logic; this issue covers the wiring.

References

  • android/src/main/java/com/comapeo/core/ComapeoPrefs.kt
  • android/src/test/java/com/comapeo/core/ComapeoPrefsTest.kt
  • Plan: docs/sentry-integration-plan.md §9.8

🤖 Generated with Claude Code

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading android/src/main/java/com/comapeo/core/ComapeoPrefs.kt and the existing tests in android/src/test/java/com/comapeo/core/ComapeoPrefsTest.kt, then inspect the AndroidManifest metadata used by SentryConfig.loadFromManifest. Add a Robolectric or instrumented test covering open(context), SharedPreferences wiring, default precedence, and storage key names; it is done when those production-factory paths are verified.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin
Domain
mobile, testing
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.