Skip to content

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

@gmaclennan

Description

@gmaclennan

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions