Skip to content

Commit eb94f14

Browse files
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>
1 parent c368812 commit eb94f14

3 files changed

Lines changed: 32 additions & 9 deletions

File tree

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ kotlinx-io = "0.8.2"
2121
ktor = "3.2.3"
2222
logging = "7.0.14"
2323
mockk = "1.14.9"
24-
mokksy = "0.6.2"
24+
mokksy = "0.8.0"
2525
serialization = "1.9.0"
2626
slf4j = "2.0.17"
2727
junit = "5.14.2"

kotlin-sdk-client/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/client/AbstractStreamableHttpClientTest.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import io.ktor.client.engine.apache5.Apache5
55
import io.ktor.client.plugins.logging.LogLevel
66
import io.ktor.client.plugins.logging.Logging
77
import io.ktor.client.plugins.sse.SSE
8+
import org.junit.jupiter.api.AfterAll
89
import org.junit.jupiter.api.AfterEach
910
import org.junit.jupiter.api.TestInstance
1011

@@ -16,7 +17,13 @@ internal abstract class AbstractStreamableHttpClientTest {
1617

1718
@AfterEach
1819
fun afterEach() {
19-
mockMcp.checkForUnmatchedRequests()
20+
mockMcp.verifyNoUnexpectedRequests()
21+
}
22+
23+
@AfterAll
24+
fun afterAll() {
25+
mockMcp.verifyNoUnmatchedStubs()
26+
mockMcp.close()
2027
}
2128

2229
protected suspend fun connect(client: Client) {

kotlin-sdk-client/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/client/MockMcp.kt

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package io.modelcontextprotocol.kotlin.sdk.client
33
import dev.mokksy.mokksy.BuildingStep
44
import dev.mokksy.mokksy.Mokksy
55
import dev.mokksy.mokksy.StubConfiguration
6+
import dev.mokksy.mokksy.shutdown
7+
import dev.mokksy.mokksy.start
68
import io.ktor.http.ContentType
79
import io.ktor.http.HttpMethod
810
import io.ktor.http.HttpStatusCode
@@ -21,16 +23,23 @@ import kotlinx.serialization.json.putJsonObject
2123

2224
const val MCP_SESSION_ID_HEADER = "MCP-Session-Id"
2325

24-
internal class MockMcp(verbose: Boolean = false) {
26+
internal class MockMcp(verbose: Boolean = false) : AutoCloseable {
2527

26-
private val mokksy: Mokksy = Mokksy(verbose = verbose)
28+
private val mokksy: Mokksy = Mokksy(verbose = verbose).apply {
29+
start()
30+
}
31+
32+
fun verifyNoUnexpectedRequests() {
33+
mokksy.verifyNoUnexpectedRequests()
34+
}
2735

28-
fun checkForUnmatchedRequests() {
29-
mokksy.checkForUnmatchedRequests()
36+
fun verifyNoUnmatchedStubs() {
37+
mokksy.verifyNoUnmatchedStubs()
3038
}
3139

3240
val url = "${mokksy.baseUrl()}/mcp"
3341

42+
@Suppress("LongParameterList")
3443
fun onInitialize(
3544
clientName: String? = null,
3645
sessionId: String,
@@ -108,6 +117,7 @@ internal class MockMcp(verbose: Boolean = false) {
108117
}
109118
}
110119

120+
@Suppress("LongParameterList")
111121
fun handleWithResult(
112122
httpMethod: HttpMethod = HttpMethod.Post,
113123
jsonRpcMethod: String,
@@ -124,9 +134,9 @@ internal class MockMcp(verbose: Boolean = false) {
124134
expectedSessionId = expectedSessionId,
125135
bodyPredicates = bodyPredicates,
126136
) respondsWith {
127-
val requestId = when (request.body.id) {
128-
is RequestId.NumberId -> (request.body.id as RequestId.NumberId).value.toString()
129-
is RequestId.StringId -> "\"${(request.body.id as RequestId.StringId).value}\""
137+
val requestId = when (val id = request.body().id) {
138+
is RequestId.NumberId -> id.value.toString()
139+
is RequestId.StringId -> "\"${id.value}\""
130140
}
131141
val resultObject = result.invoke()
132142
// language=json
@@ -143,6 +153,7 @@ internal class MockMcp(verbose: Boolean = false) {
143153
}
144154
}
145155

156+
@Suppress("LongParameterList")
146157
fun handleWithResult(
147158
httpMethod: HttpMethod = HttpMethod.Post,
148159
jsonRpcMethod: String,
@@ -167,6 +178,7 @@ internal class MockMcp(verbose: Boolean = false) {
167178
)
168179
}
169180

181+
@Suppress("LongParameterList")
170182
fun handleJSONRPCRequest(
171183
httpMethod: HttpMethod = HttpMethod.Post,
172184
jsonRpcMethod: String,
@@ -222,4 +234,8 @@ internal class MockMcp(verbose: Boolean = false) {
222234
body = null
223235
}
224236
}
237+
238+
override fun close() {
239+
mokksy.shutdown()
240+
}
225241
}

0 commit comments

Comments
 (0)