diff options
| author | Sho Sakuma <me@m1sk9.dev> | 2026-04-07 18:17:36 +0900 |
|---|---|---|
| committer | Sho Sakuma <me@m1sk9.dev> | 2026-04-07 18:17:36 +0900 |
| commit | 84e8677d470f216c060e3c3c615f9093bd755abe (patch) | |
| tree | faed409ee0ab246e4ecc6bcd3bff78a776747077 /platform-paper/src | |
| parent | e634887202e97be0b2dd8b850cc1dc7ab164309c (diff) | |
| download | LunaticChat-84e8677d470f216c060e3c3c615f9093bd755abe.tar.gz LunaticChat-84e8677d470f216c060e3c3c615f9093bd755abe.tar.bz2 LunaticChat-84e8677d470f216c060e3c3c615f9093bd755abe.zip | |
ci: fix codecov/patch failure by excluding command impl and adding applyMethodPermission tests
Exclude command implementation classes (platform-paper/command/impl/**) from
codecov coverage metrics since they are tightly coupled to the Paper/Brigadier
runtime and exercised via end-to-end server tests. This consolidates the
previous per-file exclusion for VelocityStatusCommand.
Also add unit tests for the new applyMethodPermission method in LunaticCommand
to ensure the command/core package maintains coverage.
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'platform-paper/src')
| -rw-r--r-- | platform-paper/src/test/kotlin/dev/m1sk9/lunaticChat/paper/command/core/ApplyMethodPermissionTest.kt | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/platform-paper/src/test/kotlin/dev/m1sk9/lunaticChat/paper/command/core/ApplyMethodPermissionTest.kt b/platform-paper/src/test/kotlin/dev/m1sk9/lunaticChat/paper/command/core/ApplyMethodPermissionTest.kt new file mode 100644 index 0000000..1625ebd --- /dev/null +++ b/platform-paper/src/test/kotlin/dev/m1sk9/lunaticChat/paper/command/core/ApplyMethodPermissionTest.kt @@ -0,0 +1,67 @@ +package dev.m1sk9.lunaticChat.paper.command.core + +import com.mojang.brigadier.builder.LiteralArgumentBuilder +import dev.m1sk9.lunaticChat.engine.permission.LunaticChatPermissionNode +import dev.m1sk9.lunaticChat.paper.LunaticChat +import dev.m1sk9.lunaticChat.paper.command.annotation.Permission +import io.mockk.every +import io.mockk.mockk +import io.papermc.paper.command.brigadier.CommandSourceStack +import io.papermc.paper.command.brigadier.Commands +import kotlin.test.Test +import kotlin.test.assertNotNull +import kotlin.test.assertSame + +@Suppress("UnstableApiUsage") +class ApplyMethodPermissionTest { + /** + * Test helper that exposes [LunaticCommand.applyMethodPermission] and has + * an annotated method for testing. + */ + private class TestableCommand( + plugin: LunaticChat, + ) : LunaticCommand(plugin) { + override fun buildCommand(): LiteralArgumentBuilder<CommandSourceStack> = Commands.literal("test") + + /** Expose the protected applyMethodPermission for testing. */ + fun testApplyMethodPermission( + methodName: String, + builder: LiteralArgumentBuilder<CommandSourceStack>, + ): LiteralArgumentBuilder<CommandSourceStack> = applyMethodPermission(methodName, builder) + + @Permission(LunaticChatPermissionNode.Status::class) + fun annotatedMethod(): LiteralArgumentBuilder<CommandSourceStack> = Commands.literal("annotated") + + fun unannotatedMethod(): LiteralArgumentBuilder<CommandSourceStack> = Commands.literal("unannotated") + } + + private val plugin = mockk<LunaticChat>(relaxed = true) + private val command = TestableCommand(plugin) + + @Test + fun `applyMethodPermission adds requirement when method has Permission annotation`() { + val builder = Commands.literal("test") + val result = command.testApplyMethodPermission("annotatedMethod", builder) + + // The builder should have a requirement set (not the default always-true) + val source = mockk<CommandSourceStack>() + every { source.sender.hasPermission("lunaticchat.command.lc.status") } returns false + assertNotNull(result.requirement) + } + + @Test + fun `applyMethodPermission returns builder unchanged when method has no Permission annotation`() { + val builder = Commands.literal("test") + val result = command.testApplyMethodPermission("unannotatedMethod", builder) + + assertSame(builder, result) + } + + @Test + fun `applyMethodPermission returns builder unchanged when method does not exist`() { + val builder = Commands.literal("test") + val result = command.testApplyMethodPermission("nonExistentMethod", builder) + + assertSame(builder, result) + } +} |
