nip55: add permission decision and duration mapping round-trip test (#375) - #385
Conversation
WalkthroughAdds a new JUnit test file, ChangesRound-trip enum mapping tests
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related issues
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
app/src/test/kotlin/io/privkey/keep/nip55/PermissionMappingRoundTripTest.kt (1)
29-45: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider consolidating the three reflective helpers.
durationToUniffi,durationToDomain, anddecisionToDomainrepeat the samegetDeclaredMethod→isAccessible→invokepattern 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
📒 Files selected for processing (1)
app/src/test/kotlin/io/privkey/keep/nip55/PermissionMappingRoundTripTest.kt
Summary by CodeRabbit