kotlin-sdk/test-utils
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Konstantin Pavlov a38818018a
fix!(server): #575 Rethrow CancellationException in StdioServerTransport, fix ReadBuffer (#571)
## Rethrow CancellationException in StdioServerTransport, fix ReadBuffer

### Changes
1. StdioServerTransport
- Replace generic `Throwable` catches with specific
`CancellationException` and `Exception` for clarity and correctness.
**breaking change** `Throwable` is not handled any more!
    - Refactor launching jobs to separate methods
- Introduce `READ_BUFFER_SIZE` constant to replace inline buffer size
literals.
- Add suppress annotations for clearer intent and constructor
documentation for better usability.
    - Extend StdioServerTransportTest

2. ReadBuffer

Previously, readMessage() returned null after consuming an unparseable
line even when more complete lines existed in the buffer. This caused
valid messages following a bad line in the same chunk to be silently
dropped until the next chunk arrived (or forever, in tests).
    
Fix the loop so null means only "no complete line available", not
"encountered a parse failure". Blank/whitespace-only lines are now
silently skipped via isBlank() rather than forwarded to the deserializer
and logged as errors.
    
    Refactor the method into three focused helpers:
     - readMessage() — outer loop over lines
- readLine() — consume the next newline-delimited line from the buffer
     - tryRecover()  — attempt deserialization from the first '{' onward

3. Add utility method `runIntegrationTest` for integration testing
(`runBlocking` + `withTimeout`). Use it in StdioServerTransportTest

4. Store processing Job reference and `calcelAndJoin()` it on close.
Partially addressing #574

## Motivation and Context

See #575, #564, #242 

## How Has This Been Tested?
Unit test added

## Breaking Changes

Semantic change: `Throwable` and CancellationException are not handled
any more!

## Types of changes

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Documentation update

## Checklist
<!-- Go over all the following points, and put an `x` in all the boxes
that apply. -->
- [x] I have read the [MCP
Documentation](https://modelcontextprotocol.io)
- [x] My code follows the repository's style guidelines
- [x] New and existing tests pass locally
- [ ] I have added appropriate error handling
- [ ] I have added or updated documentation as needed

## Additional context
<!-- Add any other context, implementation notes, or design decisions
-->
2026-03-03 16:10:25 +02:00
..
src fix!(server): #575 Rethrow CancellationException in StdioServerTransport, fix ReadBuffer (#571) 2026-03-03 16:10:25 +02:00
build.gradle.kts refactor: Refactor serialization tests (#527) 2026-02-17 12:16:02 +02:00
detekt-baseline.xml refactor: Refactor serialization tests (#527) 2026-02-17 12:16:02 +02:00