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
3 changed files with 32 additions and 9 deletions
|
|
@ -21,7 +21,7 @@ kotlinx-io = "0.8.2"
|
||||||
ktor = "3.2.3"
|
ktor = "3.2.3"
|
||||||
logging = "7.0.14"
|
logging = "7.0.14"
|
||||||
mockk = "1.14.9"
|
mockk = "1.14.9"
|
||||||
mokksy = "0.6.2"
|
mokksy = "0.8.0"
|
||||||
serialization = "1.9.0"
|
serialization = "1.9.0"
|
||||||
slf4j = "2.0.17"
|
slf4j = "2.0.17"
|
||||||
junit = "5.14.2"
|
junit = "5.14.2"
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import io.ktor.client.engine.apache5.Apache5
|
||||||
import io.ktor.client.plugins.logging.LogLevel
|
import io.ktor.client.plugins.logging.LogLevel
|
||||||
import io.ktor.client.plugins.logging.Logging
|
import io.ktor.client.plugins.logging.Logging
|
||||||
import io.ktor.client.plugins.sse.SSE
|
import io.ktor.client.plugins.sse.SSE
|
||||||
|
import org.junit.jupiter.api.AfterAll
|
||||||
import org.junit.jupiter.api.AfterEach
|
import org.junit.jupiter.api.AfterEach
|
||||||
import org.junit.jupiter.api.TestInstance
|
import org.junit.jupiter.api.TestInstance
|
||||||
|
|
||||||
|
|
@ -16,7 +17,13 @@ internal abstract class AbstractStreamableHttpClientTest {
|
||||||
|
|
||||||
@AfterEach
|
@AfterEach
|
||||||
fun afterEach() {
|
fun afterEach() {
|
||||||
mockMcp.checkForUnmatchedRequests()
|
mockMcp.verifyNoUnexpectedRequests()
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterAll
|
||||||
|
fun afterAll() {
|
||||||
|
mockMcp.verifyNoUnmatchedStubs()
|
||||||
|
mockMcp.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
protected suspend fun connect(client: Client) {
|
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.BuildingStep
|
||||||
import dev.mokksy.mokksy.Mokksy
|
import dev.mokksy.mokksy.Mokksy
|
||||||
import dev.mokksy.mokksy.StubConfiguration
|
import dev.mokksy.mokksy.StubConfiguration
|
||||||
|
import dev.mokksy.mokksy.shutdown
|
||||||
|
import dev.mokksy.mokksy.start
|
||||||
import io.ktor.http.ContentType
|
import io.ktor.http.ContentType
|
||||||
import io.ktor.http.HttpMethod
|
import io.ktor.http.HttpMethod
|
||||||
import io.ktor.http.HttpStatusCode
|
import io.ktor.http.HttpStatusCode
|
||||||
|
|
@ -21,16 +23,23 @@ import kotlinx.serialization.json.putJsonObject
|
||||||
|
|
||||||
const val MCP_SESSION_ID_HEADER = "MCP-Session-Id"
|
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() {
|
fun verifyNoUnexpectedRequests() {
|
||||||
mokksy.checkForUnmatchedRequests()
|
mokksy.verifyNoUnexpectedRequests()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun verifyNoUnmatchedStubs() {
|
||||||
|
mokksy.verifyNoUnmatchedStubs()
|
||||||
}
|
}
|
||||||
|
|
||||||
val url = "${mokksy.baseUrl()}/mcp"
|
val url = "${mokksy.baseUrl()}/mcp"
|
||||||
|
|
||||||
|
@Suppress("LongParameterList")
|
||||||
fun onInitialize(
|
fun onInitialize(
|
||||||
clientName: String? = null,
|
clientName: String? = null,
|
||||||
sessionId: String,
|
sessionId: String,
|
||||||
|
|
@ -108,6 +117,7 @@ internal class MockMcp(verbose: Boolean = false) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("LongParameterList")
|
||||||
fun handleWithResult(
|
fun handleWithResult(
|
||||||
httpMethod: HttpMethod = HttpMethod.Post,
|
httpMethod: HttpMethod = HttpMethod.Post,
|
||||||
jsonRpcMethod: String,
|
jsonRpcMethod: String,
|
||||||
|
|
@ -124,9 +134,9 @@ internal class MockMcp(verbose: Boolean = false) {
|
||||||
expectedSessionId = expectedSessionId,
|
expectedSessionId = expectedSessionId,
|
||||||
bodyPredicates = bodyPredicates,
|
bodyPredicates = bodyPredicates,
|
||||||
) respondsWith {
|
) respondsWith {
|
||||||
val requestId = when (request.body.id) {
|
val requestId = when (val id = request.body().id) {
|
||||||
is RequestId.NumberId -> (request.body.id as RequestId.NumberId).value.toString()
|
is RequestId.NumberId -> id.value.toString()
|
||||||
is RequestId.StringId -> "\"${(request.body.id as RequestId.StringId).value}\""
|
is RequestId.StringId -> "\"${id.value}\""
|
||||||
}
|
}
|
||||||
val resultObject = result.invoke()
|
val resultObject = result.invoke()
|
||||||
// language=json
|
// language=json
|
||||||
|
|
@ -143,6 +153,7 @@ internal class MockMcp(verbose: Boolean = false) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("LongParameterList")
|
||||||
fun handleWithResult(
|
fun handleWithResult(
|
||||||
httpMethod: HttpMethod = HttpMethod.Post,
|
httpMethod: HttpMethod = HttpMethod.Post,
|
||||||
jsonRpcMethod: String,
|
jsonRpcMethod: String,
|
||||||
|
|
@ -167,6 +178,7 @@ internal class MockMcp(verbose: Boolean = false) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("LongParameterList")
|
||||||
fun handleJSONRPCRequest(
|
fun handleJSONRPCRequest(
|
||||||
httpMethod: HttpMethod = HttpMethod.Post,
|
httpMethod: HttpMethod = HttpMethod.Post,
|
||||||
jsonRpcMethod: String,
|
jsonRpcMethod: String,
|
||||||
|
|
@ -222,4 +234,8 @@ internal class MockMcp(verbose: Boolean = false) {
|
||||||
body = null
|
body = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun close() {
|
||||||
|
mokksy.shutdown()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue