swift-sdk/Tests/MCPTests/VersioningTests.swift
Mattt 720a8102e9
Implement client protocol version negotiation in server initialization (#107)
* 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
2025-05-07 05:58:11 -07:00

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")
}
}