Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : ORIX Astra9// File : Tests/AstraLocalTests/DiscoveryTests.swift10// Module : AstraLocalTests11// Repository : https://git.spboucher.ai/orix-astra12// Created : 2026-11-2213// Last Modified : 2026-11-2214//15// =============================================================================16// AUTHOR & PROFESSIONAL AFFILIATION17// =============================================================================18//19// Author : Simon-Pierre Boucher20// Position : Professor of Finance21// Institution : Université du Québec en Outaouais (UQO)22// Department : Département des sciences administratives23// Organization : SP Boucher24//25// Website : https://spboucher.ai26// Git : https://git.spboucher.ai27//28// =============================================================================29// OFFICIAL CONTACT DIRECTORY30// =============================================================================31//32// General : info@spboucher.ai33// Professional : contact@spboucher.ai34// Direct : simon@spboucher.ai35// Research : research@spboucher.ai36// Development : dev@spboucher.ai37// Support : support@spboucher.ai38// Security/Admin : admin@spboucher.ai39// Notifications : notifications@spboucher.ai40//41// Preferred Contact: support@spboucher.ai42//43// =============================================================================44// COPYRIGHT & INTELLECTUAL PROPERTY45// =============================================================================46//47// Copyright (c) 202648// Simon-Pierre Boucher49//50// All rights reserved where applicable.51//52// This file is governed by the applicable project license,53// copyright notices, institutional agreements and relevant law.54//55// Unless expressly authorized by the applicable license or56// rights holder, copying, redistribution, sublicensing,57// publication and commercial exploitation are not permitted.58//59// Existing third-party rights and notices remain unaffected.60//61// =============================================================================62// CONFIDENTIALITY & SECURITY63// =============================================================================64//65// Classification : Public66// Distribution : Public repository; use is governed by the project license67// Security Contact : admin@spboucher.ai68//69// Access to this source does not independently grant permission70// to redistribute or disclose confidential materials.71//72// Do not embed credentials, private keys, access tokens,73// certificates or confidential personal information.74//75// =============================================================================76// LICENSE & MAINTENANCE77// =============================================================================78//79// License : Proprietary, all rights reserved (see license file)80// License File : LICENSE81// Maintainer : Simon-Pierre Boucher82// Technical Contact: dev@spboucher.ai83//84// =============================================================================85// END OF SP BOUCHER SOURCE HEADER86// =============================================================================8788import AstraCore89import Foundation90import Testing91@testable import AstraLocal9293/// Parsing and policy tests over responses recorded from the public Hugging Face API on 2026-11-22 (no key), in `Tests/AstraLocalFixtures/hub`.94@Suite struct HubDiscoveryTests {95 static let qwen = ("mlx-community/Qwen3-0.6B-4bit", "73e3e38d981303bc594367cd910ea6eb48349da8")96 static let asr = ("mlx-community/Qwen3-ASR-0.6B-8bit", "")97 static let phi3 = ("microsoft/Phi-3-mini-4k-instruct", "f39ac1d28e925b323eae81227eaba4464caced4e")98 static let llama = ("meta-llama/Llama-3.2-1B-Instruct", "9213176726f574b556790deb65791e0c5aa438b6")99 static let gguf = ("bartowski/Qwen_Qwen3-0.6B-GGUF", "60b85c0e3d8fe0f6474f406922a26d12aca4550d")100 static let whisper = ("mlx-community/whisper-tiny", "78c52ab98ca87f570bc57ad852e15ef7060f9f76")101 static let vlm = ("mlx-community/SmolVLM2-256M-Video-Instruct-mlx", "79901655c1a3d7ed6646c91325e3fde47e40e611")102103 static func revision(_ repo: String) throws -> String {104 let info = try #require(JSONValue.parse(try RecordedFixture.data("hub/info_\(repo.replacingOccurrences(of: "/", with: "_")).json")))105 return try #require(info["sha"]?.stringValue)106 }107 static func inspected(_ repo: String, tree: Bool = true, config: Bool = true) async throws -> (HubRepositoryInspection, HubDiscovery, HubStub) {108 let hub = HubStub()109 try hub.publish(repo: repo, revision: try revision(repo), tree: tree, config: config)110 let discovery = HubDiscovery(transport: hub)111 return (try await discovery.inspect(repo: repo), discovery, hub)112 }113114 // MARK: Search115116 @Test func searchAsksForSafetensorsTotalsAndParsesTheListing() async throws {117 let hub = HubStub(), discovery = HubDiscovery(transport: hub)118 let query = HubSearchQuery(text: "Qwen3", limit: 6)119 let url = try discovery.searchURL(query)120 // `full=true` does not return the safetensors totals: every field is expanded by name.121 #expect(url.absoluteString.contains("expand%5B%5D=safetensors") && url.absoluteString.contains("expand%5B%5D=config"))122 #expect(!url.absoluteString.contains("full=true"))123 #expect(url.absoluteString.hasPrefix("https://huggingface.co/api/models?search=Qwen3&author=mlx-community&sort=downloads&direction=-1&limit=6"))124 hub.respond(url.absoluteString, try RecordedFixture.data("hub/search.json"))125126 let results = try await discovery.search(query)127 #expect(results.map(\.repo) == ["mlx-community/Qwen3.8-27B-4bit", "mlx-community/Qwen3-ASR-0.6B-8bit", "mlx-community/Qwen3-4B-Instruct-2507-4bit",128 "mlx-community/Qwen3.5-4B-MLX-4bit", "mlx-community/Qwen3.5-0.8B-4bit", "mlx-community/Qwen3-0.6B-4bit"])129 let small = try #require(results.last)130 #expect(small.author == "mlx-community" && small.name == "Qwen3-0.6B-4bit" && small.modelType == "qwen3" && small.pipelineTag == "text-generation")131 #expect(small.quantizationBits == 4 && small.safetensorsParameters == 596_049_920 && !small.isGated && small.hasChatTemplate)132 #expect(small.revision == Self.qwen.1 && small.downloads == 51_110 && small.libraryName == "mlx")133 // 596 M elements at 4.5 bits: about 335 MB, the size of the real weight file (335,450,584 bytes).134 let estimate = try #require(small.estimatedBytes)135 #expect(abs(Double(estimate) - 335_450_584) / 335_450_584 < 0.02)136 #expect(small.preliminary.isSupported)137 // The speech model's architecture is not one the runtime loads.138 let speech = try #require(results.first { $0.name == "Qwen3-ASR-0.6B-8bit" })139 #expect(speech.modelType == "qwen3_asr" && speech.quantizationBits == 8)140 #expect(speech.preliminary.reason == "The architecture “qwen3_asr” is not one that mlx-swift-lm 3.33.0 can load.")141 #expect(hub.requests.count == 1 && hub.requests.allSatisfy { $0.value(forHTTPHeaderField: "Authorization") == nil })142 }143144 @Test func searchFiltersByQuantizationSizeAndTask() async throws {145 let hub = HubStub(), discovery = HubDiscovery(transport: hub)146 func run(_ query: HubSearchQuery) async throws -> [String] {147 hub.respond(try discovery.searchURL(query).absoluteString, try RecordedFixture.data("hub/search.json"))148 return try await discovery.search(query).map(\.name)149 }150 #expect(try await run(HubSearchQuery(text: "Qwen3", quantizationBits: 8)) == ["Qwen3-ASR-0.6B-8bit"])151 #expect(try await run(HubSearchQuery(text: "Qwen3", quantizationBits: 4)).count == 5)152 #expect(try await run(HubSearchQuery(text: "Qwen3", maxBytes: 1 << 30)) == ["Qwen3-ASR-0.6B-8bit", "Qwen3.5-0.8B-4bit", "Qwen3-0.6B-4bit"])153 #expect(try await run(HubSearchQuery(text: "Qwen3", minBytes: 10 << 30)) == ["Qwen3.8-27B-4bit"])154 let task = try discovery.searchURL(HubSearchQuery(text: "smol", author: nil, pipelineTask: "image-text-to-text", sort: .likes, limit: 500))155 #expect(task.absoluteString.contains("pipeline_tag=image-text-to-text") && task.absoluteString.contains("sort=likes") && task.absoluteString.contains("limit=50"))156 #expect(!task.absoluteString.contains("author="))157 #expect(throws: HubError.self) { try discovery.searchURL(HubSearchQuery(text: "", author: nil)) }158 #expect(throws: HubError.self) { try discovery.searchURL(HubSearchQuery(text: "x", author: "a/b?c")) }159 #expect(HubDiscovery.quantizationBits(config: nil, tags: [], name: "gemma-3-1b-it-qat-4bit") == 4)160 #expect(HubDiscovery.quantizationBits(config: nil, tags: ["8-bit"], name: "x") == 8)161 #expect(HubDiscovery.quantizationBits(config: nil, tags: [], name: "SmolLM2-135M-Instruct") == nil)162 #expect(HubDiscovery.quantizationBits(config: ["quantization": ["bits": 6]], tags: [], name: "x-4bit") == 6)163 }164165 // MARK: Inspection and compatibility166167 @Test func aSupportedRepositoryBecomesAnExperimentalVerifiedDownloadCard() async throws {168 let (r, discovery, hub) = try await Self.inspected(Self.qwen.0)169 #expect(r.repo == Self.qwen.0 && r.revision == Self.qwen.1 && r.author == "mlx-community" && r.name == "Qwen3-0.6B-4bit")170 #expect(r.modelType == "qwen3" && r.architectures == ["Qwen3ForCausalLM"] && !r.requiresCustomCode && !r.isGated)171 #expect(r.license == "apache-2.0" && r.baseModels == ["Qwen/Qwen3-0.6B"] && r.contextLength == 40_960 && r.quantizationBits == 4)172 #expect(r.hasTokenizer && r.hasChatTemplate && !r.hasVisionConfig && r.libraryName == "mlx")173 #expect(r.weightFiles.map(\.path) == ["model.safetensors"])174 #expect(r.weightFiles[0].sha256 == "392e8d466d56100ada00eb82031fb854297fc9e389b7d303eba3af114e87bce2" && r.weightFiles[0].size == 335_450_584)175 #expect(r.ignoredFiles == [".gitattributes", "README.md"])176 guard case .supported(let vision, let notes) = discovery.compatibility(of: r) else { Issue.record("expected supported"); return }177 #expect(!vision && notes[0].contains("“qwen3”") && notes[0].contains("Nobody has run this repository"))178179 let card = try discovery.card(from: r)180 #expect(card.id == "Qwen3-0.6B-4bit" && card.status == .experimental && card.redistributable == false && card.baseURL == nil)181 #expect(card.fallbackBaseURL == "https://huggingface.co/mlx-community/Qwen3-0.6B-4bit/resolve/\(Self.qwen.1)/")182 #expect(card.sourceURLs.map(\.host) == ["huggingface.co"])183 #expect(card.revision == Self.qwen.1 && card.architecture == "qwen3" && card.quantization == "4-bit" && card.contextLength == 40_960)184 #expect(card.statusNote?.contains("never run by Astra's author") == true && card.verified == nil && card.requiredRuntime == "mlx-swift-lm 3.33.0")185 #expect(card.capabilities == [.text] && card.licenseID == "apache-2.0" && card.minimumDeviceMemoryGB == 4)186 // Hashes come from the Hub's metadata: SHA-256 for LFS files, the git blob id for the small ones. Every file is pinned.187 let weights = try #require(card.files.first { $0.path == "model.safetensors" })188 #expect(weights.sha256 == "392e8d466d56100ada00eb82031fb854297fc9e389b7d303eba3af114e87bce2" && weights.gitBlobSHA1 == nil)189 let config = try #require(card.files.first { $0.path == "config.json" })190 #expect(config.sha256.isEmpty && config.gitBlobSHA1 == "6c974b02334f2f5f68de4cb2796ee4fe80bfc712" && config.size == 937)191 #expect(card.files.count == 9 && card.totalBytes == card.files.reduce(0) { $0 + $1.size })192 // It is the same file list the owner's catalogue pins for this model.193 #expect(card.files.map(\.path) == (try RecordedFixture.card("Qwen3-0.6B-4bit")).files.map(\.path))194 // The plan is accepted by the downloader (every file has a checksum) but the card is not a catalogue entry.195 let plan = DownloadPlan(card: card)196 try DownloadCoordinator.validate(plan)197 #expect(plan.files.allSatisfy { ($0.sha256 != nil) != ($0.gitBlobSHA1 != nil) })198 #expect(throws: CatalogError.self) { try card.validate() }199 // The engine classes it as experimental, never as verified.200 let d = FakeDevice.iPhone(8)201 #expect(CompatibilityEngine.assess(card: card, device: d.device, memory: d.memory).compatibility == .experimental)202 #expect(CompatibilityEngine.assess(card: card, device: d.device, memory: d.memory).basis == .estimated)203 // Three requests, none with credentials, all to the Hub.204 #expect(hub.urls == ["https://huggingface.co/api/models/\(Self.qwen.0)",205 "https://huggingface.co/api/models/\(Self.qwen.0)/tree/\(Self.qwen.1)?recursive=true&limit=1000",206 "https://huggingface.co/\(Self.qwen.0)/resolve/\(Self.qwen.1)/config.json"])207 #expect(hub.requests.allSatisfy { $0.value(forHTTPHeaderField: "Authorization") == nil && $0.httpMethod == "GET" })208 }209210 @Test func unsupportedArchitectureIsRefusedWithTheReason() async throws {211 let (r, discovery, _) = try await Self.inspected(Self.asr.0)212 #expect(r.modelType == "qwen3_asr" && !r.weightFiles.isEmpty)213 #expect(discovery.compatibility(of: r) == .unsupported(reason: "The architecture “qwen3_asr” is not one that mlx-swift-lm 3.33.0 can load."))214 #expect(throws: AstraError.self) { try discovery.card(from: r) }215 }216217 @Test func customCodeRepositoryIsRefusedAndItsPythonIsNeverPlanned() async throws {218 let (r, discovery, _) = try await Self.inspected(Self.phi3.0)219 #expect(r.requiresCustomCode && r.modelType == "phi3") // phi3 itself is a supported architecture: the refusal is about the code220 #expect(discovery.compatibility(of: r) == .unsupported(reason: "This model needs custom code, which Astra never executes."))221 #expect(discovery.compatibility(of: r).reason?.contains("needs custom code, which Astra never executes") == true)222 #expect(r.ignoredFiles.contains("modeling_phi3.py") && r.ignoredFiles.contains("configuration_phi3.py") && r.ignoredFiles.contains("sample_finetune.py"))223 #expect(!r.plannedFiles.contains { $0.path.hasSuffix(".py") || $0.path.hasSuffix(".md") || $0.path == "LICENSE" })224 #expect(throws: AstraError.self) { try discovery.card(from: r) }225 // Even without `auto_map`, the same weights would be refused as not being an MLX conversion.226 var plain = r; plain.requiresCustomCode = false227 #expect(discovery.compatibility(of: plain).reason == "This repository is not an MLX conversion (it holds weights for another framework).")228 }229230 @Test func gatedRepositoryIsRefusedWithoutTouchingItsFiles() async throws {231 let (r, discovery, hub) = try await Self.inspected(Self.llama.0, tree: false, config: false)232 #expect(r.isGated && r.plannedFiles.isEmpty)233 #expect(discovery.compatibility(of: r).reason?.hasPrefix("This repository is gated") == true)234 #expect(hub.urls == ["https://huggingface.co/api/models/\(Self.llama.0)"]) // no tree, no config, no file235 #expect(throws: AstraError.self) { try discovery.card(from: r) }236 #expect(HubDiscovery.isGated(.string("auto")) && HubDiscovery.isGated(.string("manual")) && HubDiscovery.isGated(true) && !HubDiscovery.isGated(false) && !HubDiscovery.isGated(nil))237 }238239 @Test func repositoriesWithoutSafetensorsAreRefused() async throws {240 let (g, discovery, _) = try await Self.inspected(Self.gguf.0, config: false)241 #expect(g.weightFiles.isEmpty && g.plannedFiles.isEmpty)242 #expect(discovery.compatibility(of: g).reason?.hasPrefix("This repository has no safetensors weights (it holds “Qwen_Qwen3-0.6B-") == true)243 let (w, _, _) = try await Self.inspected(Self.whisper.0)244 #expect(w.modelType == "whisper" && w.ignoredFiles.contains("weights.npz"))245 #expect(discovery.compatibility(of: w).reason?.contains("no safetensors weights (it holds “weights.npz”)") == true)246 }247248 @Test func visionRepositoryIsRecognisedThroughTheVisionTable() async throws {249 let (r, discovery, _) = try await Self.inspected(Self.vlm.0)250 #expect(r.modelType == "smolvlm" && r.hasVisionConfig && r.hasChatTemplate && r.hasTokenizer)251 guard case .supported(let vision, _) = discovery.compatibility(of: r) else { Issue.record("expected supported, got \(discovery.compatibility(of: r))"); return }252 #expect(vision)253 let card = try discovery.card(from: r)254 #expect(card.capabilities == [.text, .vision] && card.tags == ["vision", "lightweight"] && card.status == .experimental && card.quantization == "none")255 #expect(card.maxImages == 1 && card.supportsMultipleImages == false)256 // With a runtime that has no vision loader for it, the same repository is refused.257 let textOnly = HubDiscovery(transport: HubStub(), runtimeSupport: RuntimeSupport(runtime: "test runtime", textArchitectures: ["qwen3"], visionArchitectures: []))258 #expect(textOnly.compatibility(of: r).reason == "The architecture “smolvlm” is not one that test runtime can load.")259 }260261 @Test func missingTokenizerOrChatTemplateIsRefused() async throws {262 let (r, discovery, _) = try await Self.inspected(Self.qwen.0)263 var noTokenizer = r; noTokenizer.hasTokenizer = false264 #expect(discovery.compatibility(of: noTokenizer).reason?.contains("no tokenizer.json") == true)265 var noTemplate = r; noTemplate.hasChatTemplate = false266 #expect(discovery.compatibility(of: noTemplate).reason?.contains("no chat template") == true)267 var unhashed = r; unhashed.plannedFiles = unhashed.plannedFiles.map { f in var f = f; if f.path.hasSuffix(".safetensors") { f.sha256 = nil }; return f }268 #expect(discovery.compatibility(of: unhashed).reason?.contains("no SHA-256") == true)269 var disabled = r; disabled.isDisabled = true270 #expect(!discovery.compatibility(of: disabled).isSupported)271 }272273 // MARK: Allow-list274275 @Test func onlyAllowListedDataFilesAreEverPlanned() async throws {276 #expect(HubDiscovery.allowedExtensions == ["safetensors", "json", "txt", "model", "jinja", "tiktoken", "bpe"])277 for ok in ["model.safetensors", "config.json", "merges.txt", "tokenizer.model", "chat_template.jinja", "cl100k.tiktoken", "vocab.bpe", "sub/model-00001-of-00002.safetensors", "CONFIG.JSON"] {278 #expect(HubDiscovery.isAllowedFile(ok), "\(ok)")279 }280 for bad in ["modeling.py", "pytorch_model.bin", "weights.pt", "data.pkl", "run.sh", "README.md", "LICENSE", "model.gguf", "weights.npz", "lib.dylib", "x.so", "a.zip",281 "tokenizer.json.py", ".hidden.json", "sub/.secret/config.json", "../config.json", "/etc/config.json", "a/../b.json", "config.json.partial",282 ".astra/card.json", "model.safetensors.exe", "json", ".json", "x.mlmodelc", "setup.cfg", "handler.js"] {283 #expect(!HubDiscovery.isAllowedFile(bad), "\(bad)")284 }285286 // A hostile repository: valid weights surrounded by code, pickles and path tricks. Only the data files are planned.287 let sha = String(repeating: "ab", count: 20), lfs = String(repeating: "cd", count: 32), blob = String(repeating: "ef", count: 20)288 var tree: [JSONValue] = []289 for (path, size, isLFS) in [("config.json", 60, false), ("tokenizer.json", 100, false), ("tokenizer_config.json", 50, false), ("model.safetensors", 4_000, true),290 ("chat_template.jinja", 80, false), ("setup.py", 10, false), ("pytorch_model.bin", 4_000, true), ("payload.pkl", 99, true),291 ("install.sh", 5, false), ("../escape.json", 5, false), (".hidden/config.json", 5, false), ("README.md", 5, false)] {292 var item: [String: JSONValue] = ["type": "file", "path": .string(path), "size": .number(Double(size)), "oid": .string(blob)]293 if isLFS { item["lfs"] = ["oid": .string(lfs), "size": .number(Double(size))] }294 tree.append(.object(item))295 }296 let hub = HubStub()297 let info: JSONValue = ["id": "acme/tricky-mlx", "sha": .string(sha), "gated": false, "library_name": "mlx", "tags": ["mlx", "safetensors"],298 "config": ["model_type": "qwen3", "tokenizer_config": ["chat_template": "{{ messages }}"]], "cardData": ["license": "mit"]]299 hub.respond("https://huggingface.co/api/models/acme/tricky-mlx", try JSONEncoder().encode(info))300 hub.respond("https://huggingface.co/api/models/acme/tricky-mlx/tree/\(sha)?recursive=true&limit=1000", try JSONEncoder().encode(JSONValue.array(tree)))301 hub.respond("https://huggingface.co/acme/tricky-mlx/resolve/\(sha)/config.json", Data(#"{"model_type":"qwen3","max_position_embeddings":4096}"#.utf8))302 let discovery = HubDiscovery(transport: hub)303 let r = try await discovery.inspect(repo: "acme/tricky-mlx")304 #expect(r.plannedFiles.map(\.path) == ["chat_template.jinja", "config.json", "model.safetensors", "tokenizer.json", "tokenizer_config.json"])305 #expect(Set(r.ignoredFiles) == [".hidden/config.json", "../escape.json", "README.md", "install.sh", "payload.pkl", "pytorch_model.bin", "setup.py"])306 let card = try discovery.card(from: r)307 let planned = DownloadPlan(card: card).files.map(\.path)308 #expect(planned == r.plannedFiles.map(\.path) && planned.allSatisfy(HubDiscovery.isAllowedFile))309 #expect(card.totalBytes == 60 + 100 + 50 + 4_000 + 80)310 // Only metadata was requested: no file other than config.json was fetched during inspection.311 #expect(hub.urls.filter { $0.contains("/resolve/") } == ["https://huggingface.co/acme/tricky-mlx/resolve/\(sha)/config.json"])312 // The same repository with an `auto_map` in its config is refused outright.313 hub.respond("https://huggingface.co/acme/tricky-mlx/resolve/\(sha)/config.json", Data(#"{"model_type":"qwen3","auto_map":{"AutoModel":"setup.Model"}}"#.utf8))314 #expect(discovery.compatibility(of: try await discovery.inspect(repo: "acme/tricky-mlx")).reason == "This model needs custom code, which Astra never executes.")315 hub.respond("https://huggingface.co/acme/tricky-mlx/resolve/\(sha)/config.json", Data(#"{"model_type":"qwen3","trust_remote_code":true}"#.utf8))316 #expect(discovery.compatibility(of: try await discovery.inspect(repo: "acme/tricky-mlx")).reason == "This model needs custom code, which Astra never executes.")317 }318319 // MARK: Errors320321 @Test func rateLimitOfflineAndMissingRepositoriesAreTyped() async throws {322 let hub = HubStub(), discovery = HubDiscovery(transport: hub)323 let query = HubSearchQuery(text: "Qwen3")324 let url = try discovery.searchURL(query).absoluteString325326 hub.respond(url, status: 429, Data("{}".utf8), headers: ["RateLimit": "\"api\";r=0;t=274"])327 await #expect(throws: HubError.rateLimited(retryAfter: 274)) { try await discovery.search(query) }328 hub.respond(url, status: 429, Data("{}".utf8), headers: ["Retry-After": "12"])329 await #expect(throws: HubError.rateLimited(retryAfter: 12)) { try await discovery.search(query) }330 hub.respond(url, status: 429)331 await #expect(throws: HubError.rateLimited(retryAfter: nil)) { try await discovery.search(query) }332 #expect(HubError.rateLimited(retryAfter: 274).errorDescription?.contains("274 s") == true)333 if case .rateLimited(let retry, _) = HubError.rateLimited(retryAfter: 274).astraError { #expect(retry == 274) } else { Issue.record("not mapped to rateLimited") }334335 hub.respond(url, status: 503)336 await #expect(throws: HubError.server(status: 503)) { try await discovery.search(query) }337 hub.respond(url, Data("<html>".utf8))338 await #expect(throws: HubError.self) { try await discovery.search(query) }339340 // Without a token the Hub answers 401 for a repository that does not exist (recorded: HTTP 401).341 await #expect(throws: HubError.notFound("mlx-community/this-repo-does-not-exist-xyz")) { try await discovery.inspect(repo: "mlx-community/this-repo-does-not-exist-xyz") }342 await #expect(throws: HubError.self) { try await discovery.inspect(repo: "not a repo") }343 await #expect(throws: HubError.self) { try await discovery.inspect(repo: "a/b", revision: "main") }344345 hub.fail(with: URLError(.notConnectedToInternet))346 do { _ = try await discovery.search(query); Issue.record("expected offline") }347 catch let error as HubError {348 guard case .offline(let detail) = error else { Issue.record("expected offline, got \(error)"); return }349 #expect(detail == "This device is offline.")350 if case .network = error.astraError {} else { Issue.record("offline must map to a network error") }351 }352 hub.fail(with: URLError(.timedOut))353 await #expect(throws: HubError.offline("The request timed out.")) { try await discovery.inspect(repo: "a/b") }354 }355}356