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:
1 parent
7ca5c710ec
commit
26b493e7e5
93 files changed
+3732
-218
No files matched your search
@@ -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])
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user