Repair Toolbox navigation, chat web lookup, and model discovery
This commit is contained in:
+73
-1
@@ -504,6 +504,18 @@ final class CustomMCPConfigurationTests: XCTestCase {
|
||||
XCTAssertTrue(tools.contains { $0.name == "search_knowledge" })
|
||||
}
|
||||
|
||||
func testRepairedGiteaProfileDiscovery() 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 Gitea profile smoke test explicitly.")
|
||||
}
|
||||
let config = try MCPServerConfiguration.File.read(URL(fileURLWithPath: path))
|
||||
let profile = try XCTUnwrap(config.mcpServers["absdev-gitea"])
|
||||
let client = try profile.makeClient()
|
||||
let tools = try await client.listTools()
|
||||
XCTAssertFalse(tools.isEmpty)
|
||||
}
|
||||
|
||||
func testGenerationMeasurementsRoundTripAndCharacterRate() throws {
|
||||
let run = GenerationMeasurement(backend: "Fixture", firstOutput: 1, seconds: 3, characters: 40,
|
||||
provider: ProviderMetrics(tokens: 7, seconds: 0), outcome: "Complete")
|
||||
@@ -525,7 +537,8 @@ final class WorkspaceLibraryTests: XCTestCase {
|
||||
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.addDocument(title: "Reference", chunks: ["This answer describes tides."],
|
||||
vectors: [DocumentVector(language: "fixture", values: [1, 0])], 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])
|
||||
@@ -534,6 +547,7 @@ final class WorkspaceLibraryTests: XCTestCase {
|
||||
try store.deleteSnippet(key)
|
||||
try store.restoreWorkspace(from: backup)
|
||||
XCTAssertEqual(try store.knowledgeStacks().map(\.id), [stack.id])
|
||||
XCTAssertEqual(try store.vectorCount(in: stack.id), 1)
|
||||
XCTAssertEqual(try store.excerpts(matching: "tides", in: stack.id).first?.title, "Reference")
|
||||
XCTAssertEqual(try store.snippets().first?.content, "Explain tides")
|
||||
}
|
||||
@@ -600,3 +614,61 @@ final class BuiltInToolsetTests: XCTestCase {
|
||||
XCTAssertEqual(page["text"], "Moon and tides\nTest passage.")
|
||||
}
|
||||
}
|
||||
|
||||
final class ToolboxRepairTests: XCTestCase {
|
||||
func testChatWebLookupResolvesTypedURLAndExplicitSearch() async throws {
|
||||
guard let endpoint = ProcessInfo.processInfo.environment["AISTUDIO_TEST_WEB_URL"],
|
||||
let base = URL(string: endpoint)?.deletingLastPathComponent() else {
|
||||
throw XCTSkip("Run Scripts/test.sh to configure the web fixture.")
|
||||
}
|
||||
XCTAssertNil(ChatWebLookup(message: "Explain tides generally"))
|
||||
let page = base.appending(path: "article")
|
||||
let retrieval = try XCTUnwrap(ChatWebLookup(message: "Can you see \(page.absoluteString)?"))
|
||||
let result = try await retrieval.resolve(searchEndpoint: "")
|
||||
XCTAssertTrue(result.reference.contains("Test passage."))
|
||||
XCTAssertTrue(result.reference.contains(page.absoluteString))
|
||||
let search = try XCTUnwrap(ChatWebLookup(message: "Search the web for tides & moon"))
|
||||
let found = try await search.resolve(searchEndpoint: endpoint)
|
||||
XCTAssertTrue(found.reference.contains("A fixture & summary"))
|
||||
let unavailable = try await search.resolve(searchEndpoint: "")
|
||||
XCTAssertTrue(unavailable.status.contains("SearXNG"))
|
||||
}
|
||||
|
||||
func testLiveLaravelRetrieval() async throws {
|
||||
guard let address = ProcessInfo.processInfo.environment["AISTUDIO_TEST_REAL_WEB_PAGE"] else {
|
||||
throw XCTSkip("Set AISTUDIO_TEST_REAL_WEB_PAGE to check a real page.")
|
||||
}
|
||||
let lookup = try XCTUnwrap(ChatWebLookup(message: "Can you see \(address)"))
|
||||
let result = try await lookup.resolve(searchEndpoint: "")
|
||||
XCTAssertTrue(result.reference.contains("Laravel"))
|
||||
XCTAssertEqual(result.status, "Retrieved 1 web source(s).")
|
||||
}
|
||||
|
||||
func testModelDecodingAndMLXFolderScan() throws {
|
||||
let model = try JSONDecoder().decode(Ollama.Model.self, from: Data(#"{"model":"example:latest"}"#.utf8))
|
||||
XCTAssertEqual(model.name, "example:latest")
|
||||
let root = FileManager.default.temporaryDirectory.appending(path: UUID().uuidString)
|
||||
defer { try? FileManager.default.removeItem(at: root) }
|
||||
let modelFolder = root.appending(path: "team/example")
|
||||
try FileManager.default.createDirectory(at: modelFolder, withIntermediateDirectories: true)
|
||||
try Data("{}".utf8).write(to: modelFolder.appending(path: "config.json"))
|
||||
try Data([1]).write(to: modelFolder.appending(path: "model.safetensors"))
|
||||
let found = try MLXLibrary.discover(in: root)
|
||||
XCTAssertEqual(found.map(\.lastPathComponent), ["example"])
|
||||
}
|
||||
|
||||
func testExternalVectorQueryReferencesSources() async throws {
|
||||
struct Knowledge: MCPToolClient {
|
||||
func listTools() async throws -> [MCPTool] { [] }
|
||||
func callTool(_ name: String, argumentsJSON: Data) async throws -> Data {
|
||||
XCTAssertEqual(name, "search_knowledge")
|
||||
let data = try HTTPMCPClient.arguments(argumentsJSON)
|
||||
XCTAssertEqual(data["query"] as? String, "tides")
|
||||
XCTAssertEqual(data["limit"] as? Int, 5)
|
||||
return Data(#"{"content":[{"type":"text","text":"source: notes.md"}]}"#.utf8)
|
||||
}
|
||||
}
|
||||
let context = try await ExternalKnowledgeSearch.references(client: Knowledge(), query: "tides")
|
||||
XCTAssertTrue(context.contains("source: notes.md"))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user