* Implement client version negotiation in server initialization * Add test coverage for version negotiation * Make Version.supported and Version.negotiate() APIs internal to not create new surface area
53 lines
1.9 KiB
Swift
53 lines
1.9 KiB
Swift
import Testing
|
|
|
|
@testable import MCP
|
|
|
|
@Suite("Version Negotiation Tests")
|
|
struct VersioningTests {
|
|
@Test("Client requests latest supported version")
|
|
func testClientRequestsLatestSupportedVersion() {
|
|
let clientVersion = Version.latest
|
|
let negotiatedVersion = Version.negotiate(clientRequestedVersion: clientVersion)
|
|
#expect(negotiatedVersion == Version.latest)
|
|
}
|
|
|
|
@Test("Client requests older supported version")
|
|
func testClientRequestsOlderSupportedVersion() {
|
|
let clientVersion = "2024-11-05"
|
|
let negotiatedVersion = Version.negotiate(clientRequestedVersion: clientVersion)
|
|
#expect(negotiatedVersion == "2024-11-05")
|
|
}
|
|
|
|
@Test("Client requests unsupported version")
|
|
func testClientRequestsUnsupportedVersion() {
|
|
let clientVersion = "2023-01-01" // An unsupported version
|
|
let negotiatedVersion = Version.negotiate(clientRequestedVersion: clientVersion)
|
|
#expect(negotiatedVersion == Version.latest)
|
|
}
|
|
|
|
@Test("Client requests empty version string")
|
|
func testClientRequestsEmptyVersionString() {
|
|
let clientVersion = ""
|
|
let negotiatedVersion = Version.negotiate(clientRequestedVersion: clientVersion)
|
|
#expect(negotiatedVersion == Version.latest)
|
|
}
|
|
|
|
@Test("Client requests garbage version string")
|
|
func testClientRequestsGarbageVersionString() {
|
|
let clientVersion = "not-a-version"
|
|
let negotiatedVersion = Version.negotiate(clientRequestedVersion: clientVersion)
|
|
#expect(negotiatedVersion == Version.latest)
|
|
}
|
|
|
|
@Test("Server's supported versions correctly defined")
|
|
func testServerSupportedVersions() {
|
|
#expect(Version.supported.contains("2025-03-26"))
|
|
#expect(Version.supported.contains("2024-11-05"))
|
|
#expect(Version.supported.count == 2)
|
|
}
|
|
|
|
@Test("Server's latest version is correct")
|
|
func testServerLatestVersion() {
|
|
#expect(Version.latest == "2025-03-26")
|
|
}
|
|
}
|