Keep multiple MCP toolsets connected and restore workspace navigation
This commit is contained in:
@@ -672,3 +672,72 @@ final class ToolboxRepairTests: XCTestCase {
|
||||
XCTAssertTrue(context.contains("source: notes.md"))
|
||||
}
|
||||
}
|
||||
|
||||
final class MultipleToolsetsTests: XCTestCase {
|
||||
private struct MockClient: MCPToolClient {
|
||||
let identifier: String
|
||||
|
||||
func listTools() async throws -> [MCPTool] {
|
||||
[MCPTool(name: "echo", description: "", inputSchemaJSON: Data("{}".utf8))]
|
||||
}
|
||||
|
||||
func callTool(_ name: String, argumentsJSON: Data) async throws -> Data {
|
||||
try await Task.sleep(for: .milliseconds(150))
|
||||
return Data(identifier.utf8)
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
func testSeparateConnectionsRunCallsAndRetainResultsIndependently() async throws {
|
||||
let studio = StudioModel()
|
||||
let first = MCPConnectionID.profile("First")
|
||||
let second = MCPConnectionID.profile("Second")
|
||||
studio.connectMCP(first, name: "First") { MockClient(identifier: "first result") }
|
||||
studio.connectMCP(second, name: "Second") { MockClient(identifier: "second result") }
|
||||
try await waitUntil { studio.activeToolsets.count == 2 }
|
||||
studio.invokeMCP(first, tool: "echo", arguments: Data("{}".utf8), searchEndpoint: "")
|
||||
studio.invokeMCP(second, tool: "echo", arguments: Data("{}".utf8), searchEndpoint: "")
|
||||
XCTAssertNotNil(studio.mcpConnections[first]?.progress)
|
||||
XCTAssertNotNil(studio.mcpConnections[second]?.progress)
|
||||
try await waitUntil {
|
||||
studio.mcpConnections[first]?.completedTool == "echo" &&
|
||||
studio.mcpConnections[second]?.completedTool == "echo"
|
||||
}
|
||||
XCTAssertEqual(studio.mcpConnections[first]?.output, "first result")
|
||||
XCTAssertEqual(studio.mcpConnections[second]?.output, "second result")
|
||||
studio.disconnectMCP(first)
|
||||
XCTAssertNil(studio.mcpConnections[first])
|
||||
XCTAssertEqual(studio.activeToolsets.map(\.id), [second])
|
||||
}
|
||||
|
||||
@MainActor
|
||||
func testInstalledServersAndBuiltInWebCanStayConnectedTogether() async throws {
|
||||
let env = ProcessInfo.processInfo.environment
|
||||
guard let path = env["AISTUDIO_TEST_REAL_MCP_CONFIG"], env["AISTUDIO_TEST_REAL_GITEA"] == "1" else {
|
||||
throw XCTSkip("Enable the installed MCP profiles smoke test explicitly.")
|
||||
}
|
||||
let config = try MCPServerConfiguration.File.read(URL(fileURLWithPath: path))
|
||||
let studio = StudioModel()
|
||||
for name in ["absdev-gitea", "local-knowledge"] {
|
||||
let profile = try XCTUnwrap(config.mcpServers[name])
|
||||
studio.connectMCP(.profile(name), name: name) { try profile.makeClient() }
|
||||
}
|
||||
studio.connectMCP(.web, name: BuiltInWebTools.name) { BuiltInWebTools(searchEndpoint: "") }
|
||||
try await waitUntil { studio.activeToolsets.count == 3 }
|
||||
XCTAssertNotNil(studio.connectedKnowledge)
|
||||
studio.disconnectMCP(.profile("absdev-gitea"))
|
||||
XCTAssertNotNil(studio.mcpConnections[.web]?.toolset)
|
||||
XCTAssertNotNil(studio.connectedKnowledge)
|
||||
studio.disconnectMCP(.profile("local-knowledge"))
|
||||
studio.disconnectMCP(.web)
|
||||
}
|
||||
|
||||
@MainActor
|
||||
private func waitUntil(_ condition: @escaping () -> Bool) async throws {
|
||||
let deadline = ContinuousClock.now + .seconds(5)
|
||||
while !condition(), ContinuousClock.now < deadline {
|
||||
try await Task.sleep(for: .milliseconds(10))
|
||||
}
|
||||
XCTAssertTrue(condition())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user