chore(deps): bump dev.mokksy:mokksy from 0.6.2 to 0.8.0 (#557)
Bumps [dev.mokksy:mokksy](https://github.com/mokksy/ai-mocks) from 0.6.2 to 0.8.0. - Update dependency and migrate to new API --------- Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Konstantin Pavlov <1517853+kpavlov@users.noreply.github.com>
This commit is contained in:
parent
c36881282f
commit
eb94f14132
2 changed files with 32 additions and 9 deletions
|
|
@ -5,6 +5,7 @@ import io.ktor.client.engine.apache5.Apache5
|
|||
import io.ktor.client.plugins.logging.LogLevel
|
||||
import io.ktor.client.plugins.logging.Logging
|
||||
import io.ktor.client.plugins.sse.SSE
|
||||
import org.junit.jupiter.api.AfterAll
|
||||
import org.junit.jupiter.api.AfterEach
|
||||
import org.junit.jupiter.api.TestInstance
|
||||
|
||||
|
|
@ -16,7 +17,13 @@ internal abstract class AbstractStreamableHttpClientTest {
|
|||
|
||||
@AfterEach
|
||||
fun afterEach() {
|
||||
mockMcp.checkForUnmatchedRequests()
|
||||
mockMcp.verifyNoUnexpectedRequests()
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
fun afterAll() {
|
||||
mockMcp.verifyNoUnmatchedStubs()
|
||||
mockMcp.close()
|
||||
}
|
||||
|
||||
protected suspend fun connect(client: Client) {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ package io.modelcontextprotocol.kotlin.sdk.client
|
|||
import dev.mokksy.mokksy.BuildingStep
|
||||
import dev.mokksy.mokksy.Mokksy
|
||||
import dev.mokksy.mokksy.StubConfiguration
|
||||
import dev.mokksy.mokksy.shutdown
|
||||
import dev.mokksy.mokksy.start
|
||||
import io.ktor.http.ContentType
|
||||
import io.ktor.http.HttpMethod
|
||||
import io.ktor.http.HttpStatusCode
|
||||
|
|
@ -21,16 +23,23 @@ import kotlinx.serialization.json.putJsonObject
|
|||
|
||||
const val MCP_SESSION_ID_HEADER = "MCP-Session-Id"
|
||||
|
||||
internal class MockMcp(verbose: Boolean = false) {
|
||||
internal class MockMcp(verbose: Boolean = false) : AutoCloseable {
|
||||
|
||||
private val mokksy: Mokksy = Mokksy(verbose = verbose)
|
||||
private val mokksy: Mokksy = Mokksy(verbose = verbose).apply {
|
||||
start()
|
||||
}
|
||||
|
||||
fun checkForUnmatchedRequests() {
|
||||
mokksy.checkForUnmatchedRequests()
|
||||
fun verifyNoUnexpectedRequests() {
|
||||
mokksy.verifyNoUnexpectedRequests()
|
||||
}
|
||||
|
||||
fun verifyNoUnmatchedStubs() {
|
||||
mokksy.verifyNoUnmatchedStubs()
|
||||
}
|
||||
|
||||
val url = "${mokksy.baseUrl()}/mcp"
|
||||
|
||||
@Suppress("LongParameterList")
|
||||
fun onInitialize(
|
||||
clientName: String? = null,
|
||||
sessionId: String,
|
||||
|
|
@ -108,6 +117,7 @@ internal class MockMcp(verbose: Boolean = false) {
|
|||
}
|
||||
}
|
||||
|
||||
@Suppress("LongParameterList")
|
||||
fun handleWithResult(
|
||||
httpMethod: HttpMethod = HttpMethod.Post,
|
||||
jsonRpcMethod: String,
|
||||
|
|
@ -124,9 +134,9 @@ internal class MockMcp(verbose: Boolean = false) {
|
|||
expectedSessionId = expectedSessionId,
|
||||
bodyPredicates = bodyPredicates,
|
||||
) respondsWith {
|
||||
val requestId = when (request.body.id) {
|
||||
is RequestId.NumberId -> (request.body.id as RequestId.NumberId).value.toString()
|
||||
is RequestId.StringId -> "\"${(request.body.id as RequestId.StringId).value}\""
|
||||
val requestId = when (val id = request.body().id) {
|
||||
is RequestId.NumberId -> id.value.toString()
|
||||
is RequestId.StringId -> "\"${id.value}\""
|
||||
}
|
||||
val resultObject = result.invoke()
|
||||
// language=json
|
||||
|
|
@ -143,6 +153,7 @@ internal class MockMcp(verbose: Boolean = false) {
|
|||
}
|
||||
}
|
||||
|
||||
@Suppress("LongParameterList")
|
||||
fun handleWithResult(
|
||||
httpMethod: HttpMethod = HttpMethod.Post,
|
||||
jsonRpcMethod: String,
|
||||
|
|
@ -167,6 +178,7 @@ internal class MockMcp(verbose: Boolean = false) {
|
|||
)
|
||||
}
|
||||
|
||||
@Suppress("LongParameterList")
|
||||
fun handleJSONRPCRequest(
|
||||
httpMethod: HttpMethod = HttpMethod.Post,
|
||||
jsonRpcMethod: String,
|
||||
|
|
@ -222,4 +234,8 @@ internal class MockMcp(verbose: Boolean = false) {
|
|||
body = null
|
||||
}
|
||||
}
|
||||
|
||||
override fun close() {
|
||||
mokksy.shutdown()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue