digidem / digidem/comapeo-core-react-native
Test: cover ComapeoPrefs.open() factory path on iOS (real UserDefaults suite)
Nobody has claimed this yet.
- 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:
open()returns aComapeoPrefsbacked by the documentedUserDefaults.standard(or a suite-named instance once the factory is refactored to accept one for testability).- The default-fallback precedence:
user write > plist default (fromSentryConfig.loadFromMainBundle) > baked-in defaultDiagnosticsEnabled. - The
object(forKey:) as? Boolsemantics: anexplicit falsewrite must persist asfalse(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.swiftios/Tests/ComapeoPrefsTests.swift- Plan:
docs/sentry-integration-plan.md§9.8
🤖 Generated with Claude Code
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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