Files
oai-swift/oAITests/OllamaProviderTests.swift
rune 76b58e6fdc Rename app from oAI to Confab
"oAI" reads as easily confused with OpenAI, both visually and in
casual conversation. Renamed to "Confab" throughout: Xcode
target/scheme/bundle ID (com.oai.Confab), Info.plist and Help Book
identity, all user-facing UI text, internal Log subsystem and color
identifiers, localization catalogs (6 languages, including a proper
reworded/retranslated Intel-deprecation notice), Help Book HTML
content, and docs (README/DEVELOPMENT/PRIVACY/SECURITY).

Deliberately cosmetic-only: the on-disk data folder
(~/Library/Application Support/oAI/), database/backup filenames,
Keychain service identifiers, and EncryptionService's key-derivation
inputs are all left untouched so existing conversations, settings,
and stored API keys survive the update with zero migration and no
re-entering credentials. Verified live: a real signed build
successfully decrypted a stored API key and loaded an existing
conversation database after the bundle ID change.

Also includes a small already-completed, previously uncommitted
model-release-date feature (ModelInfo/OpenRouterModels/
OpenRouterProvider/ModelInfoView) that happened to share several
files with this rename.

Gitignored on this branch and updated on disk but not part of this
commit: CLAUDE.md, RELEASE_NOTES.md, and the build*.sh scripts.
2026-08-02 14:58:14 +02:00

80 lines
3.3 KiB
Swift

//
// OllamaProviderTests.swift
// oAITests
//
// SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0
// Copyright (C) 2026 Rune Olsen
import Testing
import Foundation
@testable import Confab
@Suite("OllamaProvider request/response conversion")
struct OllamaProviderTests {
private var provider: OllamaProvider { OllamaProvider() }
// MARK: - buildRequestBody
@Test("Builds a basic request body with model, messages, and stream flag")
func basicRequestBody() {
let request = ChatRequest(messages: [Message(role: .user, content: "hi")], model: "llama3.2")
let body = provider.buildRequestBody(from: request, stream: true)
#expect(body["model"] as? String == "llama3.2")
#expect(body["stream"] as? Bool == true)
let messages = body["messages"] as? [[String: Any]]
#expect(messages?.count == 1)
#expect(messages?.first?["role"] as? String == "user")
#expect(messages?.first?["content"] as? String == "hi")
}
@Test("System prompt is prepended as its own system-role message")
func systemPromptPrepended() {
let request = ChatRequest(messages: [Message(role: .user, content: "hi")], model: "llama3.2", systemPrompt: "be concise")
let body = provider.buildRequestBody(from: request, stream: false)
let messages = body["messages"] as? [[String: Any]]
#expect(messages?.count == 2)
#expect(messages?.first?["role"] as? String == "system")
#expect(messages?.first?["content"] as? String == "be concise")
}
@Test("maxTokens and temperature are nested under options only when present")
func optionsOnlyWhenPresent() {
let withOptions = ChatRequest(messages: [Message(role: .user, content: "hi")], model: "llama3.2", maxTokens: 500, temperature: 0.7)
let bodyWithOptions = provider.buildRequestBody(from: withOptions, stream: false)
let options = bodyWithOptions["options"] as? [String: Any]
#expect(options?["num_predict"] as? Int == 500)
#expect(options?["temperature"] as? Double == 0.7)
let withoutOptions = ChatRequest(messages: [Message(role: .user, content: "hi")], model: "llama3.2")
let bodyWithoutOptions = provider.buildRequestBody(from: withoutOptions, stream: false)
#expect(bodyWithoutOptions["options"] == nil)
}
// MARK: - parseOllamaResponse
@Test("Parses content and token counts from a well-formed response")
func parsesWellFormedResponse() {
let json: [String: Any] = [
"message": ["content": "the answer"],
"prompt_eval_count": 10,
"eval_count": 20
]
let response = provider.parseOllamaResponse(json, model: "llama3.2")
#expect(response.content == "the answer")
#expect(response.role == "assistant")
#expect(response.finishReason == "stop")
#expect(response.usage?.promptTokens == 10)
#expect(response.usage?.completionTokens == 20)
#expect(response.usage?.totalTokens == 30)
}
@Test("Missing fields default to empty content and zero token counts")
func missingFieldsDefaultGracefully() {
let response = provider.parseOllamaResponse([:], model: "llama3.2")
#expect(response.content == "")
#expect(response.usage?.promptTokens == 0)
#expect(response.usage?.completionTokens == 0)
}
}