jaoafa / VCSpeaker.kt

🔊 Text channel, now with voice
https://jaoafa.github.io/VCSpeaker.kt/
Eclipse Public License 2.0
3 stars 1 forks source link

feat: processorの分割 #156

Closed book000 closed 3 months ago

book000 commented 4 months ago

発話そのものの可否と、メッセージメタデータを使う処理、VoiceTextパラメータの変更を必要とする機能である Processor を Replacer 同様に分割し、processText関数内でのごちゃごちゃを軽減させます。

テストケース名レビュー: https://docs.google.com/spreadsheets/d/13ofOk0xV5aIzA8RJHYRaUE1Bhf84VuaBigPSb2EXhKI/edit?usp=sharing

進捗

テストケースの整理

book000 commented 4 months ago

Replacerのテストもう少し作り込まなきゃダメかな…

book000 commented 4 months ago

https://kotest.io/docs/framework/integrations/mocking.html

book000 commented 4 months ago

さて、結合テストのバターンを考えないと…。

book000 commented 4 months ago

Attachment.downloadがですとできないやつ、HttpClient.getをmockすればいいのか?

image

book000 commented 3 months ago

画像ファイルの文字起こし処理テストに断念。とりあえずメモ message.replyがinlineなことにより、モックできないらしい


    test("download") {
        // 画像ファイル image.png
        mockkStatic("com.kotlindiscord.kord.extensions.utils._AttachmentsKt")
        val attachment = mockk<Attachment>()
        every { attachment.isImage } returns true
        every { attachment.isSpoiler } returns false
        every { attachment.filename } returns "image.png"
        coEvery { attachment.download() } returns byteArrayOf(0x00)

        // VisionApi
        mockkObject(VisionApi)
        every { VisionApi.isGoogleAppCredentialsExist() } returns true
        every { VisionApi.getTextAnnotations(any()) } returns listOf(
            VisionTextAnnotation(
                "test",
                "ja",
                1.0f,
                listOf(VisionVertex(0, 0), VisionVertex(0, 0), VisionVertex(0, 0), VisionVertex(0, 0))
            )
        )
        every { VisionApi.drawTextAnnotations(any()) } returns mockk<ImmutableImage> {
            every { output(any<PngWriter>(), any<File>()) } returns mockk()
        }

        mockkObject(VCSpeaker)
        every { VCSpeaker.storeFolder } returns File("./store-test")

        mockkObject(VisionApiCounterStore)
        every { VisionApiCounterStore.get() } returns mockk {
            every { count } returns 0
        }
        every { VisionApiCounterStore.increment() } just Runs

        mockkStatic("dev.kord.core.behavior.MessageBehaviorKt")
        val message = mockk<Message>()
        coEvery { message.reply(any()) } returns mockk<Message>()
        every { message.attachments } returns setOf(attachment)

        val voice = Voice(speaker = Speaker.Hikari)

        val (processedText, processedVoice) = AttachmentProcessor().process(message, "test", voice)

        processedText shouldBe "test 画像ファイル image.png "
        processedVoice shouldBe voice
    }
book000 commented 3 months ago

@yuuahp レビューをお願いします。基本的にはテストの追加ばっかりですが、PRあたりの変更がかなり大きくなってしまいごめんなさい

それはそれとして、assign reviewは相変わらずエラーです https://github.com/jaoafa/VCSpeaker.kt/actions/runs/9632849766/job/26566534103

yuuahp commented 3 months ago

もしかしてコミットされるとその部分のレビューのドラフト消える?

book000 commented 3 months ago

うそお!?