Skip to content

nip55: add permission decision and duration mapping round-trip test (#375) - #385

Merged
kwsantiago merged 1 commit into
mainfrom
nip55-permission-mapping-roundtrip-test
Jul 5, 2026
Merged

nip55: add permission decision and duration mapping round-trip test (#375)#385
kwsantiago merged 1 commit into
mainfrom
nip55-permission-mapping-roundtrip-test

Conversation

@wksantiago

@wksantiago wksantiago commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Tests
    • Added coverage to verify permission enum mappings round-trip correctly between app and native representations.
    • Confirmed all permission variants are mapped consistently in both directions, with matching variant counts and names.
    • Improved confidence that permission values remain stable across conversions.

@coderabbitai

coderabbitai Bot commented Jul 5, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

Adds a new JUnit test file, PermissionMappingRoundTripTest, that uses reflection to invoke private mapping functions and verify bijective round-trip mappings and full variant coverage between Kotlin's PermissionDuration/PermissionDecision enums and their Rust/UniFFI counterparts.

Changes

Round-trip enum mapping tests

Layer / File(s) Summary
Reflection-based mapping test class
app/src/test/kotlin/io/privkey/keep/nip55/PermissionMappingRoundTripTest.kt
Adds a JUnit test suite reflecting into PermissionStoreKt private mapping functions to verify name-preserving bijection, full variant coverage, and round-trip equality for PermissionDuration and PermissionDecision between Kotlin and Rust representations.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

Possibly related PRs

  • privkeyio/keep-android#365: Both PRs add NIP-55 Kotlin↔Rust FFI boundary tests relying on correct PermissionDecision enum mapping.

Suggested reviewers: kwsantiago

Poem

A rabbit hops through enums bright,
Kotlin to Rust and back to light,
Each name preserved, each size the same,
Round-trip tests confirm the game,
Hop, hop, hooray — no mismatch in sight! 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the new permission decision and duration round-trip test added in this PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch nip55-permission-mapping-roundtrip-test

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

Comment @coderabbitai help to get the list of available commands.

@wksantiago wksantiago self-assigned this Jul 5, 2026
@wksantiago wksantiago linked an issue Jul 5, 2026 that may be closed by this pull request

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
app/src/test/kotlin/io/privkey/keep/nip55/PermissionMappingRoundTripTest.kt (1)

29-45: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider consolidating the three reflective helpers.

durationToUniffi, durationToDomain, and decisionToDomain repeat the same getDeclaredMethodisAccessibleinvoke pattern with only the method name/types varying. A single generic helper (e.g. invokePrivate(name: String, paramType: Class<*>, arg: Any): Any) would remove the duplication.

♻️ Optional consolidation
-    private fun durationToUniffi(d: PermissionDuration): Nip55PermissionDuration {
-        val m = storeKt.getDeclaredMethod("toUniffi", PermissionDuration::class.java)
-        m.isAccessible = true
-        return m.invoke(null, d) as Nip55PermissionDuration
-    }
-
-    private fun durationToDomain(r: Nip55PermissionDuration): PermissionDuration {
-        val m = storeKt.getDeclaredMethod("toDomain", Nip55PermissionDuration::class.java)
-        m.isAccessible = true
-        return m.invoke(null, r) as PermissionDuration
-    }
-
-    private fun decisionToDomain(r: Nip55PermissionDecision): PermissionDecision {
-        val m = storeKt.getDeclaredMethod("toPermissionDecision", Nip55PermissionDecision::class.java)
-        m.isAccessible = true
-        return m.invoke(null, r) as PermissionDecision
-    }
+    private fun <T : Any> invokePrivate(name: String, paramType: Class<*>, arg: Any): T {
+        val m = storeKt.getDeclaredMethod(name, paramType)
+        m.isAccessible = true
+        `@Suppress`("UNCHECKED_CAST")
+        return m.invoke(null, arg) as T
+    }
+
+    private fun durationToUniffi(d: PermissionDuration): Nip55PermissionDuration =
+        invokePrivate("toUniffi", PermissionDuration::class.java, d)
+
+    private fun durationToDomain(r: Nip55PermissionDuration): PermissionDuration =
+        invokePrivate("toDomain", Nip55PermissionDuration::class.java, r)
+
+    private fun decisionToDomain(r: Nip55PermissionDecision): PermissionDecision =
+        invokePrivate("toPermissionDecision", Nip55PermissionDecision::class.java, r)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/src/test/kotlin/io/privkey/keep/nip55/PermissionMappingRoundTripTest.kt`
around lines 29 - 45, The three reflective helpers in
PermissionMappingRoundTripTest repeat the same private-method invocation
pattern, so consolidate them into one generic helper and have durationToUniffi,
durationToDomain, and decisionToDomain delegate to it. Add a single reusable
invokePrivate-style helper that takes the method name, parameter type, and
argument, performs getDeclaredMethod, sets isAccessible, and invokes it, then
update the existing helper methods to call that shared utility.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@app/src/test/kotlin/io/privkey/keep/nip55/PermissionMappingRoundTripTest.kt`:
- Around line 29-45: The three reflective helpers in
PermissionMappingRoundTripTest repeat the same private-method invocation
pattern, so consolidate them into one generic helper and have durationToUniffi,
durationToDomain, and decisionToDomain delegate to it. Add a single reusable
invokePrivate-style helper that takes the method name, parameter type, and
argument, performs getDeclaredMethod, sets isAccessible, and invokes it, then
update the existing helper methods to call that shared utility.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d9ec9c6d-7771-4b7c-8a10-fcf372715a30

📥 Commits

Reviewing files that changed from the base of the PR and between 7368c06 and 249c9c1.

📒 Files selected for processing (1)
  • app/src/test/kotlin/io/privkey/keep/nip55/PermissionMappingRoundTripTest.kt

@wksantiago
wksantiago requested a review from kwsantiago July 5, 2026 21:10
@kwsantiago
kwsantiago merged commit eea6760 into main Jul 5, 2026
4 checks passed
@kwsantiago
kwsantiago deleted the nip55-permission-mapping-roundtrip-test branch July 5, 2026 22:53
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.

tests: permission decision + duration mapping round-trips (Android)

2 participants