"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.
68 lines
2.5 KiB
Swift
68 lines
2.5 KiB
Swift
//
|
|
// ContextSelectionServiceTests.swift
|
|
// oAITests
|
|
//
|
|
// SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0
|
|
// Copyright (C) 2026 Rune Olsen
|
|
|
|
import Testing
|
|
@testable import Confab
|
|
|
|
@Suite("ContextSelectionService pure scoring helpers")
|
|
struct ContextSelectionServiceTests {
|
|
|
|
private var service: ContextSelectionService { ContextSelectionService.shared }
|
|
|
|
// MARK: - getImportanceScore
|
|
|
|
@Test("A short message with no cost or token data scores from length alone")
|
|
func lowScoreForPlainShortMessage() {
|
|
let message = Message(role: .user, content: "hi")
|
|
#expect(service.getImportanceScore(message) < 0.01)
|
|
}
|
|
|
|
@Test("Cost, length, and token factors combine to the exact weighted sum")
|
|
func combinesWeightedFactors() {
|
|
// cost 0.005 / 0.01 = 0.5 -> * 0.5 weight = 0.25
|
|
// 1000 chars / 2000 = 0.5 -> * 0.3 weight = 0.15
|
|
// 500 tokens / 1000 = 0.5 -> * 0.2 weight = 0.1
|
|
// total = 0.5
|
|
let message = Message(role: .assistant, content: String(repeating: "a", count: 1000), tokens: 500, cost: 0.005)
|
|
#expect(abs(service.getImportanceScore(message) - 0.5) < 0.0001)
|
|
}
|
|
|
|
@Test("Score is capped at 1.0 even when every factor maxes out and would otherwise overflow it")
|
|
func scoreIsCappedAtOne() {
|
|
let message = Message(
|
|
role: .assistant,
|
|
content: String(repeating: "a", count: 5000), // well past the 2000-char max
|
|
tokens: 5000, // well past the 1000-token max
|
|
cost: 1.0 // well past the $0.01 max
|
|
)
|
|
#expect(service.getImportanceScore(message) == 1.0)
|
|
}
|
|
|
|
// MARK: - estimateTokens
|
|
|
|
@Test("Uses the message's actual token count when present")
|
|
func usesActualTokenCountWhenAvailable() {
|
|
let messages = [Message(role: .user, content: "irrelevant for this test", tokens: 42)]
|
|
#expect(service.estimateTokens(messages) == 42)
|
|
}
|
|
|
|
@Test("Falls back to content.count / 4 when tokens is nil")
|
|
func fallsBackToCharacterEstimate() {
|
|
let messages = [Message(role: .user, content: String(repeating: "x", count: 40))]
|
|
#expect(service.estimateTokens(messages) == 10)
|
|
}
|
|
|
|
@Test("Sums estimates across a mix of messages with and without token counts")
|
|
func sumsAcrossMixedMessages() {
|
|
let messages = [
|
|
Message(role: .user, content: "ignored", tokens: 100),
|
|
Message(role: .assistant, content: String(repeating: "y", count: 20)), // 20/4 = 5
|
|
]
|
|
#expect(service.estimateTokens(messages) == 105)
|
|
}
|
|
}
|