digidem / digidem/comapeo-core-react-native

Test: cover ComapeoPrefs.open() factory path on iOS (real UserDefaults suite)

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

Nobody has claimed this yet.

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

Description

Background

The iOS ComapeoPrefs XCTest cases in ios/Tests/ComapeoPrefsTests.swift exercise the closure-seam constructor only — the open() factory that wires UserDefaults.standard and reads plugin defaults via SentryConfig.loadFromMainBundle is untested.

This came up in the review of the diagnostics-toggle PR (#TBD). A regression in the production factory (wrong key namespace in the read/write closures, wrong default precedence between Info.plist / baked-in, or a bool(forKey:) regression that collapses "absent" with "explicit false") wouldn't be caught by the existing tests.

The bool(forKey:) case in particular is load-bearing for the privacy model — object(forKey:) as? Bool returns nil when the key is absent so we can fall through to the plugin default, but bool(forKey:) returns false regardless. Silently swapping the production read to the wrong one would re-enable diagnostics on every device that opted out.

What's needed

A test that uses UserDefaults(suiteName: "<unique-test-suite>") (NOT .standard, which is process-wide and leaks across test runs) plus a custom Bundle.main-substitute fixture to verify:

  1. open() returns a ComapeoPrefs backed by the documented UserDefaults.standard (or a suite-named instance once the factory is refactored to accept one for testability).
  2. The default-fallback precedence: user write > plist default (from SentryConfig.loadFromMainBundle) > baked-in defaultDiagnosticsEnabled.
  3. The object(forKey:) as? Bool semantics: an explicit false write must persist as false (not silently fall back to the default).

Likely requires refactoring open() to accept an injectable UserDefaults instance for the test path. Pure Swift, no XCUITest, runs in the existing swift test target.

Why deferred

A clean test requires either factory refactoring or carefully scoped UserDefaults cleanup — out of scope for the toggle-persistence PR. The closure-seam tests cover the read/write/wipe logic; this issue covers the wiring.

References

  • ios/ComapeoPrefs.swift
  • ios/Tests/ComapeoPrefsTests.swift
  • 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

Read ios/ComapeoPrefs.swift and ios/Tests/ComapeoPrefsTests.swift, then run the existing swift test target to understand the closure-seam coverage. Focus on the open() wiring, injectable UserDefaults or scoped cleanup, and the Bundle.main-substitute fixture described in the issue. Done means tests cover user writes, plist and baked-in fallback precedence, and explicit false without leaking suite state.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
mobile, testing
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.