Add custom MCP profiles and reusable workspace libraries
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import XCTest
|
||||
import AppKit
|
||||
@testable import AIStudio
|
||||
|
||||
final class StudioTests: XCTestCase {
|
||||
@@ -475,3 +476,81 @@ final class DesktopRuntimeTests: XCTestCase {
|
||||
XCTAssertEqual(try MLXRuntimeLimits.weightBytes(in: directory), 50)
|
||||
}
|
||||
}
|
||||
|
||||
final class CustomMCPConfigurationTests: XCTestCase {
|
||||
func testCustomProfileParsesEnvAndHeaders() throws {
|
||||
let configuration = try JSONDecoder().decode(MCPServerConfiguration.File.self, from: Data(#"""
|
||||
{"mcpServers":{"remote":{"url":"https://example.com/mcp","headers":{"X-Example":"token"}},
|
||||
"local":{"command":"sh","args":["one","two with spaces"],"env":{"TEST_MCP_SETTING":"example"}}}}
|
||||
"""#.utf8))
|
||||
let local = try XCTUnwrap(configuration.mcpServers["local"])
|
||||
XCTAssertEqual(local.args, ["one", "two with spaces"])
|
||||
let launch = try MCPServerConfiguration.resolveCommand("sh", environment: local.env ?? [:], cwd: "/private/tmp")
|
||||
XCTAssertTrue(launch.executable.path.hasSuffix("/sh"))
|
||||
XCTAssertEqual(launch.environment["TEST_MCP_SETTING"], "example")
|
||||
XCTAssertEqual(launch.workingDirectory?.path, "/private/tmp")
|
||||
XCTAssertNoThrow(try configuration.mcpServers["remote"]?.makeClient())
|
||||
XCTAssertThrowsError(try HTTPMCPClient(endpoint: "https://example.com/mcp", headers: ["Host": "elsewhere"]))
|
||||
}
|
||||
|
||||
func testInstalledKnowledgeServerDiscovery() async throws {
|
||||
guard let path = ProcessInfo.processInfo.environment["AISTUDIO_TEST_REAL_MCP_CONFIG"] else {
|
||||
throw XCTSkip("Set AISTUDIO_TEST_REAL_MCP_CONFIG to the installed configuration.")
|
||||
}
|
||||
let configuration = try MCPServerConfiguration.File.read(URL(fileURLWithPath: path))
|
||||
let profile = try XCTUnwrap(configuration.mcpServers["local-knowledge"])
|
||||
let client = try profile.makeClient()
|
||||
let tools = try await client.listTools()
|
||||
XCTAssertTrue(tools.contains { $0.name == "search_knowledge" })
|
||||
}
|
||||
|
||||
func testGenerationMeasurementsRoundTripAndCharacterRate() throws {
|
||||
let run = GenerationMeasurement(backend: "Fixture", firstOutput: 1, seconds: 3, characters: 40,
|
||||
provider: ProviderMetrics(tokens: 7, seconds: 0), outcome: "Complete")
|
||||
let copy = try JSONDecoder().decode(GenerationMeasurement.self, from: JSONEncoder().encode(run))
|
||||
XCTAssertEqual(copy.id, run.id)
|
||||
XCTAssertEqual(copy.charactersPerSecond, 20)
|
||||
XCTAssertEqual(copy.provider?.tokens, 7)
|
||||
XCTAssertNil(copy.provider?.tokensPerSecond)
|
||||
}
|
||||
}
|
||||
|
||||
final class WorkspaceLibraryTests: XCTestCase {
|
||||
func testStackIsReusableAndBackupRestoresWorkspaceResources() throws {
|
||||
let folder = FileManager.default.temporaryDirectory.appending(path: UUID().uuidString)
|
||||
try FileManager.default.createDirectory(at: folder, withIntermediateDirectories: true)
|
||||
defer { try? FileManager.default.removeItem(at: folder) }
|
||||
let store = try Store(url: folder.appending(path: "workspace.sqlite"))
|
||||
let backup = folder.appending(path: "backup.sqlite")
|
||||
let stack = try store.createKnowledgeStack(title: "Customer Help")
|
||||
let chat = try store.create(title: "Chat")
|
||||
let key = UUID()
|
||||
try store.addDocument(title: "Reference", chunks: ["This answer describes tides."], in: stack.id)
|
||||
try store.saveSnippet(id: key, kind: .prompt, title: "Reusable Prompt", content: "Explain tides")
|
||||
try store.exportWorkspace(to: backup)
|
||||
XCTAssertEqual(try store.conversations().map(\.id), [chat.id])
|
||||
XCTAssertTrue(try store.searchConversations("Customer Help").isEmpty)
|
||||
try store.delete(stack.id)
|
||||
try store.deleteSnippet(key)
|
||||
try store.restoreWorkspace(from: backup)
|
||||
XCTAssertEqual(try store.knowledgeStacks().map(\.id), [stack.id])
|
||||
XCTAssertEqual(try store.excerpts(matching: "tides", in: stack.id).first?.title, "Reference")
|
||||
XCTAssertEqual(try store.snippets().first?.content, "Explain tides")
|
||||
}
|
||||
|
||||
func testReturnSendsWithoutInterruptingNewlinesOrInputComposition() {
|
||||
XCTAssertTrue(ChatComposerInput.sendsReturn(modifiers: [], marked: false))
|
||||
XCTAssertFalse(ChatComposerInput.sendsReturn(modifiers: .shift, marked: false))
|
||||
XCTAssertFalse(ChatComposerInput.sendsReturn(modifiers: .option, marked: false))
|
||||
XCTAssertFalse(ChatComposerInput.sendsReturn(modifiers: [], marked: true))
|
||||
}
|
||||
|
||||
func testWebClipExtractsStaticText() throws {
|
||||
let content = WebClipCapture.plainText("""
|
||||
<head><title>Hidden</title></head><script>ignore()</script><h1>Title</h1><p>Two & three</p>
|
||||
""")
|
||||
XCTAssertEqual(content, "Title\nTwo & three")
|
||||
XCTAssertThrowsError(try WebClipCapture.url("file:///etc/hosts"))
|
||||
XCTAssertNoThrow(try WebClipCapture.url("https://example.com"))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user