feat(m1): Ollama client, catalog, streaming chat and CLI (T1.1-T1.6)

Add endpoint policy and redirect-safe ephemeral HTTP client, error mapping, catalog cache and version checks, streaming chat with phase timeouts/cancellation, provisional Hy-MT3 prompt/language/request factory, warm-up policy, and sprachmittler-cli models/show/translate. Recapture the 7B fixtures; defer the 1.8B VERIFY items; document ADR-016. Also fix the signature checker's pipefail SIGPIPE issue.
This commit is contained in:
schihei committed 2026-11-26 13:04:22 +01:00
1 parent 7ca5c710ec
commit 26b493e7e5
93 files changed
+3732 -218

No files matched your search

@@ -0,0 +1,65 @@
import Foundation
import Testing
@testable import SprachmittlerOllama
@Suite("Endpoint policy")
struct EndpointPolicyTests {
@Test(arguments: [
"http://127.0.0.1:11434",
"https://127.0.0.1:11434",
"http://localhost:11434",
"https://LOCALHOST:11434",
"http://[::1]:11434",
])
func acceptsLoopback(_ string: String) throws {
let url = try #require(URL(string: string))
#expect(try EndpointPolicy.validate(url, allowRemote: false) == url)
}
@Test func rejectsRemoteWithoutToggle() throws {
let url = try #require(URL(string: "https://example.com:11434"))
#expect(rejection(url, allowRemote: false) == .remoteNotAllowed)
}
@Test func rejectsRemoteHTTPEvenWithToggle() throws {
let url = try #require(URL(string: "http://example.com:11434"))
#expect(rejection(url, allowRemote: true) == .remoteRequiresHTTPS)
}
@Test func acceptsRemoteHTTPSWithToggle() throws {
let url = try #require(URL(string: "https://example.com:11434"))
#expect(try EndpointPolicy.validate(url, allowRemote: true) == url)
}
@Test func rejectsUnsupportedScheme() throws {
let url = try #require(URL(string: "ftp://127.0.0.1:11434"))
#expect(rejection(url, allowRemote: false) == .scheme)
}
@Test(arguments: [
"http://user:password@127.0.0.1:11434",
"http://127.0.0.1:11434/?a=b",
"http://127.0.0.1:11434/#fragment",
])
func rejectsUserInfoQueryAndFragment(_ string: String) throws {
let url = try #require(URL(string: string))
#expect(rejection(url, allowRemote: false) == .form)
}
@Test func rejectsMissingHost() throws {
let url = try #require(URL(string: "http:///api"))
#expect(rejection(url, allowRemote: false) == .form)
#expect(EndpointPolicy.isLoopback(url) == false)
}
private func rejection(_ url: URL, allowRemote: Bool) -> EndpointRejection? {
do {
_ = try EndpointPolicy.validate(url, allowRemote: allowRemote)
return nil
} catch let error as EndpointRejection {
return error
} catch {
return nil
}
}
}
@@ -0,0 +1,39 @@
import Foundation
import Testing
@testable import SprachmittlerOllama
@Suite("Ephemeral session")
struct EphemeralSessionTests {
@Test func configurationHasNoCookiesCacheOrCredentials() {
let configuration = OllamaSessionFactory.makeConfiguration()
#expect(configuration.httpCookieStorage == nil)
#expect(configuration.urlCache == nil)
#expect(configuration.urlCredentialStorage == nil)
#expect(configuration.httpShouldSetCookies == false)
#expect(configuration.requestCachePolicy == .reloadIgnoringLocalCacheData)
#expect(configuration.waitsForConnectivity == false)
#expect(configuration.timeoutIntervalForRequest >= 180)
#expect(configuration.timeoutIntervalForResource >= 180)
}
@Test func productionClientUsesEphemeralSessionAndRedirectDelegate() throws {
let url = try #require(URL(string: "http://127.0.0.1:11434"))
let client = try OllamaHTTPClient(baseURL: url)
let configuration = client.session.configuration
#expect(configuration.httpCookieStorage == nil)
#expect(configuration.urlCache == nil)
#expect(configuration.urlCredentialStorage == nil)
#expect(configuration.httpShouldSetCookies == false)
#expect(client.session.delegate is RedirectRefusingDelegate)
}
@Test func productionClientRejectsRemoteWithoutToggle() throws {
let url = try #require(URL(string: "https://example.com:11434"))
do {
_ = try OllamaHTTPClient(baseURL: url)
Issue.record("expected remoteNotAllowed")
} catch let error as OllamaError {
#expect(error == .endpointRejected(.remoteNotAllowed))
}
}
}
@@ -0,0 +1,96 @@
import Foundation
import Testing
@testable import SprachmittlerOllama
/// T1.1: the recorded Ollama fixtures stay small, internally consistent and decodable.
@Suite("Fixture contract")
struct FixtureContractTests {
@Test func fixturesStayUnderBudget() throws {
let directory = try fixtures()
let files = try FileManager.default.contentsOfDirectory(
at: directory,
includingPropertiesForKeys: [.fileSizeKey]
)
for file in files where !file.hasDirectoryPath {
let size = try file.resourceValues(forKeys: [.fileSizeKey]).fileSize ?? 0
#expect(size < 200 * 1024, "\(file.lastPathComponent) is \(size) bytes")
}
}
@Test func captureMetaMatchesTagsAndVersion() throws {
let meta = try object("capture-meta.json")
let tags = try object("tags.json")
let version = try object("version.json")
let ollama = try #require(meta["ollama"] as? String)
// Pinned to the verified server version; update on a deliberate fixture recapture.
#expect(ollama == "0.40.18")
#expect(version["version"] as? String == ollama)
let metaModels = try #require(meta["models"] as? [[String: Any]])
#expect(!metaModels.isEmpty)
let tagModels = try #require(tags["models"] as? [[String: Any]])
for model in metaModels {
let name = try #require(model["model"] as? String)
let digest = try #require(model["digest"] as? String)
#expect(digest.count == 12)
let tag = try #require(tagModels.first { $0["name"] as? String == name })
let fullDigest = try #require(tag["digest"] as? String)
#expect(fullDigest.hasPrefix(digest))
}
}
@Test func doneReasonsAreRecorded() throws {
let stop = try lastObject(of: "chat-hf.co_tencent_Hy-MT3-7B-GGUF_Q4_K_M-en-de.ndjson")
let length = try lastObject(of: "chat-hf.co_tencent_Hy-MT3-7B-GGUF_Q4_K_M-truncated.ndjson")
#expect(stop["done_reason"] as? String == "stop")
#expect(length["done_reason"] as? String == "length")
}
@Test func everyNDJSONLineDecodes() throws {
let directory = try fixtures()
let files = try FileManager.default.contentsOfDirectory(at: directory, includingPropertiesForKeys: nil)
.filter { $0.pathExtension == "ndjson" }
#expect(!files.isEmpty)
for file in files {
let text = try String(contentsOf: file, encoding: .utf8)
let lines = text.split(separator: "\n", omittingEmptySubsequences: true)
#expect(!lines.isEmpty)
for line in lines {
let object = try? JSONSerialization.jsonObject(with: Data(line.utf8))
#expect(object != nil, "\(file.lastPathComponent): \(line.prefix(80))")
}
}
}
@Test func showFixtureHasDocumentedFields() throws {
let show = try object("show-hf.co_tencent_Hy-MT3-7B-GGUF_Q4_K_M.json")
let capabilities = try #require(show["capabilities"] as? [String])
#expect(capabilities.contains("completion"))
let parameters = try #require(show["parameters"] as? String)
#expect(parameters.contains("stop"))
let template = try #require(show["template"] as? String)
#expect(template.contains("<|startoftext|>"))
#expect(show.keys.contains("license"))
}
private func fixtures() throws -> URL {
let base = try #require(Bundle.module.resourceURL)
return base.appendingPathComponent("Fixtures")
}
private func object(_ name: String) throws -> [String: Any] {
let url = try fixtures().appendingPathComponent(name)
let data = try Data(contentsOf: url)
return try #require(try JSONSerialization.jsonObject(with: data) as? [String: Any])
}
private func lastObject(of name: String) throws -> [String: Any] {
let url = try fixtures().appendingPathComponent(name)
let text = try String(contentsOf: url, encoding: .utf8)
let line = try #require(text.split(separator: "\n").last)
return try #require(try JSONSerialization.jsonObject(with: Data(line.utf8)) as? [String: Any])
}
}
@@ -1,5 +1,5 @@
{
"date": "2026-11-26T10:50:04Z",
"date": "2026-11-26T11:36:50Z",
"ollama": "0.40.18",
"hardware": "Apple M5 Pro",
"memoryBytes": "51539607552",
@@ -1,26 +1,26 @@
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:01.999173Z","message":{"role":"assistant","content":"Size"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:02.026416Z","message":{"role":"assistant","content":" changes"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:02.048719Z","message":{"role":"assistant","content":" and"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:02.076474Z","message":{"role":"assistant","content":" roads"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:02.098414Z","message":{"role":"assistant","content":" are"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:02.119328Z","message":{"role":"assistant","content":" important"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:02.143258Z","message":{"role":"assistant","content":"."},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:02.166468Z","message":{"role":"assistant","content":" Please"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:02.191479Z","message":{"role":"assistant","content":" open"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:02.216114Z","message":{"role":"assistant","content":" https"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:02.241732Z","message":{"role":"assistant","content":"://"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:02.265654Z","message":{"role":"assistant","content":"example"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:02.287662Z","message":{"role":"assistant","content":".de"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:02.316362Z","message":{"role":"assistant","content":"/h"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:02.341857Z","message":{"role":"assistant","content":"il"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:02.364919Z","message":{"role":"assistant","content":"fe"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:02.386826Z","message":{"role":"assistant","content":" and"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:02.408914Z","message":{"role":"assistant","content":" set"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:02.431967Z","message":{"role":"assistant","content":" the"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:02.456708Z","message":{"role":"assistant","content":" limit"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:02.477947Z","message":{"role":"assistant","content":" to"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:02.49891Z","message":{"role":"assistant","content":" {{"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:02.520627Z","message":{"role":"assistant","content":"limit"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:02.542168Z","message":{"role":"assistant","content":"}}"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:02.565442Z","message":{"role":"assistant","content":"."},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:02.586143Z","message":{"role":"assistant","content":""},"done":true,"done_reason":"stop","total_duration":685861833,"load_duration":938583,"prompt_eval_count":56,"prompt_eval_cached_count":6,"prompt_eval_duration":92529000,"eval_count":26,"eval_duration":586872000}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:48.484974Z","message":{"role":"assistant","content":"Size"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:48.515194Z","message":{"role":"assistant","content":" changes"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:48.53694Z","message":{"role":"assistant","content":" and"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:48.564852Z","message":{"role":"assistant","content":" roads"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:48.5904Z","message":{"role":"assistant","content":" are"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:48.612629Z","message":{"role":"assistant","content":" important"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:48.641951Z","message":{"role":"assistant","content":"."},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:48.666052Z","message":{"role":"assistant","content":" Please"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:48.689821Z","message":{"role":"assistant","content":" open"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:48.712026Z","message":{"role":"assistant","content":" https"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:48.736654Z","message":{"role":"assistant","content":"://"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:48.76546Z","message":{"role":"assistant","content":"example"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:48.787224Z","message":{"role":"assistant","content":".de"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:48.816042Z","message":{"role":"assistant","content":"/h"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:48.841031Z","message":{"role":"assistant","content":"il"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:48.862039Z","message":{"role":"assistant","content":"fe"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:48.885918Z","message":{"role":"assistant","content":" and"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:48.908108Z","message":{"role":"assistant","content":" set"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:48.928689Z","message":{"role":"assistant","content":" the"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:48.949235Z","message":{"role":"assistant","content":" limit"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:48.974229Z","message":{"role":"assistant","content":" to"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:48.996005Z","message":{"role":"assistant","content":" {{"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:49.024238Z","message":{"role":"assistant","content":"limit"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:49.045455Z","message":{"role":"assistant","content":"}}"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:49.070118Z","message":{"role":"assistant","content":"."},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:49.092303Z","message":{"role":"assistant","content":""},"done":true,"done_reason":"stop","total_duration":707828583,"load_duration":949667,"prompt_eval_count":56,"prompt_eval_cached_count":6,"prompt_eval_duration":93676000,"eval_count":26,"eval_duration":607234000}
@@ -1,39 +1,38 @@
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:01.041299Z","message":{"role":"assistant","content":"Der"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:01.062402Z","message":{"role":"assistant","content":" schn"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:01.082942Z","message":{"role":"assistant","content":"elle"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:01.104113Z","message":{"role":"assistant","content":" bra"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:01.124845Z","message":{"role":"assistant","content":"une"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:01.145739Z","message":{"role":"assistant","content":" F"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:01.16648Z","message":{"role":"assistant","content":"uchs"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:01.187129Z","message":{"role":"assistant","content":" spring"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:01.208482Z","message":{"role":"assistant","content":"t"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:01.228993Z","message":{"role":"assistant","content":" über"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:01.249733Z","message":{"role":"assistant","content":" den"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:01.270729Z","message":{"role":"assistant","content":" fa"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:01.292143Z","message":{"role":"assistant","content":"ulen"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:01.313133Z","message":{"role":"assistant","content":" Hund"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:01.335165Z","message":{"role":"assistant","content":"."},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:01.357874Z","message":{"role":"assistant","content":" Bitte"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:01.380728Z","message":{"role":"assistant","content":" öff"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:01.40349Z","message":{"role":"assistant","content":"ne"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:01.426946Z","message":{"role":"assistant","content":" https"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:01.453306Z","message":{"role":"assistant","content":"://"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:01.475121Z","message":{"role":"assistant","content":"example"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:01.495912Z","message":{"role":"assistant","content":".com"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:01.517223Z","message":{"role":"assistant","content":"/docs"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:01.540613Z","message":{"role":"assistant","content":"?"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:01.564655Z","message":{"role":"assistant","content":"lang"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:01.586532Z","message":{"role":"assistant","content":"=en"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:01.610249Z","message":{"role":"assistant","content":" und"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:01.633386Z","message":{"role":"assistant","content":" set"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:01.658404Z","message":{"role":"assistant","content":"ze"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:01.681504Z","message":{"role":"assistant","content":" die"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:01.703193Z","message":{"role":"assistant","content":" Beg"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:01.725477Z","message":{"role":"assistant","content":"ren"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:01.749429Z","message":{"role":"assistant","content":"zung"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:01.771122Z","message":{"role":"assistant","content":" auf"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:01.792122Z","message":{"role":"assistant","content":" {{"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:01.815377Z","message":{"role":"assistant","content":"limit"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:01.836742Z","message":{"role":"assistant","content":"}}"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:01.858155Z","message":{"role":"assistant","content":"."},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:01.878784Z","message":{"role":"assistant","content":""},"done":true,"done_reason":"stop","total_duration":1097586000,"load_duration":800042,"prompt_eval_count":54,"prompt_eval_cached_count":40,"prompt_eval_duration":255365000,"eval_count":39,"eval_duration":837305000}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:47.510794Z","message":{"role":"assistant","content":"Der"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:47.535189Z","message":{"role":"assistant","content":" schn"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:47.557499Z","message":{"role":"assistant","content":"elle"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:47.580002Z","message":{"role":"assistant","content":" bra"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:47.602281Z","message":{"role":"assistant","content":"une"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:47.62429Z","message":{"role":"assistant","content":" F"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:47.648922Z","message":{"role":"assistant","content":"uchs"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:47.672854Z","message":{"role":"assistant","content":" spring"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:47.6985Z","message":{"role":"assistant","content":"t"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:47.720133Z","message":{"role":"assistant","content":" über"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:47.748481Z","message":{"role":"assistant","content":" den"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:47.773641Z","message":{"role":"assistant","content":" fa"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:47.795296Z","message":{"role":"assistant","content":"ulen"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:47.823754Z","message":{"role":"assistant","content":" Hund"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:47.845798Z","message":{"role":"assistant","content":"."},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:47.869885Z","message":{"role":"assistant","content":" Bitte"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:47.89341Z","message":{"role":"assistant","content":" öff"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:47.916502Z","message":{"role":"assistant","content":"ne"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:47.940296Z","message":{"role":"assistant","content":" https"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:47.961331Z","message":{"role":"assistant","content":"://"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:47.984869Z","message":{"role":"assistant","content":"example"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:48.008698Z","message":{"role":"assistant","content":".com"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:48.031625Z","message":{"role":"assistant","content":"/docs"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:48.053258Z","message":{"role":"assistant","content":"?"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:48.076258Z","message":{"role":"assistant","content":"lang"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:48.098998Z","message":{"role":"assistant","content":"=en"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:48.123902Z","message":{"role":"assistant","content":" und"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:48.146793Z","message":{"role":"assistant","content":" set"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:48.167094Z","message":{"role":"assistant","content":"ze"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:48.19041Z","message":{"role":"assistant","content":" die"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:48.211094Z","message":{"role":"assistant","content":" Gren"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:48.234047Z","message":{"role":"assistant","content":"ze"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:48.257057Z","message":{"role":"assistant","content":" auf"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:48.277687Z","message":{"role":"assistant","content":" {{"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:48.298089Z","message":{"role":"assistant","content":"limit"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:48.319587Z","message":{"role":"assistant","content":"}}"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:48.342369Z","message":{"role":"assistant","content":"."},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:48.363507Z","message":{"role":"assistant","content":""},"done":true,"done_reason":"stop","total_duration":913071792,"load_duration":467500,"prompt_eval_count":54,"prompt_eval_cached_count":41,"prompt_eval_duration":56906000,"eval_count":38,"eval_duration":852566000}
@@ -1,41 +1,41 @@
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:02.772327Z","message":{"role":"assistant","content":"#"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:02.794702Z","message":{"role":"assistant","content":" Release"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:02.818863Z","message":{"role":"assistant","content":"-"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:02.841715Z","message":{"role":"assistant","content":"Not"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:02.863613Z","message":{"role":"assistant","content":"izen"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:02.886164Z","message":{"role":"assistant","content":"\n\n"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:02.906353Z","message":{"role":"assistant","content":"Ö"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:02.926587Z","message":{"role":"assistant","content":"ff"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:02.946987Z","message":{"role":"assistant","content":"ne"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:02.967266Z","message":{"role":"assistant","content":" **"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:02.987899Z","message":{"role":"assistant","content":"E"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:03.009445Z","message":{"role":"assistant","content":"inst"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:03.032835Z","message":{"role":"assistant","content":"ellungen"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:03.054065Z","message":{"role":"assistant","content":"**"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:03.076403Z","message":{"role":"assistant","content":" und"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:03.098292Z","message":{"role":"assistant","content":" set"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:03.120065Z","message":{"role":"assistant","content":"ze"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:03.14216Z","message":{"role":"assistant","content":" `"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:03.165036Z","message":{"role":"assistant","content":"max"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:03.186887Z","message":{"role":"assistant","content":"_tokens"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:03.210027Z","message":{"role":"assistant","content":"`"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:03.232047Z","message":{"role":"assistant","content":" auf"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:03.253984Z","message":{"role":"assistant","content":" {{"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:03.276083Z","message":{"role":"assistant","content":"limit"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:03.299105Z","message":{"role":"assistant","content":"}}"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:03.326721Z","message":{"role":"assistant","content":"."},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:03.349855Z","message":{"role":"assistant","content":" Sie"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:03.375916Z","message":{"role":"assistant","content":"he"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:03.39872Z","message":{"role":"assistant","content":" ["},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:03.425595Z","message":{"role":"assistant","content":"die"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:03.44871Z","message":{"role":"assistant","content":" Dok"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:03.470652Z","message":{"role":"assistant","content":"ument"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:03.495128Z","message":{"role":"assistant","content":"ation"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:03.518055Z","message":{"role":"assistant","content":"]("},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:03.543014Z","message":{"role":"assistant","content":"https"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:03.564178Z","message":{"role":"assistant","content":"://"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:03.586378Z","message":{"role":"assistant","content":"example"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:03.607084Z","message":{"role":"assistant","content":".com"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:03.627655Z","message":{"role":"assistant","content":"/docs"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:03.648102Z","message":{"role":"assistant","content":")."},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:03.66923Z","message":{"role":"assistant","content":""},"done":true,"done_reason":"stop","total_duration":1060656625,"load_duration":982125,"prompt_eval_count":55,"prompt_eval_cached_count":24,"prompt_eval_duration":158860000,"eval_count":41,"eval_duration":896534000}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:49.2118Z","message":{"role":"assistant","content":"#"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:49.235709Z","message":{"role":"assistant","content":" Release"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:49.261627Z","message":{"role":"assistant","content":"-"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:49.284876Z","message":{"role":"assistant","content":"Not"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:49.309729Z","message":{"role":"assistant","content":"izen"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:49.332942Z","message":{"role":"assistant","content":"\n\n"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:49.353637Z","message":{"role":"assistant","content":"Ö"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:49.383404Z","message":{"role":"assistant","content":"ff"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:49.407232Z","message":{"role":"assistant","content":"ne"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:49.428767Z","message":{"role":"assistant","content":" **"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:49.45081Z","message":{"role":"assistant","content":"E"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:49.474696Z","message":{"role":"assistant","content":"inst"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:49.49549Z","message":{"role":"assistant","content":"ellungen"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:49.520014Z","message":{"role":"assistant","content":"**"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:49.54312Z","message":{"role":"assistant","content":" und"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:49.567111Z","message":{"role":"assistant","content":" set"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:49.5903Z","message":{"role":"assistant","content":"ze"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:49.61214Z","message":{"role":"assistant","content":" `"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:49.635474Z","message":{"role":"assistant","content":"max"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:49.658322Z","message":{"role":"assistant","content":"_tokens"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:49.679825Z","message":{"role":"assistant","content":"`"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:49.707329Z","message":{"role":"assistant","content":" auf"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:49.728885Z","message":{"role":"assistant","content":" {{"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:49.752198Z","message":{"role":"assistant","content":"limit"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:49.77604Z","message":{"role":"assistant","content":"}}"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:49.798615Z","message":{"role":"assistant","content":"."},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:49.824911Z","message":{"role":"assistant","content":" Sie"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:49.848787Z","message":{"role":"assistant","content":"he"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:49.870786Z","message":{"role":"assistant","content":" ["},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:49.893752Z","message":{"role":"assistant","content":"die"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:49.916754Z","message":{"role":"assistant","content":" Dok"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:49.940443Z","message":{"role":"assistant","content":"ument"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:49.962156Z","message":{"role":"assistant","content":"ation"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:49.984438Z","message":{"role":"assistant","content":"]("},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:50.007121Z","message":{"role":"assistant","content":"https"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:50.028935Z","message":{"role":"assistant","content":"://"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:50.052627Z","message":{"role":"assistant","content":"example"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:50.072993Z","message":{"role":"assistant","content":".com"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:50.093486Z","message":{"role":"assistant","content":"/docs"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:50.113791Z","message":{"role":"assistant","content":")."},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:50.134227Z","message":{"role":"assistant","content":""},"done":true,"done_reason":"stop","total_duration":1017156916,"load_duration":593625,"prompt_eval_count":55,"prompt_eval_cached_count":24,"prompt_eval_duration":88372000,"eval_count":41,"eval_duration":922310000}
@@ -1,17 +1,17 @@
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:03.719059Z","message":{"role":"assistant","content":"Der"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:03.741856Z","message":{"role":"assistant","content":" schn"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:03.763971Z","message":{"role":"assistant","content":"elle"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:03.788457Z","message":{"role":"assistant","content":" bra"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:03.816115Z","message":{"role":"assistant","content":"une"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:03.837982Z","message":{"role":"assistant","content":" F"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:03.859818Z","message":{"role":"assistant","content":"uchs"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:03.882871Z","message":{"role":"assistant","content":" spring"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:03.903597Z","message":{"role":"assistant","content":"t"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:03.924467Z","message":{"role":"assistant","content":" über"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:03.945168Z","message":{"role":"assistant","content":" den"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:03.96565Z","message":{"role":"assistant","content":" fa"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:03.986248Z","message":{"role":"assistant","content":"ulen"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:04.006813Z","message":{"role":"assistant","content":" Hund"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:04.027953Z","message":{"role":"assistant","content":"."},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:04.05037Z","message":{"role":"assistant","content":" Bitte"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T10:50:04.05045Z","message":{"role":"assistant","content":""},"done":true,"done_reason":"length","total_duration":360730916,"load_duration":829666,"prompt_eval_count":54,"prompt_eval_cached_count":53,"prompt_eval_duration":22903000,"eval_count":16,"eval_duration":332421000}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:50.186194Z","message":{"role":"assistant","content":"Der"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:50.208196Z","message":{"role":"assistant","content":" schn"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:50.232177Z","message":{"role":"assistant","content":"elle"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:50.254076Z","message":{"role":"assistant","content":" bra"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:50.276858Z","message":{"role":"assistant","content":"une"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:50.300817Z","message":{"role":"assistant","content":" F"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:50.32413Z","message":{"role":"assistant","content":"uchs"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:50.346233Z","message":{"role":"assistant","content":" spring"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:50.368461Z","message":{"role":"assistant","content":"t"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:50.391574Z","message":{"role":"assistant","content":" über"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:50.415355Z","message":{"role":"assistant","content":" den"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:50.436625Z","message":{"role":"assistant","content":" fa"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:50.460204Z","message":{"role":"assistant","content":"ulen"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:50.481948Z","message":{"role":"assistant","content":" Hund"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:50.504425Z","message":{"role":"assistant","content":"."},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:50.52598Z","message":{"role":"assistant","content":" Bitte"},"done":false}
{"model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","created_at":"2026-11-26T11:36:50.526122Z","message":{"role":"assistant","content":""},"done":true,"done_reason":"length","total_duration":370233958,"load_duration":782416,"prompt_eval_count":54,"prompt_eval_cached_count":53,"prompt_eval_duration":23159000,"eval_count":16,"eval_duration":340994000}
@@ -1 +1 @@
{"models":[{"name":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","size":6488609259,"digest":"262ac792aeb50fb8dfeae6feea465dfb10a0542dc9931c24de0a88d6b44fd1e7","details":{"parent_model":"","format":"gguf","family":"hunyuan-dense","families":["hunyuan-dense"],"parameter_size":"7.5B","quantization_level":"unknown"},"expires_at":"2026-11-26T12:19:57.087651+01:00","size_vram":6488609259,"context_length":8192,"runner":"llamacpp"}]}
{"models":[{"name":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","size":6488609259,"digest":"262ac792aeb50fb8dfeae6feea465dfb10a0542dc9931c24de0a88d6b44fd1e7","details":{"parent_model":"","format":"gguf","family":"hunyuan-dense","families":["hunyuan-dense"],"parameter_size":"7.5B","quantization_level":"unknown"},"expires_at":"2026-11-26T12:41:30.110955+01:00","size_vram":6488609259,"context_length":8192,"runner":"llamacpp"}]}
@@ -14,6 +14,7 @@
},
"parameters": "stop \"<|startoftext|>\"\nstop \"<|extra_4|>\"\nstop \"<|extra_0|>\"\nstop \"<|eos|>\"",
"template": "{{ if .System }}<|startoftext|>{{ .System }}<|extra_4|>{{ end }}{{ if .Prompt }}<|startoftext|>{{ .Prompt }}<|extra_0|>{{ end }}{{ .Response }}<|eos|>",
"license": null,
"model_info": {
"hunyuan-dense.block_count": 32,
"hunyuan-dense.context_length": 262144,
@@ -1 +1 @@
{"models":[{"name":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","modified_at":"2026-11-26T09:09:25.155214479+01:00","size":5145532022,"digest":"262ac792aeb50fb8dfeae6feea465dfb10a0542dc9931c24de0a88d6b44fd1e7","details":{"parent_model":"","format":"gguf","family":"hunyuan-dense","families":["hunyuan-dense"],"parameter_size":"7.5B","quantization_level":"Q4_K_M","context_length":262144,"embedding_length":4096,"runner":"ggml"},"capabilities":["completion"]},{"name":"deepseek-ocr:3b","model":"deepseek-ocr:3b","modified_at":"2026-11-12T21:19:05.025742233+01:00","size":6687240356,"digest":"0e7b018b8a22373167ee79c9a852821235488cbd2a2a5a93495558627423278c","details":{"parent_model":"","format":"gguf","family":"deepseekocr","families":["deepseekocr"],"parameter_size":"3.3B","quantization_level":"F16","context_length":8192,"embedding_length":1280,"runner":"ggml"},"capabilities":["completion","vision"]},{"name":"maternion/LightOnOCR-3:0.8b","model":"maternion/LightOnOCR-3:0.8b","modified_at":"2026-11-11T22:53:43.933731782+01:00","size":1019190827,"digest":"605bb25fbd99bc71baf607a9fba03e3ce73575e4e90ea2378c3f24578a28694b","details":{"parent_model":"LightOnOCR-3-0.8B.Q8_0.gguf","format":"gguf","family":"qwen35","families":["qwen35"],"parameter_size":"752.39M","quantization_level":"Q8_0","context_length":262144,"embedding_length":1024,"runner":"llamacpp"},"capabilities":["completion","vision","tools","thinking"]},{"name":"maternion/LightOnOCR-3:4b","model":"maternion/LightOnOCR-3:4b","modified_at":"2026-11-11T22:51:28.04473841+01:00","size":3384374666,"digest":"a1d387a47620c3e343cf8978e8fd63f5f677d2fa97bd5d3e28f031cc69b59748","details":{"parent_model":"LightOnOCR-3-4B.i1-Q4_K_M.gguf","format":"gguf","family":"qwen35","families":["qwen35"],"parameter_size":"4.2B","quantization_level":"Q4_K_M","context_length":262144,"embedding_length":2560,"runner":"llamacpp"},"capabilities":["completion","vision","tools","thinking"]},{"name":"deepseek-ocr:latest","model":"deepseek-ocr:latest","modified_at":"2026-11-11T22:49:31.646969001+01:00","size":6687240356,"digest":"0e7b018b8a22373167ee79c9a852821235488cbd2a2a5a93495558627423278c","details":{"parent_model":"","format":"gguf","family":"deepseekocr","families":["deepseekocr"],"parameter_size":"3.3B","quantization_level":"F16","context_length":8192,"embedding_length":1280,"runner":"ggml"},"capabilities":["completion","vision"]},{"name":"phonon:40m-en","model":"phonon:40m-en","modified_at":"2026-11-02T10:58:39.491697329+01:00","size":131759489,"digest":"b74a4edf2fe2cdc766ec44783089563fbf6c09a163846d7d0e1e316e98390029","details":{"parent_model":"","format":"safetensors","family":"","families":null,"parameter_size":"","quantization_level":"","runner":"mlx"},"capabilities":["speech"]},{"name":"phonon:40m-de","model":"phonon:40m-de","modified_at":"2026-10-30T16:24:22.463655473+01:00","size":125613369,"digest":"024449ea0a54272832611a4c38a16c3b2c8e67752a2e1a2fd0c4350b3561a905","details":{"parent_model":"","format":"safetensors","family":"","families":null,"parameter_size":"","quantization_level":"","runner":"mlx"},"capabilities":["speech"]},{"name":"glm-ocr:latest","model":"glm-ocr:latest","modified_at":"2026-07-27T10:24:59.910954687+02:00","size":2219299168,"digest":"6effedd0dc8aec66ad86c94b8099395376e212f22c87a9d7147c422f7e447be4","details":{"parent_model":"","format":"gguf","family":"glmocr","families":["glmocr"],"parameter_size":"1.1B","quantization_level":"F16","context_length":131072,"embedding_length":1536,"runner":"ggml"},"capabilities":["completion","vision","tools"]}]}
{"models":[{"name":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","model":"hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M","modified_at":"2026-11-26T12:06:02.554744486+01:00","size":5145532022,"digest":"262ac792aeb50fb8dfeae6feea465dfb10a0542dc9931c24de0a88d6b44fd1e7","details":{"parent_model":"","format":"gguf","family":"hunyuan-dense","families":["hunyuan-dense"],"parameter_size":"7.5B","quantization_level":"Q4_K_M","context_length":262144,"embedding_length":4096,"runner":"ggml"},"capabilities":["completion"]},{"name":"deepseek-ocr:3b","model":"deepseek-ocr:3b","modified_at":"2026-11-12T21:19:05.025742233+01:00","size":6687240356,"digest":"0e7b018b8a22373167ee79c9a852821235488cbd2a2a5a93495558627423278c","details":{"parent_model":"","format":"gguf","family":"deepseekocr","families":["deepseekocr"],"parameter_size":"3.3B","quantization_level":"F16","context_length":8192,"embedding_length":1280,"runner":"ggml"},"capabilities":["completion","vision"]},{"name":"maternion/LightOnOCR-3:0.8b","model":"maternion/LightOnOCR-3:0.8b","modified_at":"2026-11-11T22:53:43.933731782+01:00","size":1019190827,"digest":"605bb25fbd99bc71baf607a9fba03e3ce73575e4e90ea2378c3f24578a28694b","details":{"parent_model":"LightOnOCR-3-0.8B.Q8_0.gguf","format":"gguf","family":"qwen35","families":["qwen35"],"parameter_size":"752.39M","quantization_level":"Q8_0","context_length":262144,"embedding_length":1024,"runner":"llamacpp"},"capabilities":["completion","vision","tools","thinking"]},{"name":"maternion/LightOnOCR-3:4b","model":"maternion/LightOnOCR-3:4b","modified_at":"2026-11-11T22:51:28.04473841+01:00","size":3384374666,"digest":"a1d387a47620c3e343cf8978e8fd63f5f677d2fa97bd5d3e28f031cc69b59748","details":{"parent_model":"LightOnOCR-3-4B.i1-Q4_K_M.gguf","format":"gguf","family":"qwen35","families":["qwen35"],"parameter_size":"4.2B","quantization_level":"Q4_K_M","context_length":262144,"embedding_length":2560,"runner":"llamacpp"},"capabilities":["completion","vision","tools","thinking"]},{"name":"deepseek-ocr:latest","model":"deepseek-ocr:latest","modified_at":"2026-11-11T22:49:31.646969001+01:00","size":6687240356,"digest":"0e7b018b8a22373167ee79c9a852821235488cbd2a2a5a93495558627423278c","details":{"parent_model":"","format":"gguf","family":"deepseekocr","families":["deepseekocr"],"parameter_size":"3.3B","quantization_level":"F16","context_length":8192,"embedding_length":1280,"runner":"ggml"},"capabilities":["completion","vision"]},{"name":"phonon:40m-en","model":"phonon:40m-en","modified_at":"2026-11-02T10:58:39.491697329+01:00","size":131759489,"digest":"b74a4edf2fe2cdc766ec44783089563fbf6c09a163846d7d0e1e316e98390029","details":{"parent_model":"","format":"safetensors","family":"","families":null,"parameter_size":"","quantization_level":"","runner":"mlx"},"capabilities":["speech"]},{"name":"phonon:40m-de","model":"phonon:40m-de","modified_at":"2026-10-30T16:24:22.463655473+01:00","size":125613369,"digest":"024449ea0a54272832611a4c38a16c3b2c8e67752a2e1a2fd0c4350b3561a905","details":{"parent_model":"","format":"safetensors","family":"","families":null,"parameter_size":"","quantization_level":"","runner":"mlx"},"capabilities":["speech"]},{"name":"glm-ocr:latest","model":"glm-ocr:latest","modified_at":"2026-07-27T10:24:59.910954687+02:00","size":2219299168,"digest":"6effedd0dc8aec66ad86c94b8099395376e212f22c87a9d7147c422f7e447be4","details":{"parent_model":"","format":"gguf","family":"glmocr","families":["glmocr"],"parameter_size":"1.1B","quantization_level":"F16","context_length":131072,"embedding_length":1536,"runner":"ggml"},"capabilities":["completion","vision","tools"]}]}
@@ -0,0 +1,168 @@
import Foundation
import SprachmittlerTestSupport
import Testing
@testable import SprachmittlerOllama
@Suite("Ollama catalog")
struct OllamaCatalogTests {
@Test func decodesTagsAndFiltersHyMT3() throws {
let envelope = try JSONDecoder().decode(TagsEnvelope.self, from: fixture("tags.json"))
let hyMT3 = envelope.models.filter(\.isHyMT3)
#expect(hyMT3.count == 1)
#expect(hyMT3.first?.name.contains("Hy-MT3") == true)
#expect(envelope.models.count > 1)
#expect(!InstalledModel(name: "llama3:latest", model: "llama3:latest", digest: "abc").isHyMT3)
#expect(InstalledModel(name: "x/HY-MT3-1.8B:Q4", model: "x", digest: "abc").isHyMT3)
}
@Test func normalizesOnlyTrailingLatest() {
#expect(InstalledModel.normalizedName("model:latest") == "model")
#expect(InstalledModel.normalizedName("model:Q4_K_M") == "model:Q4_K_M")
#expect(InstalledModel.normalizedName("model") == "model")
#expect(InstalledModel.normalizedName("latest") == "latest")
}
@Test func parsesQuotedStopParameters() throws {
let details = try JSONDecoder().decode(ModelDetails.self, from: fixture(showFixtureName))
#expect(details.supportsCompletion)
#expect(details.capabilities == ["completion"])
let parameters = details.parsedParameters
#expect(parameters.count == 4)
#expect(parameters.allSatisfy { $0.name == "stop" })
#expect(parameters.map(\.value).contains("<|startoftext|>"))
#expect(parameters.map(\.value).contains("<|eos|>"))
#expect(!parameters.map(\.value).contains { $0.hasPrefix("\"") })
}
@Test func cachesShowDetailsByDigest() async throws {
let tags = try fixture("tags.json")
let show = try fixture(showFixtureName)
let transport = FakeOllamaHTTPTransport { request in
switch request.path {
case "/api/tags":
OllamaHTTPResponse(status: 200, body: tags)
case "/api/show":
OllamaHTTPResponse(status: 200, body: show)
default:
OllamaHTTPResponse(status: 404, body: Data())
}
}
let catalog = OllamaCatalogClient(http: transport)
let models = try await catalog.installedModels()
let model = try #require(models.first?.name)
_ = try await catalog.show(model: model)
_ = try await catalog.show(model: model)
let cachedCount = await transport.requests.filter { $0.path == "/api/show" }.count
#expect(cachedCount == 1)
await catalog.refresh()
_ = try await catalog.show(model: model)
let refreshedCount = await transport.requests.filter { $0.path == "/api/show" }.count
#expect(refreshedCount == 2)
}
@Test func showWithoutTagsEntryStillFetchesShow() async throws {
let tags = Data(#"{"models":[]}"#.utf8)
let show = try fixture(showFixtureName)
let transport = FakeOllamaHTTPTransport { request in
switch request.path {
case "/api/tags":
OllamaHTTPResponse(status: 200, body: tags)
case "/api/show":
OllamaHTTPResponse(status: 200, body: show)
default:
OllamaHTTPResponse(status: 404, body: Data())
}
}
let catalog = OllamaCatalogClient(http: transport)
let details = try await catalog.show(model: "missing-from-tags")
#expect(details.capabilities == ["completion"])
let paths = await transport.requests.map(\.path)
#expect(paths == ["/api/tags", "/api/show"])
let models = await transport.models
#expect(models == [nil, "missing-from-tags"])
}
@Test func showForwardsTheModelOnlyToShowRequests() async throws {
let tags = try fixture("tags.json")
let show = try fixture(showFixtureName)
let transport = FakeOllamaHTTPTransport { request in
switch request.path {
case "/api/tags":
OllamaHTTPResponse(status: 200, body: tags)
case "/api/show":
OllamaHTTPResponse(status: 200, body: show)
default:
OllamaHTTPResponse(status: 404, body: Data())
}
}
let catalog = OllamaCatalogClient(http: transport)
let models = try await catalog.installedModels()
let model = try #require(models.first?.name)
_ = try await catalog.show(model: model)
let recorded = await transport.models
#expect(recorded == [nil, model])
}
@Test func refusesAnOldServerVersion() async throws {
let current = FakeOllamaHTTPTransport { _ in
OllamaHTTPResponse(status: 200, body: Data(#"{"version":"0.40.18"}"#.utf8))
}
try await OllamaCatalogClient(http: current).checkMinimumVersion()
let old = FakeOllamaHTTPTransport { _ in
OllamaHTTPResponse(status: 200, body: Data(#"{"version":"0.39.9"}"#.utf8))
}
do {
try await OllamaCatalogClient(http: old).checkMinimumVersion()
Issue.record("expected unsupportedVersion")
} catch let error as OllamaError {
#expect(error == .unsupportedVersion(found: "0.39.9", required: "0.40.0"))
}
}
@Test func comparesVersionsByComponent() throws {
let current = try #require(OllamaVersion("0.40.18"))
let older = try #require(OllamaVersion("0.40.9"))
let tiny = try #require(OllamaVersion("0.9"))
let minimum = try #require(OllamaVersion("0.40"))
let padded = try #require(OllamaVersion("0.40.0"))
let prerelease = try #require(OllamaVersion("0.40.18-rc1"))
#expect(current > older)
#expect(tiny < minimum)
#expect(minimum == padded)
#expect(prerelease == current)
#expect(OllamaVersion("abc") == nil)
#expect(OllamaVersion("") == nil)
}
@Test func decodesLoadedModels() throws {
let envelope = try JSONDecoder().decode(PsEnvelope.self, from: fixture("ps.json"))
#expect(envelope.models.count == 1)
#expect(envelope.models[0].name.contains("Hy-MT3"))
#expect((envelope.models[0].size ?? 0) > 0)
}
private func fixture(_ name: String) throws -> Data {
let base = try #require(Bundle.module.resourceURL)
return try Data(contentsOf: base.appendingPathComponent("Fixtures/\(name)"))
}
private var showFixtureName: String {
"show-hf.co_tencent_Hy-MT3-7B-GGUF_Q4_K_M.json"
}
}
private struct TagsEnvelope: Decodable {
let models: [InstalledModel]
}
private struct PsEnvelope: Decodable {
let models: [LoadedModel]
}
@@ -0,0 +1,257 @@
import Foundation
import SprachmittlerTestSupport
import Testing
@testable import SprachmittlerOllama
@Suite("Ollama chat client", .serialized)
struct OllamaChatClientTests {
@Test func streamsSplitLinesAndFinalMetrics() async throws {
let first = Data(#"{"message":{"role":"assistant","content":"Hallo"},"done":false}"#.utf8)
let second = Data(#"{"message":{"role":"assistant","content":" Welt"},"done":false}"#.utf8)
let final = Data((
#"{"message":{"role":"assistant","content":""},"done":true,"#
+ #""done_reason":"stop","total_duration":123,"eval_count":2}"#
).utf8)
let cut = first.count / 2
ChatStubURLProtocol.reset(.init(chunks: [
Data(first.prefix(cut)),
Data(first.suffix(from: cut)) + Data("\n".utf8),
second + Data("\n".utf8),
final + Data("\n".utf8),
]))
defer { ChatStubURLProtocol.reset() }
let events = try await collect(chatClient().chat(request()))
#expect(events.contains(.delta("Hallo")))
#expect(events.contains(.delta(" Welt")))
guard let last = events.last, case let .done(reason, metrics) = last else {
Issue.record("missing done event")
return
}
#expect(reason == "stop")
#expect(metrics.totalDuration == 123)
#expect(metrics.evalCount == 2)
}
@Test func reportsStopAndLengthFromFixtures() async throws {
let cases = [
("chat-hf.co_tencent_Hy-MT3-7B-GGUF_Q4_K_M-en-de.ndjson", "stop"),
("chat-hf.co_tencent_Hy-MT3-7B-GGUF_Q4_K_M-truncated.ndjson", "length"),
]
for (fixtureName, expectedReason) in cases {
try ChatStubURLProtocol.reset(.init(chunks: chunks(from: fixtureName)))
let events = try await collect(chatClient().chat(request()))
guard let last = events.last, case let .done(reason, _) = last else {
Issue.record("missing done event for \(fixtureName)")
continue
}
#expect(reason == expectedReason)
}
ChatStubURLProtocol.reset()
}
@Test func streamEndingWithoutDoneFails() async throws {
let delta = Data(#"{"message":{"content":"Hallo"},"done":false}"#.utf8) + Data("\n".utf8)
ChatStubURLProtocol.reset(.init(chunks: [delta]))
defer { ChatStubURLProtocol.reset() }
do {
_ = try await collect(chatClient().chat(request()))
Issue.record("expected missing done error")
} catch let error as OllamaError {
#expect(error == .decoding("Stream ended without a done event"))
}
}
@Test func midStreamErrorLineFailsTheStream() async throws {
ChatStubURLProtocol.reset(.init(chunks: [
Data(#"{"message":{"content":"Hallo"},"done":false}"#.utf8) + Data("\n".utf8),
Data(#"{"error":"model 'missing' not found"}"#.utf8) + Data("\n".utf8),
]))
defer { ChatStubURLProtocol.reset() }
do {
_ = try await collect(chatClient().chat(request(model: "missing")))
Issue.record("expected error")
} catch let error as OllamaError {
#expect(error == .modelNotInstalled("missing"))
}
}
@Test func firstTokenTimeoutFires() async throws {
let sleeper = ManualSleeper()
ChatStubURLProtocol.reset(.init(chunks: [], hangAfterChunks: true))
defer { ChatStubURLProtocol.reset() }
let client = try chatClient(sleeper: sleeper, timeouts: testTimeouts)
let task = Task {
try await collect(client.chat(request()))
}
await sleeper.waitUntilPending(.seconds(1))
for _ in 0 ..< 1000 {
if ChatStubURLProtocol.started() {
break
}
await Task.yield()
}
await sleeper.advance(matching: .seconds(1))
do {
_ = try await task.value
Issue.record("expected first-token timeout")
} catch let error as OllamaError {
#expect(error == .timeout(.firstToken))
}
for _ in 0 ..< 1000 {
if ChatStubURLProtocol.stopped() {
break
}
await Task.yield()
}
#expect(ChatStubURLProtocol.stopped())
}
@Test func idleTimeoutFiresAfterFirstDelta() async throws {
let sleeper = ManualSleeper()
let delta = Data(#"{"message":{"content":"Hallo"},"done":false}"#.utf8) + Data("\n".utf8)
ChatStubURLProtocol.reset(.init(chunks: [delta], hangAfterChunks: true))
defer { ChatStubURLProtocol.reset() }
let client = try chatClient(sleeper: sleeper, timeouts: testTimeouts)
let task = Task {
try await collect(client.chat(request()))
}
await sleeper.waitUntilPending(.seconds(2))
await sleeper.advance(matching: .seconds(2))
do {
_ = try await task.value
Issue.record("expected idle timeout")
} catch let error as OllamaError {
#expect(error == .timeout(.idle))
}
}
@Test func totalTimeoutFires() async throws {
let sleeper = ManualSleeper()
ChatStubURLProtocol.reset(.init(chunks: [], hangAfterChunks: true))
defer { ChatStubURLProtocol.reset() }
let client = try chatClient(sleeper: sleeper, timeouts: testTimeouts)
let task = Task {
try await collect(client.chat(request()))
}
await sleeper.waitUntilPending(.seconds(3))
await sleeper.advance(matching: .seconds(3))
do {
_ = try await task.value
Issue.record("expected total timeout")
} catch let error as OllamaError {
#expect(error == .timeout(.total))
}
}
@Test func cancelMidStreamStopsURLTask() async throws {
let sleeper = ManualSleeper()
let delta = Data(#"{"message":{"content":"Hallo"},"done":false}"#.utf8) + Data("\n".utf8)
ChatStubURLProtocol.reset(.init(chunks: [delta], hangAfterChunks: true))
defer { ChatStubURLProtocol.reset() }
let client = try chatClient(sleeper: sleeper, timeouts: testTimeouts)
let task = Task {
try await collect(client.chat(request()))
}
await sleeper.waitUntilPending(.seconds(2))
task.cancel()
do {
_ = try await task.value
} catch {
// The consumer task is cancelled; the stream is expected to throw.
}
for _ in 0 ..< 1000 {
if ChatStubURLProtocol.stopped() {
break
}
await Task.yield()
}
#expect(ChatStubURLProtocol.stopped())
}
@Test func encodesExactChatRequest() throws {
let data = try JSONEncoder().encode(request())
let object = try #require(JSONSerialization.jsonObject(with: data) as? [String: Any])
#expect(Set(object.keys) == ["model", "messages", "stream", "keep_alive", "options"])
#expect(object["stream"] as? Bool == true)
#expect(object["system"] == nil)
#expect(object["images"] == nil)
#expect(object["think"] == nil)
let options = try #require(object["options"] as? [String: Any])
#expect(
Set(options.keys)
== ["temperature", "top_p", "top_k", "repeat_penalty", "num_predict", "num_ctx"]
)
let messages = try #require(object["messages"] as? [[String: Any]])
#expect(messages.count == 1)
#expect(messages[0]["role"] as? String == "user")
}
private var testTimeouts: ChatTimeouts {
ChatTimeouts(firstToken: .seconds(1), idle: .seconds(2), total: .seconds(3))
}
private func request(model: String = "test-model") -> ChatRequest {
ChatRequest(
model: model,
messages: [ChatMessage(content: "Hello.")],
keepAlive: "5m",
options: ChatOptions(
temperature: 0.7,
topP: 0.6,
topK: 20,
repeatPenalty: 1.05,
numPredict: 4096,
numCtx: 8192
)
)
}
private func chatClient(
sleeper: ManualSleeper = ManualSleeper(),
timeouts: ChatTimeouts = .standard
) throws -> OllamaChatClient {
try OllamaChatClient(http: makeClient(), sleeper: sleeper, timeouts: timeouts)
}
private func collect(
_ stream: AsyncThrowingStream<ChatEvent, any Error>
) async throws -> [ChatEvent] {
var events: [ChatEvent] = []
for try await event in stream {
events.append(event)
}
return events
}
private func chunks(from fixtureName: String) throws -> [Data] {
let base = try #require(Bundle.module.resourceURL)
let url = base.appendingPathComponent("Fixtures/\(fixtureName)")
let text = try String(contentsOf: url, encoding: .utf8)
return text.split(separator: "\n", omittingEmptySubsequences: true)
.map { Data($0.utf8) + Data("\n".utf8) }
}
private func makeClient() throws -> OllamaHTTPClient {
let url = try #require(URL(string: "http://127.0.0.1:11434"))
let configuration = OllamaSessionFactory.makeConfiguration()
configuration.protocolClasses = [ChatStubURLProtocol.self]
let session = URLSession(
configuration: configuration,
delegate: RedirectRefusingDelegate(),
delegateQueue: nil
)
return try OllamaHTTPClient(baseURL: url, session: session)
}
}
@@ -0,0 +1,29 @@
import Foundation
import Testing
@testable import SprachmittlerOllama
@Suite("Ollama error body")
struct OllamaErrorBodyTests {
@Test func decodesTheRecordedMissingModelBody() throws {
let url = try #require(Bundle.module.resourceURL)
.appendingPathComponent("Fixtures/error-missing-model.json")
let data = try Data(contentsOf: url)
let message = try #require(OllamaErrorBody.message(from: data))
#expect(message.localizedCaseInsensitiveContains("not found"))
}
@Test func fallsBackToPlainText() {
let message = OllamaErrorBody.message(from: Data("plain error".utf8))
#expect(message == "plain error")
}
@Test func truncatesToFiveHundredCharacters() throws {
let long = String(repeating: "x", count: 600)
let message = try #require(OllamaErrorBody.message(from: Data(long.utf8)))
#expect(message.count == 500)
}
@Test func returnsNilForEmptyBody() {
#expect(OllamaErrorBody.message(from: Data()) == nil)
}
}
@@ -0,0 +1,221 @@
import Foundation
import Testing
@testable import SprachmittlerOllama
/// HTTP transport tests share `StubURLProtocol`; the suite is serialized so the static stub
/// cannot leak between tests.
@Suite("Ollama HTTP transport", .serialized)
struct OllamaTransportTests {
@Test func sendsGETAndReturnsBody() async throws {
StubURLProtocol.reset(.init(chunks: [Data(#"{"version":"0.40.18"}"#.utf8)]))
defer { StubURLProtocol.reset() }
let client = try makeClient()
let response = try await client.send(.init(path: "/api/version"))
#expect(response.status == 200)
#expect(String(data: response.body, encoding: .utf8) == #"{"version":"0.40.18"}"#)
}
@Test func maps404ModelNotFound() async throws {
StubURLProtocol.reset(.init(
status: 404,
chunks: [Data(#"{"error":"model 'missing' not found"}"#.utf8)]
))
defer { StubURLProtocol.reset() }
let client = try makeClient()
do {
_ = try await client.send(.init(path: "/api/chat"), model: "missing")
Issue.record("expected modelNotInstalled")
} catch let error as OllamaError {
#expect(error == .modelNotInstalled("missing"))
}
}
@Test func maps400And500() async throws {
let client = try makeClient()
StubURLProtocol.reset(.init(status: 400, chunks: [Data(#"{"error":"bad input"}"#.utf8)]))
do {
_ = try await client.send(.init(path: "/api/chat"))
Issue.record("expected badRequest")
} catch let error as OllamaError {
#expect(error == .badRequest("bad input"))
}
StubURLProtocol.reset(.init(status: 500, chunks: [Data(#"{"error":"out of memory"}"#.utf8)]))
do {
_ = try await client.send(.init(path: "/api/chat"))
Issue.record("expected server")
} catch let error as OllamaError {
#expect(error == .server(status: 500, message: "out of memory"))
}
StubURLProtocol.reset()
}
@Test func mapsTransportFailures() async throws {
let client = try makeClient()
StubURLProtocol.reset(.init(error: URLError(.cannotConnectToHost)))
do {
_ = try await client.send(.init(path: "/api/version"))
Issue.record("expected unreachable")
} catch let error as OllamaError {
guard case .unreachable = error else {
Issue.record("expected unreachable, got \(error)")
return
}
}
StubURLProtocol.reset(.init(error: URLError(.timedOut)))
do {
_ = try await client.send(.init(path: "/api/version"))
Issue.record("expected timeout")
} catch let error as OllamaError {
#expect(error == .timeout(.connect))
}
StubURLProtocol.reset()
}
@Test func decodesJSONAndRejectsMalformedJSON() async throws {
StubURLProtocol.reset(.init(chunks: [Data(#"{"version":"0.40.18"}"#.utf8)]))
let client = try makeClient()
let version = try await client.sendJSON(.init(path: "/api/version"), as: VersionResponse.self)
#expect(version.version == "0.40.18")
StubURLProtocol.reset(.init(chunks: [Data("not json".utf8)]))
do {
_ = try await client.sendJSON(.init(path: "/api/version"), as: VersionResponse.self)
Issue.record("expected decoding error")
} catch let error as OllamaError {
guard case .decoding = error else {
Issue.record("expected decoding, got \(error)")
return
}
}
StubURLProtocol.reset()
}
@Test func joinsPathsWithoutDoubleSlash() throws {
let client = try makeClient()
#expect(
try client.makeURL(for: "/api/version").absoluteString
== "http://127.0.0.1:11434/api/version"
)
#expect(
try client.makeURL(for: "api/tags").absoluteString
== "http://127.0.0.1:11434/api/tags"
)
}
@Test func joinsPathsWithTrailingSlashAndBasePath() throws {
let trailing = try makeClient(baseURL: "http://127.0.0.1:11434/")
#expect(
try trailing.makeURL(for: "/api/tags").absoluteString
== "http://127.0.0.1:11434/api/tags"
)
let basePath = try makeClient(baseURL: "http://127.0.0.1:11434/ollama/")
#expect(
try basePath.makeURL(for: "/api/tags").absoluteString
== "http://127.0.0.1:11434/ollama/api/tags"
)
let baseNoSlash = try makeClient(baseURL: "http://127.0.0.1:11434/ollama")
#expect(
try baseNoSlash.makeURL(for: "/api/tags").absoluteString
== "http://127.0.0.1:11434/ollama/api/tags"
)
}
@Test func setsJSONHeadersOnPOST() async throws {
StubURLProtocol.reset(.init(chunks: [Data(#"{"ok":true}"#.utf8)]))
defer { StubURLProtocol.reset() }
let client = try makeClient()
_ = try await client.send(.init(
method: .post,
path: "/api/show",
body: Data(#"{"model":"x"}"#.utf8)
))
let request = try #require(StubURLProtocol.snapshot().lastRequest)
#expect(request.httpMethod == "POST")
#expect(request.value(forHTTPHeaderField: "Content-Type") == "application/json")
#expect(request.value(forHTTPHeaderField: "Accept") == "application/json")
}
@Test func delegatePassesNilToTheCompletionHandler() throws {
let url = try #require(URL(string: "http://127.0.0.1:11434/redirect"))
let delegate = RedirectRefusingDelegate()
let session = URLSession(configuration: .ephemeral)
let task = session.dataTask(with: url)
let response = try #require(HTTPURLResponse(
url: url,
statusCode: 302,
httpVersion: nil,
headerFields: ["Location": "https://example.com/steal"]
))
let box = RedirectResultBox()
delegate.urlSession(
session,
task: task,
willPerformHTTPRedirection: response,
newRequest: URLRequest(url: url)
) { request in
box.record(request)
}
#expect(box.wasCalled)
#expect(box.request == nil)
}
@Test func clientRefusesA302WithoutRequestingTheTarget() async throws {
StubURLProtocol.reset(.init(
status: 302,
headers: ["Location": "https://example.com/steal"],
chunks: []
))
defer { StubURLProtocol.reset() }
let client = try makeClient()
do {
_ = try await client.send(.init(path: "/api/version"))
Issue.record("expected redirect rejection")
} catch let error as OllamaError {
#expect(error == .endpointRejected(.redirect))
}
let snapshot = StubURLProtocol.snapshot()
#expect(snapshot.count == 1)
#expect(snapshot.lastRequest?.url?.host == "127.0.0.1")
#expect(client.session.delegate is RedirectRefusingDelegate)
}
private func makeClient(baseURL: String = "http://127.0.0.1:11434") throws -> OllamaHTTPClient {
let url = try #require(URL(string: baseURL))
let configuration = OllamaSessionFactory.makeConfiguration()
configuration.protocolClasses = [StubURLProtocol.self]
let session = URLSession(
configuration: configuration,
delegate: RedirectRefusingDelegate(),
delegateQueue: nil
)
return try OllamaHTTPClient(baseURL: url, session: session)
}
}
private struct VersionResponse: Decodable {
let version: String
}
/// A synchronous result box for the delegate callback; the callback is not concurrent here.
private final class RedirectResultBox: @unchecked Sendable {
private(set) var wasCalled = false
private(set) var request: URLRequest?
func record(_ request: URLRequest?) {
wasCalled = true
self.request = request
}
}
@@ -0,0 +1,14 @@
import Foundation
import Testing
@testable import SprachmittlerOllama
@Suite("Warm-up policy")
struct OllamaWarmUpPolicyTests {
@Test func allowsOnlyEnabledLoopbackEndpoints() throws {
let local = try #require(URL(string: "http://127.0.0.1:11434"))
let remote = try #require(URL(string: "https://example.com:11434"))
#expect(OllamaWarmUpPolicy.shouldWarmUp(endpoint: local, enabled: true))
#expect(!OllamaWarmUpPolicy.shouldWarmUp(endpoint: local, enabled: false))
#expect(!OllamaWarmUpPolicy.shouldWarmUp(endpoint: remote, enabled: true))
}
}
@@ -0,0 +1,65 @@
import Foundation
import SprachmittlerTestSupport
import Testing
@testable import SprachmittlerOllama
@Suite("Warm-up runner")
struct OllamaWarmUpRunnerTests {
@Test func consumesAndDiscardsEvents() async throws {
let box = RequestBox()
let chat = FakeOllamaChat(
events: [.delta("ignored"), .done(reason: "length", metrics: .empty)],
onRequest: { box.record($0) }
)
let request = ChatRequest(
model: "test-model",
messages: [ChatMessage(content: "Hello.")],
keepAlive: "30m",
options: ChatOptions(
temperature: 0.7,
topP: 0.6,
topK: 20,
repeatPenalty: 1.05,
numPredict: 8,
numCtx: 8192
)
)
try await OllamaWarmUpRunner(chat: chat).run(request)
#expect(box.request?.messages.first?.content == "Hello.")
#expect(box.request?.options.numPredict == 8)
}
@Test func manualSleeperCancellationResumes() async throws {
let sleeper = ManualSleeper()
let task = Task {
try await sleeper.sleep(for: .seconds(1))
}
await sleeper.waitUntilPending(.seconds(1))
task.cancel()
do {
_ = try await task.value
Issue.record("expected cancellation")
} catch is CancellationError {
// Expected.
}
}
}
private final class RequestBox: @unchecked Sendable {
private let lock = NSLock()
private var value: ChatRequest?
var request: ChatRequest? {
lock.lock()
defer { lock.unlock() }
return value
}
func record(_ request: ChatRequest) {
lock.lock()
value = request
lock.unlock()
}
}
@@ -1,28 +0,0 @@
import Foundation
import Testing
@testable import SprachmittlerOllama
@Test func moduleLinks() {
#expect(SprachmittlerOllamaModule.moduleName == "SprachmittlerOllama")
}
/// T1.1: the recorded Ollama fixtures are bundled with the test target.
@Test func recordedFixturesAreBundled() throws {
let base = try #require(Bundle.module.resourceURL).appendingPathComponent("Fixtures")
let names = ["version.json", "tags.json", "capture-meta.json"]
for name in names {
let url = base.appendingPathComponent(name)
#expect(FileManager.default.fileExists(atPath: url.path), "missing fixture \(name)")
}
let chats = try FileManager.default.contentsOfDirectory(atPath: base.path)
.filter { $0.hasPrefix("chat-") && $0.hasSuffix(".ndjson") }
#expect(!chats.isEmpty)
}
@Test func recordedVersionIsDecodable() throws {
let base = try #require(Bundle.module.resourceURL).appendingPathComponent("Fixtures")
let data = try Data(contentsOf: base.appendingPathComponent("version.json"))
let object = try #require(try JSONSerialization.jsonObject(with: data) as? [String: Any])
let version = try #require(object["version"] as? String)
#expect(!version.isEmpty)
}
@@ -0,0 +1,81 @@
import Foundation
/// A chat-only URLProtocol stub. It has its own static state, so the chat suite can run in
/// parallel with the HTTP transport suite.
final class ChatStubURLProtocol: URLProtocol, @unchecked Sendable {
struct Stub: Sendable {
var chunks: [Data] = []
var hangAfterChunks = false
}
private static let lock = NSLock()
private nonisolated(unsafe) static var stub: Stub?
private nonisolated(unsafe) static var wasStopped = false
private nonisolated(unsafe) static var wasStarted = false
static func reset(_ stub: Stub? = nil) {
lock.lock()
self.stub = stub
wasStopped = false
wasStarted = false
lock.unlock()
}
static func stopped() -> Bool {
lock.lock()
defer { lock.unlock() }
return wasStopped
}
static func started() -> Bool {
lock.lock()
defer { lock.unlock() }
return wasStarted
}
private static func beginRequest() -> Stub? {
lock.lock()
defer { lock.unlock() }
wasStarted = true
return stub
}
override static func canInit(with request: URLRequest) -> Bool {
true
}
override static func canonicalRequest(for request: URLRequest) -> URLRequest {
request
}
override func startLoading() {
guard let stub = Self.beginRequest() else {
client?.urlProtocol(self, didFailWithError: URLError(.unknown))
return
}
guard let url = request.url,
let response = HTTPURLResponse(
url: url,
statusCode: 200,
httpVersion: "HTTP/1.1",
headerFields: ["Content-Type": "application/x-ndjson"]
)
else {
client?.urlProtocol(self, didFailWithError: URLError(.badURL))
return
}
client?.urlProtocol(self, didReceive: response, cacheStoragePolicy: .notAllowed)
for chunk in stub.chunks {
client?.urlProtocol(self, didLoad: chunk)
}
if !stub.hangAfterChunks {
client?.urlProtocolDidFinishLoading(self)
}
}
override func stopLoading() {
Self.lock.lock()
Self.wasStopped = true
Self.lock.unlock()
}
}
@@ -0,0 +1,90 @@
import Foundation
/// A serialized `URLProtocol` stub for contract tests. Test suites using it must be `.serialized`.
final class StubURLProtocol: URLProtocol, @unchecked Sendable {
struct Stub: Sendable {
var status = 200
var headers: [String: String] = ["Content-Type": "application/json"]
var chunks: [Data] = []
var error: URLError?
var hangAfterChunks = false
}
struct Snapshot: Sendable {
let count: Int
let stopped: Bool
let lastRequest: URLRequest?
}
private static let lock = NSLock()
private nonisolated(unsafe) static var stub: Stub?
private nonisolated(unsafe) static var requestCount = 0
private nonisolated(unsafe) static var wasStopped = false
private nonisolated(unsafe) static var lastRequestValue: URLRequest?
static func reset(_ stub: Stub? = nil) {
lock.lock()
self.stub = stub
requestCount = 0
wasStopped = false
lastRequestValue = nil
lock.unlock()
}
static func snapshot() -> Snapshot {
lock.lock()
defer { lock.unlock() }
return Snapshot(count: requestCount, stopped: wasStopped, lastRequest: lastRequestValue)
}
private static func beginRequest(_ request: URLRequest) -> Stub? {
lock.lock()
defer { lock.unlock() }
requestCount += 1
lastRequestValue = request
return stub
}
override static func canInit(with request: URLRequest) -> Bool {
true
}
override static func canonicalRequest(for request: URLRequest) -> URLRequest {
request
}
override func startLoading() {
guard let stub = Self.beginRequest(request) else {
client?.urlProtocol(self, didFailWithError: URLError(.unknown))
return
}
if let error = stub.error {
client?.urlProtocol(self, didFailWithError: error)
return
}
guard let url = request.url,
let response = HTTPURLResponse(
url: url,
statusCode: stub.status,
httpVersion: "HTTP/1.1",
headerFields: stub.headers
)
else {
client?.urlProtocol(self, didFailWithError: URLError(.badURL))
return
}
client?.urlProtocol(self, didReceive: response, cacheStoragePolicy: .notAllowed)
for chunk in stub.chunks {
client?.urlProtocol(self, didLoad: chunk)
}
if !stub.hangAfterChunks {
client?.urlProtocolDidFinishLoading(self)
}
}
override func stopLoading() {
Self.lock.lock()
Self.wasStopped = true
Self.lock.unlock()
}
}