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.
66 lines
1.8 KiB
Swift
66 lines
1.8 KiB
Swift
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()
|
|
}
|
|
}
|