Skip to content

Commit a23856e

Browse files
authored
Add recovery during deserialization and upload test artifacts (#243)
* Add recovery during message deserialization, update workflow, use JUnit Platform for JVM tests
1 parent b37a0f6 commit a23856e

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

.github/workflows/validate-pr.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,38 @@ name: Validate PR
33
on:
44
workflow_dispatch:
55
pull_request:
6-
branches: [main]
6+
branches: [ main ]
77

88
concurrency:
9-
group: ${{ github.workflow }}-${{ github.ref }}
10-
cancel-in-progress: true
9+
group: ${{ github.workflow }}-${{ github.ref }}
10+
cancel-in-progress: true
1111

1212
jobs:
1313
validate-pr:
1414
runs-on: macos-latest
1515
name: Validate PR
1616
steps:
1717
- uses: actions/checkout@v4
18+
1819
- name: Set up JDK 21
1920
uses: actions/setup-java@v4
2021
with:
2122
java-version: '21'
2223
distribution: 'temurin'
24+
2325
- name: Setup Gradle
2426
uses: gradle/actions/setup-gradle@v4
2527

2628
- name: Clean Build with Gradle
2729
run: ./gradlew clean build
2830

31+
- name: Upload JUnit test results
32+
if: always()
33+
uses: actions/upload-artifact@v4
34+
with:
35+
name: junit-results
36+
path: '**/build/test-results/test/*.xml'
37+
2938
- name: Disable Auto-Merge on Fail
3039
if: failure()
3140
run: gh pr merge --disable-auto "$PR_URL"

kotlin-sdk-core/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/shared/ReadBuffer.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,17 @@ public class ReadBuffer {
4444
try {
4545
return deserializeMessage(line)
4646
} catch (e: Exception) {
47-
logger.error(e) { "Failed to deserialize message from line: $line\nSkipping..." }
47+
logger.error(e) { "Failed to deserialize message from line: $line\nAttempting to recover..." }
48+
// if there is a non-JSON object prefix, try to parse from the first '{' onward.
49+
val braceIndex = line.indexOf('{')
50+
if (braceIndex != -1) {
51+
val trimmed = line.substring(braceIndex)
52+
try {
53+
return deserializeMessage(trimmed)
54+
} catch (ignored: Exception) {
55+
logger.error(ignored) { "Deserialization failed for line: $line\nSkipping..." }
56+
}
57+
}
4858
}
4959

5060
return null

kotlin-sdk-test/build.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ plugins {
33
}
44

55
kotlin {
6+
jvm {
7+
testRuns["test"].executionTask.configure {
8+
useJUnitPlatform()
9+
}
10+
}
611
sourceSets {
712
commonTest {
813
dependencies {

0 commit comments

Comments
 (0)